1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// A [`Rectangle`][crate::Rectangle] data type for representing rectangles.
    ///
    /// [`Rectangle`][crate::Rectangle] is identical to `cairo_rectangle_t`. Together with Cairo’s
    /// [`cairo::Region`][crate::cairo::Region] data type, these are the central types for representing
    /// sets of pixels.
    ///
    /// The intersection of two rectangles can be computed with
    /// [`intersect()`][Self::intersect()]; to find the union of two rectangles use
    /// [`union()`][Self::union()].
    ///
    /// The [`cairo::Region`][crate::cairo::Region] type provided by Cairo is usually used for managing
    /// non-rectangular clipping of graphical operations.
    ///
    /// The Graphene library has a number of other data types for regions and
    /// volumes in 2D and 3D.
    pub struct Rectangle(BoxedInline<ffi::GdkRectangle>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gdk_rectangle_get_type(), ptr as *mut _) as *mut ffi::GdkRectangle,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gdk_rectangle_get_type(), ptr as *mut _),
        type_ => || ffi::gdk_rectangle_get_type(),
    }
}

impl Rectangle {
    /// Returns [`true`] if @self contains the point described by @x and @y.
    /// ## `x`
    /// X coordinate
    /// ## `y`
    /// Y coordinate
    ///
    /// # Returns
    ///
    /// [`true`] if @self contains the point
    #[doc(alias = "gdk_rectangle_contains_point")]
    pub fn contains_point(&self, x: i32, y: i32) -> bool {
        unsafe {
            from_glib(ffi::gdk_rectangle_contains_point(
                self.to_glib_none().0,
                x,
                y,
            ))
        }
    }

    #[doc(alias = "gdk_rectangle_equal")]
    fn equal(&self, rect2: &Rectangle) -> bool {
        unsafe {
            from_glib(ffi::gdk_rectangle_equal(
                self.to_glib_none().0,
                rect2.to_glib_none().0,
            ))
        }
    }

    /// Calculates the intersection of two rectangles.
    ///
    /// It is allowed for @dest to be the same as either @self or @src2.
    /// If the rectangles do not intersect, @dest’s width and height is set
    /// to 0 and its x and y values are undefined. If you are only interested
    /// in whether the rectangles intersect, but not in the intersecting area
    /// itself, pass [`None`] for @dest.
    /// ## `src2`
    /// a [`Rectangle`][crate::Rectangle]
    ///
    /// # Returns
    ///
    /// [`true`] if the rectangles intersect.
    ///
    /// ## `dest`
    /// return location for the
    ///   intersection of @self and @src2
    #[doc(alias = "gdk_rectangle_intersect")]
    pub fn intersect(&self, src2: &Rectangle) -> Option<Rectangle> {
        unsafe {
            let mut dest = Rectangle::uninitialized();
            let ret = from_glib(ffi::gdk_rectangle_intersect(
                self.to_glib_none().0,
                src2.to_glib_none().0,
                dest.to_glib_none_mut().0,
            ));
            if ret {
                Some(dest)
            } else {
                None
            }
        }
    }

    /// Calculates the union of two rectangles.
    ///
    /// The union of rectangles @self and @src2 is the smallest rectangle which
    /// includes both @self and @src2 within it. It is allowed for @dest to be
    /// the same as either @self or @src2.
    ///
    /// Note that this function does not ignore 'empty' rectangles (ie. with
    /// zero width or height).
    /// ## `src2`
    /// a [`Rectangle`][crate::Rectangle]
    ///
    /// # Returns
    ///
    ///
    /// ## `dest`
    /// return location for the union of @self and @src2
    #[doc(alias = "gdk_rectangle_union")]
    #[must_use]
    pub fn union(&self, src2: &Rectangle) -> Rectangle {
        unsafe {
            let mut dest = Rectangle::uninitialized();
            ffi::gdk_rectangle_union(
                self.to_glib_none().0,
                src2.to_glib_none().0,
                dest.to_glib_none_mut().0,
            );
            dest
        }
    }
}

impl PartialEq for Rectangle {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for Rectangle {}