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