1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::Window;
use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// [`DrawingContext`][crate::DrawingContext] is an object that represents the current drawing
    /// state of a [`Window`][crate::Window].
    ///
    /// It's possible to use a [`DrawingContext`][crate::DrawingContext] to draw on a [`Window`][crate::Window]
    /// via rendering API like Cairo or OpenGL.
    ///
    /// A [`DrawingContext`][crate::DrawingContext] can only be created by calling [`Window::begin_draw_frame()`][crate::Window::begin_draw_frame()]
    /// and will be valid until a call to [`Window::end_draw_frame()`][crate::Window::end_draw_frame()].
    ///
    /// [`DrawingContext`][crate::DrawingContext] is available since GDK 3.22
    #[doc(alias = "GdkDrawingContext")]
    pub struct DrawingContext(Object<ffi::GdkDrawingContext, ffi::GdkDrawingContextClass>);

    match fn {
        type_ => || ffi::gdk_drawing_context_get_type(),
    }
}

impl DrawingContext {
    /// Retrieves a Cairo context to be used to draw on the [`Window`][crate::Window]
    /// that created the [`DrawingContext`][crate::DrawingContext].
    ///
    /// The returned context is guaranteed to be valid as long as the
    /// [`DrawingContext`][crate::DrawingContext] is valid, that is between a call to
    /// [`Window::begin_draw_frame()`][crate::Window::begin_draw_frame()] and [`Window::end_draw_frame()`][crate::Window::end_draw_frame()].
    ///
    /// # Returns
    ///
    /// a Cairo context to be used to draw
    ///  the contents of the [`Window`][crate::Window]. The context is owned by the
    ///  [`DrawingContext`][crate::DrawingContext] and should not be destroyed
    #[doc(alias = "gdk_drawing_context_get_cairo_context")]
    #[doc(alias = "get_cairo_context")]
    pub fn cairo_context(&self) -> Option<cairo::Context> {
        unsafe {
            from_glib_none(ffi::gdk_drawing_context_get_cairo_context(
                self.to_glib_none().0,
            ))
        }
    }

    /// Retrieves a copy of the clip region used when creating the `self`.
    ///
    /// # Returns
    ///
    /// a Cairo region
    #[doc(alias = "gdk_drawing_context_get_clip")]
    #[doc(alias = "get_clip")]
    pub fn clip(&self) -> Option<cairo::Region> {
        unsafe { from_glib_full(ffi::gdk_drawing_context_get_clip(self.to_glib_none().0)) }
    }

    /// Retrieves the window that created the drawing `self`.
    ///
    /// # Returns
    ///
    /// a [`Window`][crate::Window]
    #[doc(alias = "gdk_drawing_context_get_window")]
    #[doc(alias = "get_window")]
    pub fn window(&self) -> Option<Window> {
        unsafe { from_glib_none(ffi::gdk_drawing_context_get_window(self.to_glib_none().0)) }
    }

    /// Checks whether the given [`DrawingContext`][crate::DrawingContext] is valid.
    ///
    /// # Returns
    ///
    /// [`true`] if the context is valid
    #[doc(alias = "gdk_drawing_context_is_valid")]
    pub fn is_valid(&self) -> bool {
        unsafe { from_glib(ffi::gdk_drawing_context_is_valid(self.to_glib_none().0)) }
    }
}

impl fmt::Display for DrawingContext {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("DrawingContext")
    }
}