Skip to main content

clutter/auto/
colorize_effect.rs

1use crate::{ActorMeta, Color, Effect, OffscreenEffect};
2use glib::{
3    object as gobject,
4    object::{Cast, ObjectType as ObjectType_},
5    signal::{connect_raw, SignalHandlerId},
6    translate::*,
7};
8use std::boxed::Box as Box_;
9use std::{fmt, mem::transmute};
10
11glib_wrapper! {
12    pub struct ColorizeEffect(Object<ffi::ClutterColorizeEffect, ffi::ClutterColorizeEffectClass, ColorizeEffectClass>) @extends OffscreenEffect, Effect, ActorMeta, gobject::InitiallyUnowned;
13
14    match fn {
15        get_type => || ffi::clutter_colorize_effect_get_type(),
16    }
17}
18
19impl ColorizeEffect {
20    /// Creates a new `ColorizeEffect` to be used with
21    /// `ActorExt::add_effect`
22    /// ## `tint`
23    /// the color to be used
24    ///
25    /// # Returns
26    ///
27    /// the newly created `ColorizeEffect` or `None`
28    pub fn new(tint: &Color) -> ColorizeEffect {
29        unsafe {
30            Effect::from_glib_none(ffi::clutter_colorize_effect_new(tint.to_glib_none().0))
31                .unsafe_cast()
32        }
33    }
34
35    /// Retrieves the tint used by `self`
36    /// ## `tint`
37    /// return location for the color used
38    pub fn get_tint(&self) -> Color {
39        unsafe {
40            let mut tint = Color::uninitialized();
41            ffi::clutter_colorize_effect_get_tint(self.to_glib_none().0, tint.to_glib_none_mut().0);
42            tint
43        }
44    }
45
46    /// Sets the tint to be used when colorizing
47    /// ## `tint`
48    /// the color to be used
49    pub fn set_tint(&self, tint: &Color) {
50        unsafe {
51            ffi::clutter_colorize_effect_set_tint(self.to_glib_none().0, tint.to_glib_none().0);
52        }
53    }
54
55    pub fn connect_property_tint_notify<F: Fn(&ColorizeEffect) + 'static>(
56        &self,
57        f: F,
58    ) -> SignalHandlerId {
59        unsafe extern "C" fn notify_tint_trampoline<F: Fn(&ColorizeEffect) + 'static>(
60            this: *mut ffi::ClutterColorizeEffect,
61            _param_spec: glib_sys::gpointer,
62            f: glib_sys::gpointer,
63        ) {
64            let f: &F = &*(f as *const F);
65            f(&from_glib_borrow(this))
66        }
67        unsafe {
68            let f: Box_<F> = Box_::new(f);
69            connect_raw(
70                self.as_ptr() as *mut _,
71                b"notify::tint\0".as_ptr() as *const _,
72                Some(transmute::<_, unsafe extern "C" fn()>(
73                    notify_tint_trampoline::<F> as *const (),
74                )),
75                Box_::into_raw(f),
76            )
77        }
78    }
79}
80
81impl fmt::Display for ColorizeEffect {
82    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
83        write!(f, "ColorizeEffect")
84    }
85}