gdk4/auto/
draw_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#![allow(deprecated)]
5
6use crate::{ffi, Display, Surface};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    /// Base class for objects implementing different rendering methods.
11    ///
12    /// [`DrawContext`][crate::DrawContext] is the base object used by contexts implementing different
13    /// rendering methods, such as [`CairoContext`][crate::CairoContext] or [`GLContext`][crate::GLContext].
14    /// It provides shared functionality between those contexts.
15    ///
16    /// You will always interact with one of those subclasses.
17    ///
18    /// A [`DrawContext`][crate::DrawContext] is always associated with a single toplevel surface.
19    ///
20    /// This is an Abstract Base Class, you cannot instantiate it.
21    ///
22    /// ## Properties
23    ///
24    ///
25    /// #### `display`
26    ///  The [`Display`][crate::Display] used to create the [`DrawContext`][crate::DrawContext].
27    ///
28    /// Readable | Writeable | Construct Only
29    ///
30    ///
31    /// #### `surface`
32    ///  The [`Surface`][crate::Surface] the context is bound to.
33    ///
34    /// Readable | Writeable | Construct Only
35    ///
36    /// # Implements
37    ///
38    /// [`DrawContextExt`][trait@crate::prelude::DrawContextExt], [`DrawContextExtManual`][trait@crate::prelude::DrawContextExtManual]
39    #[doc(alias = "GdkDrawContext")]
40    pub struct DrawContext(Object<ffi::GdkDrawContext>);
41
42    match fn {
43        type_ => || ffi::gdk_draw_context_get_type(),
44    }
45}
46
47impl DrawContext {
48    pub const NONE: Option<&'static DrawContext> = None;
49}
50
51/// Trait containing all [`struct@DrawContext`] methods.
52///
53/// # Implementors
54///
55/// [`CairoContext`][struct@crate::CairoContext], [`DrawContext`][struct@crate::DrawContext], [`GLContext`][struct@crate::GLContext], [`VulkanContext`][struct@crate::VulkanContext]
56pub trait DrawContextExt: IsA<DrawContext> + 'static {
57    /// Indicates that you are beginning the process of redrawing @region
58    /// on the @self's surface.
59    ///
60    /// Calling this function begins a drawing operation using @self on the
61    /// surface that @self was created from. The actual requirements and
62    /// guarantees for the drawing operation vary for different implementations
63    /// of drawing, so a [`CairoContext`][crate::CairoContext] and a [`GLContext`][crate::GLContext]
64    /// need to be treated differently.
65    ///
66    /// A call to this function is a requirement for drawing and must be
67    /// followed by a call to [`end_frame()`][Self::end_frame()], which will
68    /// complete the drawing operation and ensure the contents become visible
69    /// on screen.
70    ///
71    /// Note that the @region passed to this function is the minimum region that
72    /// needs to be drawn and depending on implementation, windowing system and
73    /// hardware in use, it might be necessary to draw a larger region. Drawing
74    /// implementation must use [`DrawContextExtManual::frame_region()`][crate::prelude::DrawContextExtManual::frame_region()] to
75    /// query the region that must be drawn.
76    ///
77    /// When using GTK, the widget system automatically places calls to
78    /// gdk_draw_context_begin_frame() and gdk_draw_context_end_frame() via the
79    /// use of [GskRenderer](../gsk4/class.Renderer.html)s, so application code
80    /// does not need to call these functions explicitly.
81    ///
82    /// # Deprecated since 4.16
83    ///
84    /// Drawing directly to the surface is no longer recommended.
85    ///   Use `GskRenderNode` and `GskRenderer`.
86    /// ## `region`
87    /// minimum region that should be drawn
88    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
89    #[allow(deprecated)]
90    #[doc(alias = "gdk_draw_context_begin_frame")]
91    fn begin_frame(&self, region: &cairo::Region) {
92        unsafe {
93            ffi::gdk_draw_context_begin_frame(
94                self.as_ref().to_glib_none().0,
95                region.to_glib_none().0,
96            );
97        }
98    }
99
100    /// Ends a drawing operation started with gdk_draw_context_begin_frame().
101    ///
102    /// This makes the drawing available on screen.
103    /// See [`begin_frame()`][Self::begin_frame()] for more details about drawing.
104    ///
105    /// When using a [`GLContext`][crate::GLContext], this function may call `glFlush()`
106    /// implicitly before returning; it is not recommended to call `glFlush()`
107    /// explicitly before calling this function.
108    ///
109    /// # Deprecated since 4.16
110    ///
111    /// Drawing directly to the surface is no longer recommended.
112    ///   Use `GskRenderNode` and `GskRenderer`.
113    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
114    #[allow(deprecated)]
115    #[doc(alias = "gdk_draw_context_end_frame")]
116    fn end_frame(&self) {
117        unsafe {
118            ffi::gdk_draw_context_end_frame(self.as_ref().to_glib_none().0);
119        }
120    }
121
122    /// Retrieves the [`Display`][crate::Display] the @self is created for
123    ///
124    /// # Returns
125    ///
126    /// the [`Display`][crate::Display]
127    #[doc(alias = "gdk_draw_context_get_display")]
128    #[doc(alias = "get_display")]
129    fn display(&self) -> Option<Display> {
130        unsafe {
131            from_glib_none(ffi::gdk_draw_context_get_display(
132                self.as_ref().to_glib_none().0,
133            ))
134        }
135    }
136
137    /// Retrieves the surface that @self is bound to.
138    ///
139    /// # Returns
140    ///
141    /// a [`Surface`][crate::Surface]
142    #[doc(alias = "gdk_draw_context_get_surface")]
143    #[doc(alias = "get_surface")]
144    fn surface(&self) -> Option<Surface> {
145        unsafe {
146            from_glib_none(ffi::gdk_draw_context_get_surface(
147                self.as_ref().to_glib_none().0,
148            ))
149        }
150    }
151
152    /// Returns [`true`] if @self is in the process of drawing to its surface.
153    ///
154    /// This is the case between calls to [`begin_frame()`][Self::begin_frame()]
155    /// and [`end_frame()`][Self::end_frame()]. In this situation, drawing commands
156    /// may be effecting the contents of the @self's surface.
157    ///
158    /// # Deprecated since 4.16
159    ///
160    /// Drawing directly to the surface is no longer recommended.
161    ///   Use `GskRenderNode` and `GskRenderer`.
162    ///
163    /// # Returns
164    ///
165    /// [`true`] if the context is between [`begin_frame()`][Self::begin_frame()]
166    ///   and [`end_frame()`][Self::end_frame()] calls.
167    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
168    #[allow(deprecated)]
169    #[doc(alias = "gdk_draw_context_is_in_frame")]
170    fn is_in_frame(&self) -> bool {
171        unsafe {
172            from_glib(ffi::gdk_draw_context_is_in_frame(
173                self.as_ref().to_glib_none().0,
174            ))
175        }
176    }
177}
178
179impl<O: IsA<DrawContext>> DrawContextExt for O {}