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
use crate::{ActorMeta, Color, Effect, InternalColor, OffscreenEffect, RgbaColor};
use glib::{
    object as gobject,
    object::{Cast, ObjectType as ObjectType_},
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;
use std::{fmt, mem::transmute};

glib_wrapper! {
    pub struct ColorizeEffect(Object<ffi::ClutterColorizeEffect, ffi::ClutterColorizeEffectClass, ColorizeEffectClass>) @extends OffscreenEffect, Effect, ActorMeta, gobject::InitiallyUnowned;

    match fn {
        get_type => || ffi::clutter_colorize_effect_get_type(),
    }
}

impl ColorizeEffect {
    /// Creates a new `ColorizeEffect` to be used with
    /// `ActorExt::add_effect`
    /// ## `tint`
    /// the color to be used
    ///
    /// # Returns
    ///
    /// the newly created `ColorizeEffect` or `None`
    pub fn new(tint: Color) -> ColorizeEffect {
        let RgbaColor {
            red,
            green,
            blue,
            alpha,
        } = tint.into();
        let tint = InternalColor::new(red, green, blue, alpha);

        unsafe {
            Effect::from_glib_none(ffi::clutter_colorize_effect_new(tint.to_glib_none().0))
                .unsafe_cast()
        }
    }

    /// Retrieves the tint used by `self`
    /// ## `tint`
    /// return location for the color used
    pub fn get_tint(&self) -> InternalColor {
        unsafe {
            let mut tint = InternalColor::uninitialized();
            ffi::clutter_colorize_effect_get_tint(self.to_glib_none().0, tint.to_glib_none_mut().0);
            tint
        }
    }

    /// Sets the tint to be used when colorizing
    /// ## `tint`
    /// the color to be used
    pub fn set_tint(&self, tint: &InternalColor) {
        unsafe {
            ffi::clutter_colorize_effect_set_tint(self.to_glib_none().0, tint.to_glib_none().0);
        }
    }

    pub fn connect_property_tint_notify<F: Fn(&ColorizeEffect) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_tint_trampoline<F: Fn(&ColorizeEffect) + 'static>(
            this: *mut ffi::ClutterColorizeEffect,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::tint\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_tint_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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