@@ -37,18 +37,28 @@ public class Gala.GesturePropertyTransition : Object {
3737 public Value to_value { get ; construct set ; }
3838
3939 /**
40- * If not null this can be used to have an intermediate step before animating back to the origin.
41- * Therefore using this makes mostly sense if {@link to_value} equals {@link from_value}.
42- * This is mostly used for the nudge animations when trying to switch workspaces where there isn't one anymore.
40+ * The lower max overshoot. The gesture percentage by which #this animates the property is bounded
41+ * by this property on the lower end. If it is in the form X.YY with Y not 0 the animation will be linear
42+ * until X and then take another 100% to animate until X.YY (instead of YY%).
43+ * Default is 0.
4344 */
44- public Value ? intermediate_value { get ; construct; }
45+ public double overshoot_lower_clamp { get ; set ; default = 0 ; }
46+ /**
47+ * Same as {@link overshoot_lower_clamp} but for the upper limit.
48+ * If this is less than 1 and the transition is started without a gesture it will animate to
49+ * the {@link to_value} by this percent and then back to the {@link from_value}.
50+ * Default is 1.
51+ */
52+ public double overshoot_upper_clamp { get ; set ; default = 1 ; }
4553
4654 /**
4755 * This is the from value that's actually used when calculating the animation movement.
4856 * If {@link from_value} isn't null this will be the same, otherwise it will be set to the current
4957 * value of the target property, when calling {@link start}.
5058 */
5159 private Value actual_from_value;
60+ private float from_value_float; // Only valid in the time between start () and finish ()
61+ private float to_value_float; // Only valid in the time between start () and finish ()
5262
5363 private DoneCallback ? done_callback;
5464
@@ -57,16 +67,14 @@ public class Gala.GesturePropertyTransition : Object {
5767 GestureTracker gesture_tracker,
5868 string property,
5969 Value ? from_value,
60- Value to_value,
61- Value ? intermediate_value = null
70+ Value to_value
6271 ) {
6372 Object (
6473 actor: actor,
6574 gesture_tracker: gesture_tracker,
6675 property: property,
6776 from_value: from_value,
68- to_value: to_value,
69- intermediate_value: intermediate_value
77+ to_value: to_value
7078 );
7179 }
7280
@@ -100,20 +108,44 @@ public class Gala.GesturePropertyTransition : Object {
100108 return ;
101109 }
102110
111+ // Pre calculate some things, so we don't have to do it on every update
112+ from_value_float = value_to_float (actual_from_value);
113+ to_value_float = value_to_float (to_value);
114+
103115 GestureTracker . OnBegin on_animation_begin = () = > {
104116 actor. set_property (property, actual_from_value);
105117 };
106118
107119 GestureTracker . OnUpdate on_animation_update = (percentage) = > {
108- var animation_value = GestureTracker . animation_value (value_to_float (actual_from_value), value_to_float (intermediate_value ?? to_value), percentage);
120+ var lower_clamp_int = (int ) overshoot_lower_clamp;
121+ var upper_clamp_int = (int ) overshoot_upper_clamp;
122+
123+ double stretched_percentage = 0 ;
124+ if (percentage < lower_clamp_int) {
125+ stretched_percentage = (percentage - lower_clamp_int) * - (overshoot_lower_clamp - lower_clamp_int);
126+ } else if (percentage > upper_clamp_int) {
127+ stretched_percentage = (percentage - upper_clamp_int) * (overshoot_upper_clamp - upper_clamp_int);
128+ }
129+
130+ percentage = percentage. clamp (lower_clamp_int, upper_clamp_int);
131+
132+ var animation_value = GestureTracker . animation_value (from_value_float, to_value_float, percentage, false );
133+
134+ if (stretched_percentage != 0 ) {
135+ animation_value + = (float ) stretched_percentage * (to_value_float - from_value_float);
136+ }
137+
109138 actor. set_property (property, value_from_float (animation_value));
110139 };
111140
112- GestureTracker . OnEnd on_animation_end = (percentage, cancel_action, calculated_duration) = > {
141+ GestureTracker . OnEnd on_animation_end = (percentage, completions, calculated_duration) = > {
142+ completions = completions. clamp ((int ) overshoot_lower_clamp, (int ) overshoot_upper_clamp);
143+ var target_value = from_value_float + completions * (to_value_float - from_value_float);
144+
113145 actor. save_easing_state ();
114146 actor. set_easing_mode (EASE_OUT_QUAD );
115147 actor. set_easing_duration (AnimationsSettings . get_animation_duration (calculated_duration));
116- actor. set_property (property, cancel_action ? actual_from_value : to_value );
148+ actor. set_property (property, value_from_float (target_value) );
117149 actor. restore_easing_state ();
118150
119151 unowned var transition = actor. get_transition (property);
@@ -128,21 +160,21 @@ public class Gala.GesturePropertyTransition : Object {
128160 gesture_tracker. connect_handlers (on_animation_begin, on_animation_update, on_animation_end);
129161 } else {
130162 on_animation_begin (0 );
131- if (intermediate_value != null ) {
163+ if (overshoot_upper_clamp < 1 ) {
132164 actor. save_easing_state ();
133165 actor. set_easing_mode (EASE_OUT_QUAD );
134166 actor. set_easing_duration (AnimationsSettings . get_animation_duration (gesture_tracker. min_animation_duration));
135- actor. set_property (property, intermediate_value );
167+ actor. set_property (property, value_from_float (( float ) overshoot_upper_clamp * (to_value_float - from_value_float) + from_value_float) );
136168 actor. restore_easing_state ();
137169
138170 unowned var transition = actor. get_transition (property);
139171 if (transition == null ) {
140- on_animation_end (1 , false , gesture_tracker. min_animation_duration);
172+ on_animation_end (1 , 1 , gesture_tracker. min_animation_duration);
141173 } else {
142- transition. stopped. connect (() = > on_animation_end (1 , false , gesture_tracker. min_animation_duration));
174+ transition. stopped. connect (() = > on_animation_end (1 , 1 , gesture_tracker. min_animation_duration));
143175 }
144176 } else {
145- on_animation_end (1 , false , gesture_tracker. min_animation_duration);
177+ on_animation_end (1 , 1 , gesture_tracker. min_animation_duration);
146178 }
147179 }
148180 }
0 commit comments