[gimp/gimp-2-10] Issue #2557 - Gimp Can't Rotate By More Than 180 Degree



commit f27bf95e05224025fa3c8c8c8f531ec3818cdd78
Author: Ell <ell_se yahoo com>
Date:   Sat Mar 9 07:00:08 2019 -0500

    Issue #2557 - Gimp Can't Rotate By More Than 180 Degree
    
    When the "wrap" property of a GimpSpinButton is TRUE, wrap-around
    out-of-range values entered through the spin-button's text entry,
    instead of clamping them.  Since we're using GimpSpinButton
    everywhere since last commit, this applies to all our angle-entry
    spin buttons (including spin scales).
    
    (cherry picked from commit 8b3c7ae1930e30ba7f760e5371346e32bb6fda20)

 libgimpwidgets/gimpspinbutton.c | 64 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/libgimpwidgets/gimpspinbutton.c b/libgimpwidgets/gimpspinbutton.c
index 9cfcfab04d..cf14afc9d6 100644
--- a/libgimpwidgets/gimpspinbutton.c
+++ b/libgimpwidgets/gimpspinbutton.c
@@ -37,9 +37,14 @@
  * @title: GimpSpinButton
  * @short_description: A #GtkSpinButton with a some tweaked functionality.
  *
- * #GimpSpinButton modifies the behavior of #GtkSpinButton, so that
- * when the spin-button loses focus, its adjustment value is only
- * updated if the entry text has been changed.
+ * #GimpSpinButton is a drop-in replacement for #GtkSpinButton, with the
+ * following changes:
+ *
+ *   - When the spin-button loses focus, its adjustment value is only
+ *     updated if the entry text has been changed.
+ *
+ *   - When the spin-button's "wrap" property is TRUE, values input through the
+ *     entry are wrapped around.
  **/
 
 
@@ -59,6 +64,9 @@ static gboolean   gimp_spin_button_focus_in  (GtkWidget     *widget,
 static gboolean   gimp_spin_button_focus_out (GtkWidget     *widget,
                                               GdkEventFocus *event);
 
+static gint       gimp_spin_button_input     (GtkSpinButton *spin_button,
+                                              gdouble       *new_value);
+
 static void       gimp_spin_button_changed   (GtkEditable   *editable,
                                               gpointer       data);
 
@@ -75,10 +83,13 @@ G_DEFINE_TYPE_WITH_PRIVATE (GimpSpinButton, gimp_spin_button,
 static void
 gimp_spin_button_class_init (GimpSpinButtonClass *klass)
 {
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+  GtkWidgetClass     *widget_class      = GTK_WIDGET_CLASS (klass);
+  GtkSpinButtonClass *spin_button_class = GTK_SPIN_BUTTON_CLASS (klass);
 
   widget_class->focus_in_event  = gimp_spin_button_focus_in;
   widget_class->focus_out_event = gimp_spin_button_focus_out;
+
+  spin_button_class->input      = gimp_spin_button_input;
 }
 
 static void
@@ -123,6 +134,51 @@ gimp_spin_button_focus_out (GtkWidget     *widget,
   return result;
 }
 
+static gint
+gimp_spin_button_input (GtkSpinButton *spin_button,
+                        gdouble       *new_value)
+{
+  if (gtk_spin_button_get_wrap (spin_button))
+    {
+      gdouble  value;
+      gdouble  min;
+      gdouble  max;
+      gchar   *endptr;
+
+      value = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin_button)), &endptr);
+
+      if (*endptr)
+        return FALSE;
+
+      gtk_spin_button_get_range (spin_button, &min, &max);
+
+      if (min < max)
+        {
+          gdouble rem;
+
+          rem = fmod (value - min, max - min);
+
+          if (rem < 0.0)
+            rem += max - min;
+
+          if (rem == 0.0)
+            value = CLAMP (value, min, max);
+          else
+            value = min + rem;
+        }
+      else
+        {
+          value = min;
+        }
+
+      *new_value = value;
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 gimp_spin_button_changed (GtkEditable *editable,
                           gpointer     data)


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