[gimp/soc-2011-gimpunitentry] GimpUnitEntryTable: add value getter convenience functions



commit 7e7b006227678ba24f5754870530784f1a23e33b
Author: Enrico SchroÌder <enni schroeder gmail com>
Date:   Fri Jul 8 12:28:38 2011 +0200

    GimpUnitEntryTable: add value getter convenience functions
    
    adds gimp_unit_entry_table_get_pixels() and gimp_unit_entry_table_get_value_in_unit ()

 app/actions/layers-commands.c       |    6 ++----
 libgimpwidgets/gimpunitentrytable.c |   20 ++++++++++++++++++++
 libgimpwidgets/gimpunitentrytable.h |   27 +++++++++++++--------------
 libgimpwidgets/gimpwidgets.def      |    2 ++
 4 files changed, 37 insertions(+), 18 deletions(-)
---
diff --git a/app/actions/layers-commands.c b/app/actions/layers-commands.c
index 34066b3..ecdb57f 100644
--- a/app/actions/layers-commands.c
+++ b/app/actions/layers-commands.c
@@ -984,12 +984,10 @@ layers_new_layer_response (GtkWidget          *widget,
       layer_fill_type = dialog->fill_type;
 
       dialog->xsize =
-        RINT (gimp_unit_entry_get_value_in_unit (gimp_unit_entry_table_get_entry (dialog->size_se, "width"),
-                                                 GIMP_UNIT_PIXEL));
+        RINT (gimp_unit_entry_table_get_pixels (dialog->size_se, "width"));
 
       dialog->ysize =
-        RINT (gimp_unit_entry_get_value_in_unit (gimp_unit_entry_table_get_entry (dialog->size_se, "height"),
-                                                 GIMP_UNIT_PIXEL));
+        RINT (gimp_unit_entry_table_get_pixels (dialog->size_se, "height"));
 
       layer = gimp_layer_new (dialog->image,
                               dialog->xsize,
diff --git a/libgimpwidgets/gimpunitentrytable.c b/libgimpwidgets/gimpunitentrytable.c
index d67c953..44e7b8c 100644
--- a/libgimpwidgets/gimpunitentrytable.c
+++ b/libgimpwidgets/gimpunitentrytable.c
@@ -334,6 +334,26 @@ gimp_unit_entry_table_get_entry_count (GimpUnitEntryTable *table)
   return g_list_length (table->entries);
 }
 
+/* get value of given entry in pixels */
+gdouble 
+gimp_unit_entry_table_get_pixels (GimpUnitEntryTable *table, 
+                                  const gchar *id)
+{
+  return gimp_unit_entry_table_get_value_in_unit (table, id, GIMP_UNIT_PIXEL);
+}
+gdouble 
+gimp_unit_entry_table_get_value_in_unit (GimpUnitEntryTable *table,
+                                         const gchar *id, 
+                                         GimpUnit unit)
+{
+  GimpUnitEntry *entry = gimp_unit_entry_table_get_entry (table, id);
+
+  if (entry != NULL)
+    return gimp_unit_entry_get_value_in_unit (entry, unit);
+  else
+    return -1;
+}
+
 /* sets the unit of all entries */
 void 
 gimp_unit_entry_table_set_unit (GimpUnitEntryTable *table, GimpUnit unit)
diff --git a/libgimpwidgets/gimpunitentrytable.h b/libgimpwidgets/gimpunitentrytable.h
index 722e115..189681e 100644
--- a/libgimpwidgets/gimpunitentrytable.h
+++ b/libgimpwidgets/gimpunitentrytable.h
@@ -63,34 +63,33 @@ struct _GimpUnitEntryTableClass
   guint sig_changed_id;
 };
 
-/**
- * prototypes
- **/
 GType     gimp_unit_entry_table_get_type (void);
 GObject   *gimp_unit_entry_table_new (void);
 
 /* add UnitEntry */
