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