2010-11-02 03:03:39 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpspinscale.c
|
|
|
|
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
|
2012-03-31 04:52:20 +08:00
|
|
|
* 2012 Øyvind Kolås <pippin@gimp.org>
|
2010-11-02 03:03:39 +08:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2010-11-02 03:03:39 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-11-02 05:28:18 +08:00
|
|
|
#include <gegl.h>
|
2010-11-02 03:03:39 +08:00
|
|
|
#include <gtk/gtk.h>
|
2013-05-29 04:46:22 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2019-07-31 16:16:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2012-03-31 04:34:59 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2022-02-16 18:09:30 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
#include "gimpspinscale.h"
|
|
|
|
|
2022-02-16 18:09:30 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
|
2020-01-09 07:41:48 +08:00
|
|
|
#define RELATIVE_CHANGE_SPEED 0.1
|
|
|
|
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_LABEL
|
|
|
|
};
|
|
|
|
|
2011-03-18 22:07:44 +08:00
|
|
|
typedef enum
|
|
|
|
{
|
2017-10-19 02:50:20 +08:00
|
|
|
TARGET_NONE,
|
2011-03-18 22:07:44 +08:00
|
|
|
TARGET_NUMBER,
|
2020-12-17 00:34:56 +08:00
|
|
|
TARGET_GRAB,
|
|
|
|
TARGET_GRABBING,
|
|
|
|
TARGET_RELATIVE
|
2011-03-18 22:07:44 +08:00
|
|
|
} SpinScaleTarget;
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
struct _GimpSpinScale
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinButton parent_instance;
|
|
|
|
|
2017-10-19 02:50:20 +08:00
|
|
|
gchar *label;
|
|
|
|
gchar *label_text;
|
|
|
|
gchar *label_pattern;
|
|
|
|
|
|
|
|
GtkWindow *mnemonic_window;
|
|
|
|
guint mnemonic_keyval;
|
|
|
|
gboolean mnemonics_visible;
|
|
|
|
|
2019-01-26 01:21:05 +08:00
|
|
|
gboolean constrain_drag;
|
|
|
|
|
2017-10-19 02:50:20 +08:00
|
|
|
gboolean scale_limits_set;
|
|
|
|
gdouble scale_lower;
|
|
|
|
gdouble scale_upper;
|
|
|
|
gdouble gamma;
|
|
|
|
|
|
|
|
PangoLayout *layout;
|
|
|
|
gboolean changing_value;
|
|
|
|
gboolean relative_change;
|
|
|
|
gdouble start_x;
|
|
|
|
gdouble start_value;
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
gint start_pointer_x;
|
|
|
|
gint start_pointer_y;
|
2017-10-19 02:50:20 +08:00
|
|
|
SpinScaleTarget target;
|
|
|
|
gboolean hover;
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
gboolean pointer_warp;
|
|
|
|
gint pointer_warp_x;
|
|
|
|
gint pointer_warp_start_x;
|
2010-11-02 03:03:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
static void gimp_spin_scale_dispose (GObject *object);
|
|
|
|
static void gimp_spin_scale_finalize (GObject *object);
|
|
|
|
static void gimp_spin_scale_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_spin_scale_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_spin_scale_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
|
|
|
static void gimp_spin_scale_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width);
|
|
|
|
static void gimp_spin_scale_style_updated (GtkWidget *widget);
|
|
|
|
static gboolean gimp_spin_scale_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
|
|
|
static gboolean gimp_spin_scale_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean gimp_spin_scale_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event);
|
|
|
|
static gboolean gimp_spin_scale_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event);
|
|
|
|
static gboolean gimp_spin_scale_leave_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event);
|
|
|
|
static void gimp_spin_scale_hierarchy_changed (GtkWidget *widget,
|
|
|
|
GtkWidget *old_toplevel);
|
|
|
|
static void gimp_spin_scale_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *old_screen);
|
|
|
|
|
|
|
|
static void gimp_spin_scale_value_changed (GtkSpinButton *spin_button);
|
|
|
|
static void gimp_spin_scale_settings_notify (GtkSettings *settings,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
GimpSpinScale *scale);
|
|
|
|
static void gimp_spin_scale_mnemonics_notify (GtkWindow *window,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
GimpSpinScale *scale);
|
|
|
|
static void gimp_spin_scale_setup_mnemonic (GimpSpinScale *scale,
|
|
|
|
guint previous_keyval);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2020-03-22 19:22:54 +08:00
|
|
|
static gdouble odd_pow (gdouble x,
|
|
|
|
gdouble y);
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
G_DEFINE_TYPE (GimpSpinScale, gimp_spin_scale, GIMP_TYPE_SPIN_BUTTON)
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_spin_scale_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_class_init (GimpSpinScaleClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkSpinButtonClass *spin_button_class = GTK_SPIN_BUTTON_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->dispose = gimp_spin_scale_dispose;
|
|
|
|
object_class->finalize = gimp_spin_scale_finalize;
|
|
|
|
object_class->set_property = gimp_spin_scale_set_property;
|
|
|
|
object_class->get_property = gimp_spin_scale_get_property;
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
widget_class->get_preferred_width = gimp_spin_scale_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = gimp_spin_scale_get_preferred_height;
|
|
|
|
widget_class->style_updated = gimp_spin_scale_style_updated;
|
|
|
|
widget_class->draw = gimp_spin_scale_draw;
|
2010-11-02 03:03:39 +08:00
|
|
|
widget_class->button_press_event = gimp_spin_scale_button_press;
|
|
|
|
widget_class->button_release_event = gimp_spin_scale_button_release;
|
2011-04-04 07:10:44 +08:00
|
|
|
widget_class->motion_notify_event = gimp_spin_scale_motion_notify;
|
|
|
|
widget_class->leave_notify_event = gimp_spin_scale_leave_notify;
|
2013-05-29 04:46:22 +08:00
|
|
|
widget_class->hierarchy_changed = gimp_spin_scale_hierarchy_changed;
|
|
|
|
widget_class->screen_changed = gimp_spin_scale_screen_changed;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
spin_button_class->value_changed = gimp_spin_scale_value_changed;
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_LABEL,
|
|
|
|
g_param_spec_string ("label", NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2022-02-17 02:01:39 +08:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "GimpSpinScale");
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_init (GimpSpinScale *scale)
|
|
|
|
{
|
2012-11-19 03:02:51 +08:00
|
|
|
gtk_widget_add_events (GTK_WIDGET (scale),
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK);
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
gtk_entry_set_alignment (GTK_ENTRY (scale), 1.0);
|
2011-04-16 17:52:38 +08:00
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (scale), TRUE);
|
2012-04-01 01:41:15 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_keyval = GDK_KEY_VoidSymbol;
|
|
|
|
scale->gamma = 1.0;
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_dispose (GObject *object)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
|
|
|
|
guint keyval;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
keyval = scale->mnemonic_keyval;
|
|
|
|
scale->mnemonic_keyval = GDK_KEY_VoidSymbol;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_setup_mnemonic (GIMP_SPIN_SCALE (object), keyval);
|
2011-04-21 02:12:21 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&scale->layout);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_finalize (GObject *object)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_pointer (&scale->label, g_free);
|
|
|
|
g_clear_pointer (&scale->label_text, g_free);
|
|
|
|
g_clear_pointer (&scale->label_pattern, g_free);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2013-05-28 21:29:44 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_LABEL:
|
2013-05-28 21:29:44 +08:00
|
|
|
gimp_spin_scale_set_label (scale, g_value_get_string (value));
|
2010-11-02 03:03:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
2013-05-28 21:29:44 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (object);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_LABEL:
|
2013-05-28 21:29:44 +08:00
|
|
|
g_value_set_string (value, gimp_spin_scale_get_label (scale));
|
2010-11-02 03:03:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-19 22:23:21 +08:00
|
|
|
gimp_spin_scale_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
PangoContext *context = gtk_widget_get_pango_context (widget);
|
|
|
|
PangoFontMetrics *metrics;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget,
|
|
|
|
minimum_width,
|
|
|
|
natural_width);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
metrics = pango_context_get_metrics (context,
|
|
|
|
pango_context_get_font_description (context),
|
2010-11-02 03:03:39 +08:00
|
|
|
pango_context_get_language (context));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->label)
|
2012-02-23 05:46:41 +08:00
|
|
|
{
|
2012-02-23 06:37:32 +08:00
|
|
|
gint char_width;
|
|
|
|
gint digit_width;
|
|
|
|
gint char_pixels;
|
2012-02-23 05:46:41 +08:00
|
|
|
|
|
|
|
char_width = pango_font_metrics_get_approximate_char_width (metrics);
|
|
|
|
digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
|
|
|
char_pixels = PANGO_PIXELS (MAX (char_width, digit_width));
|
|
|
|
|
|
|
|
/* ~3 chars for the ellipses */
|
2010-11-19 22:23:21 +08:00
|
|
|
*minimum_width += char_pixels * 3;
|
|
|
|
*natural_width += char_pixels * 3;
|
2012-02-23 05:46:41 +08:00
|
|
|
}
|
2010-11-02 03:03:39 +08:00
|
|
|
|
|
|
|
pango_font_metrics_unref (metrics);
|
2012-02-23 05:46:41 +08:00
|
|
|
}
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2012-02-23 05:46:41 +08:00
|
|
|
static void
|
2010-11-19 22:23:21 +08:00
|
|
|
gimp_spin_scale_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->get_preferred_height (widget,
|
|
|
|
minimum_height,
|
|
|
|
natural_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_style_updated (GtkWidget *widget)
|
2012-02-23 05:46:41 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2011-04-21 02:12:21 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&scale->layout);
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
2013-05-29 04:46:22 +08:00
|
|
|
static PangoAttrList *
|
|
|
|
pattern_to_attrs (const gchar *text,
|
|
|
|
const gchar *pattern)
|
|
|
|
{
|
|
|
|
PangoAttrList *attrs = pango_attr_list_new ();
|
|
|
|
const char *p = text;
|
|
|
|
const char *q = pattern;
|
|
|
|
const char *start;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2020-11-03 13:35:54 +08:00
|
|
|
while (*p && q && *q != '_')
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
|
|
|
p = g_utf8_next_char (p);
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
start = p;
|
|
|
|
while (*p && *q && *q == '_')
|
|
|
|
{
|
|
|
|
p = g_utf8_next_char (p);
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p > start)
|
|
|
|
{
|
|
|
|
PangoAttribute *attr = pango_attr_underline_new (PANGO_UNDERLINE_LOW);
|
|
|
|
|
|
|
|
attr->start_index = start - text;
|
|
|
|
attr->end_index = p - text;
|
|
|
|
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
static gboolean
|
2010-11-19 22:23:21 +08:00
|
|
|
gimp_spin_scale_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
cairo_save (cr);
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
|
|
|
|
cairo_restore (cr);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->label)
|
2017-10-19 02:50:20 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (widget);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkRectangle text_area;
|
|
|
|
GtkStateFlags state;
|
|
|
|
gint minimum_width;
|
|
|
|
gint natural_width;
|
2022-02-17 00:42:53 +08:00
|
|
|
PangoRectangle ink;
|
2020-06-17 00:35:58 +08:00
|
|
|
gint layout_offset_x;
|
|
|
|
gint layout_offset_y;
|
|
|
|
GdkRGBA text_color;
|
|
|
|
GdkRGBA bar_text_color;
|
|
|
|
gdouble progress_fraction;
|
2022-02-17 00:42:53 +08:00
|
|
|
gdouble progress_x;
|
|
|
|
gdouble progress_y;
|
|
|
|
gdouble progress_width;
|
|
|
|
gdouble progress_height;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
state = gtk_widget_get_state_flags (widget);
|
2012-02-23 05:46:41 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget,
|
|
|
|
&minimum_width,
|
|
|
|
&natural_width);
|
2011-04-21 02:12:21 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! scale->layout)
|
2012-02-23 05:46:41 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->layout = gtk_widget_create_pango_layout (widget,
|
|
|
|
scale->label_text);
|
|
|
|
pango_layout_set_ellipsize (scale->layout, PANGO_ELLIPSIZE_END);
|
2022-02-17 01:46:13 +08:00
|
|
|
/* Needing to force right-to-left layout when the widget is
|
|
|
|
* set so, even when the text is not RTL text. Without this,
|
|
|
|
* such case is broken because on the left side, we'd have
|
|
|
|
* both the value and the label texts.
|
|
|
|
*/
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_layout_set_auto_dir (scale->layout, FALSE);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->mnemonics_visible)
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
attrs = pattern_to_attrs (scale->label_text,
|
|
|
|
scale->label_pattern);
|
2013-05-29 04:46:22 +08:00
|
|
|
if (attrs)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_layout_set_attributes (scale->layout, attrs);
|
2013-05-29 04:46:22 +08:00
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 05:46:41 +08:00
|
|
|
}
|
2011-04-21 02:12:21 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_layout_set_width (scale->layout,
|
2012-02-23 05:46:41 +08:00
|
|
|
PANGO_SCALE *
|
2010-11-19 22:23:21 +08:00
|
|
|
(allocation.width - minimum_width));
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_layout_get_pixel_extents (scale->layout, &ink, NULL);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2012-02-23 05:46:41 +08:00
|
|
|
gtk_entry_get_layout_offsets (GTK_ENTRY (widget), NULL, &layout_offset_y);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2011-04-21 02:12:21 +08:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2022-02-17 00:42:53 +08:00
|
|
|
layout_offset_x = text_area.x + text_area.width - ink.width - 2;
|
2010-11-02 03:03:39 +08:00
|
|
|
else
|
2010-11-19 22:23:21 +08:00
|
|
|
layout_offset_x = text_area.x + 2;
|
2012-02-23 05:46:41 +08:00
|
|
|
|
2022-02-17 00:42:53 +08:00
|
|
|
layout_offset_x -= ink.x;
|
2012-02-23 05:46:41 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gtk_style_context_get_color (style, state, &text_color);
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gtk_style_context_save (style);
|
|
|
|
gtk_style_context_add_class (style, GTK_STYLE_CLASS_PROGRESSBAR);
|
|
|
|
gtk_style_context_get_color (style, state, &bar_text_color);
|
|
|
|
gtk_style_context_restore (style);
|
2013-05-14 08:00:20 +08:00
|
|
|
|
|
|
|
progress_fraction = gtk_entry_get_progress_fraction (GTK_ENTRY (widget));
|
2022-02-17 01:46:13 +08:00
|
|
|
progress_y = 0.0;
|
|
|
|
progress_width = (gdouble) text_area.width * progress_fraction;
|
|
|
|
progress_height = text_area.height;
|
2013-05-14 08:00:20 +08:00
|
|
|
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2022-02-17 01:46:13 +08:00
|
|
|
progress_x = text_area.width + text_area.x - progress_width;
|
2013-05-14 08:00:20 +08:00
|
|
|
else
|
2022-02-17 01:46:13 +08:00
|
|
|
progress_x = text_area.x;
|
2013-05-14 08:00:20 +08:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
2010-11-19 22:23:21 +08:00
|
|
|
cairo_rectangle (cr, 0, 0, text_area.width, text_area.height);
|
2013-05-14 08:00:20 +08:00
|
|
|
cairo_rectangle (cr, progress_x, progress_y,
|
|
|
|
progress_width, progress_height);
|
|
|
|
cairo_clip (cr);
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
|
|
|
|
|
2022-04-27 04:57:51 +08:00
|
|
|
/* Center the label on the widget text area. Do not necessarily
|
|
|
|
* try to align the label with the number characters in the entry
|
|
|
|
* layout, because the size might actually be different, in
|
|
|
|
* particular when the label's actual font ends up different
|
|
|
|
* (typically when displaying non-Western languages).
|
|
|
|
*/
|
|
|
|
cairo_move_to (cr, layout_offset_x,
|
|
|
|
text_area.y - ink.y + text_area.height / 2 - ink.height / 2);
|
2010-11-19 22:23:21 +08:00
|
|
|
gdk_cairo_set_source_rgba (cr, &text_color);
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_cairo_show_layout (cr, scale->layout);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2013-05-14 08:00:20 +08:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
|
|
|
cairo_rectangle (cr, progress_x, progress_y,
|
|
|
|
progress_width, progress_height);
|
|
|
|
cairo_clip (cr);
|
2010-11-19 21:08:37 +08:00
|
|
|
|
2022-04-27 04:57:51 +08:00
|
|
|
cairo_move_to (cr, layout_offset_x,
|
|
|
|
text_area.y - ink.y + text_area.height / 2 - ink.height / 2);
|
2010-11-19 22:23:21 +08:00
|
|
|
gdk_cairo_set_source_rgba (cr, &bar_text_color);
|
2024-07-29 09:51:38 +08:00
|
|
|
pango_cairo_show_layout (cr, scale->layout);
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
/* Returns TRUE if a translation should be done */
|
|
|
|
static gboolean
|
|
|
|
gtk_widget_get_translation_to_window (GtkWidget *widget,
|
|
|
|
GdkWindow *window,
|
|
|
|
int *x,
|
|
|
|
int *y)
|
|
|
|
{
|
|
|
|
GdkWindow *w, *widget_window;
|
|
|
|
|
|
|
|
if (!gtk_widget_get_has_window (widget))
|
|
|
|
{
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
|
|
|
*x = -allocation.x;
|
|
|
|
*y = -allocation.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_window = gtk_widget_get_window (widget);
|
|
|
|
|
2018-05-03 03:12:56 +08:00
|
|
|
for (w = window;
|
|
|
|
w && w != widget_window;
|
|
|
|
w = gdk_window_get_parent (w))
|
2010-11-19 22:23:21 +08:00
|
|
|
{
|
|
|
|
int wx, wy;
|
|
|
|
gdk_window_get_position (w, &wx, &wy);
|
|
|
|
*x += wx;
|
|
|
|
*y += wy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (w == NULL)
|
|
|
|
{
|
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_event_to_widget_coords (GtkWidget *widget,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble event_x,
|
|
|
|
gdouble event_y,
|
2020-06-17 00:35:58 +08:00
|
|
|
gdouble *widget_x,
|
|
|
|
gdouble *widget_y)
|
2010-11-19 22:23:21 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
GdkRectangle text_area;
|
|
|
|
gint tx, ty;
|
|
|
|
|
|
|
|
gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
|
2010-11-19 22:23:21 +08:00
|
|
|
|
|
|
|
if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty))
|
|
|
|
{
|
|
|
|
event_x += tx;
|
|
|
|
event_y += ty;
|
|
|
|
}
|
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
*widget_x = event_x - text_area.x;
|
|
|
|
*widget_y = event_y - text_area.y;
|
2010-11-19 22:23:21 +08:00
|
|
|
}
|
|
|
|
|
2011-03-18 22:07:44 +08:00
|
|
|
static SpinScaleTarget
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
gimp_spin_scale_get_target (GtkWidget *widget,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GdkEvent *event)
|
2010-11-02 03:51:13 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
GdkRectangle text_area;
|
2010-11-02 03:51:13 +08:00
|
|
|
|
2018-05-03 03:12:56 +08:00
|
|
|
gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
|
2010-11-02 03:51:13 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
if (x >= 0 && x < text_area.width &&
|
|
|
|
y >= 0 && y < text_area.height)
|
2011-03-18 22:07:44 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
PangoRectangle logical;
|
|
|
|
gint layout_x;
|
|
|
|
gint layout_y;
|
|
|
|
|
|
|
|
if (! event)
|
2020-12-17 00:34:56 +08:00
|
|
|
return TARGET_GRAB;
|
2020-06-17 00:35:58 +08:00
|
|
|
|
|
|
|
gtk_entry_get_layout_offsets (GTK_ENTRY (widget), &layout_x, &layout_y);
|
|
|
|
pango_layout_get_pixel_extents (gtk_entry_get_layout (GTK_ENTRY (widget)),
|
|
|
|
NULL, &logical);
|
|
|
|
|
2018-05-03 03:12:56 +08:00
|
|
|
layout_x -= text_area.x;
|
|
|
|
layout_y -= text_area.y;
|
2010-11-19 22:23:21 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
if (event->type != GDK_MOTION_NOTIFY)
|
2010-11-19 22:23:21 +08:00
|
|
|
{
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
GdkEventButton *event_button = (GdkEventButton *) event;
|
2020-06-17 00:35:58 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
switch (event_button->button)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
if (event_button->state & GDK_SHIFT_MASK)
|
2020-12-17 00:34:56 +08:00
|
|
|
return TARGET_RELATIVE;
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
else
|
2020-12-17 00:34:56 +08:00
|
|
|
/* Button 1 target depends on the cursor position. */
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2020-12-17 00:34:56 +08:00
|
|
|
return TARGET_RELATIVE;
|
2020-06-17 00:35:58 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
default:
|
|
|
|
return TARGET_NUMBER;
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 01:43:14 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GdkEventMotion *event_motion = (GdkEventMotion *) event;
|
|
|
|
|
|
|
|
if (event_motion->state & GDK_SHIFT_MASK)
|
|
|
|
return TARGET_RELATIVE;
|
|
|
|
}
|
2010-11-19 22:23:21 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
/* For motion events or main button clicks, the target depends on
|
|
|
|
* the position.
|
|
|
|
*/
|
2024-03-24 02:43:42 +08:00
|
|
|
if (x >= layout_x && x < layout_x + logical.width &&
|
|
|
|
y >= (layout_y + logical.height)/4 && y < 3 * (layout_y + logical.height)/4)
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
return TARGET_NUMBER;
|
|
|
|
}
|
2020-12-17 00:34:56 +08:00
|
|
|
else if (event->type == GDK_MOTION_NOTIFY)
|
|
|
|
{
|
|
|
|
return TARGET_GRAB;
|
|
|
|
}
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
else
|
|
|
|
{
|
2020-12-17 00:34:56 +08:00
|
|
|
return TARGET_GRABBING;
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
}
|
2010-11-02 03:51:13 +08:00
|
|
|
}
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
return TARGET_NONE;
|
2010-11-19 21:08:37 +08:00
|
|
|
}
|
2010-11-02 03:51:13 +08:00
|
|
|
|
2017-10-19 02:50:20 +08:00
|
|
|
static void
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_update_cursor (GtkWidget *widget,
|
|
|
|
GdkWindow *window)
|
2017-10-19 02:50:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
GdkDisplay *display = gtk_widget_get_display (widget);
|
|
|
|
GdkCursor *cursor = NULL;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
switch (scale->target)
|
2017-10-19 02:50:20 +08:00
|
|
|
{
|
2020-06-17 00:35:58 +08:00
|
|
|
case TARGET_NUMBER:
|
2020-12-17 00:34:56 +08:00
|
|
|
cursor = gdk_cursor_new_from_name (display, "text");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TARGET_GRAB:
|
|
|
|
cursor = gdk_cursor_new_from_name (display, "grab");
|
2020-06-17 00:35:58 +08:00
|
|
|
break;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-12-17 00:34:56 +08:00
|
|
|
case TARGET_GRABBING:
|
|
|
|
cursor = gdk_cursor_new_from_name (display, "grabbing");
|
2020-06-17 00:35:58 +08:00
|
|
|
break;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-12-17 00:34:56 +08:00
|
|
|
case TARGET_RELATIVE:
|
|
|
|
cursor = gdk_cursor_new_from_name (display, "col-resize");
|
2020-06-17 00:35:58 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gdk_window_set_cursor (window, cursor);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
g_clear_object (&cursor);
|
|
|
|
}
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
static void
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
gimp_spin_scale_update_target (GtkWidget *widget,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GdkEvent *event)
|
2020-06-17 00:35:58 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
SpinScaleTarget target;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
target = gimp_spin_scale_get_target (widget, x, y, (GdkEvent *) event);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (target != scale->target)
|
2020-06-17 00:35:58 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->target = target;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_update_cursor (widget, window);
|
2017-10-19 02:50:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-02-11 22:44:35 +08:00
|
|
|
gimp_spin_scale_clear_target (GtkWidget *widget,
|
|
|
|
GdkWindow *window)
|
2017-10-19 02:50:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->target != TARGET_NONE)
|
2017-10-19 02:50:20 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->target = TARGET_NONE;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_update_cursor (widget, window);
|
2017-10-19 02:50:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-19 03:01:48 +08:00
|
|
|
static void
|
|
|
|
gimp_spin_scale_get_limits (GimpSpinScale *scale,
|
|
|
|
gdouble *lower,
|
|
|
|
gdouble *upper)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->scale_limits_set)
|
2011-04-19 03:01:48 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
*lower = scale->scale_lower;
|
|
|
|
*upper = scale->scale_upper;
|
2011-04-19 03:01:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (scale);
|
|
|
|
GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
|
|
|
|
|
|
|
|
*lower = gtk_adjustment_get_lower (adjustment);
|
|
|
|
*upper = gtk_adjustment_get_upper (adjustment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
static void
|
2011-03-18 22:42:50 +08:00
|
|
|
gimp_spin_scale_change_value (GtkWidget *widget,
|
2020-01-09 07:41:48 +08:00
|
|
|
gdouble x,
|
|
|
|
guint state)
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
|
|
|
|
GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
|
|
|
|
GdkRectangle text_area;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
gdouble value;
|
|
|
|
gint digits;
|
|
|
|
gint power = 1;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area);
|
2011-04-19 03:01:48 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (widget), &lower, &upper);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2011-04-21 02:12:21 +08:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2010-11-19 22:23:21 +08:00
|
|
|
x = text_area.width - x;
|
2011-04-21 02:12:21 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->relative_change)
|
2011-03-18 22:42:50 +08:00
|
|
|
{
|
|
|
|
gdouble step;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2020-01-09 07:41:48 +08:00
|
|
|
step = (upper - lower) / text_area.width * RELATIVE_CHANGE_SPEED;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2011-04-21 02:12:21 +08:00
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
2024-07-29 09:51:38 +08:00
|
|
|
step *= x - (text_area.width - scale->start_x);
|
2011-04-21 02:12:21 +08:00
|
|
|
else
|
2024-07-29 09:51:38 +08:00
|
|
|
step *= x - scale->start_x;
|
2020-01-09 07:41:48 +08:00
|
|
|
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
gdouble page_inc = gtk_adjustment_get_page_increment (adjustment);
|
|
|
|
|
|
|
|
step = RINT (step / page_inc) * page_inc;
|
|
|
|
}
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
value = scale->start_value + step;
|
2011-03-18 22:42:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-22 19:22:54 +08:00
|
|
|
gdouble x0, x1;
|
2011-03-18 22:42:50 +08:00
|
|
|
gdouble fraction;
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
x0 = odd_pow (lower, 1.0 / scale->gamma);
|
|
|
|
x1 = odd_pow (upper, 1.0 / scale->gamma);
|
2020-03-22 19:22:54 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
fraction = x / (gdouble) text_area.width;
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2020-03-22 19:22:54 +08:00
|
|
|
value = fraction * (x1 - x0) + x0;
|
2024-07-29 09:51:38 +08:00
|
|
|
value = odd_pow (value, scale->gamma);
|
2020-01-09 07:41:48 +08:00
|
|
|
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
|
|
|
{
|
|
|
|
gdouble page_inc = gtk_adjustment_get_page_increment (adjustment);
|
|
|
|
|
|
|
|
value = RINT (value / page_inc) * page_inc;
|
|
|
|
}
|
2011-03-18 22:42:50 +08:00
|
|
|
}
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2014-06-19 21:49:27 +08:00
|
|
|
digits = gtk_spin_button_get_digits (spin_button);
|
2014-06-20 01:00:23 +08:00
|
|
|
while (digits--)
|
|
|
|
power *= 10;
|
|
|
|
|
|
|
|
/* round the value to the possible precision of the spinbutton, so
|
|
|
|
* a focus-out will not change the value again, causing inadvertend
|
|
|
|
* adjustment signals.
|
|
|
|
*/
|
|
|
|
value *= power;
|
|
|
|
value = RINT (value);
|
|
|
|
value /= power;
|
2014-06-19 21:49:27 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->constrain_drag)
|
2019-01-26 01:21:05 +08:00
|
|
|
value = rint (value);
|
|
|
|
|
2011-03-18 22:07:44 +08:00
|
|
|
gtk_adjustment_set_value (adjustment, value);
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_spin_scale_button_press (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
gdouble x, y;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->changing_value = FALSE;
|
|
|
|
scale->relative_change = FALSE;
|
|
|
|
scale->pointer_warp = FALSE;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gimp_spin_scale_event_to_widget_coords (widget, event->window,
|
|
|
|
event->x, event->y,
|
|
|
|
&x, &y);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
gimp_spin_scale_update_target (widget, event->window, x, y, (GdkEvent *) event);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
switch (scale->target)
|
2010-11-19 22:23:21 +08:00
|
|
|
{
|
2020-12-17 00:34:56 +08:00
|
|
|
case TARGET_GRAB:
|
|
|
|
case TARGET_GRABBING:
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->changing_value = TRUE;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gtk_widget_grab_focus (widget);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2020-01-09 07:41:48 +08:00
|
|
|
gimp_spin_scale_change_value (widget, x, event->state);
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_update_cursor (widget, event->window);
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
return TRUE;
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2020-12-17 00:34:56 +08:00
|
|
|
case TARGET_RELATIVE:
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->changing_value = TRUE;
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
gtk_widget_grab_focus (widget);
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->relative_change = TRUE;
|
|
|
|
scale->start_x = x;
|
|
|
|
scale->start_value = gtk_adjustment_get_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)));
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->start_pointer_x = floor (event->x_root);
|
|
|
|
scale->start_pointer_y = floor (event->y_root);
|
2018-05-03 03:20:19 +08:00
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_update_cursor (widget, event->window);
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
return TRUE;
|
2011-03-18 22:07:44 +08:00
|
|
|
|
2020-11-05 01:32:27 +08:00
|
|
|
case TARGET_NUMBER:
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
return TRUE;
|
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
default:
|
|
|
|
break;
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_spin_scale_button_release (GtkWidget *widget,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
gdouble x, y;
|
2010-11-19 22:23:21 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_event_to_widget_coords (widget, event->window,
|
|
|
|
event->x, event->y,
|
|
|
|
&x, &y);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->changing_value)
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->changing_value = FALSE;
|
2010-11-02 03:03:39 +08:00
|
|
|
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
/* don't change the value if we're in the middle of a pointer warp, since
|
|
|
|
* we didn't adjust start_x yet. see the comment in
|
|
|
|
* gimp_spin_scale_motion_notify().
|
|
|
|
*/
|
2024-07-29 09:51:38 +08:00
|
|
|
if (! scale->pointer_warp)
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_change_value (widget, x, event->state);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->relative_change)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2018-05-01 05:50:00 +08:00
|
|
|
gdk_device_warp (gdk_event_get_device ((GdkEvent *) event),
|
|
|
|
gdk_event_get_screen ((GdkEvent *) event),
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->start_pointer_x,
|
|
|
|
scale->start_pointer_y);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
}
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->hover)
|
2020-06-17 00:35:58 +08:00
|
|
|
{
|
|
|
|
gimp_spin_scale_update_target (widget, event->window,
|
|
|
|
0.0, 0.0, NULL);
|
|
|
|
}
|
2017-10-19 02:50:20 +08:00
|
|
|
else
|
2020-06-17 00:35:58 +08:00
|
|
|
{
|
|
|
|
gimp_spin_scale_clear_target (widget, event->window);
|
|
|
|
}
|
2017-10-19 02:50:20 +08:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2011-04-04 07:10:44 +08:00
|
|
|
gimp_spin_scale_motion_notify (GtkWidget *widget,
|
2010-11-02 03:03:39 +08:00
|
|
|
GdkEventMotion *event)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
gdouble x, y;
|
2010-11-19 22:23:21 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_event_to_widget_coords (widget, event->window,
|
|
|
|
event->x, event->y,
|
|
|
|
&x, &y);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2012-11-19 03:02:51 +08:00
|
|
|
gdk_event_request_motions (event);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->hover = TRUE;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->changing_value)
|
2010-11-02 03:03:39 +08:00
|
|
|
{
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
GdkScreen *screen;
|
|
|
|
GdkDisplay *display;
|
|
|
|
gint pointer_x;
|
|
|
|
gint pointer_y;
|
2018-05-01 05:50:00 +08:00
|
|
|
GdkMonitor *monitor;
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
GdkRectangle monitor_geometry;
|
|
|
|
|
|
|
|
screen = gdk_event_get_screen ((GdkEvent *) event);
|
|
|
|
display = gdk_screen_get_display (screen);
|
|
|
|
|
|
|
|
pointer_x = floor (event->x_root);
|
|
|
|
pointer_y = floor (event->y_root);
|
|
|
|
|
2018-05-01 05:50:00 +08:00
|
|
|
monitor = gdk_display_get_monitor_at_point (display, pointer_x, pointer_y);
|
|
|
|
gdk_monitor_get_geometry (monitor, &monitor_geometry);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
|
|
|
|
/* when applying a relative change, we wrap the pointer around the left
|
|
|
|
* and right edges of the current monitor, so that the adjustment is not
|
|
|
|
* limited by the monitor geometry. when the pointer reaches one of the
|
|
|
|
* monitor edges, we move it one pixel away from the opposite edge, so
|
|
|
|
* that it can be subsequently moved in the other direction, and adjust
|
|
|
|
* start_x accordingly.
|
|
|
|
*
|
2018-05-01 05:50:00 +08:00
|
|
|
* unfortunately, we can't rely on gdk_device_warp() to actually
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
* move the pointer (for example, it doesn't work on wayland), and
|
|
|
|
* there's no easy way to tell whether the pointer moved or not. in
|
|
|
|
* particular, even when the pointer doesn't move, gdk still simulates a
|
|
|
|
* motion event, and reports the "new" pointer position until a real
|
|
|
|
* motion event occurs.
|
|
|
|
*
|
|
|
|
* in order not to erroneously adjust start_x when
|
2018-05-01 05:50:00 +08:00
|
|
|
* gdk_device_warp() fails, we remember that we *tried* to warp
|
|
|
|
* the pointer, and defer the actual adjustment of start_x until
|
|
|
|
* a future motion event, where the pointer's x coordinate is
|
|
|
|
* different from the one passed to gdk_device_warp(). when
|
|
|
|
* that happens, we "guess" whether the pointer got warped or
|
|
|
|
* not by comparing its x coordinate to the one passed to
|
|
|
|
* gdk_device_warp(): if their difference is less than half the
|
|
|
|
* monitor width, then we assume the pointer got warped
|
|
|
|
* (otherwise, the user must have very quickly moved the mouse
|
|
|
|
* across half the screen.) yes, this is an ugly ugly hack :)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
*/
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->pointer_warp)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
if (pointer_x == scale->pointer_warp_x)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
return TRUE;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->pointer_warp = FALSE;
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (ABS (pointer_x - scale->pointer_warp_x) < monitor_geometry.width / 2)
|
|
|
|
scale->start_x = scale->pointer_warp_start_x;
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
}
|
|
|
|
|
2020-06-17 00:35:58 +08:00
|
|
|
gimp_spin_scale_change_value (widget, x, event->state);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->relative_change)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2017-11-02 14:25:11 +08:00
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
gdouble value;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
|
|
|
|
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
|
|
|
|
|
|
|
|
value = gtk_adjustment_get_value (adjustment);
|
|
|
|
lower = gtk_adjustment_get_lower (adjustment);
|
|
|
|
upper = gtk_adjustment_get_upper (adjustment);
|
|
|
|
|
|
|
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
|
|
|
{
|
|
|
|
gdouble temp;
|
|
|
|
|
|
|
|
value = -value;
|
|
|
|
|
|
|
|
temp = lower;
|
|
|
|
lower = -upper;
|
|
|
|
upper = -temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pointer_x <= monitor_geometry.x &&
|
|
|
|
value > lower)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->pointer_warp = TRUE;
|
|
|
|
scale->pointer_warp_x = (monitor_geometry.width - 1) + pointer_x - 1;
|
|
|
|
scale->pointer_warp_start_x = scale->start_x + (monitor_geometry.width - 2);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
}
|
2017-11-02 14:25:11 +08:00
|
|
|
else if (pointer_x >= monitor_geometry.x + (monitor_geometry.width - 1) &&
|
|
|
|
value < upper)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->pointer_warp = TRUE;
|
|
|
|
scale->pointer_warp_x = pointer_x - (monitor_geometry.width - 1) + 1;
|
|
|
|
scale->pointer_warp_start_x = scale->start_x - (monitor_geometry.width - 2);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->pointer_warp)
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
{
|
2018-05-01 05:50:00 +08:00
|
|
|
gdk_device_warp (gdk_event_get_device ((GdkEvent *) event),
|
|
|
|
screen,
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->pointer_warp_x,
|
2018-05-01 05:50:00 +08:00
|
|
|
pointer_y);
|
app: wrap pointer around screen edges during relative spin scale adjustment
While applying a relative spin scale adjusment (i.e., when dragging
from the lower half of the spin scale), wrap the pointer around the
screen edges (of the current monitor), so that the maximal possible
adjustment amount isn't artifically limited by the screen geometry.
This is especially useful for spin scales in dockables, since
dockables are normally placed near the edge of the screen.
When the mouse is released, move the pointer back to its initial
position (at the beginning of the drag), to allow for subsequent
adjustments.
Unfortunately, moving the pointer programatically isn't supported
on all envrionments (Wayland, Xephyr, ...), and worse yet,
detecting that the pointer failed to move is tricky, so we have to
resort to an ungly hack to maintain the current behavior in this
case. Gah :P
2017-11-02 03:43:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:51:13 +08:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, event);
|
|
|
|
|
|
|
|
if (! (event->state &
|
|
|
|
(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) &&
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->hover)
|
2010-11-02 03:51:13 +08:00
|
|
|
{
|
2018-02-11 22:44:35 +08:00
|
|
|
gimp_spin_scale_update_target (widget, event->window,
|
app: improve GimpSpinScale usability for keyboard editing of value.
Currently to edit the value with the keyboard (i.e. get a focus on the
text entry part of the widget), we can click on the scale which gives us
edit focus, but it implies to change the value (which may not be
wanted).
An interaction method exists to do just this, which is the secondary
button (middle click). Unfortunately, though powerful, it is totally
"hidden feature". People expects to be able to click on the numbers they
see and start typing.
This change allows just this. Now when clicking on the number part, it
selects the whole text input contents (same as with middle-click ever
since commit 3449652fe8), without changing the value. You just enter in
text input mode.
To properly advertize the behavior change, the cursor will also change
when hovering, showing a text cursor over the existing number text.
As many of my changes, this change was designed together with Aryeom and
triggered originally by her usability feedbacks and inputs.
2020-12-16 21:56:29 +08:00
|
|
|
x, y, (GdkEvent *) event);
|
2010-11-02 03:51:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
2011-04-04 07:10:44 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_spin_scale_leave_notify (GtkWidget *widget,
|
|
|
|
GdkEventCrossing *event)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->hover = FALSE;
|
2017-10-19 02:50:20 +08:00
|
|
|
|
2010-11-19 22:23:21 +08:00
|
|
|
if (! (event->state &
|
|
|
|
(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)))
|
|
|
|
{
|
|
|
|
gimp_spin_scale_clear_target (widget, event->window);
|
2017-10-19 02:50:20 +08:00
|
|
|
}
|
2011-04-04 07:10:44 +08:00
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event);
|
|
|
|
}
|
|
|
|
|
2013-05-29 04:46:22 +08:00
|
|
|
static void
|
|
|
|
gimp_spin_scale_hierarchy_changed (GtkWidget *widget,
|
|
|
|
GtkWidget *old_toplevel)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_setup_mnemonic (GIMP_SPIN_SCALE (widget),
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_keyval);
|
2013-05-29 04:46:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *old_screen)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (widget);
|
|
|
|
GtkSettings *settings;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&scale->layout);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
if (old_screen)
|
|
|
|
{
|
|
|
|
settings = gtk_settings_get_for_screen (old_screen);
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (settings,
|
|
|
|
gimp_spin_scale_settings_notify,
|
|
|
|
scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! gtk_widget_has_screen (widget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
settings = gtk_widget_get_settings (widget);
|
|
|
|
|
|
|
|
g_signal_connect (settings, "notify::gtk-enable-mnemonics",
|
|
|
|
G_CALLBACK (gimp_spin_scale_settings_notify),
|
|
|
|
scale);
|
|
|
|
g_signal_connect (settings, "notify::gtk-enable-accels",
|
|
|
|
G_CALLBACK (gimp_spin_scale_settings_notify),
|
|
|
|
scale);
|
|
|
|
|
|
|
|
gimp_spin_scale_settings_notify (settings, NULL, scale);
|
|
|
|
}
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
static void
|
|
|
|
gimp_spin_scale_value_changed (GtkSpinButton *spin_button)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GimpSpinScale *scale = GIMP_SPIN_SCALE (spin_button);
|
|
|
|
GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button);
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
gdouble value;
|
|
|
|
gdouble x0, x1;
|
|
|
|
gdouble x;
|
2011-04-19 03:01:48 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (spin_button), &lower, &upper);
|
|
|
|
|
|
|
|
value = CLAMP (gtk_adjustment_get_value (adjustment), lower, upper);
|
2010-11-02 03:03:39 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
x0 = odd_pow (lower, 1.0 / scale->gamma);
|
|
|
|
x1 = odd_pow (upper, 1.0 / scale->gamma);
|
|
|
|
x = odd_pow (value, 1.0 / scale->gamma);
|
2020-03-22 19:22:54 +08:00
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
gtk_entry_set_progress_fraction (GTK_ENTRY (spin_button),
|
2020-03-22 19:22:54 +08:00
|
|
|
(x - x0) / (x1 - x0));
|
2010-11-02 03:03:39 +08:00
|
|
|
}
|
|
|
|
|
2013-05-29 04:46:22 +08:00
|
|
|
static void
|
|
|
|
gimp_spin_scale_settings_notify (GtkSettings *settings,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
GimpSpinScale *scale)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (scale));
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (toplevel))
|
|
|
|
gimp_spin_scale_mnemonics_notify (GTK_WINDOW (toplevel), NULL, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_mnemonics_notify (GtkWindow *window,
|
|
|
|
const GParamSpec *pspec,
|
|
|
|
GimpSpinScale *scale)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
gboolean mnemonics_visible = FALSE;
|
|
|
|
gboolean enable_mnemonics;
|
|
|
|
gboolean auto_mnemonics;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
g_object_get (gtk_widget_get_settings (GTK_WIDGET (scale)),
|
|
|
|
"gtk-enable-mnemonics", &enable_mnemonics,
|
|
|
|
"gtk-auto-mnemonics", &auto_mnemonics,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (enable_mnemonics &&
|
|
|
|
(! auto_mnemonics ||
|
|
|
|
gtk_widget_is_sensitive (GTK_WIDGET (scale))))
|
|
|
|
{
|
|
|
|
g_object_get (window,
|
|
|
|
"mnemonics-visible", &mnemonics_visible,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->mnemonics_visible != mnemonics_visible)
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonics_visible = mnemonics_visible;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&scale->layout);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (scale));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_spin_scale_setup_mnemonic (GimpSpinScale *scale,
|
|
|
|
guint previous_keyval)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (scale);
|
|
|
|
GtkWidget *toplevel;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->mnemonic_window)
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
g_signal_handlers_disconnect_by_func (scale->mnemonic_window,
|
2013-05-29 04:46:22 +08:00
|
|
|
gimp_spin_scale_mnemonics_notify,
|
|
|
|
scale);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
gtk_window_remove_mnemonic (scale->mnemonic_window,
|
2013-05-29 04:46:22 +08:00
|
|
|
previous_keyval,
|
|
|
|
widget);
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_window = NULL;
|
2013-05-29 04:46:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
toplevel = gtk_widget_get_toplevel (widget);
|
|
|
|
|
|
|
|
if (gtk_widget_is_toplevel (toplevel) &&
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_keyval != GDK_KEY_VoidSymbol)
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
|
|
|
gtk_window_add_mnemonic (GTK_WINDOW (toplevel),
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_keyval,
|
2013-05-29 04:46:22 +08:00
|
|
|
widget);
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_window = GTK_WINDOW (toplevel);
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
g_signal_connect (toplevel, "notify::mnemonics-visible",
|
|
|
|
G_CALLBACK (gimp_spin_scale_mnemonics_notify),
|
|
|
|
scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-22 19:22:54 +08:00
|
|
|
static gdouble
|
|
|
|
odd_pow (gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
if (x >= 0.0)
|
|
|
|
return pow (x, y);
|
|
|
|
else
|
|
|
|
return -pow (-x, y);
|
|
|
|
}
|
|
|
|
|
2011-04-19 03:01:48 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2010-11-02 03:03:39 +08:00
|
|
|
GtkWidget *
|
|
|
|
gimp_spin_scale_new (GtkAdjustment *adjustment,
|
|
|
|
const gchar *label,
|
|
|
|
gint digits)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GIMP_TYPE_SPIN_SCALE,
|
|
|
|
"adjustment", adjustment,
|
|
|
|
"label", label,
|
|
|
|
"digits", digits,
|
|
|
|
NULL);
|
|
|
|
}
|
2011-04-19 03:01:48 +08:00
|
|
|
|
2013-05-29 04:46:22 +08:00
|
|
|
static gboolean
|
|
|
|
separate_uline_pattern (const gchar *str,
|
|
|
|
guint *accel_key,
|
|
|
|
gchar **new_str,
|
|
|
|
gchar **pattern)
|
|
|
|
{
|
|
|
|
gboolean underscore;
|
|
|
|
const gchar *src;
|
|
|
|
gchar *dest;
|
|
|
|
gchar *pattern_dest;
|
|
|
|
|
|
|
|
*accel_key = GDK_KEY_VoidSymbol;
|
|
|
|
*new_str = g_new (gchar, strlen (str) + 1);
|
|
|
|
*pattern = g_new (gchar, g_utf8_strlen (str, -1) + 1);
|
|
|
|
|
|
|
|
underscore = FALSE;
|
|
|
|
|
|
|
|
src = str;
|
|
|
|
dest = *new_str;
|
|
|
|
pattern_dest = *pattern;
|
|
|
|
|
|
|
|
while (*src)
|
|
|
|
{
|
|
|
|
gunichar c;
|
|
|
|
const gchar *next_src;
|
|
|
|
|
|
|
|
c = g_utf8_get_char (src);
|
|
|
|
if (c == (gunichar)-1)
|
|
|
|
{
|
|
|
|
g_warning ("Invalid input string");
|
|
|
|
g_free (*new_str);
|
|
|
|
g_free (*pattern);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
next_src = g_utf8_next_char (src);
|
|
|
|
|
|
|
|
if (underscore)
|
|
|
|
{
|
|
|
|
if (c == '_')
|
|
|
|
*pattern_dest++ = ' ';
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pattern_dest++ = '_';
|
|
|
|
if (*accel_key == GDK_KEY_VoidSymbol)
|
|
|
|
*accel_key = gdk_keyval_to_lower (gdk_unicode_to_keyval (c));
|
|
|
|
}
|
|
|
|
|
|
|
|
while (src < next_src)
|
|
|
|
*dest++ = *src++;
|
|
|
|
|
|
|
|
underscore = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (c == '_')
|
|
|
|
{
|
|
|
|
underscore = TRUE;
|
|
|
|
src = next_src;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (src < next_src)
|
|
|
|
*dest++ = *src++;
|
|
|
|
|
|
|
|
*pattern_dest++ = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = 0;
|
|
|
|
*pattern_dest = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:29:44 +08:00
|
|
|
void
|
|
|
|
gimp_spin_scale_set_label (GimpSpinScale *scale,
|
|
|
|
const gchar *label)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
guint accel_key = GDK_KEY_VoidSymbol;
|
|
|
|
gchar *text = NULL;
|
|
|
|
gchar *pattern = NULL;
|
2013-05-28 21:29:44 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (label == scale->label)
|
2013-05-28 21:29:44 +08:00
|
|
|
return;
|
|
|
|
|
2013-05-29 04:46:22 +08:00
|
|
|
if (label && ! separate_uline_pattern (label, &accel_key, &text, &pattern))
|
|
|
|
return;
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (scale->label);
|
|
|
|
scale->label = g_strdup (label);
|
2013-05-28 21:29:44 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (scale->label_text);
|
|
|
|
scale->label_text = text; /* don't dup */
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_free (scale->label_pattern);
|
|
|
|
scale->label_pattern = pattern; /* don't dup */
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
if (scale->mnemonic_keyval != accel_key)
|
2013-05-29 04:46:22 +08:00
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
guint previous = scale->mnemonic_keyval;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->mnemonic_keyval = accel_key;
|
2013-05-29 04:46:22 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_setup_mnemonic (scale, previous);
|
|
|
|
}
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
g_clear_object (&scale->layout);
|
2013-05-28 21:29:44 +08:00
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (scale));
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (scale), "label");
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *
|
|
|
|
gimp_spin_scale_get_label (GimpSpinScale *scale)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), NULL);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
return scale->label;
|
2013-05-28 21:29:44 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 03:01:48 +08:00
|
|
|
void
|
|
|
|
gimp_spin_scale_set_scale_limits (GimpSpinScale *scale,
|
|
|
|
gdouble lower,
|
|
|
|
gdouble upper)
|
|
|
|
{
|
2024-07-29 09:51:38 +08:00
|
|
|
GtkSpinButton *spin_button;
|
|
|
|
GtkAdjustment *adjustment;
|
2011-04-19 03:01:48 +08:00
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
|
|
|
|
|
|
|
|
spin_button = GTK_SPIN_BUTTON (scale);
|
|
|
|
adjustment = gtk_spin_button_get_adjustment (spin_button);
|
|
|
|
|
|
|
|
g_return_if_fail (lower >= gtk_adjustment_get_lower (adjustment));
|
|
|
|
g_return_if_fail (upper <= gtk_adjustment_get_upper (adjustment));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->scale_limits_set = TRUE;
|
|
|
|
scale->scale_lower = lower;
|
|
|
|
scale->scale_upper = upper;
|
|
|
|
scale->gamma = 1.0;
|
2011-04-19 03:01:48 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_value_changed (spin_button);
|
|
|
|
}
|
|
|
|
|
2012-03-31 04:34:59 +08:00
|
|
|
void
|
2013-05-28 21:19:04 +08:00
|
|
|
gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale)
|
2012-03-31 04:34:59 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->scale_limits_set = FALSE;
|
|
|
|
scale->scale_lower = 0.0;
|
|
|
|
scale->scale_upper = 0.0;
|
2012-03-31 06:44:41 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale));
|
2012-03-31 04:34:59 +08:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:19:04 +08:00
|
|
|
gboolean
|
|
|
|
gimp_spin_scale_get_scale_limits (GimpSpinScale *scale,
|
|
|
|
gdouble *lower,
|
|
|
|
gdouble *upper)
|
2012-03-31 04:34:59 +08:00
|
|
|
{
|
2013-05-28 21:19:04 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), FALSE);
|
2012-03-31 04:34:59 +08:00
|
|
|
|
2013-05-28 21:19:04 +08:00
|
|
|
if (lower)
|
2024-07-29 09:51:38 +08:00
|
|
|
*lower = scale->scale_lower;
|
2013-05-28 21:19:04 +08:00
|
|
|
|
|
|
|
if (upper)
|
2024-07-29 09:51:38 +08:00
|
|
|
*upper = scale->scale_upper;
|
2013-05-28 21:19:04 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
return scale->scale_limits_set;
|
2012-03-31 04:34:59 +08:00
|
|
|
}
|
|
|
|
|
2011-04-19 03:01:48 +08:00
|
|
|
void
|
2013-05-28 21:19:04 +08:00
|
|
|
gimp_spin_scale_set_gamma (GimpSpinScale *scale,
|
|
|
|
gdouble gamma)
|
2011-04-19 03:01:48 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->gamma = gamma;
|
2011-04-19 03:01:48 +08:00
|
|
|
|
|
|
|
gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale));
|
|
|
|
}
|
|
|
|
|
2013-05-28 21:19:04 +08:00
|
|
|
gdouble
|
|
|
|
gimp_spin_scale_get_gamma (GimpSpinScale *scale)
|
2011-04-19 03:01:48 +08:00
|
|
|
{
|
2013-05-28 21:19:04 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), 1.0);
|
2011-04-19 03:01:48 +08:00
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
return scale->gamma;
|
2011-04-19 03:01:48 +08:00
|
|
|
}
|
2019-01-26 01:21:05 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_spin_scale_set_constrain_drag:
|
|
|
|
* @scale: the #GimpSpinScale.
|
|
|
|
* @constrain: whether constraining to integer values when dragging with
|
|
|
|
* pointer.
|
|
|
|
*
|
|
|
|
* If @constrain_drag is TRUE, dragging the scale with the pointer will
|
|
|
|
* only result into integer values. It will still possible to set the
|
|
|
|
* scale to fractional values (if the spin scale "digits" is above 0)
|
|
|
|
* for instance with keyboard edit.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_spin_scale_set_constrain_drag (GimpSpinScale *scale,
|
|
|
|
gboolean constrain)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_SPIN_SCALE (scale));
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
scale->constrain_drag = constrain;
|
2019-01-26 01:21:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_spin_scale_get_constrain_drag (GimpSpinScale *scale)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), 1.0);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
return scale->constrain_drag;
|
2019-01-26 01:21:05 +08:00
|
|
|
}
|
2023-01-24 06:25:55 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_spin_scale_get_mnemonic_keyval:
|
|
|
|
* @scale: the #GimpSpinScale.
|
|
|
|
*
|
|
|
|
* If @scale has been set with a mnemonic key in its label text, this function
|
|
|
|
* returns the keyval used for the mnemonic accelerator.
|
|
|
|
*
|
|
|
|
* Returns: the keyval usable for accelerators, or [const@Gdk.KEY_VoidSymbol].
|
|
|
|
*/
|
|
|
|
const guint
|
|
|
|
gimp_spin_scale_get_mnemonic_keyval (GimpSpinScale *scale)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), GDK_KEY_VoidSymbol);
|
|
|
|
|
2024-07-29 09:51:38 +08:00
|
|
|
return scale->mnemonic_keyval;
|
2023-01-24 06:25:55 +08:00
|
|
|
}
|