[glide] Add some basic support for editing geometry to the inspector



commit 7012e79f867f45c6e6acee8ce40dfe3547ab0ebc
Author: Robert Carr <racarr Valentine localdomain>
Date:   Sat May 1 23:14:42 2010 -0400

    Add some basic support for editing geometry to the inspector

 src/glide-inspector-actor-priv.h |    4 +++
 src/glide-inspector-actor.c      |   54 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 2 deletions(-)
---
diff --git a/src/glide-inspector-actor-priv.h b/src/glide-inspector-actor-priv.h
index cbc0ae7..085ab98 100644
--- a/src/glide-inspector-actor-priv.h
+++ b/src/glide-inspector-actor-priv.h
@@ -34,6 +34,10 @@ struct _GlideInspectorActorPrivate
   GtkWidget *y_spin;
   GtkWidget *width_spin;
   GtkWidget *height_spin;
+  
+  gulong allocation_changed_id;
+  
+  gboolean ignore_change;
 };
 
 G_END_DECLS
diff --git a/src/glide-inspector-actor.c b/src/glide-inspector-actor.c
index 20bb08a..75dc42f 100644
--- a/src/glide-inspector-actor.c
+++ b/src/glide-inspector-actor.c
@@ -33,6 +33,31 @@ enum {
 };
 
 static void
+glide_inspector_actor_apply_geometry (GlideInspectorActor *ins)
+{
+  gfloat width, height, x, y;
+  
+  width = gtk_spin_button_get_value (GTK_SPIN_BUTTON (ins->priv->width_spin));
+  height = gtk_spin_button_get_value (GTK_SPIN_BUTTON (ins->priv->height_spin));
+  x = gtk_spin_button_get_value (GTK_SPIN_BUTTON (ins->priv->x_spin));
+  y = gtk_spin_button_get_value (GTK_SPIN_BUTTON (ins->priv->y_spin));
+  
+  clutter_actor_set_position (CLUTTER_ACTOR (ins->priv->actor), x, y);
+  clutter_actor_set_size (CLUTTER_ACTOR (ins->priv->actor), width, height);
+}
+
+static void
+glide_inspector_actor_geometry_spin_changed (GtkWidget *spin,
+					     gpointer user_data)
+{
+  GlideInspectorActor *ins = (GlideInspectorActor *)user_data;
+  
+  if (ins->priv->ignore_change)
+    return;
+  glide_inspector_actor_apply_geometry (ins);
+}
+
+static void
 glide_inspector_actor_update_geometry (GlideInspectorActor *ins)
 {
   gfloat width, height;
@@ -40,11 +65,23 @@ glide_inspector_actor_update_geometry (GlideInspectorActor *ins)
   
   clutter_actor_get_size (CLUTTER_ACTOR (ins->priv->actor), &width, &height);
   clutter_actor_get_position (CLUTTER_ACTOR (ins->priv->actor), &x, &y);
-  
+
+  ins->priv->ignore_change = TRUE;
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (ins->priv->x_spin), x);
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (ins->priv->y_spin), y);
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (ins->priv->width_spin), width);
   gtk_spin_button_set_value (GTK_SPIN_BUTTON (ins->priv->height_spin), height);
+  ins->priv->ignore_change = FALSE;
+}
+
+static void
+glide_inspector_actor_allocation_changed (GObject *object,
+					  GParamSpec *pspec,
+					  gpointer user_data)
+{
+  GlideInspectorActor *ins = (GlideInspectorActor *)user_data;
+  
+  glide_inspector_actor_update_geometry (ins);
 }
 
 static void
@@ -124,6 +161,10 @@ glide_inspector_actor_make_geometry_control (GlideInspectorActor *ins, const gch
   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
   
   gtk_container_add (GTK_CONTAINER (ret),hbox);
+
+  g_signal_connect (button, "value-changed", G_CALLBACK (glide_inspector_actor_geometry_spin_changed),
+		    ins);
+
   return ret;
 }
 
@@ -248,8 +289,13 @@ glide_inspector_actor_get_actor (GlideInspectorActor *inspector)
 
 void
 glide_inspector_actor_set_actor (GlideInspectorActor *inspector,
-				   GlideActor *actor)
+				 GlideActor *actor)
 {
+  if (inspector->priv->allocation_changed_id)
+    {
+      g_signal_handler_disconnect (inspector->priv->actor, inspector->priv->allocation_changed_id);
+      inspector->priv->allocation_changed_id = 0;
+    }
   inspector->priv->actor = actor;
   
   if (GLIDE_IS_SLIDE (actor))
@@ -261,6 +307,10 @@ glide_inspector_actor_set_actor (GlideInspectorActor *inspector,
       gtk_widget_set_sensitive (GTK_WIDGET (inspector), TRUE);
       glide_inspector_actor_update_name (inspector);
       glide_inspector_actor_update_geometry (inspector);
+      
+      inspector->priv->allocation_changed_id = g_signal_connect (actor, "notify::allocation",
+								 G_CALLBACK (glide_inspector_actor_allocation_changed),
+								 inspector);
     }
   
   g_object_notify (G_OBJECT (inspector), "actor");



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