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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
use crate::Display;
use crate::Surface;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
glib::wrapper! {
/// Base class for objects implementing different rendering methods.
///
/// [`DrawContext`][crate::DrawContext] is the base object used by contexts implementing different
/// rendering methods, such as [`CairoContext`][crate::CairoContext] or [`GLContext`][crate::GLContext].
/// It provides shared functionality between those contexts.
///
/// You will always interact with one of those subclasses.
///
/// A [`DrawContext`][crate::DrawContext] is always associated with a single toplevel surface.
///
/// This is an Abstract Base Class, you cannot instantiate it.
///
/// # Implements
///
/// [`DrawContextExt`][trait@crate::prelude::DrawContextExt], [`DrawContextExtManual`][trait@crate::prelude::DrawContextExtManual]
#[doc(alias = "GdkDrawContext")]
pub struct DrawContext(Object<ffi::GdkDrawContext>);
match fn {
type_ => || ffi::gdk_draw_context_get_type(),
}
}
pub const NONE_DRAW_CONTEXT: Option<&DrawContext> = None;
/// Trait containing all [`struct@DrawContext`] methods.
///
/// # Implementors
///
/// [`CairoContext`][struct@crate::CairoContext], [`DrawContext`][struct@crate::DrawContext], [`GLContext`][struct@crate::GLContext], [`VulkanContext`][struct@crate::VulkanContext]
pub trait DrawContextExt: 'static {
/// Indicates that you are beginning the process of redrawing `region`
/// on the `self`'s surface.
///
/// Calling this function begins a drawing operation using `self` on the
/// surface that `self` was created from. The actual requirements and
/// guarantees for the drawing operation vary for different implementations
/// of drawing, so a [`CairoContext`][crate::CairoContext] and a [`GLContext`][crate::GLContext]
/// need to be treated differently.
///
/// A call to this function is a requirement for drawing and must be
/// followed by a call to [``end_frame()``][`Self::end_frame()`], which will
/// complete the drawing operation and ensure the contents become visible
/// on screen.
///
/// Note that the `region` passed to this function is the minimum region that
/// needs to be drawn and depending on implementation, windowing system and
/// hardware in use, it might be necessary to draw a larger region. Drawing
/// implementation must use [``DrawContextExtManual::frame_region()``][crate::prelude::`DrawContextExtManual::frame_region()`] to
/// query the region that must be drawn.
///
/// When using GTK, the widget system automatically places calls to
/// [`begin_frame()`][Self::begin_frame()] and [`end_frame()`][Self::end_frame()] via the
/// use of `Gsk::Renderer`s, so application code does not need to call
/// these functions explicitly.
/// ## `region`
/// minimum region that should be drawn
#[doc(alias = "gdk_draw_context_begin_frame")]
fn begin_frame(&self, region: &cairo::Region);
/// Ends a drawing operation started with [`begin_frame()`][Self::begin_frame()].
///
/// This makes the drawing available on screen.
/// See [``begin_frame()``][`Self::begin_frame()`] for more details about drawing.
///
/// When using a [`GLContext`][crate::GLContext], this function may call `glFlush()`
/// implicitly before returning; it is not recommended to call `glFlush()`
/// explicitly before calling this function.
#[doc(alias = "gdk_draw_context_end_frame")]
fn end_frame(&self);
/// Retrieves the [`Display`][crate::Display] the `self` is created for
///
/// # Returns
///
/// the [`Display`][crate::Display]
#[doc(alias = "gdk_draw_context_get_display")]
#[doc(alias = "get_display")]
fn display(&self) -> Option<Display>;
/// Retrieves the surface that `self` is bound to.
///
/// # Returns
///
/// a [`Surface`][crate::Surface]
#[doc(alias = "gdk_draw_context_get_surface")]
#[doc(alias = "get_surface")]
fn surface(&self) -> Option<Surface>;
/// Returns [`true`] if `self` is in the process of drawing to its surface.
///
/// This is the case between calls to [``begin_frame()``][`Self::begin_frame()`]
/// and [``end_frame()``][`Self::end_frame()`]. In this situation, drawing commands
/// may be effecting the contents of the `self`'s surface.
///
/// # Returns
///
/// [`true`] if the context is between [``begin_frame()``][`Self::begin_frame()`]
/// and [``end_frame()``][`Self::end_frame()`] calls.
#[doc(alias = "gdk_draw_context_is_in_frame")]
fn is_in_frame(&self) -> bool;
}
impl<O: IsA<DrawContext>> DrawContextExt for O {
fn begin_frame(&self, region: &cairo::Region) {
unsafe {
ffi::gdk_draw_context_begin_frame(
self.as_ref().to_glib_none().0,
region.to_glib_none().0,
);
}
}
fn end_frame(&self) {
unsafe {
ffi::gdk_draw_context_end_frame(self.as_ref().to_glib_none().0);
}
}
fn display(&self) -> Option<Display> {
unsafe {
from_glib_none(ffi::gdk_draw_context_get_display(
self.as_ref().to_glib_none().0,
))
}
}
fn surface(&self) -> Option<Surface> {
unsafe {
from_glib_none(ffi::gdk_draw_context_get_surface(
self.as_ref().to_glib_none().0,
))
}
}
fn is_in_frame(&self) -> bool {
unsafe {
from_glib(ffi::gdk_draw_context_is_in_frame(
self.as_ref().to_glib_none().0,
))
}
}
}
impl fmt::Display for DrawContext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("DrawContext")
}
}