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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::Snapshot;
use glib::translate::*;
use graphene::{Point, Rect};
use gsk::ColorStop;

impl Snapshot {
    /// Appends a stroked border rectangle inside the given `outline`.
    ///
    /// The four sides of the border can have different widths and colors.
    /// ## `outline`
    /// a [`gsk::RoundedRect`][crate::gsk::RoundedRect] describing the outline of the border
    /// ## `border_width`
    /// the stroke width of the border on
    ///  the top, right, bottom and left side respectively.
    /// ## `border_color`
    /// the color used on the top, right,
    ///  bottom and left side.
    #[doc(alias = "gtk_snapshot_append_border")]
    pub fn append_border(
        &self,
        outline: &gsk::RoundedRect,
        border_width: &[f32; 4],
        border_color: &[gdk::RGBA; 4],
    ) {
        unsafe {
            let border_color_ptr: Vec<gdk::ffi::GdkRGBA> =
                border_color.iter().map(|c| *c.to_glib_none().0).collect();
            ffi::gtk_snapshot_append_border(
                self.to_glib_none().0,
                outline.to_glib_none().0,
                border_width,
                border_color_ptr.as_ptr() as *const _,
            )
        }
    }

    /// Appends a linear gradient node with the given stops to `self`.
    /// ## `bounds`
    /// the rectangle to render the linear gradient into
    /// ## `start_point`
    /// the point at which the linear gradient will begin
    /// ## `end_point`
    /// the point at which the linear gradient will finish
    /// ## `stops`
    /// a pointer to an array of [`gsk::ColorStop`][crate::gsk::ColorStop]
    ///  defining the gradient
    #[doc(alias = "gtk_snapshot_append_linear_gradient")]
    pub fn append_linear_gradient(
        &self,
        bounds: &Rect,
        start_point: &Point,
        end_point: &Point,
        stops: &[ColorStop],
    ) {
        let n_stops = stops.len() as usize;
        unsafe {
            ffi::gtk_snapshot_append_linear_gradient(
                self.to_glib_none().0,
                bounds.to_glib_none().0,
                start_point.to_glib_none().0,
                end_point.to_glib_none().0,
                stops.to_glib_none().0,
                n_stops,
            );
        }
    }

    /// Appends a radial gradient node with the given stops to `self`.
    /// ## `bounds`
    /// the rectangle to render the readial gradient into
    /// ## `center`
    /// the center point for the radial gradient
    /// ## `hradius`
    /// the horizontal radius
    /// ## `vradius`
    /// the vertical radius
    /// ## `start`
    /// the start position (on the horizontal axis)
    /// ## `end`
    /// the end position (on the horizontal axis)
    /// ## `stops`
    /// a pointer to an array of [`gsk::ColorStop`][crate::gsk::ColorStop]
    ///  defining the gradient
    #[doc(alias = "gtk_snapshot_append_radial_gradient")]
    pub fn append_radial_gradient(
        &self,
        bounds: &graphene::Rect,
        center: &graphene::Point,
        hradius: f32,
        vradius: f32,
        start: f32,
        end: f32,
        stops: &[gsk::ColorStop],
    ) {
        let n_stops = stops.len() as usize;
        unsafe {
            ffi::gtk_snapshot_append_radial_gradient(
                self.to_glib_none().0,
                bounds.to_glib_none().0,
                center.to_glib_none().0,
                hradius,
                vradius,
                start,
                end,
                stops.to_glib_none().0,
                n_stops,
            );
        }
    }

