[gitg] Only animate panes when gtk_enable_animations is set



commit f7275d2603bf766e2e464f407dd9e31583c2b636
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sat Aug 1 14:03:46 2015 +0200

    Only animate panes when gtk_enable_animations is set

 gitg/gitg-animated-paned.vala        |   53 +++++++++++++++++++++++++++-------
 gitg/history/gitg-history-paned.vala |   19 +++++++----
 2 files changed, 54 insertions(+), 18 deletions(-)
---
diff --git a/gitg/gitg-animated-paned.vala b/gitg/gitg-animated-paned.vala
index 91321f0..358de5d 100644
--- a/gitg/gitg-animated-paned.vala
+++ b/gitg/gitg-animated-paned.vala
@@ -51,17 +51,10 @@ public class AnimatedPaned : Gtk.Paned
                default = 250;
        }
 
-       private bool on_animate_step(Gtk.Widget widget, Gdk.FrameClock clock)
+       private bool update_position(double factor)
        {
-               var elapsed = (clock.get_frame_time() - d_slide_start);
-               var factor = (double)elapsed / (double)d_slide_duration;
-
-               if (factor > 1)
-               {
-                       factor = 1;
-               }
-
                var pos = (int)Math.round((d_target_pos - d_start_pos) * factor) + d_start_pos;
+
                set_position(pos);
                queue_draw();
 
@@ -92,6 +85,21 @@ public class AnimatedPaned : Gtk.Paned
                return true;
        }
 
+       private bool on_animate_step(Gtk.Widget widget, Gdk.FrameClock clock)
+       {
+               var elapsed = (clock.get_frame_time() - d_slide_start);
+               var factor = (double)elapsed / (double)d_slide_duration;
+
+               if (!update_position(Math.fmin(factor, 1)))
+               {
+                       d_tick_id = 0;
+                       notify_property("is-animating");
+                       return false;
+               }
+
+               return true;
+       }
+
        public override void dispose()
        {
                if (d_tick_id != 0)
@@ -119,6 +127,8 @@ public class AnimatedPaned : Gtk.Paned
        private async void slide_async(SlidePanedChild child,
                                       SlideDirection  direction)
        {
+               var should_animate = get_settings().gtk_enable_animations;
+
                if (d_tick_id == 0)
                {
                        if (direction == SlideDirection.OUT)
@@ -126,7 +136,17 @@ public class AnimatedPaned : Gtk.Paned
                                d_original_pos = get_position();
                        }
 
-                       d_tick_id = add_tick_callback(on_animate_step);
+                       if (should_animate)
+                       {
+                               d_tick_id = add_tick_callback(on_animate_step);
+                               notify_property("is-animating");
+                       }
+               }
+               else if (d_tick_id != 0 && !should_animate)
+               {
+                       remove_tick_callback(d_tick_id);
+                       d_tick_id = 0;
+                       notify_property("is-animating");
                }
 
                d_slide_start = get_frame_clock().get_frame_time();
@@ -181,7 +201,18 @@ public class AnimatedPaned : Gtk.Paned
                }
 
                d_async_callback = slide_async.callback;
-               d_slide_duration = (int64)(factor * transition_duration) * 1000;
+
+               if (should_animate)
+               {
+                       d_slide_duration = (int64)(factor * transition_duration) * 1000;
+               }
+               else
+               {
+                       Idle.add(() => {
+                               update_position(1);
+                               return false;
+                       });
+               }
 
                yield;
        }
diff --git a/gitg/history/gitg-history-paned.vala b/gitg/history/gitg-history-paned.vala
index e99b014..7453aae 100644
--- a/gitg/history/gitg-history-paned.vala
+++ b/gitg/history/gitg-history-paned.vala
@@ -236,15 +236,20 @@ class Paned : Gitg.AnimatedPaned
                var w = position + hw;
                var h = alloc.height + d_box_sidebar.spacing + d_stack_switcher_panels.margin_bottom;
 
-               int wx;
-               window.get_position(out wx, null);
-
-               c.render_frame(context, wx, y, w, h);
+               if (window != null)
+               {
+                       int wx;
+                       window.get_position(out wx, null);
+                       c.render_frame(context, wx, y, w, h);
+               }
 
-               int hx;
-               handlewin.get_position(out hx, null);
+               if (handlewin != null)
+               {
+                       int hx;
+                       handlewin.get_position(out hx, null);
 
-               c.render_background(context, hx, y, hw, h);
+                       c.render_background(context, hx, y, hw, h);
+               }
 
                c.restore();
 



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