[baobab/animated-notebook: 4/4] Add a cross-fade effect when changing toolbars



commit bf552362e4072f81ae0952f249882efb8b22dc42
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Sun Oct 21 21:15:29 2012 +0200

    Add a cross-fade effect when changing toolbars

 configure.ac                        |    2 +-
 src/Makefile.am                     |    1 +
 src/baobab-cross-fade-notebook.vala |   60 +++++++++++++++++++++++++++++++++++
 src/baobab-main-window.ui           |   43 ++++++++++++++----------
 src/baobab-window.vala              |    7 ++--
 src/fixes.vapi                      |    4 ++
 6 files changed, 95 insertions(+), 22 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8164369..f4b2746 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ YELP_HELP_INIT
 
 PKG_CHECK_MODULES(BAOBAB, [
     gtk+-3.0 >= 3.5.9
-    clutter-gtk-1.0
+    clutter-gtk-1.0 >= 1.4
     gio-2.0 >= 2.30.0
 ])
 
diff --git a/src/Makefile.am b/src/Makefile.am
index cc5f4cb..1c5d54c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ VALA_SOURCES = \
 	baobab-application.vala		\
 	baobab-cellrenderers.vala	\
 	baobab-connect-server.vala	\
+	baobab-cross-fade-notebook.vala	\
 	baobab-location.vala		\
 	baobab-location-list.vala	\
 	baobab-location-widget.vala	\
diff --git a/src/baobab-cross-fade-notebook.vala b/src/baobab-cross-fade-notebook.vala
new file mode 100644
index 0000000..c1f82c6
--- /dev/null
+++ b/src/baobab-cross-fade-notebook.vala
@@ -0,0 +1,60 @@
+/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+namespace Baobab {
+
+    public class CrossFadeNotebook : Gtk.Grid, Gtk.Buildable {
+
+        Gtk.Widget current_page = null;
+        GtkClutter.Embed embed;
+
+        construct {
+            embed = new GtkClutter.Embed ();
+            add (embed);
+            embed.show ();
+
+            vexpand = false;
+            hexpand = false;
+
+            GtkClutter.embed_set_use_layout_size (embed, true);
+            var stage = embed.get_stage ();
+            stage.set_layout_manager (new Clutter.BinLayout (Clutter.BinAlignment.FILL, Clutter.BinAlignment.FILL));
+        }
+
+        public void add_page (Gtk.Widget widget) {
+            var actor = new GtkClutter.Actor.with_contents (widget);
+            widget.set_data ("clutter_actor", actor);
+            embed.get_stage ().add_child (actor);
+
+            select_page (widget);
+        }
+
+        public void select_page (Gtk.Widget widget) {
+            if (current_page == widget) {
+                return;
+            }
+
+            if (current_page != null) {
+                var cur_actor = current_page.get_data<Clutter.Actor> ("clutter_actor");
+                cur_actor.reactive = false;
+                cur_actor.save_easing_state ();
+                cur_actor.set_easing_duration (500);
+                cur_actor.opacity = 0;
+                cur_actor.restore_easing_state ();
+            }
+
+            var actor = widget.get_data<Clutter.Actor> ("clutter_actor");
+            actor.reactive = true;
+            actor.save_easing_state ();
+            actor.set_easing_duration (500);
+            actor.opacity = 0xff;
+            actor.restore_easing_state ();
+
+            current_page = widget;
+        }
+
+        // GtkBuildable interface
+
+        public void add_child (Gtk.Builder builder, Object child, string? type) {
+            add_page (child as Gtk.Widget);
+        }
+    }
+}
diff --git a/src/baobab-main-window.ui b/src/baobab-main-window.ui
index 0b4d6e5..d0e71d8 100644
--- a/src/baobab-main-window.ui
+++ b/src/baobab-main-window.ui
@@ -17,25 +17,32 @@
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <child>
-      <object class="GdMainToolbar" id="home-toolbar">
+      <object class="BaobabCrossFadeNotebook" id="toolbar-notebook">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="vexpand">False</property>
-        <style>
-          <class name="menubar"/>
-          <class name="baobab-toolbar"/>
-        </style>
-      </object>
-    </child>
-    <child>
-      <object class="GdMainToolbar" id="result-toolbar">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="vexpand">False</property>
-        <style>
-          <class name="menubar"/>
-          <class name="baobab-toolbar"/>
-        </style>
+        <child>
+          <object class="GdMainToolbar" id="home-toolbar">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="vexpand">False</property>
+            <property name="hexpand">True</property>
+            <style>
+              <class name="menubar"/>
+              <class name="baobab-toolbar"/>
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GdMainToolbar" id="result-toolbar">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="vexpand">False</property>
+            <property name="hexpand">True</property>
+            <style>
+              <class name="menubar"/>
+              <class name="baobab-toolbar"/>
+            </style>
+          </object>
+        </child>
       </object>
     </child>
     <child>
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 55a11c2..2445d2a 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -27,6 +27,7 @@ namespace Baobab {
         Cc.Notebook main_notebook;
         Gtk.Grid home_page;
         Gtk.Grid result_page;
+        CrossFadeNotebook toolbar_notebook;
         Gd.MainToolbar home_toolbar;
         Gd.MainToolbar result_toolbar;
         Gtk.InfoBar infobar;
@@ -112,6 +113,7 @@ namespace Baobab {
 
             // Cache some objects from the builder.
             main_notebook = builder.get_object ("main-notebook") as Cc.Notebook;
+            toolbar_notebook = builder.get_object ("toolbar-notebook") as CrossFadeNotebook;
             home_page = builder.get_object ("home-page") as Gtk.Grid;
             result_page = builder.get_object ("result-page") as Gtk.Grid;
             infobar = builder.get_object ("infobar") as Gtk.InfoBar;
@@ -492,20 +494,19 @@ namespace Baobab {
         }
 
         void set_ui_state (UIPage page, bool busy) {
-            home_toolbar.visible = (page == UIPage.HOME);
-            result_toolbar.visible = (page == UIPage.RESULT);
-
             set_busy (busy);
 
             if (page == UIPage.HOME) {
                 var action = lookup_action ("reload") as SimpleAction;
                 action.set_enabled (false);
                 main_notebook.select_page (home_page, true);
+                toolbar_notebook.select_page (home_toolbar);
             } else {
                 var action = lookup_action ("reload") as SimpleAction;
                 action.set_enabled (true);
                 result_toolbar.set_labels (active_location.name, null);
                 main_notebook.select_page (result_page, true);
+                toolbar_notebook.select_page (result_toolbar);
             }
         }
 
diff --git a/src/fixes.vapi b/src/fixes.vapi
index 66c0bba..079dcff 100644
--- a/src/fixes.vapi
+++ b/src/fixes.vapi
@@ -6,3 +6,7 @@ namespace GLib2 {
 		public void* join ();
 	}
 }
+
+namespace GtkClutter {
+	public void embed_set_use_layout_size (Embed embed, bool use_layout_size);
+}



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