animate/legacy/
backend.rs

1use glib::{
2    object::ObjectType as ObjectType_,
3    signal::{connect_raw, SignalHandlerId},
4    translate::*,
5};
6use std::boxed::Box as Box_;
7use std::{fmt, mem::transmute};
8
9glib_wrapper! {
10    pub struct Backend(Object<ffi::ClutterBackend, ffi::ClutterBackendClass, BackendClass>);
11
12    match fn {
13        get_type => || ffi::clutter_backend_get_type(),
14    }
15}
16
17impl Backend {
18    /// Retrieves the font options for `self`.
19    ///
20    /// # Returns
21    ///
22    /// the font options of the `Backend`.
23    ///  The returned `cairo::FontOptions` is owned by the backend and should
24    ///  not be modified or freed
25    pub fn get_font_options(&self) -> Option<cairo::FontOptions> {
26        unsafe { from_glib_none(ffi::clutter_backend_get_font_options(self.to_glib_none().0)) }
27    }
28
29    /// Gets the resolution for font handling on the screen.
30    ///
31    /// The resolution is a scale factor between points specified in a
32    /// `pango::FontDescription` and cairo units. The default value is 96.0,
33    /// meaning that a 10 point font will be 13 units
34    /// high (10 * 96. / 72. = 13.3).
35    ///
36    /// will set the resolution using the current backend when
37    /// initializing; the resolution is also stored in the
38    /// `Settings:font-dpi` property.
39    ///
40    /// # Returns
41    ///
42    /// the current resolution, or -1 if no resolution
43    ///  has been set.
44    pub fn get_resolution(&self) -> f64 {
45        unsafe { ffi::clutter_backend_get_resolution(self.to_glib_none().0) }
46    }
47
48    /// Sets the new font options for `self`. The `Backend` will
49    /// copy the `cairo::FontOptions`.
50    ///
51    /// If `options` is `None`, the first following call to
52    /// `Backend::get_font_options` will return the default font
53    /// options for `self`.
54    ///
55    /// This function is intended for actors creating a Pango layout
56    /// using the PangoCairo API.
57    /// ## `options`
58    /// Cairo font options for the backend, or `None`
59    pub fn set_font_options(&self, options: &cairo::FontOptions) {
60        unsafe {
61            ffi::clutter_backend_set_font_options(self.to_glib_none().0, options.to_glib_none().0);
62        }
63    }
64
65    /// The ::font-changed signal is emitted each time the font options
66    /// have been changed through `Settings`.
67    pub fn connect_font_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
68        unsafe extern "C" fn font_changed_trampoline<F: Fn(&Backend) + 'static>(
69            this: *mut ffi::ClutterBackend,
70            f: glib_sys::gpointer,
71        ) {
72            let f: &F = &*(f as *const F);
73            f(&from_glib_borrow(this))
74        }
75        unsafe {
76            let f: Box_<F> = Box_::new(f);
77            connect_raw(
78                self.as_ptr() as *mut _,
79                b"font-changed\0".as_ptr() as *const _,
80                Some(transmute::<_, unsafe extern "C" fn()>(
81                    font_changed_trampoline::<F> as *const (),
82                )),
83                Box_::into_raw(f),
84            )
85        }
86    }
87
88    /// The ::resolution-changed signal is emitted each time the font
89    /// resolutions has been changed through `Settings`.
90    pub fn connect_resolution_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
91        unsafe extern "C" fn resolution_changed_trampoline<F: Fn(&Backend) + 'static>(
92            this: *mut ffi::ClutterBackend,
93            f: glib_sys::gpointer,
94        ) {
95            let f: &F = &*(f as *const F);
96            f(&from_glib_borrow(this))
97        }
98        unsafe {
99            let f: Box_<F> = Box_::new(f);
100            connect_raw(
101                self.as_ptr() as *mut _,
102                b"resolution-changed\0".as_ptr() as *const _,
103                Some(transmute::<_, unsafe extern "C" fn()>(
104                    resolution_changed_trampoline::<F> as *const (),
105                )),
106                Box_::into_raw(f),
107            )
108        }
109    }
110
111    /// The ::settings-changed signal is emitted each time the `Settings`
112    /// properties have been changed.
113    pub fn connect_settings_changed<F: Fn(&Backend) + 'static>(&self, f: F) -> SignalHandlerId {
114        unsafe extern "C" fn settings_changed_trampoline<F: Fn(&Backend) + 'static>(
115            this: *mut ffi::ClutterBackend,
116            f: glib_sys::gpointer,
117        ) {
118            let f: &F = &*(f as *const F);
119            f(&from_glib_borrow(this))
120        }
121        unsafe {
122            let f: Box_<F> = Box_::new(f);
123            connect_raw(
124                self.as_ptr() as *mut _,
125                b"settings-changed\0".as_ptr() as *const _,
126                Some(transmute::<_, unsafe extern "C" fn()>(
127                    settings_changed_trampoline::<F> as *const (),
128                )),
129                Box_::into_raw(f),
130            )
131        }
132    }
133}
134
135impl fmt::Display for Backend {
136    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
137        write!(f, "Backend")
138    }
139}