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