Skip to main content

gdk/auto/
drawing_context.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
5use crate::{Window, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    /// [`DrawingContext`][crate::DrawingContext] is an object that represents the current drawing
10    /// state of a [`Window`][crate::Window].
11    ///
12    /// It's possible to use a [`DrawingContext`][crate::DrawingContext] to draw on a [`Window`][crate::Window]
13    /// via rendering API like Cairo or OpenGL.
14    ///
15    /// A [`DrawingContext`][crate::DrawingContext] can only be created by calling [`Window::begin_draw_frame()`][crate::Window::begin_draw_frame()]
16    /// and will be valid until a call to [`Window::end_draw_frame()`][crate::Window::end_draw_frame()].
17    ///
18    /// [`DrawingContext`][crate::DrawingContext] is available since GDK 3.22
19    ///
20    /// ## Properties
21    ///
22    ///
23    /// #### `clip`
24    ///  The clip region applied to the drawing context.
25    ///
26    /// Readable | Writable | Construct Only
27    ///
28    ///
29    /// #### `window`
30    ///  The [`Window`][crate::Window] that created the drawing context.
31    ///
32    /// Readable | Writable | Construct Only
33    #[doc(alias = "GdkDrawingContext")]
34    pub struct DrawingContext(Object<ffi::GdkDrawingContext, ffi::GdkDrawingContextClass>);
35
36    match fn {
37        type_ => || ffi::gdk_drawing_context_get_type(),
38    }
39}
40
41impl DrawingContext {
42    /// Retrieves a Cairo context to be used to draw on the [`Window`][crate::Window]
43    /// that created the [`DrawingContext`][crate::DrawingContext].
44    ///
45    /// The returned context is guaranteed to be valid as long as the
46    /// [`DrawingContext`][crate::DrawingContext] is valid, that is between a call to
47    /// [`Window::begin_draw_frame()`][crate::Window::begin_draw_frame()] and [`Window::end_draw_frame()`][crate::Window::end_draw_frame()].
48    ///
49    /// # Returns
50    ///
51    /// a Cairo context to be used to draw
52    ///  the contents of the [`Window`][crate::Window]. The context is owned by the
53    ///  [`DrawingContext`][crate::DrawingContext] and should not be destroyed
54    #[doc(alias = "gdk_drawing_context_get_cairo_context")]
55    #[doc(alias = "get_cairo_context")]
56    pub fn cairo_context(&self) -> Option<cairo::Context> {
57        unsafe {
58            from_glib_none(ffi::gdk_drawing_context_get_cairo_context(
59                self.to_glib_none().0,
60            ))
61        }
62    }
63
64    /// Retrieves a copy of the clip region used when creating the `self`.
65    ///
66    /// # Returns
67    ///
68    /// a Cairo region
69    #[doc(alias = "gdk_drawing_context_get_clip")]
70    #[doc(alias = "get_clip")]
71    pub fn clip(&self) -> Option<cairo::Region> {
72        unsafe { from_glib_full(ffi::gdk_drawing_context_get_clip(self.to_glib_none().0)) }
73    }
74
75    /// Retrieves the window that created the drawing `self`.
76    ///
77    /// # Returns
78    ///
79    /// a [`Window`][crate::Window]
80    #[doc(alias = "gdk_drawing_context_get_window")]
81    #[doc(alias = "get_window")]
82    pub fn window(&self) -> Option<Window> {
83        unsafe { from_glib_none(ffi::gdk_drawing_context_get_window(self.to_glib_none().0)) }
84    }
85
86    /// Checks whether the given [`DrawingContext`][crate::DrawingContext] is valid.
87    ///
88    /// # Returns
89    ///
90    /// [`true`] if the context is valid
91    #[doc(alias = "gdk_drawing_context_is_valid")]
92    pub fn is_valid(&self) -> bool {
93        unsafe { from_glib(ffi::gdk_drawing_context_is_valid(self.to_glib_none().0)) }
94    }
95}