[gnome-shell/wip/fmuellner/ease-actors: 3/6] environment: Patch in some implicit animation convenience



commit 275749198eba8e04ba962313fcae324c0a9b6dfb
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jun 10 02:52:12 2017 +0200

    environment: Patch in some implicit animation convenience
    
    Setting up implicit animations is more verbose than using tweener, in
    particular when setting up callbacks to run on update or completion.
    In order to make its use more convenient, monkey-patch ClutterActor
    with an ease() method that works similarly to Tweener.addTween().

 js/ui/environment.js | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
---
diff --git a/js/ui/environment.js b/js/ui/environment.js
index a3a0623d4..f3b63becd 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -69,6 +69,42 @@ function _adjustEasingTime(msecs) {
     return St.get_slow_down_factor() * msecs;
 }
 
+function _easeActor(actor, props, easingParams) {
+    let { duration, delay, mode, onStopped, onUpdate } = easingParams;
+
+    let animatedProps = Object.keys(props).map(p => p.replace('_', '-', 'g'));
+
+    actor.save_easing_state();
+
+    if (duration)
+        actor.set_easing_duration(duration);
+
+    if (delay)
+        actor.set_easing_delay(delay);
+
+    if (mode)
+        actor.set_easing_mode(mode);
+
+    Object.assign(actor, props);
+
+    let transition = actor.get_transition(animatedProps[0]);
+
+    if (onUpdate && transition)
+        transition.connect('new-frame', onUpdate);
+
+    if (onStopped) {
+        // Use getter instead of easingParams.duration for adjusted time
+        if (!actor.mapped || !actor.get_easing_duration())
+            onStopped(true);
+        else if (transition)
+            transition.connect('stopped', function(t, isFinished) {
+                onStopped(isFinished);
+            });
+    }
+
+    actor.restore_easing_state();
+}
+
 function _loggingFunc() {
     let fields = {'MESSAGE': [].join.call(arguments, ', ')};
     let domain = "GNOME Shell";
@@ -114,6 +150,10 @@ function init() {
         origSetEasingDelay.call(this, _adjustEasingTime(msecs));
     };
 
+    Clutter.Actor.prototype.ease = function(props, easingParams) {
+        _easeActor(this, props, easingParams);
+    };
+
     Clutter.Actor.prototype.toString = function() {
         return St.describe_actor(this);
     };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]