[gimp] Issue #2557 - Gimp Can't Rotate By More Than 180 Degree
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Issue #2557 - Gimp Can't Rotate By More Than 180 Degree
- Date: Sat, 9 Mar 2019 12:44:02 +0000 (UTC)
commit 8b3c7ae1930e30ba7f760e5371346e32bb6fda20
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).
libgimpwidgets/gimpspinbutton.c | 64 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 4 deletions(-)
---
diff --git a/libgimpwidgets/gimpspinbutton.c b/libgimpwidgets/gimpspinbutton.c
index 094846c1cd..17f760ba56 100644
--- a/libgimpwidgets/gimpspinbutton.c
+++ b/libgimpwidgets/gimpspinbutton.c
@@ -36,9 +36,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.
**/
@@ -58,6 +63,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);
@@ -74,10 +82,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
@@ -122,6 +133,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]