[gimp/soc-2011-gimpunitentry: 19/68] GimpUnitEntry: add function to set value in a certain unit



commit 509030f379d1aabb1181e65a5bf51142b711c4c3
Author: Enrico Schröder <enni schroeder gmail com>
Date:   Mon Jun 13 14:32:30 2011 +0200

    GimpUnitEntry: add function to set value in a certain unit
    
    add _set_value_in_unit which allows to set the value of an entry in a different unit then the entry is in

 libgimpwidgets/gimpunitadjustment.c |   11 +++++++++++
 libgimpwidgets/gimpunitadjustment.h |    1 +
 libgimpwidgets/gimpunitentry.c      |    8 ++++++++
 libgimpwidgets/gimpunitentry.h      |    1 +
 4 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/libgimpwidgets/gimpunitadjustment.c b/libgimpwidgets/gimpunitadjustment.c
index c9e1b7b..7fa8493 100644
--- a/libgimpwidgets/gimpunitadjustment.c
+++ b/libgimpwidgets/gimpunitadjustment.c
@@ -179,6 +179,17 @@ gimp_unit_adjustment_set_value (GimpUnitAdjustment *adj, gdouble value)
 
   gtk_adjustment_set_value (GTK_ADJUSTMENT (adj), value);
 }
+void
+gimp_unit_adjustment_set_value_in_unit (GimpUnitAdjustment *adj, 
+                                        gdouble value, 
+                                        GimpUnit unit)
+{
+  /* convert from given unit to adjustments unit */
+  value = gimp_units_to_pixels (value, unit, adj->resolution);
+  value = gimp_pixels_to_units (value, adj->unit, adj->resolution);
+
+  gimp_unit_adjustment_set_value (adj, value);
+}
 gdouble 
 gimp_unit_adjustment_get_value (GimpUnitAdjustment *adj)
 {
diff --git a/libgimpwidgets/gimpunitadjustment.h b/libgimpwidgets/gimpunitadjustment.h
index 7514953..06d653b 100644
--- a/libgimpwidgets/gimpunitadjustment.h
+++ b/libgimpwidgets/gimpunitadjustment.h
@@ -68,6 +68,7 @@ GObject *gimp_unit_adjustment_new (void);
 void    gimp_unit_adjustment_set_unit (GimpUnitAdjustment *adj, GimpUnit unit);
 /* sets/gets the value of an adjustment */
 void    gimp_unit_adjustment_set_value (GimpUnitAdjustment *adj, gdouble value);
+void    gimp_unit_adjustment_set_value_in_unit (GimpUnitAdjustment *adj, gdouble value, GimpUnit unit);
 gdouble gimp_unit_adjustment_get_value (GimpUnitAdjustment *adj);
 gdouble gimp_unit_adjustment_get_value_in_unit    (GimpUnitAdjustment *adj, GimpUnit unit);
 void    gimp_unit_adjustment_set_resolution (GimpUnitAdjustment *adj, gdouble res);
diff --git a/libgimpwidgets/gimpunitentry.c b/libgimpwidgets/gimpunitentry.c
index d14b58c..d16644e 100644
--- a/libgimpwidgets/gimpunitentry.c
+++ b/libgimpwidgets/gimpunitentry.c
@@ -432,6 +432,14 @@ gimp_unit_entry_get_value_in_unit (GimpUnitEntry *entry, GimpUnit unit)
   GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
   return gimp_unit_adjustment_get_value_in_unit (adj, unit);
 }
+void 
+gimp_unit_entry_set_value_in_unit (GimpUnitEntry *entry,
+                                   gdouble value, 
+                                   GimpUnit unit)
+{
+  GimpUnitAdjustment *adj = gimp_unit_entry_get_adjustment (entry);
+  gimp_unit_adjustment_set_value_in_unit (adj, value, unit);
+}
 GimpUnit 
 gimp_unit_entry_get_unit (GimpUnitEntry *entry)
 {
diff --git a/libgimpwidgets/gimpunitentry.h b/libgimpwidgets/gimpunitentry.h
index b623543..6810e49 100644
--- a/libgimpwidgets/gimpunitentry.h
+++ b/libgimpwidgets/gimpunitentry.h
@@ -75,6 +75,7 @@ const gchar* gimp_unit_entry_get_id (GimpUnitEntry *entry);
 void gimp_unit_entry_set_unit (GimpUnitEntry *entry, GimpUnit unit);
 void gimp_unit_entry_set_resolution (GimpUnitEntry *entry, gdouble resolution);
 void gimp_unit_entry_set_value (GimpUnitEntry *entry, gdouble value);
+void gimp_unit_entry_set_value_in_unit (GimpUnitEntry *entry, gdouble value, GimpUnit unit);
 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);


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