1use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Point, Quad, Rect};
8
9impl Quad {
10 #[doc(alias = "graphene_quad_init")]
24 pub fn new(p1: &Point, p2: &Point, p3: &Point, p4: &Point) -> Self {
25 assert_initialized_main_thread!();
26 unsafe {
27 let mut quad = Self::uninitialized();
28 ffi::graphene_quad_init(
29 quad.to_glib_none_mut().0,
30 p1.to_glib_none().0,
31 p2.to_glib_none().0,
32 p3.to_glib_none().0,
33 p4.to_glib_none().0,
34 );
35 quad
36 }
37 }
38
39 #[doc(alias = "graphene_quad_init_from_rect")]
48 #[doc(alias = "init_from_rect")]
49 pub fn from_rect(r: &Rect) -> Self {
50 assert_initialized_main_thread!();
51 unsafe {
52 let mut quad = Self::uninitialized();
53 ffi::graphene_quad_init_from_rect(quad.to_glib_none_mut().0, r.to_glib_none().0);
54 quad
55 }
56 }
57
58 #[doc(alias = "graphene_quad_init_from_points")]
66 #[doc(alias = "init_from_points")]
67 pub fn from_points(points: &[Point; 4]) -> Self {
68 assert_initialized_main_thread!();
69 unsafe {
70 let points = [
71 *points[0].to_glib_none().0,
72 *points[1].to_glib_none().0,
73 *points[2].to_glib_none().0,
74 *points[3].to_glib_none().0,
75 ];
76 let mut quad = Self::uninitialized();
77 ffi::graphene_quad_init_from_points(
78 quad.to_glib_none_mut().0,
79 points.as_ptr() as *const _,
80 );
81 quad
82 }
83 }
84
85 #[doc(alias = "graphene_quad_get_point")]
93 #[doc(alias = "get_point")]
94 pub fn point(&self, index_: u32) -> Point {
95 assert!(index_ < 4);
96 unsafe { from_glib_none(ffi::graphene_quad_get_point(self.to_glib_none().0, index_)) }
97 }
98
99 #[inline]
100 pub fn points(&self) -> &[Point; 4] {
101 unsafe { &*(&self.inner.points as *const [ffi::graphene_point_t; 4] as *const [Point; 4]) }
102 }
103}
104
105impl fmt::Debug for Quad {
106 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
107 f.debug_struct("Quad")
108 .field("points", &self.points())
109 .finish()
110 }
111}