[gimp/soc-2011-gimpunitentry] GimpUnitEntry: add preliminary support for entering units



commit bf31f336ae26089cbebac11458ff9f00ce54e549
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Sun Jun 19 17:12:13 2011 +0200

    GimpUnitEntry: add preliminary support for entering units
    
    Adds a preliminary resolution input mode. Parsing is disabled for that mode, the user can just enter a number which is interpreted as a resolution. It needs to be discussed if that solution is sufficient.

 libgimpwidgets/gimpunitentry.c |   33 ++++++++++++++++++++++++++++++---
 libgimpwidgets/gimpunitentry.h |    9 +++++----
 libgimpwidgets/gimpwidgets.def |    1 +
 3 files changed, 36 insertions(+), 7 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitentry.c b/libgimpwidgets/gimpunitentry.c
index d16644e..43468ed 100644
--- a/libgimpwidgets/gimpunitentry.c
+++ b/libgimpwidgets/gimpunitentry.c
@@ -103,7 +103,8 @@ gimp_unit_entry_init (GimpUnitEntry *unitEntry)
                                   GTK_ADJUSTMENT (adjustment));
 
   /* some default values */
-  unitEntry->dontUpdateText = FALSE;                                 
+  unitEntry->dontUpdateText = FALSE;  
+  unitEntry->resMode        = FALSE;                               
 
   /* connect signals */
   /* we don't need all of them... */
@@ -241,7 +242,17 @@ on_output (GtkSpinButton *spin, gpointer data)
   }
   
   /* set text of the entry */
-  text = gimp_unit_adjustment_to_string (adj);
+  if (!entry->resMode)
+  {
+    text = gimp_unit_adjustment_to_string (adj);
+  }
+  else
+  {
+    text = g_malloc (30 * sizeof (gchar));
+    sprintf (text, "%.1f px/%s", 
+             gimp_unit_adjustment_get_value (adj),
+             gimp_unit_get_abbreviation (gimp_unit_adjustment_get_unit (adj)));
+  }
 
   DEBUG (("on_output: %s\n", text);)
 
@@ -270,12 +281,15 @@ void on_text_changed (GtkEditable *editable, gpointer user_data)
 
   DEBUG (("on_text_changed\n");)
 
+  if (!entry->resMode)
+  {
   /* disable updating the displayed text (user input must not be overwriten) */
   entry->dontUpdateText = TRUE;
   /* parse input */
   gimp_unit_entry_parse (entry);
   /* reenable updating */
   entry->dontUpdateText = FALSE;
+  }
 }
 
 static 
@@ -283,10 +297,13 @@ gint on_input        (GtkSpinButton *spinButton,
                       gpointer       arg1,
                       gpointer       user_data)
 {
+  if (!GIMP_UNIT_ENTRY (spinButton)->resMode)
+  {
   /* parse and set value ourselves before GtkSpinButton does so, because
      GtkSpinButton would truncate our input and ignore parts of it */
   gimp_unit_entry_parse (GIMP_UNIT_ENTRY (spinButton));
   on_output (spinButton, (gpointer)GIMP_UNIT_ENTRY(spinButton)->unitAdjustment);
+  }
 
   /* we want GtkSpinButton to handle the input nontheless (there is no problem anymore
      since we done the parsing), so we return FALSE */
@@ -305,7 +322,10 @@ void on_populate_popup (GtkEntry *entry,
   menuItem = gtk_separator_menu_item_new ();
   gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuItem);
 
-  for (i = gimp_unit_get_number_of_units()-1; i >= 0; i--)
+  /* ignore PIXEL when in resolution mode */
+  (GIMP_UNIT_ENTRY (entry)->resMode) ? (i = 1) : (i = 0); 
+
+  for (; i < gimp_unit_get_number_of_units(); i++)
   {
     menuItem = gtk_menu_item_new_with_label (gimp_unit_get_singular (i));
     gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuItem);
@@ -452,3 +472,10 @@ gimp_unit_entry_set_bounds (GimpUnitEntry *entry, GimpUnit unit, gdouble upper,
   GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
   gimp_unit_adjustment_set_bounds (adj, unit, upper, lower);
 }
+
+void
+gimp_unit_entry_set_res_mode (GimpUnitEntry *entry,
+                              gboolean activate)
+{
+  entry->resMode = TRUE;
+}
diff --git a/libgimpwidgets/gimpunitentry.h b/libgimpwidgets/gimpunitentry.h
index 6810e49..937f293 100644
--- a/libgimpwidgets/gimpunitentry.h
+++ b/libgimpwidgets/gimpunitentry.h
@@ -48,12 +48,12 @@ struct _GimpUnitEntry
   /* private */
   GimpUnitAdjustment *unitAdjustment; /* for convinience */
 
-  /* set TRUE while up/down buttons/keys pressed or scrolling so that we can disable
-     our parsing and display the changed value */
-  gboolean          buttonPressed;    
-  gboolean          scrolling;
+  /* flag set TRUE when entry's text should not be overwritten
+     (i.e. during user input) */
   gboolean          dontUpdateText;
 
+  /* set TRUE when the entry shall be used for resolution input */
+  gboolean          resMode;
   const gchar *id; /* identifier string of unit entry (used by GimpUnitEntryTable) */
 };
 
@@ -80,6 +80,7 @@ gdouble gimp_unit_entry_get_value (GimpUnitEntry *entry);
 gdouble gimp_unit_entry_get_value_in_unit (GimpUnitEntry *entry, GimpUnit unit);
 GimpUnit gimp_unit_entry_get_unit (GimpUnitEntry *entry);
 void gimp_unit_entry_set_bounds (GimpUnitEntry *entry, GimpUnit unit, gdouble upper, gdouble lower);
+void gimp_unit_entry_set_res_mode (GimpUnitEntry *entry, gboolean activate);
 
 G_END_DECLS
 
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index 174544f..bc97347 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -382,6 +382,7 @@ EXPORTS
 	gimp_unit_entry_new
 	gimp_unit_entry_set_bounds
 	gimp_unit_entry_set_resolution
+	gimp_unit_entry_set_res_mode
 	gimp_unit_entry_set_unit
 	gimp_unit_entry_set_value
 	gimp_unit_entry_set_value_in_unit



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