diff options
| author | Eduard Braun <eduard.braun2@gmx.de> | 2018-03-11 15:06:37 +0000 |
|---|---|---|
| committer | Eduard Braun <eduard.braun2@gmx.de> | 2018-03-12 18:28:38 +0000 |
| commit | a2f91dc91e9eb8a963cc0aed4f4155b23ad05fca (patch) | |
| tree | b8d87c632cb34144dd19a2cb02ea05574a0d034e | |
| parent | Speed up removing items from SPCanvasGroup (diff) | |
| download | inkscape-a2f91dc91e9eb8a963cc0aed4f4155b23ad05fca.tar.gz inkscape-a2f91dc91e9eb8a963cc0aed4f4155b23ad05fca.zip | |
Allow to constrain color slider values by pressing Ctrl key
Currently
- steps of 16 (for sliders with 0-255 range) and
- steps of 10 (for all other cases)
are hardcoded but could be made a preference if there's demand for it.
| -rw-r--r-- | src/ui/widget/color-scales.cpp | 13 | ||||
| -rw-r--r-- | src/ui/widget/color-scales.h | 2 | ||||
| -rw-r--r-- | src/ui/widget/color-slider.cpp | 8 |
3 files changed, 18 insertions, 5 deletions
diff --git a/src/ui/widget/color-scales.cpp b/src/ui/widget/color-scales.cpp index cb1f36066..cb6349c4b 100644 --- a/src/ui/widget/color-scales.cpp +++ b/src/ui/widget/color-scales.cpp @@ -244,9 +244,18 @@ gfloat ColorScales::getScaled(const GtkAdjustment *a) return val; } -void ColorScales::setScaled(GtkAdjustment *a, gfloat v) +void ColorScales::setScaled(GtkAdjustment *a, gfloat v, bool constrained) { - gfloat val = v * gtk_adjustment_get_upper(a); + gdouble upper = gtk_adjustment_get_upper(a); + gfloat val = v * upper; + if (constrained) { + // TODO: do we want preferences for these? + if (upper == 255) { + val = round(val/16) * 16; + } else { + val = round(val/10) * 10; + } + } gtk_adjustment_set_value(a, val); } diff --git a/src/ui/widget/color-scales.h b/src/ui/widget/color-scales.h index 0b7cae47e..1fc465418 100644 --- a/src/ui/widget/color-scales.h +++ b/src/ui/widget/color-scales.h @@ -30,7 +30,7 @@ public: static const gchar *SUBMODE_NAMES[]; static gfloat getScaled(const GtkAdjustment *a); - static void setScaled(GtkAdjustment *a, gfloat v); + static void setScaled(GtkAdjustment *a, gfloat v, bool constrained = false); ColorScales(SelectedColor &color, SPColorScalesMode mode); virtual ~ColorScales(); diff --git a/src/ui/widget/color-slider.cpp b/src/ui/widget/color-slider.cpp index 761f2e748..ed034598e 100644 --- a/src/ui/widget/color-slider.cpp +++ b/src/ui/widget/color-slider.cpp @@ -157,7 +157,9 @@ bool ColorSlider::on_button_press_event(GdkEventButton *event) signal_grabbed.emit(); _dragging = true; _oldvalue = _value; - ColorScales::setScaled(_adjustment->gobj(), CLAMP((gfloat)(event->x - cx) / cw, 0.0, 1.0)); + gfloat value = CLAMP((gfloat)(event->x - cx) / cw, 0.0, 1.0); + bool constrained = event->state & GDK_CONTROL_MASK; + ColorScales::setScaled(_adjustment->gobj(), value, constrained); signal_dragged.emit(); auto window = _gdk_window->gobj(); @@ -213,7 +215,9 @@ bool ColorSlider::on_motion_notify_event(GdkEventMotion *event) Gtk::Allocation allocation = get_allocation(); cx = get_style_context()->get_padding(get_state_flags()).get_left(); cw = allocation.get_width() - 2 * cx; - ColorScales::setScaled(_adjustment->gobj(), CLAMP((gfloat)(event->x - cx) / cw, 0.0, 1.0)); + gfloat value = CLAMP((gfloat)(event->x - cx) / cw, 0.0, 1.0); + bool constrained = event->state & GDK_CONTROL_MASK; + ColorScales::setScaled(_adjustment->gobj(), value, constrained); signal_dragged.emit(); } |
