[gnome-boxes] Remove deprecated clutter stuff from Revealer



commit e3e4c4562c66dbc063a90508cd90b845a0be12a1
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Jan 10 09:45:15 2013 +0100

    Remove deprecated clutter stuff from Revealer
    
    This switches from using direct "animate" calls to using implicit
    animations. Also, we animate the translation rather than the position
    of the items as this is unrelated to the allocation and thus avoids
    lots of resize calculations.
    
    We also use a new custom layout manager instead of the bin as binlayout
    allocates a smaller child when we change the height (if resize==true)
    rather than clipping it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691078

 src/revealer.vala |  142 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 91 insertions(+), 51 deletions(-)
---
diff --git a/src/revealer.vala b/src/revealer.vala
index a7a7465..2788400 100644
--- a/src/revealer.vala
+++ b/src/revealer.vala
@@ -1,9 +1,37 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 using Clutter;
 
+public class Boxes.RevealerLayout : Clutter.FixedLayout {
+    private bool horizontal;
+
+    public RevealerLayout (bool horizontal) {
+        this.horizontal = horizontal;
+    }
+
+    public override void allocate (Clutter.Container container, Clutter.ActorBox allocation, Clutter.AllocationFlags flags) {
+        foreach (var child in (container as Clutter.Actor).get_children ()) {
+            float width, height;
+            float availible_w, availible_h;
+
+            child.get_preferred_size (null, null, out width, out height);
+            allocation.get_size (out availible_w, out availible_h);
+
+            Clutter.ActorBox box = { 0, 0, width, height };
+
+            if (horizontal)
+                box.x2 = availible_w;
+            else
+                box.y2 = availible_h;
+
+            child.allocate (box, flags);
+        }
+    }
+}
+
 public class Boxes.Revealer: Clutter.Actor {
     private bool horizontal;
     private bool children_visible;
+    private string animation_prop;
     public uint duration;
     public bool resize;
 
@@ -27,21 +55,26 @@ public class Boxes.Revealer: Clutter.Actor {
 
     public Revealer (bool horizontal) {
         this.horizontal = horizontal;
+        if (horizontal)
+            animation_prop = "translation-y";
+        else
+            animation_prop = "translation-x";
         clip_to_allocation = true;
         children_visible = true;
         duration = 250;
 
-        if (horizontal) {
-            var layout = new Clutter.BinLayout (Clutter.BinAlignment.FILL,
-                                                Clutter.BinAlignment.FIXED);
-            this.set_layout_manager (layout);
-        } else {
-            var layout = new Clutter.BinLayout (Clutter.BinAlignment.FIXED,
-                                                Clutter.BinAlignment.FILL);
-            this.set_layout_manager (layout);
-        }
+        this.set_layout_manager (new RevealerLayout(horizontal));
+        if (horizontal)
+            this.x_expand = true;
+        else
+            this.y_expand = true;
 
         this.actor_added.connect ( (child) => {
+            if (horizontal)
+                child.x_align = Clutter.ActorAlign.FILL;
+            else
+                child.y_align = Clutter.ActorAlign.FILL;
+
             if (children_visible)
                 child.show ();
             else
@@ -49,6 +82,18 @@ public class Boxes.Revealer: Clutter.Actor {
         });
     }
 
+    private float get_child_size (Clutter.Actor child) {
+        if (horizontal) {
+            float height;
+            child.get_preferred_height (-1, null, out height);
+            return height;
+        } else {
+            float width;
+            child.get_preferred_width (-1, null, out width);
+            return width;
+        }
+    }
+
     public void reveal () {
         if (resize) {
             if (horizontal)
@@ -59,62 +104,45 @@ public class Boxes.Revealer: Clutter.Actor {
 
         var max = 0.0f;
         foreach (var child in get_children ()) {
-            if (!children_visible)
+            if (!children_visible) {
                 child.show ();
-            if (horizontal) {
-                if (!children_visible) {
-                    float height;
-                    child.get_preferred_height (-1, null, out height);
-                    child.y = -height;
-                    max = float.max (max, height);
-                }
-                child.animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "y", 0f);
-            } else {
-                if (!children_visible) {
-                    float width;
-                    child.get_preferred_width (-1, null, out width);
-                    child.x = -width;
-                    max = float.max (max, width);
-                }
-                child.animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "x", 0f);
+                var size = get_child_size (child);
+                max = float.max (max, size);
+                child.set (animation_prop, -size);
             }
+
+            child.save_easing_state ();
+            child.set_easing_duration (duration);
+             child.set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
+            child.set (animation_prop, 0.0f);
+            child.restore_easing_state ();
         }
 
         if (resize) {
+            save_easing_state ();
+            set_easing_mode (Clutter.AnimationMode.EASE_IN_QUAD);
+            set_easing_duration (duration);
             if (horizontal)
-                animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "height", max);
+                height = max;
             else
-                animate (Clutter.AnimationMode.EASE_IN_QUAD, duration, "width", max);
+                width = max;
+            restore_easing_state ();
         }
 
         children_visible = true;
     }
 
     private void unreveal_child (Clutter.Actor child) {
-        if (horizontal) {
-            float height;
-            child.get_preferred_height (-1, null, out height);
-            var anim = child.animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "y", -height);
-            anim.completed.connect (() => {
-                child.hide ();
-                children_visible = false;
-            });
-        } else {
-            float width;
-            child.get_preferred_width (-1, null, out width);
-            var anim = child.animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "x", -width);
-            anim.completed.connect (() => {
-                child.hide ();
-                children_visible = false;
-            });
-        }
+        child.save_easing_state ();
+        child.set_easing_duration (duration);
+        child.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
+        child.set (animation_prop, -get_child_size (child));
+        child.restore_easing_state ();
+        child.get_transition (animation_prop).stopped.connect (() => {
+            child.hide ();
+            children_visible = false;
+        });
 
-        if (resize) {
-            if (horizontal)
-                animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "height", 0.0f);
-            else
-                animate (Clutter.AnimationMode.EASE_OUT_QUAD, duration, "width", 0.0f);
-        }
     }
 
     public void unreveal () {
@@ -126,6 +154,18 @@ public class Boxes.Revealer: Clutter.Actor {
             found_child = true;
             unreveal_child (child);
         }
+
+        if (resize) {
+            save_easing_state ();
+            set_easing_duration (duration);
+            set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
+            if (horizontal)
+                height = 0.0f;
+            else
+                width = 0.0f;
+            restore_easing_state ();
+        }
+
         if (!found_child)
             children_visible = false;
     }



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