From 339797dbb45ab5ea34f71d4b1df2a542e47e2738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sat, 10 Jun 2017 02:52:12 +0200 Subject: [PATCH] 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(). https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/22 --- js/ui/environment.js | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/js/ui/environment.js b/js/ui/environment.js index eeae4bce8..4f28c9c30 100644 --- a/js/ui/environment.js +++ b/js/ui/environment.js @@ -63,6 +63,54 @@ function _adjustEasingTime(msecs) { return St.get_slow_down_factor() * msecs; } +function _easeActor(actor, props, easingParams) { + let { duration, delay, mode, + onStopped, onUpdate, onComplete } = 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); + + actor.set(props); + + if (onUpdate || onComplete || onStopped) { + let transition = actor.get_transition(animatedProps[0]); + + if (transition) { + let updateId = 0; + if (onUpdate) + updateId = transition.connect('new-frame', onUpdate); + + let id = transition.connect('stopped', isFinished => { + if (updateId != 0) + transition.disconnect(updateId); + transition.disconnect(id); + + if (onComplete) + onComplete(); + if (onStopped) + onStopped(isFinished); + }); + } else { + if (onComplete) + onComplete(); + if (onStopped) + onStopped(true); + } + } + + actor.restore_easing_state(); +} + function _loggingFunc() { let fields = {'MESSAGE': [].join.call(arguments, ', ')}; let domain = "GNOME Shell"; @@ -108,6 +156,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); };