    /// Appends a conic gradient node with the given stops to `self`.
    /// ## `bounds`
    /// the rectangle to render the gradient into
    /// ## `center`
    /// the center point of the conic gradient
    /// ## `rotation`
    /// the clockwise rotation in degrees of the starting angle.
    ///  0 means the starting angle is the top.
    /// ## `stops`
    /// a pointer to an array of [`gsk::ColorStop`][crate::gsk::ColorStop]
    ///  defining the gradient
    #[doc(alias = "gtk_snapshot_append_conic_gradient")]
    pub fn append_conic_gradient(
        &self,
        bounds: &graphene::Rect,
        center: &graphene::Point,
        rotation: f32,
        stops: &[gsk::ColorStop],
    ) {
        let n_stops = stops.len() as usize;
        unsafe {
            ffi::gtk_snapshot_append_conic_gradient(
                self.to_glib_none().0,
                bounds.to_glib_none().0,
                center.to_glib_none().0,
                rotation,
                stops.to_glib_none().0,
                n_stops,
            );
        }
    }

    /// Appends a repeating radial gradient node with the given stops to `self`.
    /// ## `bounds`
    /// the rectangle to render the readial gradient into
    /// ## `center`
    /// the center point for the radial gradient
    /// ## `hradius`
    /// the horizontal radius
    /// ## `vradius`
    /// the vertical radius
    /// ## `start`
    /// the start position (on the horizontal axis)
    /// ## `end`
    /// the end position (on the horizontal axis)
    /// ## `stops`
    /// a pointer to an array of [`gsk::ColorStop`][crate::gsk::ColorStop]
    ///  defining the gradient
    #[doc(alias = "gtk_snapshot_append_repeating_radial_gradient")]
    pub fn append_repeating_radial_gradient(
        &self,
        bounds: &graphene::Rect,
        center: &graphene::Point,
        hradius: f32,
        vradius: f32,
        start: f32,
        end: f32,
        stops: &[gsk::ColorStop],
    ) {
        let n_stops = stops.len() as usize;
        unsafe {
            ffi::gtk_snapshot_append_repeating_radial_gradient(
                self.to_glib_none().0,
                bounds.to_glib_none().0,
                center.to_glib_none().0,
                hradius,
                vradius,
                start,
                end,
                stops.to_glib_none().0,
                n_stops,
            );
        }
    }

    /// Appends a repeating linear gradient node with the given stops to `self`.
    /// ## `bounds`
    /// the rectangle to render the linear gradient into
    /// ## `start_point`
    /// the point at which the linear gradient will begin
    /// ## `end_point`
    /// the point at which the linear gradient will finish
    /// ## `stops`
    /// a pointer to an array of [`gsk::ColorStop`][crate::gsk::ColorStop]
    ///  defining the gradient
    #[doc(alias = "gtk_snapshot_append_repeating_linear_gradient")]
    pub fn append_repeating_linear_gradient(
        &self,
        bounds: &Rect,
        start_point: &Point,
        end_point: &Point,
        stops: &[ColorStop],
    ) {
        let n_stops = stops.len() as usize;
        unsafe {
            ffi::gtk_snapshot_append_repeating_linear_gradient(
                self.to_glib_none().0,
                bounds.to_glib_none().0,
                start_point.to_glib_none().0,
                end_point.to_glib_none().0,
                stops.to_glib_none().0,
                n_stops,
            );
        }
    }

    /// Inserts a debug node with a message.
    ///
    /// Debug nodes don't affect the rendering at all, but can be
    /// helpful in identifying parts of a render node tree dump,
    /// for example in the GTK inspector.
    /// ## `message`
    /// a printf-style format string
    #[doc(alias = "gtk_snapshot_push_debug")]
    pub fn push_debug(&self, message: &str) {
        unsafe { ffi::gtk_snapshot_push_debug(self.to_glib_none().0, message.to_glib_none().0) }
    }

    /// Appends `node` to the current render node of `self`,
    /// without changing the current node.
    ///
    /// If `self` does not have a current node yet, `node`
    /// will become the initial node.
    /// ## `node`
    /// a [`gsk::RenderNode`][crate::gsk::RenderNode]
    #[doc(alias = "gtk_snapshot_append_node")]
    pub fn append_node<P: AsRef<gsk::RenderNode>>(&self, node: &P) {
        unsafe {
            ffi::gtk_snapshot_append_node(self.to_glib_none().0, node.as_ref().to_glib_none().0);
        }
    }
}