-GtkWidget* gimp_unit_entry_table_add_entry (GimpUnitEntryTable *table, const gchar* id, const gchar *label, gint x, gint y);
+GtkWidget* gimp_unit_entry_table_add_entry          (GimpUnitEntryTable *table, const gchar* id, const gchar *label, gint x, gint y);
 GtkWidget* gimp_unit_entry_table_add_entry_defaults (GimpUnitEntryTable *table, const gchar* id, const gchar *label);
-//void gimp_unit_entry_table_add_entries ()
+//void gimp_unit_entry_table_add_entries            ()
 /* add preview label showing the current value of two entries in given unit */
-void gimp_unit_entry_table_add_label (GimpUnitEntryTable *table, GimpUnit unit, const char* id1, const char* id2);
+void gimp_unit_entry_table_add_label                (GimpUnitEntryTable *table, GimpUnit unit, const char* id1, const char* id2);
 /* add chain button connecting the two given UnitEntries */
-GtkWidget* gimp_unit_entry_table_add_chainbutton (GimpUnitEntryTable *table, const char* id1, const char*id2);
+GtkWidget* gimp_unit_entry_table_add_chainbutton    (GimpUnitEntryTable *table, const char* id1, const char*id2);
 /* get UnitEntry by id */
-GimpUnitEntry* gimp_unit_entry_table_get_entry (GimpUnitEntryTable *table, const gchar* id);
+GimpUnitEntry* gimp_unit_entry_table_get_entry      (GimpUnitEntryTable *table, const gchar* id);
 /* get UnitEntry by index */
-GimpUnitEntry* gimp_unit_entry_table_get_nth_entry (GimpUnitEntryTable *table, gint index);
+GimpUnitEntry* gimp_unit_entry_table_get_nth_entry  (GimpUnitEntryTable *table, gint index);
 /* get count of attached unit entries */
-gint gimp_unit_entry_table_get_entry_count (GimpUnitEntryTable *table);
+gint gimp_unit_entry_table_get_entry_count          (GimpUnitEntryTable *table);
+gdouble gimp_unit_entry_table_get_pixels            (GimpUnitEntryTable *table, const gchar *id);
+gdouble gimp_unit_entry_table_get_value_in_unit     (GimpUnitEntryTable *table, const gchar *id, GimpUnit unit);
 /* sets the unit of all entries */
-void gimp_unit_entry_table_set_unit (GimpUnitEntryTable *table, GimpUnit unit);
+void gimp_unit_entry_table_set_unit                 (GimpUnitEntryTable *table, GimpUnit unit);
 /* sets the resolution of all entries */
-void gimp_unit_entry_table_set_resolution (GimpUnitEntryTable *table, gdouble res);
+void gimp_unit_entry_table_set_resolution           (GimpUnitEntryTable *table, gdouble res);
 /* sets resolution mode for all entries */
-void gimp_unit_entry_table_set_res_mode (GimpUnitEntryTable *table, gboolean enable);
+void gimp_unit_entry_table_set_res_mode             (GimpUnitEntryTable *table, gboolean enable);
 /* calls gtk_entry_set_activates_default for all UnitEntries */
-void gimp_unit_entry_table_set_activates_default (GimpUnitEntryTable *table, gboolean setting);
+void gimp_unit_entry_table_set_activates_default    (GimpUnitEntryTable *table, gboolean setting);
 G_END_DECLS
 
 #endif /*__GIMP_UNIT_ENTRY_TABLE_H__*/
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index 12ceb4f..faa05b9 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -395,7 +395,9 @@ EXPORTS
 	gimp_unit_entry_table_get_entry
 	gimp_unit_entry_table_get_entry_count
 	gimp_unit_entry_table_get_nth_entry
+	gimp_unit_entry_table_get_pixels
 	gimp_unit_entry_table_get_type
+	gimp_unit_entry_table_get_value_in_unit
 	gimp_unit_entry_table_new
 	gimp_unit_entry_table_set_activates_default
 	gimp_unit_entry_table_set_res_mode



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