1use std::fmt;
4
5use glib::translate::*;
6
7use crate::{ffi, Point, Quad, Rect};
8
9impl Quad {
10 #[doc(alias = "graphene_quad_init")]
11 pub fn new(p1: &Point, p2: &Point, p3: &Point, p4: &Point) -> Self {
12 assert_initialized_main_thread!();
13 unsafe {
14 let mut quad = Self::uninitialized();
15 ffi::graphene_quad_init(
16 quad.to_glib_none_mut().0,
17 p1.to_glib_none().0,
18 p2.to_glib_none().0,
19 p3.to_glib_none().0,
20 p4.to_glib_none().0,
21 );
22 quad
23 }
24 }
25
26 #[doc(alias = "graphene_quad_init_from_rect")]
27 #[doc(alias = "init_from_rect")]
28 pub fn from_rect(r: &Rect) -> Self {
29 assert_initialized_main_thread!();
30 unsafe {
31 let mut quad = Self::uninitialized();
32 ffi::graphene_quad_init_from_rect(quad.to_glib_none_mut().0, r.to_glib_none().0);
33 quad
34 }
35 }
36
37 #[doc(alias = "graphene_quad_init_from_points")]
38 #[doc(alias = "init_from_points")]
39 pub fn from_points(points: &[Point; 4]) -> Self {
40 assert_initialized_main_thread!();
41 unsafe {
42 let points = [
43 *points[0].to_glib_none().0,
44 *points[1].to_glib_none().0,
45 *points[2].to_glib_none().0,
46 *points[3].to_glib_none().0,
47 ];
48 let mut quad = Self::uninitialized();
49 ffi::graphene_quad_init_from_points(
50 quad.to_glib_none_mut().0,
51 points.as_ptr() as *const _,
52 );
53 quad
54 }
55 }
56
57 #[doc(alias = "graphene_quad_get_point")]
58 #[doc(alias = "get_point")]
59 pub fn point(&self, index_: u32) -> Point {
60 assert!(index_ < 4);
61 unsafe { from_glib_none(ffi::graphene_quad_get_point(self.to_glib_none().0, index_)) }
62 }
63
64 #[inline]
65 pub fn points(&self) -> &[Point; 4] {
66 unsafe { &*(&self.inner.points as *const [ffi::graphene_point_t; 4] as *const [Point; 4]) }
67 }
68}
69
70impl fmt::Debug for Quad {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 f.debug_struct("Quad")
73 .field("points", &self.points())
74 .finish()
75 }
76}