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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
// 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

#[cfg(any(feature = "v3_22", feature = "dox"))]
use cairo;
use gdk_sys;
use glib::translate::*;
use std::fmt;
#[cfg(any(feature = "v3_22", feature = "dox"))]
use Window;

glib_wrapper! {
    /// `DrawingContext` is an object that represents the current drawing
    /// state of a `Window`.
    ///
    /// It's possible to use a `DrawingContext` to draw on a `Window`
    /// via rendering API like Cairo or OpenGL.
    ///
    /// A `DrawingContext` can only be created by calling `WindowExt::begin_draw_frame`
    /// and will be valid until a call to `WindowExt::end_draw_frame`.
    ///
    /// `DrawingContext` is available since GDK 3.22
    ///
    /// Feature: `v3_22`
    pub struct DrawingContext(Object<gdk_sys::GdkDrawingContext, gdk_sys::GdkDrawingContextClass, DrawingContextClass>);

    match fn {
        get_type => || gdk_sys::gdk_drawing_context_get_type(),
    }
}

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

    /// Retrieves a copy of the clip region used when creating the `self`.
    ///
    /// Feature: `v3_22`
    ///
    ///
    /// # Returns
    ///
    /// a Cairo region
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_clip(&self) -> Option<cairo::Region> {
        unsafe { from_glib_full(gdk_sys::gdk_drawing_context_get_clip(self.to_glib_none().0)) }
    }

    /// Retrieves the window that created the drawing `self`.
    ///
    /// Feature: `v3_22`
    ///
    ///
    /// # Returns
    ///
    /// a `Window`
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_window(&self) -> Option<Window> {
        unsafe {
            from_glib_none(gdk_sys::gdk_drawing_context_get_window(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether the given `DrawingContext` is valid.
    ///
    /// Feature: `v3_22`
    ///
    ///
    /// # Returns
    ///
    /// `true` if the context is valid
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn is_valid(&self) -> bool {
        unsafe { from_glib(gdk_sys::gdk_drawing_context_is_valid(self.to_glib_none().0)) }
    }
}

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