[glide] More inspector



commit f895acc4dc977b4b1dc03d469e4499f7c895df3c
Author: Robert Carr <racarr Valentine localdomain>
Date:   Sun May 2 00:30:50 2010 -0400

    More inspector

 src/glide-gtk-util.c             |    8 +++
 src/glide-gtk-util.h             |    2 +
 src/glide-inspector-actor-priv.h |    3 +
 src/glide-inspector-actor.c      |  112 ++++++++++++++++++++++++++++++++++++--
 4 files changed, 120 insertions(+), 5 deletions(-)
---
diff --git a/src/glide-gtk-util.c b/src/glide-gtk-util.c
index 49d81d5..cb683e0 100644
--- a/src/glide-gtk-util.c
+++ b/src/glide-gtk-util.c
@@ -136,3 +136,11 @@ glide_gtk_util_show_error_dialog (const gchar *text,
   
   return d;
 }
+
+#define SMALL_FONT_RC "style \"small-font\" {font_name = \"Sans 10\"} widget \"*\" style \"small-font\""
+
+void
+glide_gtk_util_set_widget_font_small (GtkWidget *w)
+{
+  gtk_widget_modify_font (w, pango_font_description_from_string ("Sans 8"));
+}
diff --git a/src/glide-gtk-util.h b/src/glide-gtk-util.h
index cebb969..5793061 100644
--- a/src/glide-gtk-util.h
+++ b/src/glide-gtk-util.h
@@ -34,5 +34,7 @@ void glide_clutter_color_from_gdk_color (GdkColor *c, ClutterColor *cc);
 
 GtkWidget * glide_gtk_util_show_error_dialog (const gchar *text, const gchar *secondary);
 
+void glide_gtk_util_set_widget_font_small (GtkWidget *w);
+
 
 #endif
diff --git a/src/glide-inspector-actor-priv.h b/src/glide-inspector-actor-priv.h
index 085ab98..ce39c02 100644
--- a/src/glide-inspector-actor-priv.h
+++ b/src/glide-inspector-actor-priv.h
@@ -35,6 +35,9 @@ struct _GlideInspectorActorPrivate
   GtkWidget *width_spin;
   GtkWidget *height_spin;
   
+  GtkWidget *centerh_button;
+  GtkWidget *centerv_button;
+  
   gulong allocation_changed_id;
   
   gboolean ignore_change;
diff --git a/src/glide-inspector-actor.c b/src/glide-inspector-actor.c
index 79f4a8d..ab833b5 100644
--- a/src/glide-inspector-actor.c
+++ b/src/glide-inspector-actor.c
@@ -21,7 +21,12 @@
 
 #include "glide-slide.h"
 
+#include "glide-undo-manager.h"
+
+#include "glide-gtk-util.h"
+
 #include <string.h>
+#include <math.h>
 
 #define GLIDE_INSPECTOR_ACTOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GLIDE_TYPE_INSPECTOR_ACTOR, GlideInspectorActorPrivate))
 
@@ -33,6 +38,60 @@ enum {
 };
 
 static void
