|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: LGPL-3.0-or-later |
| 3 | + * SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io) |
| 4 | + */ |
| 5 | + |
| 6 | +public class Gala.PropertyAnimator : Object { |
| 7 | + public struct AnimatableProperty { |
| 8 | + string property; |
| 9 | + Type value_type; |
| 10 | + Value? from_value; |
| 11 | + Value target_value; |
| 12 | + } |
| 13 | + |
| 14 | + public delegate void OnStopped (Clutter.Actor actor); |
| 15 | + |
| 16 | + private Clutter.Actor actor; |
| 17 | + private OnStopped on_stopped; |
| 18 | + |
| 19 | + public PropertyAnimator ( |
| 20 | + Clutter.Actor actor, |
| 21 | + uint duration, |
| 22 | + Clutter.AnimationMode animation_mode, |
| 23 | + AnimatableProperty[] properties, |
| 24 | + OnStopped on_stopped |
| 25 | + ) { |
| 26 | + this.actor = actor; |
| 27 | + this.on_stopped = on_stopped; |
| 28 | + |
| 29 | + ref (); |
| 30 | + |
| 31 | + if (!Meta.Prefs.get_gnome_animations ()) { |
| 32 | + call_on_stopped (); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + for (var i = 0; i < properties.length; i++) { |
| 37 | + var property = properties[i]; |
| 38 | + |
| 39 | + Value actor_current_property = {}; |
| 40 | + actor.get_property (property.property, ref actor_current_property); |
| 41 | + |
| 42 | + var transition = new Clutter.PropertyTransition (property.property) { |
| 43 | + progress_mode = animation_mode, |
| 44 | + remove_on_complete = true, |
| 45 | + duration = duration, |
| 46 | + interval = new Clutter.Interval.with_values ( |
| 47 | + property.value_type, |
| 48 | + property.from_value ?? actor_current_property, |
| 49 | + property.target_value |
| 50 | + ) |
| 51 | + }; |
| 52 | + |
| 53 | + if (i == 0) { |
| 54 | + transition.stopped.connect (call_on_stopped); |
| 55 | + } |
| 56 | + |
| 57 | + actor.add_transition (property.property, transition); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + private void call_on_stopped () { |
| 62 | + on_stopped (actor); |
| 63 | + unref (); |
| 64 | + } |
| 65 | +} |
0 commit comments