gtk4/auto/snapshot.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{StyleContext, ffi};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// Assists in creating [`gsk::RenderNode`][crate::gsk::RenderNode]s for widgets.
11 ///
12 /// It functions in a similar way to a cairo context, and maintains a stack
13 /// of render nodes and their associated transformations.
14 ///
15 /// The node at the top of the stack is the one that `gtk_snapshot_append_…()`
16 /// functions operate on. Use the `gtk_snapshot_push_…()` functions and
17 /// [`SnapshotExt::pop()`][crate::prelude::SnapshotExt::pop()] to change the current node.
18 ///
19 /// The typical way to obtain a [`Snapshot`][crate::Snapshot] object is as an argument to
20 /// the [`WidgetImpl::snapshot()`][crate::subclass::prelude::WidgetImpl::snapshot()] vfunc. If you need to create your own
21 /// [`Snapshot`][crate::Snapshot], use [`new()`][Self::new()].
22 ///
23 /// Note that [`Snapshot`][crate::Snapshot] applies some optimizations, so the node
24 /// it produces may not match the API calls 1:1. For example, it will
25 /// omit clip nodes if the child node is entirely contained within the
26 /// clip rectangle.
27 ///
28 /// # Implements
29 ///
30 /// [`SnapshotExt`][trait@crate::prelude::SnapshotExt], [`trait@gdk::prelude::SnapshotExt`], [`trait@glib::ObjectExt`], [`SnapshotExtManual`][trait@crate::prelude::SnapshotExtManual]
31 #[doc(alias = "GtkSnapshot")]
32 pub struct Snapshot(Object<ffi::GtkSnapshot, ffi::GtkSnapshotClass>) @extends gdk::Snapshot;
33
34 match fn {
35 type_ => || ffi::gtk_snapshot_get_type(),
36 }
37}
38
39impl Snapshot {
40 pub const NONE: Option<&'static Snapshot> = None;
41
42 /// Creates a new [`Snapshot`][crate::Snapshot].
43 ///
44 /// # Returns
45 ///
46 /// a newly-allocated [`Snapshot`][crate::Snapshot]
47 #[doc(alias = "gtk_snapshot_new")]
48 pub fn new() -> Snapshot {
49 assert_initialized_main_thread!();
50 unsafe { from_glib_full(ffi::gtk_snapshot_new()) }
51 }
52}
53
54impl Default for Snapshot {
55 fn default() -> Self {
56 Self::new()
57 }
58}
59
60/// Trait containing all [`struct@Snapshot`] methods.
61///
62/// # Implementors
63///
64/// [`Snapshot`][struct@crate::Snapshot]
65pub trait SnapshotExt: IsA<Snapshot> + 'static {
66 /// Creates a new [`gsk::CairoNode`][crate::gsk::CairoNode] and appends it to the current
67 /// render node of @self, without changing the current node.
68 /// ## `bounds`
69 /// the bounds for the new node
70 ///
71 /// # Returns
72 ///
73 /// a [`cairo::Context`][crate::cairo::Context] suitable for drawing the contents of
74 /// the newly created render node
75 #[doc(alias = "gtk_snapshot_append_cairo")]
76 fn append_cairo(&self, bounds: &graphene::Rect) -> cairo::Context {
77 unsafe {
78 from_glib_full(ffi::gtk_snapshot_append_cairo(
79 self.as_ref().to_glib_none().0,
80 bounds.to_glib_none().0,
81 ))
82 }
83 }
84
85 /// Creates a new render node drawing the @color into the
86 /// given @bounds and appends it to the current render node
87 /// of @self.
88 ///
89 /// You should try to avoid calling this function if
90 /// @color is transparent.
91 /// ## `color`
92 /// the color to draw
93 /// ## `bounds`
94 /// the bounds for the new node
95 #[doc(alias = "gtk_snapshot_append_color")]
96 fn append_color(&self, color: &gdk::RGBA, bounds: &graphene::Rect) {
97 unsafe {
98 ffi::gtk_snapshot_append_color(
99 self.as_ref().to_glib_none().0,
100 color.to_glib_none().0,
101 bounds.to_glib_none().0,
102 );
103 }
104 }
105
106 /// Appends a conic gradient node with the given stops to @self.
107 /// ## `bounds`
108 /// the rectangle to render the gradient into
109 /// ## `center`
110 /// the center point of the conic gradient
111 /// ## `rotation`
112 /// the clockwise rotation in degrees of the starting angle.
113 /// 0 means the starting angle is the top.
114 /// ## `stops`
115 /// the color stops defining the gradient
116 #[doc(alias = "gtk_snapshot_append_conic_gradient")]
117 fn append_conic_gradient(
118 &self,
119 bounds: &graphene::Rect,
120 center: &graphene::Point,
121 rotation: f32,
122 stops: &[gsk::ColorStop],
123 ) {
124 let n_stops = stops.len() as _;
125 unsafe {
126 ffi::gtk_snapshot_append_conic_gradient(
127 self.as_ref().to_glib_none().0,
128 bounds.to_glib_none().0,
129 center.to_glib_none().0,
130 rotation,
131 stops.to_glib_none().0,
132 n_stops,
133 );
134 }
135 }
136
137 /// A convenience method to fill a path with a color.
138 ///
139 /// See [`push_fill()`][Self::push_fill()] if you need
140 /// to fill a path with more complex content than
141 /// a color.
142 /// ## `path`
143 /// The path describing the area to fill
144 /// ## `fill_rule`
145 /// The fill rule to use
146 /// ## `color`
147 /// the color to fill the path with
148 #[cfg(feature = "v4_14")]
149 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
150 #[doc(alias = "gtk_snapshot_append_fill")]
151 fn append_fill(&self, path: &gsk::Path, fill_rule: gsk::FillRule, color: &gdk::RGBA) {
152 unsafe {
153 ffi::gtk_snapshot_append_fill(
154 self.as_ref().to_glib_none().0,
155 path.to_glib_none().0,
156 fill_rule.into_glib(),
157 color.to_glib_none().0,
158 );
159 }
160 }
161
162 /// Appends an inset shadow into the box given by @outline.
163 /// ## `outline`
164 /// outline of the region surrounded by shadow
165 /// ## `color`
166 /// color of the shadow
167 /// ## `dx`
168 /// horizontal offset of shadow
169 /// ## `dy`
170 /// vertical offset of shadow
171 /// ## `spread`
172 /// how far the shadow spreads towards the inside
173 /// ## `blur_radius`
174 /// how much blur to apply to the shadow
175 #[doc(alias = "gtk_snapshot_append_inset_shadow")]
176 fn append_inset_shadow(
177 &self,
178 outline: &gsk::RoundedRect,
179 color: &gdk::RGBA,
180 dx: f32,
181 dy: f32,
182 spread: f32,
183 blur_radius: f32,
184 ) {
185 unsafe {
186 ffi::gtk_snapshot_append_inset_shadow(
187 self.as_ref().to_glib_none().0,
188 outline.to_glib_none().0,
189 color.to_glib_none().0,
190 dx,
191 dy,
192 spread,
193 blur_radius,
194 );
195 }
196 }
197
198 /// Creates render nodes for rendering @layout in the given foregound @color
199 /// and appends them to the current node of @self without changing the
200 /// current node. The current theme's foreground color for a widget can be
201 /// obtained with [`WidgetExt::color()`][crate::prelude::WidgetExt::color()].
202 ///
203 /// Note that if the layout does not produce any visible output, then nodes
204 /// may not be added to the @self.
205 /// ## `layout`
206 /// the [`pango::Layout`][crate::pango::Layout] to render
207 /// ## `color`
208 /// the foreground color to render the layout in
209 #[doc(alias = "gtk_snapshot_append_layout")]
210 fn append_layout(&self, layout: &pango::Layout, color: &gdk::RGBA) {
211 unsafe {
212 ffi::gtk_snapshot_append_layout(
213 self.as_ref().to_glib_none().0,
214 layout.to_glib_none().0,
215 color.to_glib_none().0,
216 );
217 }
218 }
219
220 /// Appends a linear gradient node with the given stops to @self.
221 /// ## `bounds`
222 /// the rectangle to render the linear gradient into
223 /// ## `start_point`
224 /// the point at which the linear gradient will begin
225 /// ## `end_point`
226 /// the point at which the linear gradient will finish
227 /// ## `stops`
228 /// the color stops defining the gradient
229 #[doc(alias = "gtk_snapshot_append_linear_gradient")]
230 fn append_linear_gradient(
231 &self,
232 bounds: &graphene::Rect,
233 start_point: &graphene::Point,
234 end_point: &graphene::Point,
235 stops: &[gsk::ColorStop],
236 ) {
237 let n_stops = stops.len() as _;
238 unsafe {
239 ffi::gtk_snapshot_append_linear_gradient(
240 self.as_ref().to_glib_none().0,
241 bounds.to_glib_none().0,
242 start_point.to_glib_none().0,
243 end_point.to_glib_none().0,
244 stops.to_glib_none().0,
245 n_stops,
246 );
247 }
248 }
249
250 /// Appends @node to the current render node of @self,
251 /// without changing the current node.
252 ///
253 /// If @self does not have a current node yet, @node
254 /// will become the initial node.
255 /// ## `node`
256 /// a [`gsk::RenderNode`][crate::gsk::RenderNode]
257 #[doc(alias = "gtk_snapshot_append_node")]
258 fn append_node(&self, node: impl AsRef<gsk::RenderNode>) {
259 unsafe {
260 ffi::gtk_snapshot_append_node(
261 self.as_ref().to_glib_none().0,
262 node.as_ref().to_glib_none().0,
263 );
264 }
265 }
266
267 /// Appends an outset shadow node around the box given by @outline.
268 /// ## `outline`
269 /// outline of the region surrounded by shadow
270 /// ## `color`
271 /// color of the shadow
272 /// ## `dx`
273 /// horizontal offset of shadow
274 /// ## `dy`
275 /// vertical offset of shadow
276 /// ## `spread`
277 /// how far the shadow spreads towards the outside
278 /// ## `blur_radius`
279 /// how much blur to apply to the shadow
280 #[doc(alias = "gtk_snapshot_append_outset_shadow")]
281 fn append_outset_shadow(
282 &self,
283 outline: &gsk::RoundedRect,
284 color: &gdk::RGBA,
285 dx: f32,
286 dy: f32,
287 spread: f32,
288 blur_radius: f32,
289 ) {
290 unsafe {
291 ffi::gtk_snapshot_append_outset_shadow(
292 self.as_ref().to_glib_none().0,
293 outline.to_glib_none().0,
294 color.to_glib_none().0,
295 dx,
296 dy,
297 spread,
298 blur_radius,
299 );
300 }
301 }
302
303 /// Creates a new render node that pastes the contents
304 /// copied by a previous call to `Gtk::Snapshot::push_copy()`
305 /// ## `bounds`
306 /// the bounds for the new node
307 /// ## `nth`
308 /// the index of the copy, with 0 being the latest
309 /// copy, 1 being the copy before that, and so on.
310 #[cfg(feature = "v4_22")]
311 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
312 #[doc(alias = "gtk_snapshot_append_paste")]
313 fn append_paste(&self, bounds: &graphene::Rect, nth: usize) {
314 unsafe {
315 ffi::gtk_snapshot_append_paste(
316 self.as_ref().to_glib_none().0,
317 bounds.to_glib_none().0,
318 nth,
319 );
320 }
321 }
322
323 /// Appends a radial gradient node with the given stops to @self.
324 /// ## `bounds`
325 /// the rectangle to render the readial gradient into
326 /// ## `center`
327 /// the center point for the radial gradient
328 /// ## `hradius`
329 /// the horizontal radius
330 /// ## `vradius`
331 /// the vertical radius
332 /// ## `start`
333 /// the start position (on the horizontal axis)
334 /// ## `end`
335 /// the end position (on the horizontal axis)
336 /// ## `stops`
337 /// the color stops defining the gradient
338 #[doc(alias = "gtk_snapshot_append_radial_gradient")]
339 fn append_radial_gradient(
340 &self,
341 bounds: &graphene::Rect,
342 center: &graphene::Point,
343 hradius: f32,
344 vradius: f32,
345 start: f32,
346 end: f32,
347 stops: &[gsk::ColorStop],
348 ) {
349 let n_stops = stops.len() as _;
350 unsafe {
351 ffi::gtk_snapshot_append_radial_gradient(
352 self.as_ref().to_glib_none().0,
353 bounds.to_glib_none().0,
354 center.to_glib_none().0,
355 hradius,
356 vradius,
357 start,
358 end,
359 stops.to_glib_none().0,
360 n_stops,
361 );
362 }
363 }
364
365 /// Appends a repeating linear gradient node with the given stops to @self.
366 /// ## `bounds`
367 /// the rectangle to render the linear gradient into
368 /// ## `start_point`
369 /// the point at which the linear gradient will begin
370 /// ## `end_point`
371 /// the point at which the linear gradient will finish
372 /// ## `stops`
373 /// the color stops defining the gradient
374 #[doc(alias = "gtk_snapshot_append_repeating_linear_gradient")]
375 fn append_repeating_linear_gradient(
376 &self,
377 bounds: &graphene::Rect,
378 start_point: &graphene::Point,
379 end_point: &graphene::Point,
380 stops: &[gsk::ColorStop],
381 ) {
382 let n_stops = stops.len() as _;
383 unsafe {
384 ffi::gtk_snapshot_append_repeating_linear_gradient(
385 self.as_ref().to_glib_none().0,
386 bounds.to_glib_none().0,
387 start_point.to_glib_none().0,
388 end_point.to_glib_none().0,
389 stops.to_glib_none().0,
390 n_stops,
391 );
392 }
393 }
394
395 /// Appends a repeating radial gradient node with the given stops to @self.
396 /// ## `bounds`
397 /// the rectangle to render the readial gradient into
398 /// ## `center`
399 /// the center point for the radial gradient
400 /// ## `hradius`
401 /// the horizontal radius
402 /// ## `vradius`
403 /// the vertical radius
404 /// ## `start`
405 /// the start position (on the horizontal axis)
406 /// ## `end`
407 /// the end position (on the horizontal axis)
408 /// ## `stops`
409 /// the color stops defining the gradient
410 #[doc(alias = "gtk_snapshot_append_repeating_radial_gradient")]
411 fn append_repeating_radial_gradient(
412 &self,
413 bounds: &graphene::Rect,
414 center: &graphene::Point,
415 hradius: f32,
416 vradius: f32,
417 start: f32,
418 end: f32,
419 stops: &[gsk::ColorStop],
420 ) {
421 let n_stops = stops.len() as _;
422 unsafe {
423 ffi::gtk_snapshot_append_repeating_radial_gradient(
424 self.as_ref().to_glib_none().0,
425 bounds.to_glib_none().0,
426 center.to_glib_none().0,
427 hradius,
428 vradius,
429 start,
430 end,
431 stops.to_glib_none().0,
432 n_stops,
433 );
434 }
435 }
436
437 /// Creates a new render node drawing the @texture
438 /// into the given @bounds and appends it to the
439 /// current render node of @self.
440 ///
441 /// In contrast to [`append_texture()`][Self::append_texture()],
442 /// this function provides control about how the filter
443 /// that is used when scaling.
444 /// ## `texture`
445 /// the texture to render
446 /// ## `filter`
447 /// the filter to use
448 /// ## `bounds`
449 /// the bounds for the new node
450 #[cfg(feature = "v4_10")]
451 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
452 #[doc(alias = "gtk_snapshot_append_scaled_texture")]
453 fn append_scaled_texture(
454 &self,
455 texture: &impl IsA<gdk::Texture>,
456 filter: gsk::ScalingFilter,
457 bounds: &graphene::Rect,
458 ) {
459 unsafe {
460 ffi::gtk_snapshot_append_scaled_texture(
461 self.as_ref().to_glib_none().0,
462 texture.as_ref().to_glib_none().0,
463 filter.into_glib(),
464 bounds.to_glib_none().0,
465 );
466 }
467 }
468
469 /// A convenience method to stroke a path with a color.
470 ///
471 /// See [`push_stroke()`][Self::push_stroke()] if you need
472 /// to stroke a path with more complex content than
473 /// a color.
474 /// ## `path`
475 /// The path describing the area to fill
476 /// ## `stroke`
477 /// The stroke attributes
478 /// ## `color`
479 /// the color to fill the path with
480 #[cfg(feature = "v4_14")]
481 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
482 #[doc(alias = "gtk_snapshot_append_stroke")]
483 fn append_stroke(&self, path: &gsk::Path, stroke: &gsk::Stroke, color: &gdk::RGBA) {
484 unsafe {
485 ffi::gtk_snapshot_append_stroke(
486 self.as_ref().to_glib_none().0,
487 path.to_glib_none().0,
488 stroke.to_glib_none().0,
489 color.to_glib_none().0,
490 );
491 }
492 }
493
494 /// Creates a new render node drawing the @texture
495 /// into the given @bounds and appends it to the
496 /// current render node of @self.
497 ///
498 /// If the texture needs to be scaled to fill @bounds,
499 /// linear filtering is used. See [`append_scaled_texture()`][Self::append_scaled_texture()]
500 /// if you need other filtering, such as nearest-neighbour.
501 /// ## `texture`
502 /// the texture to render
503 /// ## `bounds`
504 /// the bounds for the new node
505 #[doc(alias = "gtk_snapshot_append_texture")]
506 fn append_texture(&self, texture: &impl IsA<gdk::Texture>, bounds: &graphene::Rect) {
507 unsafe {
508 ffi::gtk_snapshot_append_texture(
509 self.as_ref().to_glib_none().0,
510 texture.as_ref().to_glib_none().0,
511 bounds.to_glib_none().0,
512 );
513 }
514 }
515
516 /// Returns the node that was constructed by @self
517 /// and frees @self.
518 ///
519 /// See also `Gtk::Snapshot::to_node()`.
520 ///
521 /// # Returns
522 ///
523 /// a newly-created [`gsk::RenderNode`][crate::gsk::RenderNode]
524 #[doc(alias = "gtk_snapshot_free_to_node")]
525 #[doc(alias = "free_to_node")]
526 fn to_node(self) -> Option<gsk::RenderNode> {
527 unsafe {
528 from_glib_full(ffi::gtk_snapshot_free_to_node(
529 self.upcast().into_glib_ptr(),
530 ))
531 }
532 }
533
534 /// Returns a paintable for the node that was
535 /// constructed by @self and frees @self.
536 /// ## `size`
537 /// The size of the resulting paintable
538 /// or [`None`] to use the bounds of the snapshot
539 ///
540 /// # Returns
541 ///
542 /// a newly-created [`gdk::Paintable`][crate::gdk::Paintable]
543 #[doc(alias = "gtk_snapshot_free_to_paintable")]
544 #[doc(alias = "free_to_paintable")]
545 fn to_paintable(self, size: Option<&graphene::Size>) -> Option<gdk::Paintable> {
546 unsafe {
547 from_glib_full(ffi::gtk_snapshot_free_to_paintable(
548 self.upcast().into_glib_ptr(),
549 size.to_glib_none().0,
550 ))
551 }
552 }
553
554 /// Removes the top element from the stack of render nodes and
555 /// adds it to the nearest [`gsk::GLShaderNode`][crate::gsk::GLShaderNode] below it.
556 ///
557 /// This must be called the same number of times as the number
558 /// of textures is needed for the shader in
559 /// [`push_gl_shader()`][Self::push_gl_shader()].
560 ///
561 /// # Deprecated since 4.16
562 ///
563 /// GTK's new Vulkan-focused rendering
564 /// does not support this feature. Use [`GLArea`][crate::GLArea] for
565 /// OpenGL rendering.
566 #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
567 #[allow(deprecated)]
568 #[doc(alias = "gtk_snapshot_gl_shader_pop_texture")]
569 fn gl_shader_pop_texture(&self) {
570 unsafe {
571 ffi::gtk_snapshot_gl_shader_pop_texture(self.as_ref().to_glib_none().0);
572 }
573 }
574
575 /// Applies a perspective projection transform.
576 ///
577 /// See [`gsk::Transform::perspective()`][crate::gsk::Transform::perspective()] for a discussion on the details.
578 /// ## `depth`
579 /// distance of the z=0 plane
580 #[doc(alias = "gtk_snapshot_perspective")]
581 fn perspective(&self, depth: f32) {
582 unsafe {
583 ffi::gtk_snapshot_perspective(self.as_ref().to_glib_none().0, depth);
584 }
585 }
586
587 /// Removes the top element from the stack of render nodes,
588 /// and appends it to the node underneath it.
589 #[doc(alias = "gtk_snapshot_pop")]
590 fn pop(&self) {
591 unsafe {
592 ffi::gtk_snapshot_pop(self.as_ref().to_glib_none().0);
593 }
594 }
595
596 /// Blends together two images with the given blend mode.
597 ///
598 /// Until the first call to [`pop()`][Self::pop()], the
599 /// bottom image for the blend operation will be recorded.
600 /// After that call, the top image to be blended will be
601 /// recorded until the second call to [`pop()`][Self::pop()].
602 ///
603 /// Calling this function requires two subsequent calls
604 /// to [`pop()`][Self::pop()].
605 /// ## `blend_mode`
606 /// blend mode to use
607 #[doc(alias = "gtk_snapshot_push_blend")]
608 fn push_blend(&self, blend_mode: gsk::BlendMode) {
609 unsafe {
610 ffi::gtk_snapshot_push_blend(self.as_ref().to_glib_none().0, blend_mode.into_glib());
611 }
612 }
613
614 /// Blurs an image using a gaussian blur.
615 ///
616 /// The blur radius has to be set to 2x the std deviation of the blur.
617 ///
618 /// The image is recorded until the next call to [`pop()`][Self::pop()].
619 /// ## `radius`
620 /// the blur radius to use. Must be positive. May be 0
621 #[doc(alias = "gtk_snapshot_push_blur")]
622 fn push_blur(&self, radius: f64) {
623 unsafe {
624 ffi::gtk_snapshot_push_blur(self.as_ref().to_glib_none().0, radius);
625 }
626 }
627
628 /// Clips an image to a rectangle.
629 ///
630 /// The image is recorded until the next call to [`pop()`][Self::pop()].
631 /// ## `bounds`
632 /// the rectangle to clip to
633 #[doc(alias = "gtk_snapshot_push_clip")]
634 fn push_clip(&self, bounds: &graphene::Rect) {
635 unsafe {
636 ffi::gtk_snapshot_push_clip(self.as_ref().to_glib_none().0, bounds.to_glib_none().0);
637 }
638 }
639
640 /// Modifies the colors of an image by applying an affine transformation
641 /// in RGB space.
642 ///
643 /// In particular, the colors will be transformed by applying
644 ///
645 /// pixel = transpose(color_matrix) * pixel + color_offset
646 ///
647 /// for every pixel. The transformation operates on unpremultiplied
648 /// colors, with color components ordered R, G, B, A.
649 ///
650 /// The image is recorded until the next call to [`pop()`][Self::pop()].
651 /// ## `color_matrix`
652 /// the color matrix to use
653 /// ## `color_offset`
654 /// the color offset to use
655 #[doc(alias = "gtk_snapshot_push_color_matrix")]
656 fn push_color_matrix(&self, color_matrix: &graphene::Matrix, color_offset: &graphene::Vec4) {
657 unsafe {
658 ffi::gtk_snapshot_push_color_matrix(
659 self.as_ref().to_glib_none().0,
660 color_matrix.to_glib_none().0,
661 color_offset.to_glib_none().0,
662 );
663 }
664 }
665
666 /// Modifies the colors of an image by applying a transfer
667 /// function for each component.
668 ///
669 /// The transfer functions operate on unpremultiplied colors.
670 ///
671 /// The image is recorded until the next call to [`pop()`][Self::pop()].
672 /// ## `red`
673 /// the transfer for the red component
674 /// ## `green`
675 /// the transfer for the green component
676 /// ## `blue`
677 /// the transfer for the blue component
678 /// ## `alpha`
679 /// the transfer for the alpha component
680 #[cfg(feature = "v4_20")]
681 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
682 #[doc(alias = "gtk_snapshot_push_component_transfer")]
683 fn push_component_transfer(
684 &self,
685 red: &gsk::ComponentTransfer,
686 green: &gsk::ComponentTransfer,
687 blue: &gsk::ComponentTransfer,
688 alpha: &gsk::ComponentTransfer,
689 ) {
690 unsafe {
691 ffi::gtk_snapshot_push_component_transfer(
692 self.as_ref().to_glib_none().0,
693 red.to_glib_none().0,
694 green.to_glib_none().0,
695 blue.to_glib_none().0,
696 alpha.to_glib_none().0,
697 );
698 }
699 }
700
701 /// Until the first call to [`pop()`][Self::pop()], the
702 /// mask image for the mask operation will be recorded.
703 ///
704 /// After that call, the child image will be recorded until
705 /// the second call to [`pop()`][Self::pop()].
706 ///
707 /// Calling this function requires 2 subsequent calls to gtk_snapshot_pop().
708 /// ## `op`
709 /// The Porter/Duff compositing operator to use
710 #[cfg(feature = "v4_22")]
711 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
712 #[doc(alias = "gtk_snapshot_push_composite")]
713 fn push_composite(&self, op: gsk::PorterDuff) {
714 unsafe {
715 ffi::gtk_snapshot_push_composite(self.as_ref().to_glib_none().0, op.into_glib());
716 }
717 }
718
719 #[cfg(feature = "v4_22")]
720 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
721 #[doc(alias = "gtk_snapshot_push_copy")]
722 fn push_copy(&self) {
723 unsafe {
724 ffi::gtk_snapshot_push_copy(self.as_ref().to_glib_none().0);
725 }
726 }
727
728 /// Snapshots a cross-fade operation between two images with the
729 /// given @progress.
730 ///
731 /// Until the first call to [`pop()`][Self::pop()], the start image
732 /// will be snapshot. After that call, the end image will be recorded
733 /// until the second call to [`pop()`][Self::pop()].
734 ///
735 /// Calling this function requires two subsequent calls
736 /// to [`pop()`][Self::pop()].
737 /// ## `progress`
738 /// progress between 0.0 and 1.0
739 #[doc(alias = "gtk_snapshot_push_cross_fade")]
740 fn push_cross_fade(&self, progress: f64) {
741 unsafe {
742 ffi::gtk_snapshot_push_cross_fade(self.as_ref().to_glib_none().0, progress);
743 }
744 }
745
746 /// Fills the area given by @path and @fill_rule with an image and discards everything
747 /// outside of it.
748 ///
749 /// The image is recorded until the next call to [`pop()`][Self::pop()].
750 ///
751 /// If you want to fill the path with a color, [`append_fill()`][Self::append_fill()]
752 /// than rendering new ones, use [`append_fill()`][Self::append_fill()]
753 /// may be more convenient.
754 /// ## `path`
755 /// The path describing the area to fill
756 /// ## `fill_rule`
757 /// The fill rule to use
758 #[cfg(feature = "v4_14")]
759 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
760 #[doc(alias = "gtk_snapshot_push_fill")]
761 fn push_fill(&self, path: &gsk::Path, fill_rule: gsk::FillRule) {
762 unsafe {
763 ffi::gtk_snapshot_push_fill(
764 self.as_ref().to_glib_none().0,
765 path.to_glib_none().0,
766 fill_rule.into_glib(),
767 );
768 }
769 }
770
771 /// Push a [`gsk::GLShaderNode`][crate::gsk::GLShaderNode].
772 ///
773 /// The node uses the given [`gsk::GLShader`][crate::gsk::GLShader] and uniform values
774 /// Additionally this takes a list of @n_children other nodes
775 /// which will be passed to the [`gsk::GLShaderNode`][crate::gsk::GLShaderNode].
776 ///
777 /// The @take_args argument is a block of data to use for uniform
778 /// arguments, as per types and offsets defined by the @shader.
779 /// Normally this is generated by `Gsk::GLShader::format_args()`
780 /// or `Gsk::ShaderArgsBuilder`.
781 ///
782 /// The snapshotter takes ownership of @take_args, so the caller should
783 /// not free it after this.
784 ///
785 /// If the renderer doesn't support GL shaders, or if there is any
786 /// problem when compiling the shader, then the node will draw pink.
787 /// You should use [`GLShader::compile()`][crate::gsk::GLShader::compile()] to ensure the @shader
788 /// will work for the renderer before using it.
789 ///
790 /// If the shader requires textures (see [`GLShader::n_textures()`][crate::gsk::GLShader::n_textures()]),
791 /// then it is expected that you call [`gl_shader_pop_texture()`][Self::gl_shader_pop_texture()]
792 /// the number of times that are required. Each of these calls will generate
793 /// a node that is added as a child to the [`gsk::GLShaderNode`][crate::gsk::GLShaderNode], which in turn
794 /// will render these offscreen and pass as a texture to the shader.
795 ///
796 /// Once all textures (if any) are pop:ed, you must call the regular
797 /// [`pop()`][Self::pop()].
798 ///
799 /// If you want to use pre-existing textures as input to the shader rather
800 /// than rendering new ones, use [`append_texture()`][Self::append_texture()] to
801 /// push a texture node. These will be used directly rather than being
802 /// re-rendered.
803 ///
804 /// For details on how to write shaders, see [`gsk::GLShader`][crate::gsk::GLShader].
805 ///
806 /// # Deprecated since 4.16
807 ///
808 /// GTK's new Vulkan-focused rendering
809 /// does not support this feature. Use [`GLArea`][crate::GLArea] for
810 /// OpenGL rendering.
811 /// ## `shader`
812 /// The code to run
813 /// ## `bounds`
814 /// the rectangle to render into
815 /// ## `take_args`
816 /// Data block with arguments for the shader.
817 #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
818 #[allow(deprecated)]
819 #[doc(alias = "gtk_snapshot_push_gl_shader")]
820 fn push_gl_shader(
821 &self,
822 shader: &gsk::GLShader,
823 bounds: &graphene::Rect,
824 take_args: glib::Bytes,
825 ) {
826 unsafe {
827 ffi::gtk_snapshot_push_gl_shader(
828 self.as_ref().to_glib_none().0,
829 shader.to_glib_none().0,
830 bounds.to_glib_none().0,
831 take_args.into_glib_ptr(),
832 );
833 }
834 }
835
836 //#[cfg(feature = "v4_22")]
837 //#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
838 //#[doc(alias = "gtk_snapshot_push_isolation")]
839 //fn push_isolation(&self, features: /*Ignored*/gsk::Isolation) {
840 // unsafe { TODO: call ffi:gtk_snapshot_push_isolation() }
841 //}
842
843 /// Until the first call to [`pop()`][Self::pop()], the
844 /// mask image for the mask operation will be recorded.
845 ///
846 /// After that call, the source image will be recorded until
847 /// the second call to [`pop()`][Self::pop()].
848 ///
849 /// Calling this function requires 2 subsequent calls to gtk_snapshot_pop().
850 /// ## `mask_mode`
851 /// mask mode to use
852 #[cfg(feature = "v4_10")]
853 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
854 #[doc(alias = "gtk_snapshot_push_mask")]
855 fn push_mask(&self, mask_mode: gsk::MaskMode) {
856 unsafe {
857 ffi::gtk_snapshot_push_mask(self.as_ref().to_glib_none().0, mask_mode.into_glib());
858 }
859 }
860
861 /// Modifies the opacity of an image.
862 ///
863 /// The image is recorded until the next call to [`pop()`][Self::pop()].
864 /// ## `opacity`
865 /// the opacity to use
866 #[doc(alias = "gtk_snapshot_push_opacity")]
867 fn push_opacity(&self, opacity: f64) {
868 unsafe {
869 ffi::gtk_snapshot_push_opacity(self.as_ref().to_glib_none().0, opacity);
870 }
871 }
872
873 /// Creates a node that repeats the child node.
874 ///
875 /// The child is recorded until the next call to [`pop()`][Self::pop()].
876 /// ## `bounds`
877 /// the bounds within which to repeat
878 /// ## `child_bounds`
879 /// the bounds of the child or [`None`]
880 /// to use the full size of the collected child node
881 #[doc(alias = "gtk_snapshot_push_repeat")]
882 fn push_repeat(&self, bounds: &graphene::Rect, child_bounds: Option<&graphene::Rect>) {
883 unsafe {
884 ffi::gtk_snapshot_push_repeat(
885 self.as_ref().to_glib_none().0,
886 bounds.to_glib_none().0,
887 child_bounds.to_glib_none().0,
888 );
889 }
890 }
891
892 /// Clips an image to a rounded rectangle.
893 ///
894 /// The image is recorded until the next call to [`pop()`][Self::pop()].
895 /// ## `bounds`
896 /// the rounded rectangle to clip to
897 #[doc(alias = "gtk_snapshot_push_rounded_clip")]
898 fn push_rounded_clip(&self, bounds: &gsk::RoundedRect) {
899 unsafe {
900 ffi::gtk_snapshot_push_rounded_clip(
901 self.as_ref().to_glib_none().0,
902 bounds.to_glib_none().0,
903 );
904 }
905 }
906
907 /// Applies a shadow to an image.
908 ///
909 /// The image is recorded until the next call to [`pop()`][Self::pop()].
910 /// ## `shadow`
911 /// the first shadow specification
912 #[doc(alias = "gtk_snapshot_push_shadow")]
913 fn push_shadow(&self, shadow: &[gsk::Shadow]) {
914 let n_shadows = shadow.len() as _;
915 unsafe {
916 ffi::gtk_snapshot_push_shadow(
917 self.as_ref().to_glib_none().0,
918 shadow.to_glib_none().0,
919 n_shadows,
920 );
921 }
922 }
923
924 /// Strokes the given @path with the attributes given by @stroke and
925 /// an image.
926 ///
927 /// The image is recorded until the next call to [`pop()`][Self::pop()].
928 ///
929 /// Note that the strokes are subject to the same transformation as
930 /// everything else, so uneven scaling will cause horizontal and vertical
931 /// strokes to have different widths.
932 ///
933 /// If you want to stroke the path with a color, [`append_stroke()`][Self::append_stroke()]
934 /// may be more convenient.
935 /// ## `path`
936 /// The path to stroke
937 /// ## `stroke`
938 /// The stroke attributes
939 #[cfg(feature = "v4_14")]
940 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
941 #[doc(alias = "gtk_snapshot_push_stroke")]
942 fn push_stroke(&self, path: &gsk::Path, stroke: &gsk::Stroke) {
943 unsafe {
944 ffi::gtk_snapshot_push_stroke(
945 self.as_ref().to_glib_none().0,
946 path.to_glib_none().0,
947 stroke.to_glib_none().0,
948 );
949 }
950 }
951
952 /// Creates a render node for the CSS background according to @context,
953 /// and appends it to the current node of @self, without changing
954 /// the current node.
955 ///
956 /// # Deprecated since 4.10
957 ///
958 /// ## `context`
959 /// the style context that defines the background
960 /// ## `x`
961 /// X origin of the rectangle
962 /// ## `y`
963 /// Y origin of the rectangle
964 /// ## `width`
965 /// rectangle width
966 /// ## `height`
967 /// rectangle height
968 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
969 #[allow(deprecated)]
970 #[doc(alias = "gtk_snapshot_render_background")]
971 fn render_background(
972 &self,
973 context: &impl IsA<StyleContext>,
974 x: f64,
975 y: f64,
976 width: f64,
977 height: f64,
978 ) {
979 unsafe {
980 ffi::gtk_snapshot_render_background(
981 self.as_ref().to_glib_none().0,
982 context.as_ref().to_glib_none().0,
983 x,
984 y,
985 width,
986 height,
987 );
988 }
989 }
990
991 /// Creates a render node for the focus outline according to @context,
992 /// and appends it to the current node of @self, without changing
993 /// the current node.
994 ///
995 /// # Deprecated since 4.10
996 ///
997 /// ## `context`
998 /// the style context that defines the focus ring
999 /// ## `x`
1000 /// X origin of the rectangle
1001 /// ## `y`
1002 /// Y origin of the rectangle
1003 /// ## `width`
1004 /// rectangle width
1005 /// ## `height`
1006 /// rectangle height
1007 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1008 #[allow(deprecated)]
1009 #[doc(alias = "gtk_snapshot_render_focus")]
1010 fn render_focus(
1011 &self,
1012 context: &impl IsA<StyleContext>,
1013 x: f64,
1014 y: f64,
1015 width: f64,
1016 height: f64,
1017 ) {
1018 unsafe {
1019 ffi::gtk_snapshot_render_focus(
1020 self.as_ref().to_glib_none().0,
1021 context.as_ref().to_glib_none().0,
1022 x,
1023 y,
1024 width,
1025 height,
1026 );
1027 }
1028 }
1029
1030 /// Creates a render node for the CSS border according to @context,
1031 /// and appends it to the current node of @self, without changing
1032 /// the current node.
1033 ///
1034 /// # Deprecated since 4.10
1035 ///
1036 /// ## `context`
1037 /// the style context that defines the frame
1038 /// ## `x`
1039 /// X origin of the rectangle
1040 /// ## `y`
1041 /// Y origin of the rectangle
1042 /// ## `width`
1043 /// rectangle width
1044 /// ## `height`
1045 /// rectangle height
1046 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1047 #[allow(deprecated)]
1048 #[doc(alias = "gtk_snapshot_render_frame")]
1049 fn render_frame(
1050 &self,
1051 context: &impl IsA<StyleContext>,
1052 x: f64,
1053 y: f64,
1054 width: f64,
1055 height: f64,
1056 ) {
1057 unsafe {
1058 ffi::gtk_snapshot_render_frame(
1059 self.as_ref().to_glib_none().0,
1060 context.as_ref().to_glib_none().0,
1061 x,
1062 y,
1063 width,
1064 height,
1065 );
1066 }
1067 }
1068
1069 /// Draws a text caret using @self at the specified index of @layout.
1070 ///
1071 /// # Deprecated since 4.10
1072 ///
1073 /// ## `context`
1074 /// a [`StyleContext`][crate::StyleContext]
1075 /// ## `x`
1076 /// X origin
1077 /// ## `y`
1078 /// Y origin
1079 /// ## `layout`
1080 /// the [`pango::Layout`][crate::pango::Layout] of the text
1081 /// ## `index`
1082 /// the index in the [`pango::Layout`][crate::pango::Layout]
1083 /// ## `direction`
1084 /// the [`pango::Direction`][crate::pango::Direction] of the text
1085 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1086 #[allow(deprecated)]
1087 #[doc(alias = "gtk_snapshot_render_insertion_cursor")]
1088 fn render_insertion_cursor(
1089 &self,
1090 context: &impl IsA<StyleContext>,
1091 x: f64,
1092 y: f64,
1093 layout: &pango::Layout,
1094 index: i32,
1095 direction: pango::Direction,
1096 ) {
1097 unsafe {
1098 ffi::gtk_snapshot_render_insertion_cursor(
1099 self.as_ref().to_glib_none().0,
1100 context.as_ref().to_glib_none().0,
1101 x,
1102 y,
1103 layout.to_glib_none().0,
1104 index,
1105 direction.into_glib(),
1106 );
1107 }
1108 }
1109
1110 /// Creates a render node for rendering @layout according to the style
1111 /// information in @context, and appends it to the current node of @self,
1112 /// without changing the current node.
1113 ///
1114 /// # Deprecated since 4.10
1115 ///
1116 /// ## `context`
1117 /// the style context that defines the text
1118 /// ## `x`
1119 /// X origin of the rectangle
1120 /// ## `y`
1121 /// Y origin of the rectangle
1122 /// ## `layout`
1123 /// the [`pango::Layout`][crate::pango::Layout] to render
1124 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1125 #[allow(deprecated)]
1126 #[doc(alias = "gtk_snapshot_render_layout")]
1127 fn render_layout(
1128 &self,
1129 context: &impl IsA<StyleContext>,
1130 x: f64,
1131 y: f64,
1132 layout: &pango::Layout,
1133 ) {
1134 unsafe {
1135 ffi::gtk_snapshot_render_layout(
1136 self.as_ref().to_glib_none().0,
1137 context.as_ref().to_glib_none().0,
1138 x,
1139 y,
1140 layout.to_glib_none().0,
1141 );
1142 }
1143 }
1144
1145 /// Restores @self to the state saved by a preceding call to
1146 /// [`save()`][Self::save()] and removes that state from the stack of
1147 /// saved states.
1148 #[doc(alias = "gtk_snapshot_restore")]
1149 fn restore(&self) {
1150 unsafe {
1151 ffi::gtk_snapshot_restore(self.as_ref().to_glib_none().0);
1152 }
1153 }
1154
1155 /// Rotates @@self's coordinate system by @angle degrees in 2D space -
1156 /// or in 3D speak, rotates around the Z axis. The rotation happens around
1157 /// the origin point of (0, 0) in the @self's current coordinate system.
1158 ///
1159 /// To rotate around axes other than the Z axis, use [`gsk::Transform::rotate_3d()`][crate::gsk::Transform::rotate_3d()].
1160 /// ## `angle`
1161 /// the rotation angle, in degrees (clockwise)
1162 #[doc(alias = "gtk_snapshot_rotate")]
1163 fn rotate(&self, angle: f32) {
1164 unsafe {
1165 ffi::gtk_snapshot_rotate(self.as_ref().to_glib_none().0, angle);
1166 }
1167 }
1168
1169 /// Rotates @self's coordinate system by @angle degrees around @axis.
1170 ///
1171 /// For a rotation in 2D space, use [`gsk::Transform::rotate()`][crate::gsk::Transform::rotate()].
1172 /// ## `angle`
1173 /// the rotation angle, in degrees (clockwise)
1174 /// ## `axis`
1175 /// The rotation axis
1176 #[doc(alias = "gtk_snapshot_rotate_3d")]
1177 fn rotate_3d(&self, angle: f32, axis: &graphene::Vec3) {
1178 unsafe {
1179 ffi::gtk_snapshot_rotate_3d(
1180 self.as_ref().to_glib_none().0,
1181 angle,
1182 axis.to_glib_none().0,
1183 );
1184 }
1185 }
1186
1187 /// Makes a copy of the current state of @self and saves it
1188 /// on an internal stack.
1189 ///
1190 /// When [`restore()`][Self::restore()] is called, @self will
1191 /// be restored to the saved state.
1192 ///
1193 /// Multiple calls to [`save()`][Self::save()] and [`restore()`][Self::restore()]
1194 /// can be nested; each call to `gtk_snapshot_restore()` restores the state from
1195 /// the matching paired `gtk_snapshot_save()`.
1196 ///
1197 /// It is necessary to clear all saved states with corresponding
1198 /// calls to `gtk_snapshot_restore()`.
1199 #[doc(alias = "gtk_snapshot_save")]
1200 fn save(&self) {
1201 unsafe {
1202 ffi::gtk_snapshot_save(self.as_ref().to_glib_none().0);
1203 }
1204 }
1205
1206 /// Scales @self's coordinate system in 2-dimensional space by
1207 /// the given factors.
1208 ///
1209 /// Use [`scale_3d()`][Self::scale_3d()] to scale in all 3 dimensions.
1210 /// ## `factor_x`
1211 /// scaling factor on the X axis
1212 /// ## `factor_y`
1213 /// scaling factor on the Y axis
1214 #[doc(alias = "gtk_snapshot_scale")]
1215 fn scale(&self, factor_x: f32, factor_y: f32) {
1216 unsafe {
1217 ffi::gtk_snapshot_scale(self.as_ref().to_glib_none().0, factor_x, factor_y);
1218 }
1219 }
1220
1221 /// Scales @self's coordinate system by the given factors.
1222 /// ## `factor_x`
1223 /// scaling factor on the X axis
1224 /// ## `factor_y`
1225 /// scaling factor on the Y axis
1226 /// ## `factor_z`
1227 /// scaling factor on the Z axis
1228 #[doc(alias = "gtk_snapshot_scale_3d")]
1229 fn scale_3d(&self, factor_x: f32, factor_y: f32, factor_z: f32) {
1230 unsafe {
1231 ffi::gtk_snapshot_scale_3d(
1232 self.as_ref().to_glib_none().0,
1233 factor_x,
1234 factor_y,
1235 factor_z,
1236 );
1237 }
1238 }
1239
1240 /// Transforms @self's coordinate system with the given @transform.
1241 /// ## `transform`
1242 /// the transform to apply
1243 #[doc(alias = "gtk_snapshot_transform")]
1244 fn transform(&self, transform: Option<&gsk::Transform>) {
1245 unsafe {
1246 ffi::gtk_snapshot_transform(self.as_ref().to_glib_none().0, transform.to_glib_none().0);
1247 }
1248 }
1249
1250 /// Transforms @self's coordinate system with the given @matrix.
1251 /// ## `matrix`
1252 /// the matrix to multiply the transform with
1253 #[doc(alias = "gtk_snapshot_transform_matrix")]
1254 fn transform_matrix(&self, matrix: &graphene::Matrix) {
1255 unsafe {
1256 ffi::gtk_snapshot_transform_matrix(
1257 self.as_ref().to_glib_none().0,
1258 matrix.to_glib_none().0,
1259 );
1260 }
1261 }
1262
1263 /// Translates @self's coordinate system by @point in 2-dimensional space.
1264 /// ## `point`
1265 /// the point to translate the snapshot by
1266 #[doc(alias = "gtk_snapshot_translate")]
1267 fn translate(&self, point: &graphene::Point) {
1268 unsafe {
1269 ffi::gtk_snapshot_translate(self.as_ref().to_glib_none().0, point.to_glib_none().0);
1270 }
1271 }
1272
1273 /// Translates @self's coordinate system by @point.
1274 /// ## `point`
1275 /// the point to translate the snapshot by
1276 #[doc(alias = "gtk_snapshot_translate_3d")]
1277 fn translate_3d(&self, point: &graphene::Point3D) {
1278 unsafe {
1279 ffi::gtk_snapshot_translate_3d(self.as_ref().to_glib_none().0, point.to_glib_none().0);
1280 }
1281 }
1282}
1283
1284impl<O: IsA<Snapshot>> SnapshotExt for O {}