summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2018-11-16 14:03:11 +0000
committerTavmjong Bah <tavmjong@free.fr>2018-11-16 14:03:11 +0000
commit8feb1faf32539dcb22065607b8be783c12a1a41c (patch)
tree415e47b9446ceea46bd6feab1d37d02c2e0459ba /src
parentRemove Adwaita-hicolor icon themes toggles making more compat (diff)
downloadinkscape-8feb1faf32539dcb22065607b8be783c12a1a41c.tar.gz
inkscape-8feb1faf32539dcb22065607b8be783c12a1a41c.zip
Rewrite of Gimp Color Wheel in C++.
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/widget/color-wheel-selector.cpp66
-rw-r--r--src/ui/widget/color-wheel-selector.h8
-rw-r--r--src/ui/widget/ink-color-wheel.cpp675
-rw-r--r--src/ui/widget/ink-color-wheel.h86
-rw-r--r--src/widgets/gimp/CMakeLists.txt2
-rw-r--r--src/widgets/gimp/gimpcolorwheel.c1484
-rw-r--r--src/widgets/gimp/gimpcolorwheel.h97
8 files changed, 786 insertions, 1634 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 47ff6884e..96658b2a1 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -170,6 +170,7 @@ set(ui_SRC
widget/frame.cpp
widget/highlight-picker.cpp
widget/imagetoggler.cpp
+ widget/ink-color-wheel.cpp
widget/ink-select-one-action.cpp
widget/ink-spinscale.cpp
widget/insertordericon.cpp
@@ -394,6 +395,7 @@ set(ui_SRC
widget/highlight-picker.h
widget/insertordericon.h
widget/imagetoggler.h
+ widget/ink-color-wheel.h
widget/ink-select-one-action.h
widget/ink-spinscale.h
widget/labelled.h
diff --git a/src/ui/widget/color-wheel-selector.cpp b/src/ui/widget/color-wheel-selector.cpp
index c0a27a552..1c2660876 100644
--- a/src/ui/widget/color-wheel-selector.cpp
+++ b/src/ui/widget/color-wheel-selector.cpp
@@ -17,7 +17,7 @@
#include "ui/dialog-events.h"
#include "ui/widget/color-scales.h"
#include "ui/widget/color-slider.h"
-#include "widgets/gimp/gimpcolorwheel.h"
+#include "ui/widget/ink-color-wheel.h"
namespace Inkscape {
namespace UI {
@@ -46,8 +46,6 @@ ColorWheelSelector::ColorWheelSelector(SelectedColor &color)
ColorWheelSelector::~ColorWheelSelector()
{
- _wheel = nullptr;
-
_color_changed_connection.disconnect();
_color_dragged_connection.disconnect();
}
@@ -57,14 +55,12 @@ void ColorWheelSelector::_initUI()
/* Create components */
gint row = 0;
- _wheel = gimp_color_wheel_new();
- gtk_widget_show(_wheel);
-
- gtk_widget_set_halign(_wheel, GTK_ALIGN_FILL);
- gtk_widget_set_valign(_wheel, GTK_ALIGN_FILL);
- gtk_widget_set_hexpand(_wheel, TRUE);
- gtk_widget_set_vexpand(_wheel, TRUE);
- gtk_grid_attach(GTK_GRID(gobj()), _wheel, 0, row, 3, 1);
+ _wheel = Gtk::manage(new Inkscape::UI::Widget::ColorWheel());
+ _wheel->set_halign(Gtk::ALIGN_FILL);
+ _wheel->set_valign(Gtk::ALIGN_FILL);
+ _wheel->set_hexpand(true);
+ _wheel->set_vexpand(true);
+ attach(*_wheel, 0, row, 3, 1);
row++;
@@ -72,15 +68,9 @@ void ColorWheelSelector::_initUI()
Gtk::Label *label = Gtk::manage(new Gtk::Label(_("_A:"), true));
label->set_halign(Gtk::ALIGN_END);
label->set_valign(Gtk::ALIGN_CENTER);
- label->show();
- #if GTK_CHECK_VERSION(3, 12, 0)
label->set_margin_start(XPAD);
label->set_margin_end(XPAD);
- #else
- label->set_margin_left(XPAD);
- label->set_margin_right(XPAD);
- #endif
label->set_margin_top(YPAD);
label->set_margin_bottom(YPAD);
label->set_halign(Gtk::ALIGN_FILL);
@@ -93,15 +83,9 @@ void ColorWheelSelector::_initUI()
/* Slider */
_slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(_alpha_adjustment));
_slider->set_tooltip_text(_("Alpha (opacity)"));
- _slider->show();
- #if GTK_CHECK_VERSION(3, 12, 0)
_slider->set_margin_start(XPAD);
_slider->set_margin_end(XPAD);
- #else
- _slider->set_margin_left(XPAD);
- _slider->set_margin_right(XPAD);
- #endif
_slider->set_margin_top(YPAD);
_slider->set_margin_bottom(YPAD);
_slider->set_hexpand(true);
@@ -117,15 +101,9 @@ void ColorWheelSelector::_initUI()
spin_button->set_tooltip_text(_("Alpha (opacity)"));
sp_dialog_defocus_on_enter(GTK_WIDGET(spin_button->gobj()));
label->set_mnemonic_widget(*spin_button);
- spin_button->show();
- #if GTK_CHECK_VERSION(3, 12, 0)
spin_button->set_margin_start(XPAD);
spin_button->set_margin_end(XPAD);
- #else
- spin_button->set_margin_left(XPAD);
- spin_button->set_margin_right(XPAD);
- #endif
spin_button->set_margin_top(YPAD);
spin_button->set_margin_bottom(YPAD);
spin_button->set_halign(Gtk::ALIGN_CENTER);
@@ -137,8 +115,9 @@ void ColorWheelSelector::_initUI()
_slider->signal_grabbed.connect(sigc::mem_fun(*this, &ColorWheelSelector::_sliderGrabbed));
_slider->signal_released.connect(sigc::mem_fun(*this, &ColorWheelSelector::_sliderReleased));
_slider->signal_value_changed.connect(sigc::mem_fun(*this, &ColorWheelSelector::_sliderChanged));
+ _wheel->signal_color_changed().connect(sigc::mem_fun(*this, &ColorWheelSelector::_wheelChanged));
- g_signal_connect(G_OBJECT(_wheel), "changed", G_CALLBACK(_wheelChanged), this);
+ show_all();
}
void ColorWheelSelector::on_show()
@@ -192,19 +171,14 @@ void ColorWheelSelector::_sliderChanged()
_color.setAlpha(ColorScales::getScaled(_alpha_adjustment->gobj()));
}
-void ColorWheelSelector::_wheelChanged(GimpColorWheel *wheel, ColorWheelSelector *wheelSelector)
+void ColorWheelSelector::_wheelChanged()
{
- if (wheelSelector->_updating) {
+ if (_updating) {
return;
}
- gdouble h = 0;
- gdouble s = 0;
- gdouble v = 0;
- gimp_color_wheel_get_color(wheel, &h, &s, &v);
-
- float rgb[3] = { 0, 0, 0 };
- SPColor::hsv_to_rgb_floatv(rgb, h, s, v);
+ double rgb[3] = { 0, 0, 0 };
+ _wheel->get_rgb(rgb[0], rgb[1], rgb[2]);
SPColor color(rgb[0], rgb[1], rgb[2]);
@@ -212,13 +186,13 @@ void ColorWheelSelector::_wheelChanged(GimpColorWheel *wheel, ColorWheelSelector
guint32 mid = color.toRGBA32(0x7f);
guint32 end = color.toRGBA32(0xff);
- wheelSelector->_updating = true;
- wheelSelector->_slider->setColors(start, mid, end);
- wheelSelector->_color.preserveICC();
+ _updating = true;
+ _slider->setColors(start, mid, end);
+ _color.preserveICC();
- wheelSelector->_color.setHeld(gimp_color_wheel_is_adjusting(wheel));
- wheelSelector->_color.setColor(color);
- wheelSelector->_updating = false;
+ _color.setHeld(_wheel->is_adjusting());
+ _color.setColor(color);
+ _updating = false;
}
void ColorWheelSelector::_updateDisplay()
@@ -234,7 +208,7 @@ void ColorWheelSelector::_updateDisplay()
{
float hsv[3] = { 0, 0, 0 };
SPColor::rgb_to_hsv_floatv(hsv, _color.color().v.c[0], _color.color().v.c[1], _color.color().v.c[2]);
- gimp_color_wheel_set_color(GIMP_COLOR_WHEEL(_wheel), hsv[0], hsv[1], hsv[2]);
+ _wheel->set_rgb(_color.color().v.c[0], _color.color().v.c[1], _color.color().v.c[2]);
}
guint32 start = _color.color().toRGBA32(0x00);
diff --git a/src/ui/widget/color-wheel-selector.h b/src/ui/widget/color-wheel-selector.h
index a5e492f4b..59cf6b626 100644
--- a/src/ui/widget/color-wheel-selector.h
+++ b/src/ui/widget/color-wheel-selector.h
@@ -16,14 +16,12 @@
#include "ui/selected-color.h"
-typedef struct _GimpColorWheel GimpColorWheel;
-
namespace Inkscape {
namespace UI {
namespace Widget {
class ColorSlider;
-
+class ColorWheel;
class ColorWheelSelector
: public Gtk::Grid
{
@@ -43,14 +41,14 @@ protected:
void _sliderGrabbed();
void _sliderReleased();
void _sliderChanged();
- static void _wheelChanged(GimpColorWheel *wheel, ColorWheelSelector *cs);
+ void _wheelChanged();
void _updateDisplay();
SelectedColor &_color;
bool _updating;
Glib::RefPtr<Gtk::Adjustment> _alpha_adjustment;
- GtkWidget *_wheel;
+ Inkscape::UI::Widget::ColorWheel *_wheel;
Inkscape::UI::Widget::ColorSlider *_slider;
private:
diff --git a/src/ui/widget/ink-color-wheel.cpp b/src/ui/widget/ink-color-wheel.cpp
new file mode 100644
index 000000000..09688eca9
--- /dev/null
+++ b/src/ui/widget/ink-color-wheel.cpp
@@ -0,0 +1,675 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Color wheel widget. Outer ring for Hue. Inner triangle for Saturation and Value.
+ *
+ * Copyright (C) 2018 Tavmjong Bah
+ *
+ * The contents of this file may be used under the GNU General Public License Version 2 or later.
+ *
+ */
+
+#include "ink-color-wheel.h"
+
+// A point with a color value.
+class color_point {
+public:
+ color_point() : x(0), y(0), r(0), g(0), b(0) {};
+ color_point(double x, double y, double r, double g, double b) : x(x), y(y), r(r), g(g), b(b) {};
+ color_point(double x, double y, guint32 color) : x(x), y(y),
+ r(((color & 0xff0000) >> 16)/255.0),
+ g(((color & 0xff00) >> 8)/255.0),
+ b(((color & 0xff) )/255.0) {};
+ guint32 get_color() { return (int(r*255) << 16 | int(g*255) << 8 | int(b*255)); };
+ double x;
+ double y;
+ double r;
+ double g;
+ double b;
+};
+
+inline double lerp(const double& v0, const double& v1, const double& t0, const double&t1, const double& t) {
+ double s = 0;
+ if (t0 != t1) {
+ s = (t - t0)/(t1 - t0);
+ }
+ return (1.0 - s) * v0 + s * v1;
+}
+
+inline color_point lerp(const color_point& v0, const color_point& v1, const double &t0, const double &t1, const double& t) {
+ double x = lerp(v0.x, v1.x, t0, t1, t);
+ double y = lerp(v0.y, v1.y, t0, t1, t);
+ double r = lerp(v0.r, v1.r, t0, t1, t);
+ double g = lerp(v0.g, v1.g, t0, t1, t);
+ double b = lerp(v0.b, v1.b, t0, t1, t);
+ return (color_point(x, y, r, g, b));
+}
+
+inline double clamp(const double& value, const double& min, const double& max) {
+ if (value < min) return min;
+ if (value > max) return max;
+ return value;
+}
+
+// h, s, and v in range 0 to 1. Returns rgb value useful for use in Cairo.
+guint32 hsv_to_rgb(double h, double s, double v) {
+
+ if (h < 0.0 || h > 1.0 ||
+ s < 0.0 || s > 1.0 ||
+ v < 0.0 || v > 1.0) {
+ std::cerr << "ColorWheel: hsv_to_rgb: input out of bounds: (0-1)"
+ << " h: " << h << " s: " << s << " v: " << v << std::endl;
+ return 0x0;
+ }
+
+ double r = v;
+ double g = v;
+ double b = v;
+
+ if (s != 0.0) {
+ double c = s * v;
+ if (h == 1.0) h = 0.0;
+ h *= 6.0;
+
+ double f = h - (int)h;
+ double p = v * (1.0 - s);
+ double q = v * (1.0 - s * f);
+ double t = v * (1.0 - s * (1.0 - f));
+
+ switch ((int)h) {
+ case 0: r = v; g = t; b = p; break;
+ case 1: r = q; g = v; b = p; break;
+ case 2: r = p; g = v; b = t; break;
+ case 3: r = p; g = q; b = v; break;
+ case 4: r = t; g = p; b = v; break;
+ case 5: r = v; g = p; b = q; break;
+ default: g_assert_not_reached();
+ }
+ }
+ guint32 rgb = (((int)floor (r*255 + 0.5) << 16) |
+ ((int)floor (g*255 + 0.5) << 8) |
+ ((int)floor (b*255 + 0.5) ));
+ return rgb;
+}
+
+double luminance(guint32 color)
+{
+ double r(((color & 0xff0000) >> 16)/255.0);
+ double g(((color & 0xff00) >> 8)/255.0);
+ double b(((color & 0xff) )/255.0);
+ return (r * 0.2125 + g * 0.7154 + b * 0.0721);
+}
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+ColorWheel::ColorWheel()
+ : _hue(0.0)
+ , _saturation(1.0)
+ , _value(1.0)
+ , _ring_width(0.2)
+ , _mode(DRAG_NONE)
+ , _focus_on_ring(true)
+{
+ set_name("ColorWheel");
+ add_events(Gdk::BUTTON_PRESS_MASK |
+ Gdk::BUTTON_RELEASE_MASK |
+ Gdk::BUTTON_MOTION_MASK |
+ Gdk::KEY_PRESS_MASK );
+ set_can_focus();
+}
+
+void
+ColorWheel::set_rgb(const double& r, const double&g, const double&b, bool override_hue)
+{
+ double Min = std::min({r, g, b});
+ double Max = std::max({r, g, b});
+ _value = Max;
+ if (Min == Max) {
+ if (override_hue) {
+ _hue = 0.0;
+ }
+ } else {
+ if (Max == r) {
+ _hue = ((g-b)/(Max-Min) )/6.0;
+ } else if (Max == g) {
+ _hue = ((b-r)/(Max-Min) + 2)/6.0;
+ } else {
+ _hue = ((r-g)/(Max-Min) + 4)/6.0;
+ }
+ if (_hue < 0.0) {
+ _hue += 1.0;
+ }
+ }
+ if (Max == 0) {
+ _saturation = 0;
+ } else {
+ _saturation = (Max - Min)/Max;
+ }
+}
+
+void
+ColorWheel::get_rgb(double& r, double& g, double& b)
+{
+ guint32 color = get_rgb();
+ r = ((color & 0xff0000) >> 16)/255.0;
+ g = ((color & 0x00ff00) >> 8)/255.0;
+ b = ((color & 0x0000ff) )/255.0;
+}
+
+guint32
+ColorWheel::get_rgb()
+{
+ return hsv_to_rgb(_hue, _saturation, _value);
+}
+
+bool
+ColorWheel::on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr) {
+
+ Cairo::RefPtr<Cairo::Surface> surface = cr->get_target();
+ Cairo::RefPtr<Cairo::ImageSurface> image_surface =
+ Cairo::RefPtr<Cairo::ImageSurface>::cast_dynamic(surface);
+ if (!image_surface) {
+ std::cerr << "ColorWheel::on_draw: Failed Cast!" << std::endl;
+ return false;
+ }
+
+ Gtk::Allocation allocation = get_allocation();
+ const int width = allocation.get_width();
+ const int height = allocation.get_height();
+
+ Cairo::Format format = image_surface->get_format();
+ const int stride = Cairo::ImageSurface::format_stride_for_width(format, width);
+
+ int cx = width/2;
+ int cy = height/2;
+
+ int focus_line_width;
+ int focus_padding;
+ get_style_property("focus-line-width", focus_line_width);
+ get_style_property("focus-padding", focus_padding);
+
+ // Paint ring
+ guint32* buffer_ring = g_new (guint32, height * stride / 4);
+ double r_max = std::min( width, height)/2.0 - 2 * (focus_line_width + focus_padding);
+ double r_min = r_max * (1.0 - _ring_width);
+ double r2_max = (r_max+1) * (r_max+1); // Must expand a bit to avoid edge effects.
+ double r2_min = (r_min-1) * (r_min-1); // Must shrink a bit to avoid edge effects.
+
+ for (int i = 0; i < height; ++i) {
+ guint32* p = buffer_ring + i * width;
+ double dy = (cy - i);
+ for (int j = 0; j < width; ++j) {
+ double dx = (j - cx);
+ double r2 = dx * dx + dy * dy;
+ if (r2 < r2_min || r2 > r2_max) {
+ *p++ = 0; // Save calculation time.
+ } else {
+ double angle = atan2 (dy, dx);
+ if (angle < 0.0) {
+ angle += 2.0 * M_PI;
+ }
+ double hue = angle/(2.0 * M_PI);
+
+ *p++ = hsv_to_rgb(hue, 1.0, 1.0);
+ }
+ }
+ }
+
+ Cairo::RefPtr<::Cairo::ImageSurface> source_ring =
+ ::Cairo::ImageSurface::create((unsigned char *)buffer_ring,
+ Cairo::FORMAT_RGB24,
+ width, height, stride);
+
+ cr->set_antialias(Cairo::ANTIALIAS_SUBPIXEL);
+
+ // Paint line on ring in source (so it gets clipped by stroke).
+ double l = 0.0;
+ guint32 color_on_ring = hsv_to_rgb(_hue, 1.0, 1.0);
+ if (luminance(color_on_ring) < 0.5) l = 1.0;
+
+ Cairo::RefPtr<::Cairo::Context> cr_source_ring = ::Cairo::Context::create(source_ring);
+ cr_source_ring->set_source_rgb(l, l, l);
+
+ cr_source_ring->move_to (cx, cy);
+ cr_source_ring->line_to (cx + cos(_hue * M_PI * 2.0) * r_max+1,
+ cy - sin(_hue * M_PI * 2.0) * r_max+1);
+ cr_source_ring->stroke();
+
+ // Paint with ring surface, clipping to ring.
+ cr->save();
+ cr->set_source(source_ring, 0, 0);
+ cr->set_line_width (r_max - r_min);
+ cr->begin_new_path();
+ cr->arc(cx, cy, (r_max + r_min)/2.0, 0, 2.0 * M_PI);
+ cr->stroke();
+ cr->restore();
+
+ // Draw focus
+ if (has_focus() && _focus_on_ring) {
+ Glib::RefPtr<Gtk::StyleContext> style_context = get_style_context();
+ style_context->render_focus(cr, 0, 0, width, height);
+ }
+
+ // Paint triangle.
+ /* The triangle is painted by first finding color points on the
+ * edges of the triangle at the same y value via linearly
+ * interpolating between corner values, and then interpolating along
+ * x between the those edge points. The interpolation is in sRGB
+ * space which leads to a complicated mapping between x/y and
+ * saturation/value. This was probably done to remove the need to
+ * convert between HSV and RGB for each pixel.
+ * Black corner: v = 0, s = 1
+ * White corner: v = 1, s = 0
+ * Color corner; v = 1, s = 1
+ */
+ const int padding = 3; // Avoid edge artifacts (only needed in y).
+ double x0, y0, x1, y1, x2, y2;
+ triangle_corners(x0, y0, x1, y1, x2, y2);
+ guint32 color0 = hsv_to_rgb(_hue, 1.0, 1.0);
+ guint32 color1 = hsv_to_rgb(_hue, 1.0, 0.0);
+ guint32 color2 = hsv_to_rgb(_hue, 0.0, 1.0);
+
+ color_point p0 (x0, y0, color0);
+ color_point p1 (x1, y1, color1);
+ color_point p2 (x2, y2, color2);
+
+ // Reorder so we paint from top down.
+ if (p1.y > p2.y) {
+ std::swap(p1, p2);
+ }
+
+ if (p0.y > p2.y) {
+ std::swap(p0, p2);
+ }
+
+ if (p0.y > p1.y) {
+ std::swap(p0, p1);
+ }
+
+ guint32* buffer_triangle = g_new (guint32, height * stride / 4);
+
+ for (int y = 0; y < height; ++y) {
+ guint32* p = buffer_triangle + y * width;
+
+ if (p0.y <= y+padding && y-padding < p2.y) {
+
+ // Get values on side at position y.
+ color_point side0;
+ if (y < p1.y) {
+ side0 = lerp(p0, p1, p0.y, p1.y, y);
+ } else {
+ side0 = lerp(p1, p2, p1.y, p2.y, y);
+ }
+ color_point side1 = lerp(p0, p2, p0.y, p2.y, y);
+
+ // side0 should be on left
+ if (side0.x > side1.x) {
+ std::swap (side0, side1);
+ }
+
+ int x_start = std::max(0, int(side0.x));
+ int x_end = std::min(int(side1.x), width);
+
+ for (int x = 0; x < width; ++x) {
+ if (x < x_start) {
+ *p++ = side0.get_color();
+ } else if (x < x_end) {
+ *p++ = lerp(side0, side1, side0.x, side1.x, x).get_color();
+ } else {
+ *p++ = side1.get_color();
+ }
+ }
+ }
+ }
+
+ Cairo::RefPtr<::Cairo::ImageSurface> source_triangle =
+ ::Cairo::ImageSurface::create((unsigned char *)buffer_triangle,
+ Cairo::FORMAT_RGB24,
+ width, height, stride);
+
+ // Paint with triangle surface, clipping to triangle.
+ cr->save();
+ cr->set_source(source_triangle, 0, 0);
+ cr->move_to(p0.x, p0.y);
+ cr->line_to(p1.x, p1.y);
+ cr->line_to(p2.x, p2.y);
+ cr->close_path();
+ cr->fill();
+ cr->restore();
+
+
+ // Draw marker
+ double mx = x1 + (x2-x1) * _value + (x0-x2) * _saturation * _value;
+ double my = y1 + (y2-y1) * _value + (y0-y2) * _saturation * _value;
+
+ double a = 0.0;
+ guint32 color_at_marker = get_rgb();
+ if (luminance(color_at_marker) < 0.5) a = 1.0;
+
+ cr->set_source_rgb(a, a, a);
+ cr->begin_new_path();
+ cr->arc(mx, my, 4, 0, 2 * M_PI);
+ cr->stroke();
+
+ // Draw focus
+ if (has_focus() && !_focus_on_ring) {
+ Glib::RefPtr<Gtk::StyleContext> style_context = get_style_context();
+ style_context->render_focus(cr, mx-4, my-4, 8, 8); // This doesn't seem to work.
+ cr->set_line_width(0.5);
+ cr->set_source_rgb(1-a, 1-a, 1-a);
+ cr->begin_new_path();
+ cr->arc(mx, my, 7, 0, 2 * M_PI);
+ cr->stroke();
+ }
+
+ return true;
+}
+
+// Find triangle corners given hue and radius.
+void
+ColorWheel::triangle_corners(double &x0, double &y0,
+ double &x1, double &y1,
+ double &x2, double &y2)
+{
+ Gtk::Allocation allocation = get_allocation();
+ const int width = allocation.get_width();
+ const int height = allocation.get_height();
+
+ int cx = width/2;
+ int cy = height/2;
+
+ int focus_line_width;
+ int focus_padding;
+ get_style_property("focus-line-width", focus_line_width);
+ get_style_property("focus-padding", focus_padding);
+
+ double r_max = std::min( width, height)/2.0 - 2 * (focus_line_width + focus_padding);
+ double r_min = r_max * (1.0 - _ring_width);
+
+ double angle = _hue * 2.0 * M_PI;
+
+ x0 = cx + cos(angle) * r_min;
+ y0 = cy - sin(angle) * r_min;
+ x1 = cx + cos(angle + 2.0 * M_PI / 3.0) * r_min;
+ y1 = cy - sin(angle + 2.0 * M_PI / 3.0) * r_min;
+ x2 = cx + cos(angle + 4.0 * M_PI / 3.0) * r_min;
+ y2 = cy - sin(angle + 4.0 * M_PI / 3.0) * r_min;
+}
+
+void
+ColorWheel::set_from_xy(const double& x, const double& y)
+{
+ Gtk::Allocation allocation = get_allocation();
+ const int width = allocation.get_width();
+ const int height = allocation.get_height();
+ double cx = width/2.0;
+ double cy = height/2.0;
+ double r = std::min(cx, cy) * (1 - _ring_width);
+
+ // We calculate RGB value under the cursor by rotating the cursor
+ // and triangle by the hue value and looking at position in the
+ // now right pointing triangle.
+ double angle = _hue * 2 * M_PI;
+ double Sin = sin(angle);
+ double Cos = cos(angle);
+ double xp = ((x-cx) * Cos - (y-cy) * Sin) / r;
+ double yp = ((x-cx) * Sin + (y-cy) * Cos) / r;
+
+ double xt = lerp(0.0, 1.0, -0.5, 1.0, xp);
+ xt = clamp(xt, 0, 1);
+
+ double dy = (1-xt) * cos(M_PI/6.0);
+ double yt = lerp(0.0, 1.0, -dy, dy, yp);
+ yt = clamp(yt, 0, 1);
+
+ color_point c0(0, 0, yt, yt, yt); // Grey point along base.
+ color_point c1(0, 0, hsv_to_rgb(_hue, 1, 1)); // Hue point at apex
+ color_point c = lerp(c0, c1, 0, 1, xt);
+
+ set_rgb(c.r, c.g, c.b, false); // Don't override previous hue.
+}
+
+bool
+ColorWheel::is_in_ring(const double& x, const double& y)
+{
+ Gtk::Allocation allocation = get_allocation();
+ const int width = allocation.get_width();
+ const int height = allocation.get_height();
+
+ int cx = width/2;
+ int cy = height/2;
+
+ int focus_line_width;
+ int focus_padding;
+ get_style_property("focus-line-width", focus_line_width);
+ get_style_property("focus-padding", focus_padding);
+
+ double r_max = std::min( width, height)/2.0 - 2 * (focus_line_width + focus_padding);
+ double r_min = r_max * (1.0 - _ring_width);
+ double r2_max = r_max * r_max;
+ double r2_min = r_min * r_min;
+
+ double dx = x - cx;
+ double dy = y - cy;
+ double r2 = dx * dx + dy * dy;
+
+ return (r2_min < r2 && r2 < r2_max);
+}
+
+bool
+ColorWheel::is_in_triangle(const double& x, const double& y)
+{
+ double x0, y0, x1, y1, x2, y2;
+ triangle_corners(x0, y0, x1, y1, x2, y2);
+
+ double det = (x2-x1) * (y0-y1) - (y2-y1) * (x0-x1);
+ double s = ((x -x1) * (y0-y1) - (y -y1) * (x0-x1)) / det;
+ double t = ((x2-x1) * (y -y1) - (y2-y1) * (x -x1)) / det;
+
+ return (s >= 0.0 && t >= 0.0 && s+t <= 1.0);
+}
+
+bool
+ColorWheel::on_focus(Gtk::DirectionType direction)
+{
+ // In forward direction, focus passes from no focus to ring focus to triangle focus to no focus.
+ if (!has_focus()) {
+ _focus_on_ring = (direction == Gtk::DIR_TAB_FORWARD);
+ grab_focus();
+ return true;
+ }
+
+ // Already have focus
+ bool keep_focus = false;
+
+ switch (direction) {
+ case Gtk::DIR_UP:
+ case Gtk::DIR_LEFT:
+ case Gtk::DIR_TAB_BACKWARD:
+ if (!_focus_on_ring) {
+ _focus_on_ring = true;
+ keep_focus = true;
+ }
+ break;
+
+ case Gtk::DIR_DOWN:
+ case Gtk::DIR_RIGHT:
+ case Gtk::DIR_TAB_FORWARD:
+ if (_focus_on_ring) {
+ _focus_on_ring = false;
+ keep_focus = true;
+ }
+ break;
+ }
+
+ queue_draw(); // Update focus indicators.
+
+ return keep_focus;
+}
+
+bool
+ColorWheel::on_button_press_event(GdkEventButton* event)
+{
+ // Seat is automatically grabbed.
+ double x = event->x;
+ double y = event->y;
+
+ if (is_in_ring(x, y) ) {
+ _mode = DRAG_H;
+ grab_focus();
+ _focus_on_ring = true;
+ return true;
+ }
+
+ if (is_in_triangle(x, y)) {
+ _mode = DRAG_SV;
+ grab_focus();
+ _focus_on_ring = false;
+ return true;
+ }
+
+ return false;
+}
+
+bool
+ColorWheel::on_button_release_event(GdkEventButton* event)
+{
+ _mode == DRAG_NONE;
+ return true;
+}
+
+bool
+ColorWheel::on_motion_notify_event(GdkEventMotion* event)
+{
+ double x = event->x;
+ double y = event->y;
+
+ Gtk::Allocation allocation = get_allocation();
+ const int width = allocation.get_width();
+ const int height = allocation.get_height();
+ double cx = width/2.0;
+ double cy = height/2.0;
+ double r = std::min(cx, cy) * (1 - _ring_width);
+
+ if (_mode == DRAG_H) {
+
+ double angle = -atan2(y-cy, x-cx);
+ if (angle < 0) angle += 2.0 * M_PI;
+ _hue = angle / (2.0 * M_PI);
+
+ queue_draw();
+ _signal_color_changed.emit();
+ return true;
+ }
+
+ if (_mode == DRAG_SV) {
+
+ set_from_xy(x, y);
+ _signal_color_changed.emit();
+ queue_draw();
+ return true;
+ }
+
+ return false;
+}
+
+bool
+ColorWheel::on_key_press_event(GdkEventKey* key_event)
+{
+ bool consumed = false;
+
+ unsigned int key = 0;
+ gdk_keymap_translate_keyboard_state( Gdk::Display::get_default()->get_keymap(),
+ key_event->hardware_keycode,
+ (GdkModifierType)key_event->state,
+ 0, &key, nullptr, nullptr, nullptr );
+
+ double x0, y0, x1, y1, x2, y2;
+ triangle_corners(x0, y0, x1, y1, x2, y2);
+
+ // Marker position
+ double mx = x1 + (x2-x1) * _value + (x0-x2) * _saturation * _value;
+ double my = y1 + (y2-y1) * _value + (y0-y2) * _saturation * _value;
+
+
+ const double delta_hue = 2.0/360.0;
+
+ switch (key) {
+
+ case GDK_KEY_Up:
+ case GDK_KEY_KP_Up:
+ if (_focus_on_ring) {
+ _hue += delta_hue;
+ } else {
+ my -= 1.0;
+ set_from_xy(mx, my);
+ }
+ consumed = true;
+ break;
+
+ case GDK_KEY_Down:
+ case GDK_KEY_KP_Down:
+ if (_focus_on_ring) {
+ _hue -= delta_hue;
+ } else {
+ my += 1.0;
+ set_from_xy(mx, my);
+ }
+ consumed = true;
+ break;
+
+ case GDK_KEY_Left:
+ case GDK_KEY_KP_Left:
+ if (_focus_on_ring) {
+ _hue += delta_hue;
+ } else {
+ mx -= 1.0;
+ set_from_xy(mx, my);
+ }
+ consumed = true;
+ break;
+
+ case GDK_KEY_Right:
+ case GDK_KEY_KP_Right:
+ if (_focus_on_ring) {
+ _hue -= delta_hue;
+ } else {
+ mx += 1.0;
+ set_from_xy(mx, my);
+ }
+ consumed = true;
+ break;
+
+ }
+
+ if (consumed) {
+ if (_hue >= 1.0) _hue -= 1.0;
+ if (_hue < 0.0) _hue += 1.0;
+ _signal_color_changed.emit();
+ queue_draw();
+ }
+
+ return consumed;
+}
+
+sigc::signal<void>
+ColorWheel::signal_color_changed()
+{
+ return _signal_color_changed;
+}
+
+} // Namespace Inkscape
+}
+}
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/ink-color-wheel.h b/src/ui/widget/ink-color-wheel.h
new file mode 100644
index 000000000..c6333b702
--- /dev/null
+++ b/src/ui/widget/ink-color-wheel.h
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Color wheel widget. Outer ring for Hue. Inner triangle for Saturation and Value.
+ *
+ * Copyright (C) 2018 Tavmjong Bah
+ *
+ * The contents of this file may be used under the GNU General Public License Version 2 or later.
+ *
+ */
+
+#ifndef INK_COLORWHEEL_H
+#define INK_COLORWHEEL_H
+
+/* Rewrite of the C Gimp ColorWheel which came originally from GTK2. */
+
+#include <gtkmm.h>
+#include <iostream>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class ColorWheel : public Gtk::DrawingArea
+{
+public:
+ ColorWheel();
+ void set_rgb(const double& r, const double& g, const double& b, bool override_hue = true);
+ void get_rgb(double& r, double& g, double& b);
+ guint32 get_rgb();
+ bool is_adjusting() {return _mode != DRAG_NONE;}
+
+protected:
+ bool on_draw(const::Cairo::RefPtr<::Cairo::Context>& cr) override;
+
+private:
+ void triangle_corners(double& x0, double& y0,
+ double& x1, double& y1,
+ double& x2, double& y2);
+ void set_from_xy(const double& x, const double& y);
+ bool is_in_ring( const double& x, const double& y);
+ bool is_in_triangle(const double& x, const double& y);
+
+ enum DragMode {
+ DRAG_NONE,
+ DRAG_H,
+ DRAG_SV
+ };
+
+ double _hue; // Range [0,1)
+ double _saturation;
+ double _value;
+ double _ring_width;
+ DragMode _mode;
+ bool _focus_on_ring;
+
+ // Callbacks
+ bool on_focus(Gtk::DirectionType direction) override;
+ bool on_button_press_event(GdkEventButton* event) override;
+ bool on_button_release_event(GdkEventButton* event) override;
+ bool on_motion_notify_event(GdkEventMotion* event) override;
+ bool on_key_press_event(GdkEventKey* key_event) override;
+
+ // Signals
+public:
+ sigc::signal<void> signal_color_changed();
+
+protected:
+ sigc::signal<void> _signal_color_changed;
+
+};
+
+} // Namespace Inkscape
+}
+}
+#endif // INK_COLOR_WHEEL_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/widgets/gimp/CMakeLists.txt b/src/widgets/gimp/CMakeLists.txt
index 0c8686cdd..c870b7528 100644
--- a/src/widgets/gimp/CMakeLists.txt
+++ b/src/widgets/gimp/CMakeLists.txt
@@ -1,11 +1,9 @@
# SPDX-License-Identifier: GPL-2.0-or-later
set(gimpwidgets_SRC
- gimpcolorwheel.c
ruler.cpp
# -------
# Headers
- gimpcolorwheel.h
ruler.h
)
diff --git a/src/widgets/gimp/gimpcolorwheel.c b/src/widgets/gimp/gimpcolorwheel.c
deleted file mode 100644
index 87f17eac6..000000000
--- a/src/widgets/gimp/gimpcolorwheel.c
+++ /dev/null
@@ -1,1484 +0,0 @@
-// SPDX-License-Identifier: LGPL-3.0-or-later
-/* HSV color selector for GTK+
- *
- * Copyright (C) 1999 The Free Software Foundation
- *
- * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
- * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
- * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
- * Michael Natterer <mitch@gimp.org> (ported back to GIMP)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GTK+ Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-/*
- * This widget was adopted by Inkscape by Alex Valavanis <valavanisalex@gmail.com>
- * on 2013-01-08. Last merges with GIMP code were applied using the following
- * commits from the GIMP git repository at
- * http://git.gnome.org/browse/gimp/tree/modules/gimpcolorwheel.c
- *
- * Gtk+ 2 code merge: commit 632c5 (2013-01-06)
- * Gtk+ 3 code merge: commit bcfc6, gtk3-port branch (2013-01-06)
- */
-
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
-
-#include "gimpcolorwheel.h"
-#include <math.h>
-
-
-/* Default ring fraction */
-#define DEFAULT_FRACTION 0.1
-
-/* Default width/height */
-#define DEFAULT_SIZE 100
-
-/* Default ring width */
-#define DEFAULT_RING_WIDTH 10
-
-
-/* Dragging modes */
-typedef enum
-{
- DRAG_NONE,
- DRAG_H,
- DRAG_SV
-} DragMode;
-
-/* Private part of the GimpColorWheel structure */
-typedef struct
-{
- /* Color value */
- gdouble h;
- gdouble s;
- gdouble v;
-
- /* ring_width is this fraction of size */
- gdouble ring_fraction;
-
- /* Size and ring width */
- gint size;
- gint ring_width;
-
- /* Window for capturing events */
- GdkWindow *window;
-
- /* Dragging mode */
- DragMode mode;
-
- guint focus_on_ring : 1;
-} GimpColorWheelPrivate;
-
-enum
-{
- CHANGED,
- MOVE,
- LAST_SIGNAL
-};
-
-static void gimp_color_wheel_map (GtkWidget *widget);
-static void gimp_color_wheel_unmap (GtkWidget *widget);
-static void gimp_color_wheel_realize (GtkWidget *widget);
-static void gimp_color_wheel_unrealize (GtkWidget *widget);
-static void gimp_color_wheel_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gboolean gimp_color_wheel_button_press (GtkWidget *widget,
- GdkEventButton *event);
-static gboolean gimp_color_wheel_button_release (GtkWidget *widget,
- GdkEventButton *event);
-static gboolean gimp_color_wheel_motion (GtkWidget *widget,
- GdkEventMotion *event);
-static gboolean gimp_color_wheel_draw (GtkWidget *widget,
- cairo_t *cr);
-static void gimp_color_wheel_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width);
-static void gimp_color_wheel_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height);
-static gboolean gimp_color_wheel_grab_broken (GtkWidget *widget,
- GdkEventGrabBroken *event);
-static gboolean gimp_color_wheel_focus (GtkWidget *widget,
- GtkDirectionType direction);
-static void gimp_color_wheel_move (GimpColorWheel *wheel,
- GtkDirectionType dir);
-
-
-static guint wheel_signals[LAST_SIGNAL];
-
-G_DEFINE_TYPE (GimpColorWheel, gimp_color_wheel, GTK_TYPE_WIDGET)
-
-#define parent_class gimp_color_wheel_parent_class
-
-
-static void
-gimp_color_wheel_class_init (GimpColorWheelClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- GimpColorWheelClass *wheel_class = GIMP_COLOR_WHEEL_CLASS (class);
- GtkBindingSet *binding_set;
-
- widget_class->map = gimp_color_wheel_map;
- widget_class->unmap = gimp_color_wheel_unmap;
- widget_class->realize = gimp_color_wheel_realize;
- widget_class->unrealize = gimp_color_wheel_unrealize;
- widget_class->size_allocate = gimp_color_wheel_size_allocate;
- widget_class->button_press_event = gimp_color_wheel_button_press;
- widget_class->button_release_event = gimp_color_wheel_button_release;
- widget_class->motion_notify_event = gimp_color_wheel_motion;
- widget_class->get_preferred_width = gimp_color_wheel_get_preferred_width;
- widget_class->get_preferred_height = gimp_color_wheel_get_preferred_height;
- widget_class->draw = gimp_color_wheel_draw;
- widget_class->focus = gimp_color_wheel_focus;
- widget_class->grab_broken_event = gimp_color_wheel_grab_broken;
-
- wheel_class->move = gimp_color_wheel_move;
-
- wheel_signals[CHANGED] =
- g_signal_new ("changed",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GimpColorWheelClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- wheel_signals[MOVE] =
- g_signal_new ("move",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GimpColorWheelClass, move),
- NULL, NULL,
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, 1,
- GTK_TYPE_DIRECTION_TYPE);
-
- binding_set = gtk_binding_set_by_class (class);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_UP);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_UP);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_DOWN);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_DOWN);
-
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_RIGHT);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_RIGHT);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_LEFT);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0,
- "move", 1,
- G_TYPE_ENUM, GTK_DIR_LEFT);
-
- g_type_class_add_private (object_class, sizeof (GimpColorWheelPrivate));
-}
-
-static void
-gimp_color_wheel_init (GimpColorWheel *wheel)
-{
- GimpColorWheelPrivate *priv;
-
- priv = G_TYPE_INSTANCE_GET_PRIVATE (wheel, GIMP_TYPE_COLOR_WHEEL,
- GimpColorWheelPrivate);
-
- wheel->priv = priv;
-
- gtk_widget_set_has_window (GTK_WIDGET (wheel), FALSE);
- gtk_widget_set_can_focus (GTK_WIDGET (wheel), TRUE);
-
- priv->ring_fraction = DEFAULT_FRACTION;
- priv->size = DEFAULT_SIZE;
- priv->ring_width = DEFAULT_RING_WIDTH;
-}
-
-static void
-gimp_color_wheel_map (GtkWidget *widget)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
-
- GTK_WIDGET_CLASS (parent_class)->map (widget);
-
- gdk_window_show (priv->window);
-}
-
-static void
-gimp_color_wheel_unmap (GtkWidget *widget)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
-
- gdk_window_hide (priv->window);
-
- GTK_WIDGET_CLASS (parent_class)->unmap (widget);
-}
-
-static void
-gimp_color_wheel_realize (GtkWidget *widget)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- GtkAllocation allocation;
- GdkWindowAttr attr;
- gint attr_mask;
- GdkWindow *parent_window;
-
- gtk_widget_get_allocation (widget, &allocation);
-
- gtk_widget_set_realized (widget, TRUE);
-
- attr.window_type = GDK_WINDOW_CHILD;
- attr.x = allocation.x;
- attr.y = allocation.y;
- attr.width = allocation.width;
- attr.height = allocation.height;
- attr.wclass = GDK_INPUT_ONLY;
- attr.event_mask = (gtk_widget_get_events (widget) |
- GDK_KEY_PRESS_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK);
-
- attr_mask = GDK_WA_X | GDK_WA_Y;
-
- parent_window = gtk_widget_get_parent_window (widget);
-
- gtk_widget_set_window (widget, parent_window);
- g_object_ref (parent_window);
-
- priv->window = gdk_window_new (parent_window, &attr, attr_mask);
- gdk_window_set_user_data (priv->window, wheel);
-}
-
-static void
-gimp_color_wheel_unrealize (GtkWidget *widget)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
-
- gdk_window_set_user_data (priv->window, NULL);
- gdk_window_destroy (priv->window);
- priv->window = NULL;
-
- GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
-}
-
-static void
-gimp_color_wheel_get_preferred_width (GtkWidget *widget,
- gint *minimum_width,
- gint *natural_width)
-{
- gint focus_width;
- gint focus_pad;
-
- gtk_widget_style_get (widget,
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- *minimum_width = *natural_width = DEFAULT_SIZE + 2 * (focus_width + focus_pad);
-}
-
-static void
-gimp_color_wheel_get_preferred_height (GtkWidget *widget,
- gint *minimum_height,
- gint *natural_height)
-{
- gint focus_width;
- gint focus_pad;
-
- gtk_widget_style_get (widget,
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- *minimum_height = *natural_height = DEFAULT_SIZE + 2 * (focus_width + focus_pad);
-}
-
-static void
-gimp_color_wheel_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- gint focus_width;
- gint focus_pad;
-
- gtk_widget_set_allocation (widget, allocation);
-
- gtk_widget_style_get (widget,
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- priv->size = MIN (allocation->width - 2 * (focus_width + focus_pad),
- allocation->height - 2 * (focus_width + focus_pad));
-
- priv->ring_width = priv->size * priv->ring_fraction;
-
- if (gtk_widget_get_realized (widget))
- gdk_window_move_resize (priv->window,
- allocation->x,
- allocation->y,
- allocation->width,
- allocation->height);
-}
-
-
-/* Utility functions */
-
-#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
-
-/* Converts from HSV to RGB */
-static void
-hsv_to_rgb (gdouble *h,
- gdouble *s,
- gdouble *v)
-{
- gdouble hue, saturation, value;
- gdouble f, p, q, t;
-
- if (*s == 0.0)
- {
- *h = *v;
- *s = *v;
- /* *v = *v; -- heh */
- }
- else
- {
- hue = *h * 6.0;
- saturation = *s;
- value = *v;
-
- if (hue == 6.0)
- hue = 0.0;
-
- f = hue - (int) hue;
- p = value * (1.0 - saturation);
- q = value * (1.0 - saturation * f);
- t = value * (1.0 - saturation * (1.0 - f));
-
- switch ((int) hue)
- {
- case 0:
- *h = value;
- *s = t;
- *v = p;
- break;
-
- case 1:
- *h = q;
- *s = value;
- *v = p;
- break;
-
- case 2:
- *h = p;
- *s = value;
- *v = t;
- break;
-
- case 3:
- *h = p;
- *s = q;
- *v = value;
- break;
-
- case 4:
- *h = t;
- *s = p;
- *v = value;
- break;
-
- case 5:
- *h = value;
- *s = p;
- *v = q;
- break;
-
- default:
- g_assert_not_reached ();
- }
- }
-}
-
-/* Computes the vertices of the saturation/value triangle */
-static void
-compute_triangle (GimpColorWheel *wheel,
- gint *hx,
- gint *hy,
- gint *sx,
- gint *sy,
- gint *vx,
- gint *vy)
-{
- GimpColorWheelPrivate *priv = wheel->priv;
- GtkAllocation allocation;
- gdouble center_x;
- gdouble center_y;
- gdouble inner, outer;
- gdouble angle;
-
- gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation);
-
- center_x = allocation.width / 2.0;
- center_y = allocation.height / 2.0;
-
- outer = priv->size / 2.0;
- inner = outer - priv->ring_width;
- angle = priv->h * 2.0 * G_PI;
-
- *hx = floor (center_x + cos (angle) * inner + 0.5);
- *hy = floor (center_y - sin (angle) * inner + 0.5);
- *sx = floor (center_x + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
- *sy = floor (center_y - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5);
- *vx = floor (center_x + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
- *vy = floor (center_y - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5);
-}
-
-/* Computes whether a point is inside the hue ring */
-static gboolean
-is_in_ring (GimpColorWheel *wheel,
- gdouble x,
- gdouble y)
-{
- GimpColorWheelPrivate *priv = wheel->priv;
- GtkAllocation allocation;
- gdouble dx, dy, dist;
- gdouble center_x;
- gdouble center_y;
- gdouble inner, outer;
-
- gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation);
-
- center_x = allocation.width / 2.0;
- center_y = allocation.height / 2.0;
-
- outer = priv->size / 2.0;
- inner = outer - priv->ring_width;
-
- dx = x - center_x;
- dy = center_y - y;
- dist = dx * dx + dy * dy;
-
- return (dist >= inner * inner && dist <= outer * outer);
-}
-
-/* Computes a saturation/value pair based on the mouse coordinates */
-static void
-compute_sv (GimpColorWheel *wheel,
- gdouble x,
- gdouble y,
- gdouble *s,
- gdouble *v)
-{
- GtkAllocation allocation;
- gint ihx, ihy, isx, isy, ivx, ivy;
- gdouble hx, hy, sx, sy, vx, vy;
- gdouble center_x;
- gdouble center_y;
-
- gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation);
-
- compute_triangle (wheel, &ihx, &ihy, &isx, &isy, &ivx, &ivy);
-
- center_x = allocation.width / 2.0;
- center_y = allocation.height / 2.0;
-
- hx = ihx - center_x;
- hy = center_y - ihy;
- sx = isx - center_x;
- sy = center_y - isy;
- vx = ivx - center_x;
- vy = center_y - ivy;
- x -= center_x;
- y = center_y - y;
-
- if (vx * (x - sx) + vy * (y - sy) < 0.0)
- {
- *s = 1.0;
- *v = (((x - sx) * (hx - sx) + (y - sy) * (hy-sy))
- / ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy)));
-
- if (*v < 0.0)
- *v = 0.0;
- else if (*v > 1.0)
- *v = 1.0;
- }
- else if (hx * (x - sx) + hy * (y - sy) < 0.0)
- {
- *s = 0.0;
- *v = (((x - sx) * (vx - sx) + (y - sy) * (vy - sy))
- / ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy)));
-
- if (*v < 0.0)
- *v = 0.0;
- else if (*v > 1.0)
- *v = 1.0;
- }
- else if (sx * (x - hx) + sy * (y - hy) < 0.0)
- {
- *v = 1.0;
- *s = (((x - vx) * (hx - vx) + (y - vy) * (hy - vy)) /
- ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy)));
-
- if (*s < 0.0)
- *s = 0.0;
- else if (*s > 1.0)
- *s = 1.0;
- }
- else
- {
- *v = (((x - sx) * (hy - vy) - (y - sy) * (hx - vx))
- / ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx)));
-
- if (*v<= 0.0)
- {
- *v = 0.0;
- *s = 0.0;
- }
- else
- {
- if (*v > 1.0)
- *v = 1.0;
-
- if (fabs (hy - vy) < fabs (hx - vx))
- *s = (x - sx - *v * (vx - sx)) / (*v * (hx - vx));
- else
- *s = (y - sy - *v * (vy - sy)) / (*v * (hy - vy));
-
- if (*s < 0.0)
- *s = 0.0;
- else if (*s > 1.0)
- *s = 1.0;
- }
- }
-}
-
-/* Computes whether a point is inside the saturation/value triangle */
-static gboolean
-is_in_triangle (GimpColorWheel *wheel,
- gdouble x,
- gdouble y)
-{
- gint hx, hy, sx, sy, vx, vy;
- gdouble det, s, v;
-
- compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy);
-
- det = (vx - sx) * (hy - sy) - (vy - sy) * (hx - sx);
-
- s = ((x - sx) * (hy - sy) - (y - sy) * (hx - sx)) / det;
- v = ((vx - sx) * (y - sy) - (vy - sy) * (x - sx)) / det;
-
- return (s >= 0.0 && v >= 0.0 && s + v <= 1.0);
-}
-
-/* Computes a value based on the mouse coordinates */
-static double
-compute_v (GimpColorWheel *wheel,
- gdouble x,
- gdouble y)
-{
- GtkAllocation allocation;
- gdouble center_x;
- gdouble center_y;
- gdouble dx, dy;
- gdouble angle;
-
- gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation);
-
- center_x = allocation.width / 2.0;
- center_y = allocation.height / 2.0;
-
- dx = x - center_x;
- dy = center_y - y;
-
- angle = atan2 (dy, dx);
- if (angle < 0.0)
- angle += 2.0 * G_PI;
-
- return angle / (2.0 * G_PI);
-}
-
-static void
-set_cross_grab (GimpColorWheel *wheel,
- GdkEvent *event)
-{
- GimpColorWheelPrivate *priv = wheel->priv;
- GdkCursor *cursor;
-
- cursor =
- gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (wheel)),
- GDK_CROSSHAIR);
-
- GdkDevice *device = gtk_get_current_event_device();
-#if GTK_CHECK_VERSION(3,20,0)
- GdkSeat *seat = gdk_device_get_seat(device);
- gdk_seat_grab (seat,
- priv->window,
- GDK_SEAT_CAPABILITY_ALL_POINTING,
- FALSE,
- cursor,
- event,
- NULL,
- NULL);
-#else
- gdk_device_grab (device,
- priv->window,
- GDK_OWNERSHIP_NONE,
- FALSE,
- GDK_POINTER_MOTION_MASK |
- GDK_POINTER_MOTION_HINT_MASK |
- GDK_BUTTON_RELEASE_MASK,
- cursor, gtk_get_current_event_time());
-#endif
-
- g_object_unref (cursor);
-}
-
-static gboolean gimp_color_wheel_grab_broken(GtkWidget *widget, GdkEventGrabBroken *event)
-{
- (void)event;
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
-
- priv->mode = DRAG_NONE;
-
- return TRUE;
-}
-
-static gboolean
-gimp_color_wheel_button_press (GtkWidget *widget,
- GdkEventButton *event)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- gdouble x, y;
-
- if (priv->mode != DRAG_NONE || event->button != 1)
- return FALSE;
-
- x = event->x;
- y = event->y;
-
- if (is_in_ring (wheel, x, y))
- {
- priv->mode = DRAG_H;
- set_cross_grab (wheel, (GdkEvent *)event);
-
- gimp_color_wheel_set_color (wheel,
- compute_v (wheel, x, y),
- priv->s,
- priv->v);
-
- gtk_widget_grab_focus (widget);
- priv->focus_on_ring = TRUE;
-
- return TRUE;
- }
-
- if (is_in_triangle (wheel, x, y))
- {
- gdouble s, v;
-
- priv->mode = DRAG_SV;
- set_cross_grab (wheel, (GdkEvent *)event);
-
- compute_sv (wheel, x, y, &s, &v);
- gimp_color_wheel_set_color (wheel, priv->h, s, v);
-
- gtk_widget_grab_focus (widget);
- priv->focus_on_ring = FALSE;
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-static gboolean
-gimp_color_wheel_button_release (GtkWidget *widget,
- GdkEventButton *event)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- DragMode mode;
- gdouble x, y;
-
- if (priv->mode == DRAG_NONE || event->button != 1)
- return FALSE;
-
- /* Set the drag mode to DRAG_NONE so that signal handlers for "catched"
- * can see that this is the final color state.
- */
-
- mode = priv->mode;
- priv->mode = DRAG_NONE;
-
- x = event->x;
- y = event->y;
-
- if (mode == DRAG_H)
- {
- gimp_color_wheel_set_color (wheel,
- compute_v (wheel, x, y), priv->s, priv->v);
- }
- else if (mode == DRAG_SV)
- {
- gdouble s, v;
-
- compute_sv (wheel, x, y, &s, &v);
- gimp_color_wheel_set_color (wheel, priv->h, s, v);
- }
- else
- g_assert_not_reached ();
-
- GdkDevice *device = gtk_get_current_event_device();
-#if GTK_CHECK_VERSION(3,20,0)
- GdkSeat *seat = gdk_device_get_seat(device);
- gdk_seat_ungrab (seat);
-#else
- gdk_device_ungrab (device,
- (GdkEvent *)event);
-#endif
-
- return TRUE;
-}
-
-static gboolean
-gimp_color_wheel_motion (GtkWidget *widget,
- GdkEventMotion *event)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- gdouble x, y;
-
- if (priv->mode == DRAG_NONE)
- return FALSE;
-
- gdk_event_request_motions (event);
- x = event->x;
- y = event->y;
-
- if (priv->mode == DRAG_H)
- {
- gimp_color_wheel_set_color (wheel,
- compute_v (wheel, x, y), priv->s, priv->v);
- return TRUE;
- }
- else if (priv->mode == DRAG_SV)
- {
- gdouble s, v;
-
- compute_sv (wheel, x, y, &s, &v);
- gimp_color_wheel_set_color (wheel, priv->h, s, v);
- return TRUE;
- }
-
- g_assert_not_reached ();
-
- return FALSE;
-}
-
-
-/* Redrawing */
-
-/* Paints the hue ring */
-static void
-paint_ring (GimpColorWheel *wheel,
- cairo_t *cr)
-{
- GtkWidget *widget = GTK_WIDGET (wheel);
- GimpColorWheelPrivate *priv = wheel->priv;
- gint width, height;
- gint xx, yy;
- gdouble dx, dy, dist;
- gdouble center_x;
- gdouble center_y;
- gdouble inner, outer;
- guint32 *buf, *p;
- gdouble angle;
- gdouble hue;
- gdouble r, g, b;
- cairo_surface_t *source;
- cairo_t *source_cr;
- gint stride;
-
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
-
- center_x = width / 2.0;
- center_y = height / 2.0;
-
- outer = priv->size / 2.0;
- inner = outer - priv->ring_width;
-
- /* Create an image initialized with the ring colors */
-
- stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
- buf = g_new (guint32, height * stride / 4);
-
- for (yy = 0; yy < height; yy++)
- {
- p = buf + yy * width;
- dy = -(yy - center_y);
-
- for (xx = 0; xx < width; xx++)
- {
- dx = xx - center_x;
-
- dist = dx * dx + dy * dy;
- if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1)))
- {
- *p++ = 0;
- continue;
- }
-
- angle = atan2 (dy, dx);
- if (angle < 0.0)
- angle += 2.0 * G_PI;
-
- hue = angle / (2.0 * G_PI);
-
- r = hue;
- g = 1.0;
- b = 1.0;
- hsv_to_rgb (&r, &g, &b);
-
- *p++ = (((int)floor (r * 255 + 0.5) << 16) |
- ((int)floor (g * 255 + 0.5) << 8) |
- (int)floor (b * 255 + 0.5));
- }
- }
-
- source = cairo_image_surface_create_for_data ((unsigned char *)buf,
- CAIRO_FORMAT_RGB24,
- width, height, stride);
-
- /* Now draw the value marker onto the source image, so that it
- * will get properly clipped at the edges of the ring
- */
- source_cr = cairo_create (source);
-
- r = priv->h;
- g = 1.0;
- b = 1.0;
- hsv_to_rgb (&r, &g, &b);
-
- if (INTENSITY (r, g, b) > 0.5)
- cairo_set_source_rgb (source_cr, 0.0, 0.0, 0.0);
- else
- cairo_set_source_rgb (source_cr, 1.0, 1.0, 1.0);
-
- cairo_move_to (source_cr, center_x, center_y);
- cairo_line_to (source_cr,
- center_x + cos (priv->h * 2.0 * G_PI) * priv->size / 2,
- center_y - sin (priv->h * 2.0 * G_PI) * priv->size / 2);
- cairo_stroke (source_cr);
- cairo_destroy (source_cr);
-
- /* Draw the ring using the source image */
-
- cairo_save (cr);
-
- cairo_set_source_surface (cr, source, 0, 0);
- cairo_surface_destroy (source);
-
- cairo_set_line_width (cr, priv->ring_width);
- cairo_new_path (cr);
- cairo_arc (cr,
- center_x, center_y,
- priv->size / 2.0 - priv->ring_width / 2.0,
- 0, 2 * G_PI);
- cairo_stroke (cr);
-
- cairo_restore (cr);
-
- g_free (buf);
-}
-
-/* Converts an HSV triplet to an integer RGB triplet */
-static void
-get_color (gdouble h,
- gdouble s,
- gdouble v,
- gint *r,
- gint *g,
- gint *b)
-{
- hsv_to_rgb (&h, &s, &v);
-
- *r = floor (h * 255 + 0.5);
- *g = floor (s * 255 + 0.5);
- *b = floor (v * 255 + 0.5);
-}
-
-#define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
-
-#define LERP(a, b, v1, v2, i) (((v2) - (v1) != 0) \
- ? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1))) \
- : (a))
-
-/* Number of pixels we extend out from the edges when creating
- * color source to avoid artifacts
- */
-#define PAD 3
-
-/* Paints the HSV triangle */
-static void
-paint_triangle (GimpColorWheel *wheel,
- cairo_t *cr,
- gboolean draw_focus)
-{
- GtkWidget *widget = GTK_WIDGET (wheel);
- GimpColorWheelPrivate *priv = wheel->priv;
- gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
- gint x1, y1, r1, g1, b1; /* First vertex in scanline order */
- gint x2, y2, r2, g2, b2; /* Second vertex */
- gint x3, y3, r3, g3, b3; /* Third vertex */
- gint t;
- guint32 *buf, *p, c;
- gint xl, xr, rl, rr, gl, gr, bl, br; /* Scanline data */
- gint xx, yy;
- gint x_interp, y_interp;
- gint x_start, x_end;
- cairo_surface_t *source;
- gdouble r, g, b;
- gint stride;
- gint width, height;
- GtkStyleContext *context;
-
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
-
- /* Compute triangle's vertices */
-
- compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy);
-
- x1 = hx;
- y1 = hy;
- get_color (priv->h, 1.0, 1.0, &r1, &g1, &b1);
-
- x2 = sx;
- y2 = sy;
- get_color (priv->h, 1.0, 0.0, &r2, &g2, &b2);
-
- x3 = vx;
- y3 = vy;
- get_color (priv->h, 0.0, 1.0, &r3, &g3, &b3);
-
- if (y2 > y3)
- {
- SWAP (x2, x3, t);
- SWAP (y2, y3, t);
- SWAP (r2, r3, t);
- SWAP (g2, g3, t);
- SWAP (b2, b3, t);
- }
-
- if (y1 > y3)
- {
- SWAP (x1, x3, t);
- SWAP (y1, y3, t);
- SWAP (r1, r3, t);
- SWAP (g1, g3, t);
- SWAP (b1, b3, t);
- }
-
- if (y1 > y2)
- {
- SWAP (x1, x2, t);
- SWAP (y1, y2, t);
- SWAP (r1, r2, t);
- SWAP (g1, g2, t);
- SWAP (b1, b2, t);
- }
-
- /* Shade the triangle */
-
- stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width);
- buf = g_new (guint32, height * stride / 4);
-
- for (yy = 0; yy < height; yy++)
- {
- p = buf + yy * width;
-
- if (yy >= y1 - PAD && yy < y3 + PAD)
- {
- y_interp = CLAMP (yy, y1, y3);
-
- if (y_interp < y2)
- {
- xl = LERP (x1, x2, y1, y2, y_interp);
-
- rl = LERP (r1, r2, y1, y2, y_interp);
- gl = LERP (g1, g2, y1, y2, y_interp);
- bl = LERP (b1, b2, y1, y2, y_interp);
- }
- else
- {
- xl = LERP (x2, x3, y2, y3, y_interp);
-
- rl = LERP (r2, r3, y2, y3, y_interp);
- gl = LERP (g2, g3, y2, y3, y_interp);
- bl = LERP (b2, b3, y2, y3, y_interp);
- }
-
- xr = LERP (x1, x3, y1, y3, y_interp);
-
- rr = LERP (r1, r3, y1, y3, y_interp);
- gr = LERP (g1, g3, y1, y3, y_interp);
- br = LERP (b1, b3, y1, y3, y_interp);
-
- if (xl > xr)
- {
- SWAP (xl, xr, t);
- SWAP (rl, rr, t);
- SWAP (gl, gr, t);
- SWAP (bl, br, t);
- }
-
- x_start = MAX (xl - PAD, 0);
- x_end = MIN (xr + PAD, width);
- x_start = MIN (x_start, x_end);
-
- c = (rl << 16) | (gl << 8) | bl;
-
- for (xx = 0; xx < x_start; xx++)
- *p++ = c;
-
- for (; xx < x_end; xx++)
- {
- x_interp = CLAMP (xx, xl, xr);
-
- *p++ = ((LERP (rl, rr, xl, xr, x_interp) << 16) |
- (LERP (gl, gr, xl, xr, x_interp) << 8) |
- LERP (bl, br, xl, xr, x_interp));
- }
-
- c = (rr << 16) | (gr << 8) | br;
-
- for (; xx < width; xx++)
- *p++ = c;
- }
- }
-
- source = cairo_image_surface_create_for_data ((unsigned char *)buf,
- CAIRO_FORMAT_RGB24,
- width, height, stride);
-
- /* Draw a triangle with the image as a source */
-
- cairo_set_source_surface (cr, source, 0, 0);
- cairo_surface_destroy (source);
-
- cairo_move_to (cr, x1, y1);
- cairo_line_to (cr, x2, y2);
- cairo_line_to (cr, x3, y3);
- cairo_close_path (cr);
- cairo_fill (cr);
-
- g_free (buf);
-
- /* Draw value marker */
-
- xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
- yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
-
- r = priv->h;
- g = priv->s;
- b = priv->v;
- hsv_to_rgb (&r, &g, &b);
-
- context = gtk_widget_get_style_context (widget);
-
- gtk_style_context_save (context);
-
- if (INTENSITY (r, g, b) > 0.5)
- {
- gtk_style_context_add_class (context, "light-area-focus");
- cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
- }
- else
- {
- gtk_style_context_add_class (context, "dark-area-focus");
- cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
- }
-
-#define RADIUS 4
-#define FOCUS_RADIUS 6
-
- cairo_new_path (cr);
- cairo_arc (cr, xx, yy, RADIUS, 0, 2 * G_PI);
- cairo_stroke (cr);
-
- /* Draw focus outline */
-
- if (draw_focus && ! priv->focus_on_ring)
- {
- gint focus_width;
- gint focus_pad;
-
- gtk_widget_style_get (widget,
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- gtk_render_focus (context, cr,
- xx - FOCUS_RADIUS - focus_width - focus_pad,
- yy - FOCUS_RADIUS - focus_width - focus_pad,
- 2 * (FOCUS_RADIUS + focus_width + focus_pad),
- 2 * (FOCUS_RADIUS + focus_width + focus_pad));
- }
-
- gtk_style_context_restore (context);
-}
-
-static gboolean
-gimp_color_wheel_draw (GtkWidget *widget,
- cairo_t *cr)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
- gboolean draw_focus;
-
- draw_focus = gtk_widget_has_visible_focus (widget);
-
- paint_ring (wheel, cr);
- paint_triangle (wheel, cr, draw_focus);
-
- if (draw_focus && priv->focus_on_ring)
- {
- GtkStyleContext *context = gtk_widget_get_style_context (widget);
-
- gtk_render_focus (context, cr, 0, 0,
- gtk_widget_get_allocated_width (widget),
- gtk_widget_get_allocated_height (widget));
- }
-
- return FALSE;
-}
-
-static gboolean
-gimp_color_wheel_focus (GtkWidget *widget,
- GtkDirectionType dir)
-{
- GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget);
- GimpColorWheelPrivate *priv = wheel->priv;
-
- if (!gtk_widget_has_focus (widget))
- {
- if (dir == GTK_DIR_TAB_BACKWARD)
- priv->focus_on_ring = FALSE;
- else
- priv->focus_on_ring = TRUE;
-
- gtk_widget_grab_focus (widget);
- return TRUE;
- }
-
- switch (dir)
- {
- case GTK_DIR_UP:
- if (priv->focus_on_ring)
- return FALSE;
- else
- priv->focus_on_ring = TRUE;
- break;
-
- case GTK_DIR_DOWN:
- if (priv->focus_on_ring)
- priv->focus_on_ring = FALSE;
- else
- return FALSE;
- break;
-
- case GTK_DIR_LEFT:
- case GTK_DIR_TAB_BACKWARD:
- if (priv->focus_on_ring)
- return FALSE;
- else
- priv->focus_on_ring = TRUE;
- break;
-
- case GTK_DIR_RIGHT:
- case GTK_DIR_TAB_FORWARD:
- if (priv->focus_on_ring)
- priv->focus_on_ring = FALSE;
- else
- return FALSE;
- break;
- }
-
- gtk_widget_queue_draw (widget);
-
- return TRUE;
-}
-
-/**
- * gimp_color_wheel_new:
- *
- * Creates a new HSV color selector.
- *
- * Return value: A newly-created HSV color selector.
- *
- * Since: 2.10
- */
-GtkWidget*
-gimp_color_wheel_new (void)
-{
- return g_object_new (GIMP_TYPE_COLOR_WHEEL, NULL);
-}
-
-/**
- * gimp_color_wheel_set_color:
- * @hsv: An HSV color selector
- * @h: Hue
- * @s: Saturation
- * @v: Value
- *
- * Sets the current color in an HSV color selector.
- * Color component values must be in the [0.0, 1.0] range.
- *
- * Since: 2.10
- */
-void
-gimp_color_wheel_set_color (GimpColorWheel *wheel,
- gdouble h,
- gdouble s,
- gdouble v)
-{
- GimpColorWheelPrivate *priv;
-
- g_return_if_fail (GIMP_IS_COLOR_WHEEL (wheel));
- g_return_if_fail (h >= 0.0 && h <= 1.0);
- g_return_if_fail (s >= 0.0 && s <= 1.0);
- g_return_if_fail (v >= 0.0 && v <= 1.0);
-
- priv = wheel->priv;
-
- if(h == 0.0 && s == 0.0) {
- h = priv->h;
- }
-
- priv->h = h;
- priv->s = s;
- priv->v = v;
-
- g_signal_emit (wheel, wheel_signals[CHANGED], 0);
-
- gtk_widget_queue_draw (GTK_WIDGET (wheel));
-}
-
-/**
- * gimp_color_wheel_get_color:
- * @hsv: An HSV color selector
- * @h: (out): Return value for the hue
- * @s: (out): Return value for the saturation
- * @v: (out): Return value for the value
- *
- * Queries the current color in an HSV color selector.
- * Returned values will be in the [0.0, 1.0] range.
- *
- * Since: 2.10
- */
-void
-gimp_color_wheel_get_color (GimpColorWheel *wheel,
- gdouble *h,
- gdouble *s,
- gdouble *v)
-{
- GimpColorWheelPrivate *priv;
-
- g_return_if_fail (GIMP_IS_COLOR_WHEEL (wheel));
-
- priv = wheel->priv;
-
- if (h) *h = priv->h;
- if (s) *s = priv->s;
- if (v) *v = priv->v;
-}
-
-/**
- * gimp_color_wheel_set_ring_fraction:
- * @ring: A wheel color selector
- * @fraction: Ring fraction
- *
- * Sets the ring fraction of a wheel color selector.
- *
- * Since: 2.10
- */
-void
-gimp_color_wheel_set_ring_fraction (GimpColorWheel *hsv,
- gdouble fraction)
-{
- GimpColorWheelPrivate *priv;
-
- g_return_if_fail (GIMP_IS_COLOR_WHEEL (hsv));
-
- priv = hsv->priv;
-
- priv->ring_fraction = CLAMP (fraction, 0.01, 0.99);
-
- gtk_widget_queue_draw (GTK_WIDGET (hsv));
-}
-
-/**
- * gimp_color_wheel_get_ring_fraction:
- * @ring: A wheel color selector
- *
- * Returns value: The ring fraction of the wheel color selector.
- *
- * Since: 2.10
- */
-gdouble
-gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel)
-{
- GimpColorWheelPrivate *priv;
-
- g_return_val_if_fail (GIMP_IS_COLOR_WHEEL (wheel), DEFAULT_FRACTION);
-
- priv = wheel->priv;
-
- return priv->ring_fraction;
-}
-
-/**
- * gimp_color_wheel_is_adjusting:
- * @hsv: A #GimpColorWheel
- *
- * An HSV color selector can be said to be adjusting if multiple rapid
- * changes are being made to its value, for example, when the user is
- * adjusting the value with the mouse. This function queries whether
- * the HSV color selector is being adjusted or not.
- *
- * Return value: %TRUE if clients can ignore changes to the color value,
- * since they may be transitory, or %FALSE if they should consider
- * the color value status to be final.
- *
- * Since: 2.14
- */
-gboolean
-gimp_color_wheel_is_adjusting (GimpColorWheel *wheel)
-{
- GimpColorWheelPrivate *priv;
-
- g_return_val_if_fail (GIMP_IS_COLOR_WHEEL (wheel), FALSE);
-
- priv = wheel->priv;
-
- return priv->mode != DRAG_NONE;
-}
-
-static void
-gimp_color_wheel_move (GimpColorWheel *wheel,
- GtkDirectionType dir)
-{
- GimpColorWheelPrivate *priv = wheel->priv;
- gdouble hue, sat, val;
- gint hx, hy, sx, sy, vx, vy; /* HSV vertices */
- gint x, y; /* position in triangle */
-
- hue = priv->h;
- sat = priv->s;
- val = priv->v;
-
- compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy);
-
- x = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);
- y = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5);
-
-#define HUE_DELTA 0.002
- switch (dir)
- {
- case GTK_DIR_UP:
- if (priv->focus_on_ring)
- hue += HUE_DELTA;
- else
- {
- y -= 1;
- compute_sv (wheel, x, y, &sat, &val);
- }
- break;
-
- case GTK_DIR_DOWN:
- if (priv->focus_on_ring)
- hue -= HUE_DELTA;
- else
- {
- y += 1;
- compute_sv (wheel, x, y, &sat, &val);
- }
- break;
-
- case GTK_DIR_LEFT:
- if (priv->focus_on_ring)
- hue += HUE_DELTA;
- else
- {
- x -= 1;
- compute_sv (wheel, x, y, &sat, &val);
- }
- break;
-
- case GTK_DIR_RIGHT:
- if (priv->focus_on_ring)
- hue -= HUE_DELTA
- ;
- else
- {
- x += 1;
- compute_sv (wheel, x, y, &sat, &val);
- }
- break;
-
- default:
- /* we don't care about the tab directions */
- break;
- }
-
- /* Wrap */
- if (hue < 0.0)
- hue = 1.0;
- else if (hue > 1.0)
- hue = 0.0;
-
- gimp_color_wheel_set_color (wheel, hue, sat, val);
-}
diff --git a/src/widgets/gimp/gimpcolorwheel.h b/src/widgets/gimp/gimpcolorwheel.h
deleted file mode 100644
index e79fc1575..000000000
--- a/src/widgets/gimp/gimpcolorwheel.h
+++ /dev/null
@@ -1,97 +0,0 @@
-// SPDX-License-Identifier: LGPL-3.0-or-later
-/** @file
- * HSV color selector for GTK+
- */
-/* HSV color selector for GTK+
- *
- * Copyright (C) 1999 The Free Software Foundation
- *
- * Authors: Simon Budig <Simon.Budig@unix-ag.org> (original code)
- * Federico Mena-Quintero <federico@gimp.org> (cleanup for GTK+)
- * Jonathan Blandford <jrb@redhat.com> (cleanup for GTK+)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GTK+ Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __GIMP_COLOR_WHEEL_H__
-#define __GIMP_COLOR_WHEEL_H__
-
-G_BEGIN_DECLS
-
-#define GIMP_TYPE_COLOR_WHEEL (gimp_color_wheel_get_type ())
-#define GIMP_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_WHEEL, GimpColorWheel))
-#define GIMP_COLOR_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_WHEEL, GimpColorWheelClass))
-#define GIMP_IS_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_WHEEL))
-#define GIMP_IS_COLOR_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_WHEEL))
-#define GIMP_COLOR_WHEEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_WHEEL, GimpColorWheelClass))
-
-
-typedef struct _GimpColorWheel GimpColorWheel;
-typedef struct _GimpColorWheelClass GimpColorWheelClass;
-
-struct _GimpColorWheel
-{
- GtkWidget parent_instance;
-
- /* Private data */
- gpointer priv;
-};
-
-struct _GimpColorWheelClass
-{
- GtkWidgetClass parent_class;
-
- /* Notification signals */
- void (* changed) (GimpColorWheel *wheel);
-
- /* Keybindings */
- void (* move) (GimpColorWheel *wheel,
- GtkDirectionType type);
-
- /* Padding for future expansion */
- void (*_gimp_reserved1) ();
- void (*_gimp_reserved2) ();
- void (*_gimp_reserved3) ();
- void (*_gimp_reserved4) ();
-};
-
-
-GType gimp_color_wheel_get_type (void) G_GNUC_CONST;
-GtkWidget * gimp_color_wheel_new (void);
-
-void gimp_color_wheel_set_color (GimpColorWheel *wheel,
- double h,
- double s,
- double v);
-void gimp_color_wheel_get_color (GimpColorWheel *wheel,
- gdouble *h,
- gdouble *s,
- gdouble *v);
-
-void gimp_color_wheel_set_ring_fraction (GimpColorWheel *wheel,
- gdouble fraction);
-gdouble gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel);
-
-gboolean gimp_color_wheel_is_adjusting (GimpColorWheel *wheel);
-
-G_END_DECLS
-
-#endif /* __GIMP_COLOR_WHEEL_H__ */