+glide_inspector_actor_get_center_pos (ClutterActor *actor, 
+				      gfloat *x,
+				      gfloat *y)
+{
+  ClutterActor *parent = clutter_actor_get_stage (actor);
+  gfloat p_width, p_height, width, height;
+  
+  clutter_actor_get_size (parent, &p_width, &p_height);
+  clutter_actor_get_size (actor, &width, &height);
+  
+  *x = floor(p_width/2.0 - width/2.0);
+  *y = floor(p_height/2.0 - height/2.0);
+}
+
+static void
+glide_inspector_actor_update_center_button_sensitive (GlideInspectorActor *ins)
+{
+  gfloat cx, cy, ax, ay;
+  
+  clutter_actor_get_position (CLUTTER_ACTOR (ins->priv->actor), &ax, &ay);
+  glide_inspector_actor_get_center_pos (CLUTTER_ACTOR (ins->priv->actor), &cx, &cy);
+  
+  gtk_widget_set_sensitive (ins->priv->centerh_button, TRUE);
+  gtk_widget_set_sensitive (ins->priv->centerv_button, TRUE);
+  
+  if (cx == ax)
+    gtk_widget_set_sensitive (ins->priv->centerh_button, FALSE);
+  if (cy == ay)
+    gtk_widget_set_sensitive (ins->priv->centerv_button, FALSE);
+}
+
+static void
+glide_inspector_actor_center_horizontally (GtkWidget *button,
+					   gpointer user_data)
+{
+  GlideInspectorActor *ins = (GlideInspectorActor *)user_data;
+  gfloat x, y;
+  
+  glide_inspector_actor_get_center_pos (CLUTTER_ACTOR (ins->priv->actor), &x, &y);
+  clutter_actor_set_x (CLUTTER_ACTOR (ins->priv->actor), x);
+}
+
+static void
+glide_inspector_actor_center_vertically (GtkWidget *button,
+					 gpointer user_data)
+{
+  GlideInspectorActor *ins = (GlideInspectorActor *)user_data;
+  gfloat x, y;
+  
+  glide_inspector_actor_get_center_pos (CLUTTER_ACTOR (ins->priv->actor), &x, &y);
+  clutter_actor_set_y (CLUTTER_ACTOR (ins->priv->actor), y);
+}
+
+static void
 glide_inspector_actor_apply_geometry (GlideInspectorActor *ins)
 {
   gfloat width, height, x, y;
@@ -81,6 +140,7 @@ glide_inspector_actor_allocation_changed (GObject *object,
 {
   GlideInspectorActor *ins = (GlideInspectorActor *)user_data;
   
+  glide_inspector_actor_update_center_button_sensitive (ins);
   glide_inspector_actor_update_geometry (ins);
 }
 
@@ -153,6 +213,8 @@ glide_inspector_actor_make_geometry_control (GlideInspectorActor *ins, const gch
   // TODO: Range
   GtkWidget *button = gtk_spin_button_new_with_range(0,1000,1);
   
+  glide_gtk_util_set_widget_font_small (button);
+  
   *privloc = button;
 
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
@@ -172,20 +234,23 @@ glide_inspector_actor_make_geometry_controls (GlideInspectorActor *ins)
 {
   GtkWidget *ret = gtk_alignment_new (0.5,0,0.9,1);
   GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
-  GtkWidget *hbox1;
+  GtkWidget *hbox1, *hbox2;
   
-  hbox1 = gtk_hbox_new (FALSE, 5);
+  hbox1 = gtk_hbox_new (TRUE, 5);
+  hbox2 = gtk_hbox_new (TRUE, 5);
   
   gtk_box_pack_start (GTK_BOX (hbox1), glide_inspector_actor_make_geometry_control (ins, "x:", &ins->priv->x_spin),
 		      TRUE, TRUE, 0);
   gtk_box_pack_start (GTK_BOX (hbox1), glide_inspector_actor_make_geometry_control (ins, "y:", &ins->priv->y_spin),
 		      TRUE, TRUE, 0);
   
-  gtk_box_pack_start (GTK_BOX (vbox), hbox1, FALSE, FALSE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), glide_inspector_actor_make_geometry_control (ins, "Width:", &ins->priv->width_spin),
+
+  gtk_box_pack_start (GTK_BOX (hbox2), glide_inspector_actor_make_geometry_control (ins, "Width:", &ins->priv->width_spin),
 		      TRUE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX (vbox), glide_inspector_actor_make_geometry_control (ins, "Height:", &ins->priv->height_spin),
+  gtk_box_pack_start (GTK_BOX (hbox2), glide_inspector_actor_make_geometry_control (ins, "Height:", &ins->priv->height_spin),
 		      TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox1, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
   
   
   gtk_container_add (GTK_CONTAINER (ret), vbox);
@@ -229,15 +294,52 @@ glide_inspector_actor_make_name_box (GlideInspectorActor *ins)
   return ret;
 }
 
+static GtkWidget *
+glide_inspector_actor_make_center_box (GlideInspectorActor *ins)
+{
+  GtkWidget *ret = gtk_hbox_new (FALSE, 0);
+  GtkWidget *center_label = gtk_label_new (NULL);
+  GtkWidget *button_box = gtk_hbox_new (TRUE, 0);
+  GtkWidget *alignment = gtk_alignment_new (0.5,0,1,1);
+  GtkWidget *hori = gtk_button_new_with_label ("Horizontally");
+  GtkWidget *vert = gtk_button_new_with_label ("Vertically");
+  
+  gtk_button_set_relief (GTK_BUTTON (hori), GTK_RELIEF_NONE);
+  gtk_button_set_relief (GTK_BUTTON (vert), GTK_RELIEF_NONE);
+  
+  glide_gtk_util_set_widget_font_small (gtk_bin_get_child (GTK_BIN (hori)));
+  glide_gtk_util_set_widget_font_small (gtk_bin_get_child (GTK_BIN (vert)));
+  
+  gtk_label_set_markup (GTK_LABEL (center_label), "<b>Center: </b>");
+
+  gtk_box_pack_start (GTK_BOX (button_box), hori, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (button_box), vert, FALSE, FALSE, 0);
+  
+  gtk_container_add (GTK_CONTAINER (alignment), button_box);
+  
+  gtk_box_pack_start (GTK_BOX (ret), center_label, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (ret), alignment, TRUE, FALSE, 0);
+  
+  g_signal_connect (hori, "clicked", G_CALLBACK (glide_inspector_actor_center_horizontally), ins);
+  g_signal_connect (vert, "clicked", G_CALLBACK (glide_inspector_actor_center_vertically), ins);
+
+  ins->priv->centerh_button = hori;
+  ins->priv->centerv_button = vert;
+
+  return ret;
+}
+
 static void
 glide_inspector_actor_setup_ui (GlideInspectorActor *ins)
 {
   GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
   GtkWidget *name_box = glide_inspector_actor_make_name_box (ins);
   GtkWidget *geometry_box = glide_inspector_actor_make_geometry_box (ins);
+  GtkWidget *center_box = glide_inspector_actor_make_center_box (ins);
   
   gtk_box_pack_start (GTK_BOX (vbox), name_box, FALSE, FALSE, 2);
   gtk_box_pack_start (GTK_BOX (vbox), geometry_box, FALSE, FALSE, 2);
+  gtk_box_pack_start (GTK_BOX (vbox), center_box, FALSE, FALSE, 2);
   
   gtk_container_add (GTK_CONTAINER (ins), vbox);
 }



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