Skip to main content

animate/legacy/
offscreen_effect.rs

1use crate::{ActorMeta, Effect, InternalRect};
2use glib::{object as gobject, object::IsA, translate::*};
3use std::fmt;
4
5glib_wrapper! {
6    pub struct OffscreenEffect(Object<ffi::ClutterOffscreenEffect, ffi::ClutterOffscreenEffectClass, OffscreenEffectClass>) @extends Effect, ActorMeta, gobject::InitiallyUnowned;
7
8    match fn {
9        get_type => || ffi::clutter_offscreen_effect_get_type(),
10    }
11}
12
13/// Trait containing all `OffscreenEffect` methods.
14///
15/// # Implementors
16///
17/// [`BlurEffect`](struct.BlurEffect.html), [`BrightnessContrastEffect`](struct.BrightnessContrastEffect.html), [`ColorizeEffect`](struct.ColorizeEffect.html), [`DeformEffect`](struct.DeformEffect.html), [`DesaturateEffect`](struct.DesaturateEffect.html), [`OffscreenEffect`](struct.OffscreenEffect.html), [`ShaderEffect`](struct.ShaderEffect.html)
18pub trait OffscreenEffectExt: 'static {
19    //fn create_texture(&self, width: f32, height: f32) -> /*Unimplemented*/Option<dx::Handle>;
20
21    // /// Retrieves the material used as a render target for the offscreen
22    // /// buffer created by `self`
23    // ///
24    // /// You should only use the returned `dx::Material` when painting. The
25    // /// returned material might change between different frames.
26    // ///
27    // /// # Returns
28    // ///
29    // /// a `dx::Material` or `None`. The
30    // ///  returned material is owned by internals and it should not be
31    // ///  modified or freed
32
33    // fn get_target(&self) -> Option<dx::Material>;
34
35    /// Retrieves the origin and size of the offscreen buffer used by `self` to
36    /// paint the actor to which it has been applied.
37    ///
38    /// This function should only be called by `OffscreenEffect`
39    /// implementations, from within the `OffscreenEffectClass.paint_target`()
40    /// virtual function.
41    /// ## `rect`
42    /// return location for the target area
43    ///
44    /// # Returns
45    ///
46    /// `true` if the offscreen buffer has a valid rectangle,
47    ///  and `false` otherwise
48    fn get_target_rect(&self) -> Option<InternalRect>;
49
50    //fn get_texture(&self) -> /*Unimplemented*/Option<dx::Handle>;
51
52    /// Calls the `paint_target` virtual function of the `self`
53    fn paint_target(&self);
54}
55
56impl<O: IsA<OffscreenEffect>> OffscreenEffectExt for O {
57    //fn create_texture(&self, width: f32, height: f32) -> /*Unimplemented*/Option<dx::Handle> {
58    //    unsafe { TODO: call clutter_sys:clutter_offscreen_effect_create_texture() }
59    //}
60
61    // fn get_target(&self) -> Option<dx::Material> {
62    //     unsafe {
63    //         from_glib_none(ffi::clutter_offscreen_effect_get_target(
64    //             self.as_ref().to_glib_none().0,
65    //         ))
66    //     }
67    // }
68
69    fn get_target_rect(&self) -> Option<InternalRect> {
70        unsafe {
71            let mut rect = InternalRect::uninitialized();
72            let ret = from_glib(ffi::clutter_offscreen_effect_get_target_rect(
73                self.as_ref().to_glib_none().0,
74                rect.to_glib_none_mut().0,
75            ));
76            if ret {
77                Some(rect)
78            } else {
79                None
80            }
81        }
82    }
83
84    //fn get_texture(&self) -> /*Unimplemented*/Option<dx::Handle> {
85    //    unsafe { TODO: call clutter_sys:clutter_offscreen_effect_get_texture() }
86    //}
87
88    fn paint_target(&self) {
89        unsafe {
90            ffi::clutter_offscreen_effect_paint_target(self.as_ref().to_glib_none().0);
91        }
92    }
93}
94
95impl fmt::Display for OffscreenEffect {
96    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97        write!(f, "OffscreenEffect")
98    }
99}