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.
615 ///
616 /// The image is recorded until the next call to [`pop()`][Self::pop()].
617 /// ## `radius`
618 /// the blur radius to use. Must be positive
619 #[doc(alias = "gtk_snapshot_push_blur")]
620 fn push_blur(&self, radius: f64) {
621 unsafe {
622 ffi::gtk_snapshot_push_blur(self.as_ref().to_glib_none().0, radius);
623 }
624 }
625
626 /// Clips an image to a rectangle.
627 ///
628 /// The image is recorded until the next call to [`pop()`][Self::pop()].
629 /// ## `bounds`
630 /// the rectangle to clip to
631 #[doc(alias = "gtk_snapshot_push_clip")]
632 fn push_clip(&self, bounds: &graphene::Rect) {
633 unsafe {
634 ffi::gtk_snapshot_push_clip(self.as_ref().to_glib_none().0, bounds.to_glib_none().0);
635 }
636 }
637
638 /// Modifies the colors of an image by applying an affine transformation
639 /// in RGB space.
640 ///
641 /// In particular, the colors will be transformed by applying
642 ///
643 /// pixel = transpose(color_matrix) * pixel + color_offset
644 ///
645 /// for every pixel. The transformation operates on unpremultiplied
646 /// colors, with color components ordered R, G, B, A.
647 ///
648 /// The image is recorded until the next call to [`pop()`][Self::pop()].
649 /// ## `color_matrix`
650 /// the color matrix to use
651 /// ## `color_offset`
652 /// the color offset to use
653 #[doc(alias = "gtk_snapshot_push_color_matrix")]
654 fn push_color_matrix(&self, color_matrix: &graphene::Matrix, color_offset: &graphene::Vec4) {
655 unsafe {
656 ffi::gtk_snapshot_push_color_matrix(
657 self.as_ref().to_glib_none().0,
658 color_matrix.to_glib_none().0,
659 color_offset.to_glib_none().0,
660 );
661 }
662 }
663
664 /// Modifies the colors of an image by applying a transfer
665 /// function for each component.
666 ///
667 /// The transfer functions operate on unpremultiplied colors.
668 ///
669 /// The image is recorded until the next call to [`pop()`][Self::pop()].
670 /// ## `red`
671 /// the transfer for the red component
672 /// ## `green`
673 /// the transfer for the green component
674 /// ## `blue`
675 /// the transfer for the blue component
676 /// ## `alpha`
677 /// the transfer for the alpha component
678 #[cfg(feature = "v4_20")]
679 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
680 #[doc(alias = "gtk_snapshot_push_component_transfer")]
681 fn push_component_transfer(
682 &self,
683 red: &gsk::ComponentTransfer,
684 green: &gsk::ComponentTransfer,
685 blue: &gsk::ComponentTransfer,
686 alpha: &gsk::ComponentTransfer,
687 ) {
688 unsafe {
689 ffi::gtk_snapshot_push_component_transfer(
690 self.as_ref().to_glib_none().0,
691 red.to_glib_none().0,
692 green.to_glib_none().0,
693 blue.to_glib_none().0,
694 alpha.to_glib_none().0,
695 );
696 }
697 }
698
699 /// Until the first call to [`pop()`][Self::pop()], the
700 /// mask image for the mask operation will be recorded.
701 ///
702 /// After that call, the child image will be recorded until
703 /// the second call to [`pop()`][Self::pop()].
704 ///
705 /// Calling this function requires 2 subsequent calls to gtk_snapshot_pop().
706 /// ## `op`
707 /// The Porter/Duff compositing operator to use
708 #[cfg(feature = "v4_22")]
709 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
710 #[doc(alias = "gtk_snapshot_push_composite")]
711 fn push_composite(&self, op: gsk::PorterDuff) {
712 unsafe {
713 ffi::gtk_snapshot_push_composite(self.as_ref().to_glib_none().0, op.into_glib());
714 }
715 }
716
717 #[cfg(feature = "v4_22")]
718 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
719 #[doc(alias = "gtk_snapshot_push_copy")]
720 fn push_copy(&self) {
721 unsafe {
722 ffi::gtk_snapshot_push_copy(self.as_ref().to_glib_none().0);
723 }
724 }
725
726 /// Snapshots a cross-fade operation between two images with the
727 /// given @progress.
728 ///
729 /// Until the first call to [`pop()`][Self::pop()], the start image
730 /// will be snapshot. After that call, the end image will be recorded
731 /// until the second call to [`pop()`][Self::pop()].
732 ///
733 /// Calling this function requires two subsequent calls
734 /// to [`pop()`][Self::pop()].
735 /// ## `progress`
736 /// progress between 0.0 and 1.0
737 #[doc(alias = "gtk_snapshot_push_cross_fade")]
738 fn push_cross_fade(&self, progress: f64) {
739 unsafe {
740 ffi::gtk_snapshot_push_cross_fade(self.as_ref().to_glib_none().0, progress);
741 }
742 }
743
744 /// Fills the area given by @path and @fill_rule with an image and discards everything
745 /// outside of it.
746 ///
747 /// The image is recorded until the next call to [`pop()`][Self::pop()].
748 ///
749 /// If you want to fill the path with a color, [`append_fill()`][Self::append_fill()]
750 /// than rendering new ones, use [`append_fill()`][Self::append_fill()]
751 /// may be more convenient.
752 /// ## `path`
753 /// The path describing the area to fill
754 /// ## `fill_rule`
755 /// The fill rule to use
756 #[cfg(feature = "v4_14")]
757 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
758 #[doc(alias = "gtk_snapshot_push_fill")]
759 fn push_fill(&self, path: &gsk::Path, fill_rule: gsk::FillRule) {
760 unsafe {
761 ffi::gtk_snapshot_push_fill(
762 self.as_ref().to_glib_none().0,
763 path.to_glib_none().0,
764 fill_rule.into_glib(),
765 );
766 }
767 }
768
769 /// Push a [`gsk::GLShaderNode`][crate::gsk::GLShaderNode].
770 ///
771 /// The node uses the given [`gsk::GLShader`][crate::gsk::GLShader] and uniform values
772 /// Additionally this takes a list of @n_children other nodes
773 /// which will be passed to the [`gsk::GLShaderNode`][crate::gsk::GLShaderNode].
774 ///
775 /// The @take_args argument is a block of data to use for uniform
776 /// arguments, as per types and offsets defined by the @shader.
777 /// Normally this is generated by `Gsk::GLShader::format_args()`
778 /// or `Gsk::ShaderArgsBuilder`.
779 ///
780 /// The snapshotter takes ownership of @take_args, so the caller should
781 /// not free it after this.
782 ///
783 /// If the renderer doesn't support GL shaders, or if there is any
784 /// problem when compiling the shader, then the node will draw pink.
785 /// You should use [`GLShader::compile()`][crate::gsk::GLShader::compile()] to ensure the @shader
786 /// will work for the renderer before using it.
787 ///
788 /// If the shader requires textures (see [`GLShader::n_textures()`][crate::gsk::GLShader::n_textures()]),
789 /// then it is expected that you call [`gl_shader_pop_texture()`][Self::gl_shader_pop_texture()]
790 /// the number of times that are required. Each of these calls will generate
791 /// a node that is added as a child to the [`gsk::GLShaderNode`][crate::gsk::GLShaderNode], which in turn
792 /// will render these offscreen and pass as a texture to the shader.
793 ///
794 /// Once all textures (if any) are pop:ed, you must call the regular
795 /// [`pop()`][Self::pop()].
796 ///
797 /// If you want to use pre-existing textures as input to the shader rather
798 /// than rendering new ones, use [`append_texture()`][Self::append_texture()] to
799 /// push a texture node. These will be used directly rather than being
800 /// re-rendered.
801 ///
802 /// For details on how to write shaders, see [`gsk::GLShader`][crate::gsk::GLShader].
803 ///
804 /// # Deprecated since 4.16
805 ///
806 /// GTK's new Vulkan-focused rendering
807 /// does not support this feature. Use [`GLArea`][crate::GLArea] for
808 /// OpenGL rendering.
809 /// ## `shader`
810 /// The code to run
811 /// ## `bounds`
812 /// the rectangle to render into
813 /// ## `take_args`
814 /// Data block with arguments for the shader.
815 #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
816 #[allow(deprecated)]
817 #[doc(alias = "gtk_snapshot_push_gl_shader")]
818 fn push_gl_shader(
819 &self,
820 shader: &gsk::GLShader,
821 bounds: &graphene::Rect,
822 take_args: glib::Bytes,
823 ) {
824 unsafe {
825 ffi::gtk_snapshot_push_gl_shader(
826 self.as_ref().to_glib_none().0,
827 shader.to_glib_none().0,
828 bounds.to_glib_none().0,
829 take_args.into_glib_ptr(),
830 );
831 }
832 }
833
834 //#[cfg(feature = "v4_22")]
835 //#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
836 //#[doc(alias = "gtk_snapshot_push_isolation")]
837 //fn push_isolation(&self, features: /*Ignored*/gsk::Isolation) {
838 // unsafe { TODO: call ffi:gtk_snapshot_push_isolation() }
839 //}
840
841 /// Until the first call to [`pop()`][Self::pop()], the
842 /// mask image for the mask operation will be recorded.
843 ///
844 /// After that call, the source image will be recorded until
845 /// the second call to [`pop()`][Self::pop()].
846 ///
847 /// Calling this function requires 2 subsequent calls to gtk_snapshot_pop().
848 /// ## `mask_mode`
849 /// mask mode to use
850 #[cfg(feature = "v4_10")]
851 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
852 #[doc(alias = "gtk_snapshot_push_mask")]
853 fn push_mask(&self, mask_mode: gsk::MaskMode) {
854 unsafe {
855 ffi::gtk_snapshot_push_mask(self.as_ref().to_glib_none().0, mask_mode.into_glib());
856 }
857 }
858
859 /// Modifies the opacity of an image.
860 ///
861 /// The image is recorded until the next call to [`pop()`][Self::pop()].
862 /// ## `opacity`
863 /// the opacity to use
864 #[doc(alias = "gtk_snapshot_push_opacity")]
865 fn push_opacity(&self, opacity: f64) {
866 unsafe {
867 ffi::gtk_snapshot_push_opacity(self.as_ref().to_glib_none().0, opacity);
868 }
869 }
870
871 /// Creates a node that repeats the child node.
872 ///
873 /// The child is recorded until the next call to [`pop()`][Self::pop()].
874 /// ## `bounds`
875 /// the bounds within which to repeat
876 /// ## `child_bounds`
877 /// the bounds of the child or [`None`]
878 /// to use the full size of the collected child node
879 #[doc(alias = "gtk_snapshot_push_repeat")]
880 fn push_repeat(&self, bounds: &graphene::Rect, child_bounds: Option<&graphene::Rect>) {
881 unsafe {
882 ffi::gtk_snapshot_push_repeat(
883 self.as_ref().to_glib_none().0,
884 bounds.to_glib_none().0,
885 child_bounds.to_glib_none().0,
886 );
887 }
888 }
889
890 /// Clips an image to a rounded rectangle.
891 ///
892 /// The image is recorded until the next call to [`pop()`][Self::pop()].
893 /// ## `bounds`
894 /// the rounded rectangle to clip to
895 #[doc(alias = "gtk_snapshot_push_rounded_clip")]
896 fn push_rounded_clip(&self, bounds: &gsk::RoundedRect) {
897 unsafe {
898 ffi::gtk_snapshot_push_rounded_clip(
899 self.as_ref().to_glib_none().0,
900 bounds.to_glib_none().0,
901 );
902 }
903 }
904
905 /// Applies a shadow to an image.
906 ///
907 /// The image is recorded until the next call to [`pop()`][Self::pop()].
908 /// ## `shadow`
909 /// the first shadow specification
910 #[doc(alias = "gtk_snapshot_push_shadow")]
911 fn push_shadow(&self, shadow: &[gsk::Shadow]) {
912 let n_shadows = shadow.len() as _;
913 unsafe {
914 ffi::gtk_snapshot_push_shadow(
915 self.as_ref().to_glib_none().0,
916 shadow.to_glib_none().0,
917 n_shadows,
918 );
919 }
920 }
921
922 /// Strokes the given @path with the attributes given by @stroke and
923 /// an image.
924 ///
925 /// The image is recorded until the next call to [`pop()`][Self::pop()].
926 ///
927 /// Note that the strokes are subject to the same transformation as
928 /// everything else, so uneven scaling will cause horizontal and vertical
929 /// strokes to have different widths.
930 ///
931 /// If you want to stroke the path with a color, [`append_stroke()`][Self::append_stroke()]
932 /// may be more convenient.
933 /// ## `path`
934 /// The path to stroke
935 /// ## `stroke`
936 /// The stroke attributes
937 #[cfg(feature = "v4_14")]
938 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
939 #[doc(alias = "gtk_snapshot_push_stroke")]
940 fn push_stroke(&self, path: &gsk::Path, stroke: &gsk::Stroke) {
941 unsafe {
942 ffi::gtk_snapshot_push_stroke(
943 self.as_ref().to_glib_none().0,
944 path.to_glib_none().0,
945 stroke.to_glib_none().0,
946 );
947 }
948 }
949
950 /// Creates a render node for the CSS background according to @context,
951 /// and appends it to the current node of @self, without changing
952 /// the current node.
953 ///
954 /// # Deprecated since 4.10
955 ///
956 /// ## `context`
957 /// the style context that defines the background
958 /// ## `x`
959 /// X origin of the rectangle
960 /// ## `y`
961 /// Y origin of the rectangle
962 /// ## `width`
963 /// rectangle width
964 /// ## `height`
965 /// rectangle height
966 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
967 #[allow(deprecated)]
968 #[doc(alias = "gtk_snapshot_render_background")]
969 fn render_background(
970 &self,
971 context: &impl IsA<StyleContext>,
972 x: f64,
973 y: f64,
974 width: f64,
975 height: f64,
976 ) {
977 unsafe {
978 ffi::gtk_snapshot_render_background(
979 self.as_ref().to_glib_none().0,
980 context.as_ref().to_glib_none().0,
981 x,
982 y,
983 width,
984 height,
985 );
986 }
987 }
988
989 /// Creates a render node for the focus outline according to @context,
990 /// and appends it to the current node of @self, without changing
991 /// the current node.
992 ///
993 /// # Deprecated since 4.10
994 ///
995 /// ## `context`
996 /// the style context that defines the focus ring
997 /// ## `x`
998 /// X origin of the rectangle
999 /// ## `y`
1000 /// Y origin of the rectangle
1001 /// ## `width`
1002 /// rectangle width
1003 /// ## `height`
1004 /// rectangle height
1005 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1006 #[allow(deprecated)]
1007 #[doc(alias = "gtk_snapshot_render_focus")]
1008 fn render_focus(
1009 &self,
1010 context: &impl IsA<StyleContext>,
1011 x: f64,
1012 y: f64,
1013 width: f64,
1014 height: f64,
1015 ) {
1016 unsafe {
1017 ffi::gtk_snapshot_render_focus(
1018 self.as_ref().to_glib_none().0,
1019 context.as_ref().to_glib_none().0,
1020 x,
1021 y,
1022 width,
1023 height,
1024 );
1025 }
1026 }
1027
1028 /// Creates a render node for the CSS border according to @context,
1029 /// and appends it to the current node of @self, without changing
1030 /// the current node.
1031 ///
1032 /// # Deprecated since 4.10
1033 ///
1034 /// ## `context`
1035 /// the style context that defines the frame
1036 /// ## `x`
1037 /// X origin of the rectangle
1038 /// ## `y`
1039 /// Y origin of the rectangle
1040 /// ## `width`
1041 /// rectangle width
1042 /// ## `height`
1043 /// rectangle height
1044 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1045 #[allow(deprecated)]
1046 #[doc(alias = "gtk_snapshot_render_frame")]
1047 fn render_frame(
1048 &self,
1049 context: &impl IsA<StyleContext>,
1050 x: f64,
1051 y: f64,
1052 width: f64,
1053 height: f64,
1054 ) {
1055 unsafe {
1056 ffi::gtk_snapshot_render_frame(
1057 self.as_ref().to_glib_none().0,
1058 context.as_ref().to_glib_none().0,
1059 x,
1060 y,
1061 width,
1062 height,
1063 );
1064 }
1065 }
1066
1067 /// Draws a text caret using @self at the specified index of @layout.
1068 ///
1069 /// # Deprecated since 4.10
1070 ///
1071 /// ## `context`
1072 /// a [`StyleContext`][crate::StyleContext]
1073 /// ## `x`
1074 /// X origin
1075 /// ## `y`
1076 /// Y origin
1077 /// ## `layout`
1078 /// the [`pango::Layout`][crate::pango::Layout] of the text
1079 /// ## `index`
1080 /// the index in the [`pango::Layout`][crate::pango::Layout]
1081 /// ## `direction`
1082 /// the [`pango::Direction`][crate::pango::Direction] of the text
1083 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1084 #[allow(deprecated)]
1085 #[doc(alias = "gtk_snapshot_render_insertion_cursor")]
1086 fn render_insertion_cursor(
1087 &self,
1088 context: &impl IsA<StyleContext>,
1089 x: f64,
1090 y: f64,
1091 layout: &pango::Layout,
1092 index: i32,
1093 direction: pango::Direction,
1094 ) {
1095 unsafe {
1096 ffi::gtk_snapshot_render_insertion_cursor(
1097 self.as_ref().to_glib_none().0,
1098 context.as_ref().to_glib_none().0,
1099 x,
1100 y,
1101 layout.to_glib_none().0,
1102 index,
1103 direction.into_glib(),
1104 );
1105 }
1106 }
1107
1108 /// Creates a render node for rendering @layout according to the style
1109 /// information in @context, and appends it to the current node of @self,
1110 /// without changing the current node.
1111 ///
1112 /// # Deprecated since 4.10
1113 ///
1114 /// ## `context`
1115 /// the style context that defines the text
1116 /// ## `x`
1117 /// X origin of the rectangle
1118 /// ## `y`
1119 /// Y origin of the rectangle
1120 /// ## `layout`
1121 /// the [`pango::Layout`][crate::pango::Layout] to render
1122 #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
1123 #[allow(deprecated)]
1124 #[doc(alias = "gtk_snapshot_render_layout")]
1125 fn render_layout(
1126 &self,
1127 context: &impl IsA<StyleContext>,
1128 x: f64,
1129 y: f64,
1130 layout: &pango::Layout,
1131 ) {
1132 unsafe {
1133 ffi::gtk_snapshot_render_layout(
1134 self.as_ref().to_glib_none().0,
1135 context.as_ref().to_glib_none().0,
1136 x,
1137 y,
1138 layout.to_glib_none().0,
1139 );
1140 }
1141 }
1142
1143 /// Restores @self to the state saved by a preceding call to
1144 /// [`save()`][Self::save()] and removes that state from the stack of
1145 /// saved states.
1146 #[doc(alias = "gtk_snapshot_restore")]
1147 fn restore(&self) {
1148 unsafe {
1149 ffi::gtk_snapshot_restore(self.as_ref().to_glib_none().0);
1150 }
1151 }
1152
1153 /// Rotates @@self's coordinate system by @angle degrees in 2D space -
1154 /// or in 3D speak, rotates around the Z axis. The rotation happens around
1155 /// the origin point of (0, 0) in the @self's current coordinate system.
1156 ///
1157 /// To rotate around axes other than the Z axis, use [`gsk::Transform::rotate_3d()`][crate::gsk::Transform::rotate_3d()].
1158 /// ## `angle`
1159 /// the rotation angle, in degrees (clockwise)
1160 #[doc(alias = "gtk_snapshot_rotate")]
1161 fn rotate(&self, angle: f32) {
1162 unsafe {
1163 ffi::gtk_snapshot_rotate(self.as_ref().to_glib_none().0, angle);
1164 }
1165 }
1166
1167 /// Rotates @self's coordinate system by @angle degrees around @axis.
1168 ///
1169 /// For a rotation in 2D space, use [`gsk::Transform::rotate()`][crate::gsk::Transform::rotate()].
1170 /// ## `angle`
1171 /// the rotation angle, in degrees (clockwise)
1172 /// ## `axis`
1173 /// The rotation axis
1174 #[doc(alias = "gtk_snapshot_rotate_3d")]
1175 fn rotate_3d(&self, angle: f32, axis: &graphene::Vec3) {
1176 unsafe {
1177 ffi::gtk_snapshot_rotate_3d(
1178 self.as_ref().to_glib_none().0,
1179 angle,
1180 axis.to_glib_none().0,
1181 );
1182 }
1183 }
1184
1185 /// Makes a copy of the current state of @self and saves it
1186 /// on an internal stack.
1187 ///
1188 /// When [`restore()`][Self::restore()] is called, @self will
1189 /// be restored to the saved state.
1190 ///
1191 /// Multiple calls to [`save()`][Self::save()] and [`restore()`][Self::restore()]
1192 /// can be nested; each call to `gtk_snapshot_restore()` restores the state from
1193 /// the matching paired `gtk_snapshot_save()`.
1194 ///
1195 /// It is necessary to clear all saved states with corresponding
1196 /// calls to `gtk_snapshot_restore()`.
1197 #[doc(alias = "gtk_snapshot_save")]
1198 fn save(&self) {
1199 unsafe {
1200 ffi::gtk_snapshot_save(self.as_ref().to_glib_none().0);
1201 }
1202 }
1203
1204 /// Scales @self's coordinate system in 2-dimensional space by
1205 /// the given factors.
1206 ///
1207 /// Use [`scale_3d()`][Self::scale_3d()] to scale in all 3 dimensions.
1208 /// ## `factor_x`
1209 /// scaling factor on the X axis
1210 /// ## `factor_y`
1211 /// scaling factor on the Y axis
1212 #[doc(alias = "gtk_snapshot_scale")]
1213 fn scale(&self, factor_x: f32, factor_y: f32) {
1214 unsafe {
1215 ffi::gtk_snapshot_scale(self.as_ref().to_glib_none().0, factor_x, factor_y);
1216 }
1217 }
1218
1219 /// Scales @self's coordinate system by the given factors.
1220 /// ## `factor_x`
1221 /// scaling factor on the X axis
1222 /// ## `factor_y`
1223 /// scaling factor on the Y axis
1224 /// ## `factor_z`
1225 /// scaling factor on the Z axis
1226 #[doc(alias = "gtk_snapshot_scale_3d")]
1227 fn scale_3d(&self, factor_x: f32, factor_y: f32, factor_z: f32) {
1228 unsafe {
1229 ffi::gtk_snapshot_scale_3d(
1230 self.as_ref().to_glib_none().0,
1231 factor_x,
1232 factor_y,
1233 factor_z,
1234 );
1235 }
1236 }
1237
1238 /// Transforms @self's coordinate system with the given @transform.
1239 /// ## `transform`
1240 /// the transform to apply
1241 #[doc(alias = "gtk_snapshot_transform")]
1242 fn transform(&self, transform: Option<&gsk::Transform>) {
1243 unsafe {
1244 ffi::gtk_snapshot_transform(self.as_ref().to_glib_none().0, transform.to_glib_none().0);
1245 }
1246 }
1247
1248 /// Transforms @self's coordinate system with the given @matrix.
1249 /// ## `matrix`
1250 /// the matrix to multiply the transform with
1251 #[doc(alias = "gtk_snapshot_transform_matrix")]
1252 fn transform_matrix(&self, matrix: &graphene::Matrix) {
1253 unsafe {
1254 ffi::gtk_snapshot_transform_matrix(
1255 self.as_ref().to_glib_none().0,
1256 matrix.to_glib_none().0,
1257 );
1258 }
1259 }
1260
1261 /// Translates @self's coordinate system by @point in 2-dimensional space.
1262 /// ## `point`
1263 /// the point to translate the snapshot by
1264 #[doc(alias = "gtk_snapshot_translate")]
1265 fn translate(&self, point: &graphene::Point) {
1266 unsafe {
1267 ffi::gtk_snapshot_translate(self.as_ref().to_glib_none().0, point.to_glib_none().0);
1268 }
1269 }
1270
1271 /// Translates @self's coordinate system by @point.
1272 /// ## `point`
1273 /// the point to translate the snapshot by
1274 #[doc(alias = "gtk_snapshot_translate_3d")]
1275 fn translate_3d(&self, point: &graphene::Point3D) {
1276 unsafe {
1277 ffi::gtk_snapshot_translate_3d(self.as_ref().to_glib_none().0, point.to_glib_none().0);
1278 }
1279 }
1280}
1281
1282impl<O: IsA<Snapshot>> SnapshotExt for O {}