clutter/auto/effect.rs
1use crate::ActorMeta;
2use glib::{object as gobject, object::IsA, translate::*};
3use std::fmt;
4
5glib_wrapper! {
6 pub struct Effect(Object<ffi::ClutterEffect, ffi::ClutterEffectClass, EffectClass>) @extends ActorMeta, gobject::InitiallyUnowned;
7
8 match fn {
9 get_type => || ffi::clutter_effect_get_type(),
10 }
11}
12
13pub const NONE_EFFECT: Option<&Effect> = None;
14
15/// Trait containing all `Effect` methods.
16///
17/// # Implementors
18///
19/// [`Effect`](struct.Effect.html), [`OffscreenEffect`](struct.OffscreenEffect.html)
20pub trait EffectExt: 'static {
21 /// Queues a repaint of the effect. The effect can detect when the ‘paint’
22 /// method is called as a result of this function because it will not
23 /// have the `EffectPaintFlags::ActorDirty` flag set. In that case the
24 /// effect is free to assume that the actor has not changed its
25 /// appearance since the last time it was painted so it doesn't need to
26 /// call `ActorExt::continue_paint` if it can draw a cached
27 /// image. This is mostly intended for effects that are using a
28 /// `cogl::Offscreen` to redirect the actor (such as
29 /// `OffscreenEffect`). In that case the effect can save a bit of
30 /// rendering time by painting the cached texture without causing the
31 /// entire actor to be painted.
32 ///
33 /// This function can be used by effects that have their own animatable
34 /// parameters. For example, an effect which adds a varying degree of a
35 /// red tint to an actor by redirecting it through a CoglOffscreen
36 /// might have a property to specify the level of tint. When this value
37 /// changes, the underlying actor doesn't need to be redrawn so the
38 /// effect can call `EffectExt::queue_repaint` to make sure the
39 /// effect is repainted.
40 ///
41 /// Note however that modifying the position of the parent of an actor
42 /// may change the appearance of the actor because its transformation
43 /// matrix would change. In this case a redraw wouldn't be queued on
44 /// the actor itself so the `EffectPaintFlags::ActorDirty` would still
45 /// not be set. The effect can detect this case by keeping track of the
46 /// last modelview matrix that was used to render the actor and
47 /// veryifying that it remains the same in the next paint.
48 ///
49 /// Any other effects that are layered on top of the passed in effect
50 /// will still be passed the `EffectPaintFlags::ActorDirty` flag. If
51 /// anything queues a redraw on the actor without specifying an effect
52 /// or with an effect that is lower in the chain of effects than this
53 /// one then that will override this call. In that case this effect
54 /// will instead be called with the `EffectPaintFlags::ActorDirty`
55 /// flag set.
56 fn queue_repaint(&self);
57}
58
59impl<O: IsA<Effect>> EffectExt for O {
60 fn queue_repaint(&self) {
61 unsafe {
62 ffi::clutter_effect_queue_repaint(self.as_ref().to_glib_none().0);
63 }
64 }
65}
66
67impl fmt::Display for Effect {
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
69 write!(f, "Effect")
70 }
71}