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