summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt2
-rw-r--r--src/ui/widget/Makefile_insert2
-rw-r--r--src/ui/widget/color-slider.cpp641
-rw-r--r--src/ui/widget/color-slider.h111
-rw-r--r--src/widgets/CMakeLists.txt2
-rw-r--r--src/widgets/Makefile_insert2
-rw-r--r--src/widgets/sp-color-icc-selector.cpp79
-rw-r--r--src/widgets/sp-color-notebook.cpp4
-rw-r--r--src/widgets/sp-color-scales.cpp197
-rw-r--r--src/widgets/sp-color-scales.h19
-rw-r--r--src/widgets/sp-color-selector.cpp5
-rw-r--r--src/widgets/sp-color-slider.cpp749
-rw-r--r--src/widgets/sp-color-slider.h60
-rw-r--r--src/widgets/sp-color-wheel-selector.cpp102
-rw-r--r--src/widgets/sp-color-wheel-selector.h30
15 files changed, 983 insertions, 1022 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 991d11feb..7ff0758e7 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -117,6 +117,7 @@ set(ui_SRC
widget/clipmaskicon.cpp
widget/color-picker.cpp
widget/color-preview.cpp
+ widget/color-slider.cpp
widget/dock-item.cpp
widget/dock.cpp
widget/entity-entry.cpp
@@ -289,6 +290,7 @@ set(ui_SRC
widget/button.h
widget/color-picker.h
widget/color-preview.h
+ widget/color-slider.h
widget/combo-enums.h
widget/dock-item.h
widget/dock.h
diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert
index e18b790bd..34438a3ac 100644
--- a/src/ui/widget/Makefile_insert
+++ b/src/ui/widget/Makefile_insert
@@ -10,6 +10,8 @@ ink_common_sources += \
ui/widget/color-picker.h \
ui/widget/color-preview.cpp \
ui/widget/color-preview.h \
+ ui/widget/color-slider.cpp \
+ ui/widget/color-slider.h \
ui/widget/combo-enums.h \
ui/widget/dock.h \
ui/widget/dock.cpp \
diff --git a/src/ui/widget/color-slider.cpp b/src/ui/widget/color-slider.cpp
new file mode 100644
index 000000000..fc64fad6f
--- /dev/null
+++ b/src/ui/widget/color-slider.cpp
@@ -0,0 +1,641 @@
+/**
+ * @file
+ * A slider with colored background - implementation.
+ */
+/* Author:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ * bulia byak <buliabyak@users.sf.net>
+ *
+ * Copyright (C) 2001-2002 Lauris Kaplinski
+ *
+ * This code is in public domain
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "color-slider.h"
+
+#include <gtk/gtk.h>
+#include <gdkmm/cursor.h>
+#include <gdkmm/screen.h>
+#include <gdkmm/general.h>
+#include <gtkmm/adjustment.h>
+#if GTK_CHECK_VERSION(3,0,0)
+#include <gtkmm/stylecontext.h>
+#else
+#include <gtkmm/style.h>
+#endif
+
+#include "widgets/sp-color-scales.h"
+#include "preferences.h"
+
+static const gint SLIDER_WIDTH = 96;
+static const gint SLIDER_HEIGHT = 8;
+static const gint ARROW_SIZE = 7;
+
+static const guchar *sp_color_slider_render_gradient (gint x0, gint y0, gint width, gint height,
+ gint c[], gint dc[], guint b0, guint b1, guint mask);
+static const guchar *sp_color_slider_render_map (gint x0, gint y0, gint width, gint height,
+ guchar *map, gint start, gint step, guint b0, guint b1, guint mask);
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+#if GTK_CHECK_VERSION(3,0,0)
+ColorSlider::ColorSlider(Glib::RefPtr<Gtk::Adjustment> adjustment)
+ : _dragging(false)
+#else
+ColorSlider::ColorSlider(Gtk::Adjustment* adjustment)
+ : _dragging(false)
+ , _adjustment(NULL)
+#endif
+ , _value(0.0)
+ , _oldvalue(0.0)
+ , _mapsize(0)
+ , _map(NULL)
+{
+ _c0[0] = 0x00;
+ _c0[1] = 0x00;
+ _c0[2] = 0x00;
+ _c0[3] = 0xff;
+
+ _cm[0] = 0xff;
+ _cm[1] = 0x00;
+ _cm[2] = 0x00;
+ _cm[3] = 0xff;
+
+ _c0[0] = 0xff;
+ _c0[1] = 0xff;
+ _c0[2] = 0xff;
+ _c0[3] = 0xff;
+
+ _b0 = 0x5f;
+ _b1 = 0xa0;
+ _bmask = 0x08;
+
+ set_adjustment(adjustment);
+}
+
+ColorSlider::~ColorSlider() {
+ if (_adjustment) {
+ _adjustment_changed_connection.disconnect();
+ _adjustment_value_changed_connection.disconnect();
+#if GTK_CHECK_VERSION(3,0,0)
+ _adjustment.reset();
+#else
+ _adjustment->unreference();
+ _adjustment = NULL;
+#endif
+ }
+}
+
+void ColorSlider::on_realize() {
+ set_realized();
+
+ if(!_refGdkWindow)
+ {
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ Gtk::Allocation allocation = get_allocation();
+
+ memset(&attributes, 0, sizeof(attributes));
+ attributes.x = allocation.get_x();
+ attributes.y = allocation.get_y();
+ attributes.width = allocation.get_width();
+ attributes.height = allocation.get_height();
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gdk_screen_get_system_visual(gdk_screen_get_default());
+#if !GTK_CHECK_VERSION(3,0,0)
+ attributes.colormap = gdk_screen_get_system_colormap(gdk_screen_get_default());
+#endif
+ attributes.event_mask = get_events ();
+ attributes.event_mask |= (Gdk::EXPOSURE_MASK |
+ Gdk::BUTTON_PRESS_MASK |
+ Gdk::BUTTON_RELEASE_MASK |
+ Gdk::POINTER_MOTION_MASK |
+ Gdk::ENTER_NOTIFY_MASK |
+ Gdk::LEAVE_NOTIFY_MASK);
+
+#if GTK_CHECK_VERSION(3,0,0)
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+#else
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+#endif
+
+ _refGdkWindow = Gdk::Window::create(get_parent_window(), &attributes,
+ attributes_mask);
+ set_window(_refGdkWindow);
+ _refGdkWindow->set_user_data(gobj());
+
+#if !GTK_CHECK_VERSION(3,0,0)
+ style_attach();
+#endif
+ }
+}
+
+void ColorSlider::on_unrealize() {
+ _refGdkWindow.reset();
+
+ Gtk::Widget::on_unrealize();
+}
+
+void ColorSlider::on_size_allocate(Gtk::Allocation& allocation) {
+ set_allocation(allocation);
+
+ if (get_realized()) {
+ _refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(),
+ allocation.get_width(), allocation.get_height());
+ }
+}
+
+#if GTK_CHECK_VERSION(3,0,0)
+
+void ColorSlider::get_preferred_width_vfunc(int& minimum_width, int& natural_width) const
+{
+ Glib::RefPtr<Gtk::StyleContext>style_context = get_style_context();
+ Gtk::Border padding = style_context->get_padding(get_state_flags());
+ int width = SLIDER_WIDTH + padding.get_left() + padding.get_right();
+ minimum_width = natural_width = width;
+}
+
+void ColorSlider::get_preferred_width_for_height_vfunc(int /*height*/, int& minimum_width, int& natural_width) const
+{
+ get_preferred_width(minimum_width, natural_width);
+}
+
+void ColorSlider::get_preferred_height_vfunc(int& minimum_height, int& natural_height) const
+{
+ Glib::RefPtr<Gtk::StyleContext>style_context = get_style_context();
+ Gtk::Border padding = style_context->get_padding(get_state_flags());
+ int height = SLIDER_HEIGHT + padding.get_top() + padding.get_bottom();
+ minimum_height = natural_height = height;
+}
+
+void ColorSlider::get_preferred_height_for_width_vfunc(int /*width*/, int& minimum_height, int& natural_height) const
+{
+ get_preferred_height(minimum_height, natural_height);
+}
+
+#else
+
+void ColorSlider::on_size_request(Gtk::Requisition* requisition) {
+ GtkStyle *style = gtk_widget_get_style(gobj());
+ requisition->width = SLIDER_WIDTH + style->xthickness * 2;
+ requisition->height = SLIDER_HEIGHT + style->ythickness * 2;
+}
+
+bool ColorSlider::on_expose_event(GdkEventExpose* event) {
+ bool result = false;
+
+ if (get_is_drawable()) {
+ Cairo::RefPtr<Cairo::Context> cr = _refGdkWindow->create_cairo_context();
+ result = on_draw(cr);
+ }
+ return result;
+}
+
+#endif
+
+bool ColorSlider::on_button_press_event(GdkEventButton *event) {
+ if (event->button == 1) {
+ Gtk::Allocation allocation = get_allocation();
+ gint cx, cw;
+#if GTK_CHECK_VERSION(3,0,0)
+ cx = get_style_context()->get_padding(get_state_flags()).get_left();
+#else
+ cx = get_style()->get_xthickness();
+#endif
+ cw = allocation.get_width() - 2 * cx;
+ signal_grabbed.emit();
+ _dragging = true;
+ _oldvalue = _value;
+ ColorScales::setScaled( _adjustment->gobj(), CLAMP ((gfloat) (event->x - cx) / cw, 0.0, 1.0) );
+ signal_dragged.emit();
+
+#if GTK_CHECK_VERSION(3,0,0)
+ gdk_device_grab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)),
+ _refGdkWindow->gobj(),
+ GDK_OWNERSHIP_NONE,
+ FALSE,
+ static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK),
+ NULL,
+ event->time);
+#else
+ gdk_pointer_grab(get_window()->gobj(), FALSE,
+ static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK),
+ NULL, NULL, event->time);
+#endif
+ }
+
+ return false;
+}
+
+bool ColorSlider::on_button_release_event(GdkEventButton *event) {
+ if (event->button == 1) {
+
+#if GTK_CHECK_VERSION(3,0,0)
+ gdk_device_ungrab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)),
+ gdk_event_get_time(reinterpret_cast<GdkEvent *>(event)));
+#else
+ get_window()->pointer_ungrab(event->time);
+#endif
+
+ _dragging = false;
+ signal_released.emit();
+ if (_value != _oldvalue) {
+ signal_value_changed.emit();
+ }
+ }
+
+ return false;
+}
+
+bool ColorSlider::on_motion_notify_event(GdkEventMotion *event) {
+ if (_dragging) {
+ gint cx, cw;
+ Gtk::Allocation allocation = get_allocation();
+#if GTK_CHECK_VERSION(3,0,0)
+ cx = get_style_context()->get_padding(get_state_flags()).get_left();
+#else
+ cx = get_style()->get_xthickness();
+#endif
+ cw = allocation.get_width() - 2 * cx;
+ ColorScales::setScaled( _adjustment->gobj(), CLAMP ((gfloat) (event->x - cx) / cw, 0.0, 1.0) );
+ signal_dragged.emit();
+ }
+
+ return false;
+}
+
+#if GTK_CHECK_VERSION(3,0,0)
+void ColorSlider::set_adjustment(Glib::RefPtr<Gtk::Adjustment> adjustment) {
+#else
+void ColorSlider::set_adjustment(Gtk::Adjustment *adjustment) {
+#endif
+ if (!adjustment) {
+#if GTK_CHECK_VERSION(3,0,0)
+ _adjustment = Gtk::Adjustment::create(0.0, 0.0, 1.0, 0.01, 0.0, 0.0);
+#else
+ _adjustment = Gtk::manage(new Gtk::Adjustment(0.0, 0.0, 1.0, 0.01, 0.0, 0.0));
+#endif
+ } else {
+ adjustment->set_page_increment(0.0);
+ adjustment->set_page_size(0.0);
+ }
+
+ if (_adjustment != adjustment) {
+ if (_adjustment) {
+ _adjustment_changed_connection.disconnect();
+ _adjustment_value_changed_connection.disconnect();
+#if !GTK_CHECK_VERSION(3,0,0)
+ _adjustment->unreference();
+#endif
+ }
+
+ _adjustment = adjustment;
+ _adjustment_changed_connection = _adjustment->signal_changed().connect(
+ sigc::mem_fun(this, &ColorSlider::_on_adjustment_changed));
+ _adjustment_value_changed_connection = _adjustment->signal_value_changed().connect(
+ sigc::mem_fun(this, &ColorSlider::_on_adjustment_value_changed));
+
+ _value = ColorScales::getScaled(_adjustment->gobj());
+
+ _on_adjustment_changed();
+ }
+}
+
+void ColorSlider::_on_adjustment_changed() {
+ queue_draw();
+}
+
+void ColorSlider::_on_adjustment_value_changed() {
+ if (_value != ColorScales::getScaled( _adjustment->gobj() )) {
+ gint cx, cy, cw, ch;
+#if GTK_CHECK_VERSION(3,0,0)
+ Glib::RefPtr<Gtk::StyleContext>style_context = get_style_context();
+ Gtk::Allocation allocation = get_allocation();
+ Gtk::Border padding = style_context->get_padding(get_state_flags());
+ cx = padding.get_left();
+ cy = padding.get_top();
+#else
+ Glib::RefPtr<Gtk::Style> style = get_style();
+ Gtk::Allocation allocation = get_allocation();
+ cx = style->get_xthickness();
+ cy = style->get_ythickness();
+#endif
+ cw = allocation.get_width() - 2 * cx;
+ ch = allocation.get_height() - 2 * cy;
+ if ((gint) (ColorScales::getScaled( _adjustment->gobj() ) * cw) != (gint) (_value * cw)) {
+ gint ax, ay;
+ gfloat value;
+ value = _value;
+ _value = ColorScales::getScaled( _adjustment->gobj() );
+ ax = (int)(cx + value * cw - ARROW_SIZE / 2 - 2);
+ ay = cy;
+ queue_draw_area(ax, ay, ARROW_SIZE + 4, ch);
+ ax = (int)(cx + _value * cw - ARROW_SIZE / 2 - 2);
+ ay = cy;
+ queue_draw_area(ax, ay, ARROW_SIZE + 4, ch);
+ } else {
+ _value = ColorScales::getScaled( _adjustment->gobj() );
+ }
+ }
+}
+
+void ColorSlider::set_colors(guint32 start, guint32 mid, guint32 end) {
+ // Remove any map, if set
+ _map = 0;
+
+ _c0[0] = start >> 24;
+ _c0[1] = (start >> 16) & 0xff;
+ _c0[2] = (start >> 8) & 0xff;
+ _c0[3] = start & 0xff;
+
+ _cm[0] = mid >> 24;
+ _cm[1] = (mid >> 16) & 0xff;
+ _cm[2] = (mid >> 8) & 0xff;
+ _cm[3] = mid & 0xff;
+
+ _c1[0] = end >> 24;
+ _c1[1] = (end >> 16) & 0xff;
+ _c1[2] = (end >> 8) & 0xff;
+ _c1[3] = end & 0xff;
+
+ queue_draw();
+}
+
+void ColorSlider::set_map(const guchar *map) {
+ _map = const_cast<guchar *>(map);
+
+ queue_draw();
+}
+
+void ColorSlider::set_background(guint dark, guint light, guint size) {
+ _b0 = dark;
+ _b1 = light;
+ _bmask = size;
+
+ queue_draw();
+}
+
+bool ColorSlider::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
+ gboolean colorsOnTop = Inkscape::Preferences::get()->getBool("/options/workarounds/colorsontop", false);
+
+ Gtk::Allocation allocation = get_allocation();
+
+#if GTK_CHECK_VERSION(3,0,0)
+ Glib::RefPtr<Gtk::StyleContext> style_context = get_style_context();
+#else
+ Glib::RefPtr<Gdk::Window> window = get_window();
+ Glib::RefPtr<Gtk::Style> style = get_style();
+#endif
+
+ // Draw shadow
+ if (colorsOnTop) {
+#if GTK_CHECK_VERSION(3,0,0)
+ style_context->render_frame(cr, 0, 0,
+ allocation.get_width(), allocation.get_height());
+#else
+ gtk_paint_shadow( style->gobj(), window->gobj(),
+ gtk_widget_get_state(gobj()), GTK_SHADOW_IN,
+ NULL, gobj(), "colorslider",
+ 0, 0,
+ allocation.get_width(), allocation.get_height());
+#endif
+ }
+
+ /* Paintable part of color gradient area */
+ Gdk::Rectangle carea;
+
+#if GTK_CHECK_VERSION(3,0,0)
+ Gtk::Border padding;
+
+ padding = style_context->get_padding(get_state_flags());
+
+ carea.set_x(padding.get_left());
+ carea.set_y(padding.get_top());;
+#else
+ carea.set_x(style->get_xthickness());
+ carea.set_y(style->get_ythickness());
+#endif
+
+ carea.set_width(allocation.get_width() - 2 * carea.get_x());
+ carea.set_height(allocation.get_height() - 2 * carea.get_y());
+
+ if (_map) {
+ /* Render map pixelstore */
+ gint d = (1024 << 16) / carea.get_width();
+ gint s = 0;
+
+ const guchar *b = sp_color_slider_render_map(0, 0, carea.get_width(), carea.get_height(),
+ _map, s, d,
+ _b0, _b1, _bmask);
+
+ if (b != NULL && carea.get_width() > 0) {
+ Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB,
+ false, 8, carea.get_width(), carea.get_height(), carea.get_width() * 3);
+
+ Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_x(), carea.get_y());
+ cr->paint();
+ }
+
+ } else {
+ gint c[4], dc[4];
+
+ /* Render gradient */
+
+ // part 1: from c0 to cm
+ if (carea.get_width() > 0) {
+ for (gint i = 0; i < 4; i++) {
+ c[i] = _c0[i] << 16;
+ dc[i] = ((_cm[i] << 16) - c[i]) / (carea.get_width()/2);
+ }
+ guint wi = carea.get_width()/2;
+ const guchar *b = sp_color_slider_render_gradient(0, 0, wi, carea.get_height(),
+ c, dc, _b0, _b1, _bmask);
+
+ /* Draw pixelstore 1 */
+ if (b != NULL && wi > 0) {
+ Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB,
+ false, 8, wi, carea.get_height(), wi * 3);
+
+ Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_x(), carea.get_y());
+ cr->paint();
+ }
+ }
+
+ // part 2: from cm to c1
+ if (carea.get_width() > 0) {
+ for (gint i = 0; i < 4; i++) {
+ c[i] = _cm[i] << 16;
+ dc[i] = ((_c1[i] << 16) - c[i]) / (carea.get_width()/2);
+ }
+ guint wi = carea.get_width()/2;
+ const guchar *b = sp_color_slider_render_gradient(carea.get_width()/2, 0, wi, carea.get_height(),
+ c, dc,
+ _b0, _b1, _bmask);
+
+ /* Draw pixelstore 2 */
+ if (b != NULL && wi > 0) {
+ Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB,
+ false, 8, wi, carea.get_height(), wi * 3);
+
+ Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_width()/2 + carea.get_x(), carea.get_y());
+ cr->paint();
+ }
+ }
+ }
+
+ /* Draw shadow */
+ if (!colorsOnTop) {
+#if GTK_CHECK_VERSION(3,0,0)
+ style_context->render_frame(cr, 0, 0,
+ allocation.get_width(), allocation.get_height());
+#else
+ gtk_paint_shadow( style->gobj(), window->gobj(),
+ gtk_widget_get_state(gobj()), GTK_SHADOW_IN,
+ NULL, gobj(), "colorslider",
+ 0, 0,
+ allocation.get_width(), allocation.get_height());
+#endif
+ }
+
+ /* Draw arrow */
+ gint x = (int)(_value * (carea.get_width() - 1) - ARROW_SIZE / 2 + carea.get_x());
+ gint y1 = carea.get_y();
+ gint y2 = carea.get_y() + carea.get_height() - 1;
+ cr->set_line_width(1.0);
+
+ // Define top arrow
+ cr->move_to(x - 0.5, y1 + 0.5);
+ cr->line_to(x + ARROW_SIZE - 0.5, y1 + 0.5);
+ cr->line_to(x + (ARROW_SIZE-1)/2.0, y1 + ARROW_SIZE/2.0 + 0.5);
+ cr->line_to(x - 0.5, y1 + 0.5);
+
+ // Define bottom arrow
+ cr->move_to(x - 0.5, y2 + 0.5);
+ cr->line_to(x + ARROW_SIZE - 0.5, y2 + 0.5);
+ cr->line_to(x + (ARROW_SIZE-1)/2.0, y2 - ARROW_SIZE/2.0 + 0.5);
+ cr->line_to(x - 0.5, y2 + 0.5);
+
+ // Render both arrows
+ cr->set_source_rgb(1.0, 1.0, 1.0);
+ cr->stroke_preserve();
+ cr->set_source_rgb(0.0, 0.0, 0.0);
+ cr->fill();
+
+ return false;
+}
+
+}//namespace Widget
+}//namespace UI
+}//namespace Inkscape
+
+/* Colors are << 16 */
+
+static const guchar *
+sp_color_slider_render_gradient (gint x0, gint y0, gint width, gint height,
+ gint c[], gint dc[], guint b0, guint b1, guint mask)
+{
+ static guchar *buf = NULL;
+ static gint bs = 0;
+ guchar *dp;
+ gint x, y;
+ guint r, g, b, a;
+
+ if (buf && (bs < width * height)) {
+ g_free (buf);
+ buf = NULL;
+ }
+ if (!buf) {
+ buf = g_new (guchar, width * height * 3);
+ bs = width * height;
+ }
+
+ dp = buf;
+ r = c[0];
+ g = c[1];
+ b = c[2];
+ a = c[3];
+ for (x = x0; x < x0 + width; x++) {
+ gint cr, cg, cb, ca;
+ guchar *d;
+ cr = r >> 16;
+ cg = g >> 16;
+ cb = b >> 16;
+ ca = a >> 16;
+ d = dp;
+ for (y = y0; y < y0 + height; y++) {
+ guint bg, fc;
+ /* Background value */
+ bg = ((x & mask) ^ (y & mask)) ? b0 : b1;
+ fc = (cr - bg) * ca;
+ d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ fc = (cg - bg) * ca;
+ d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ fc = (cb - bg) * ca;
+ d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ d += 3 * width;
+ }
+ r += dc[0];
+ g += dc[1];
+ b += dc[2];
+ a += dc[3];
+ dp += 3;
+ }
+
+ return buf;
+}
+
+/* Positions are << 16 */
+
+static const guchar *
+sp_color_slider_render_map (gint x0, gint y0, gint width, gint height,
+ guchar *map, gint start, gint step, guint b0, guint b1, guint mask)
+{
+ static guchar *buf = NULL;
+ static gint bs = 0;
+ guchar *dp;
+ gint x, y;
+
+ if (buf && (bs < width * height)) {
+ g_free (buf);
+ buf = NULL;
+ }
+ if (!buf) {
+ buf = g_new (guchar, width * height * 3);
+ bs = width * height;
+ }
+
+ dp = buf;
+ for (x = x0; x < x0 + width; x++) {
+ gint cr, cg, cb, ca;
+ guchar *d = dp;
+ guchar *sp = map + 4 * (start >> 16);
+ cr = *sp++;
+ cg = *sp++;
+ cb = *sp++;
+ ca = *sp++;
+ for (y = y0; y < y0 + height; y++) {
+ guint bg, fc;
+ /* Background value */
+ bg = ((x & mask) ^ (y & mask)) ? b0 : b1;
+ fc = (cr - bg) * ca;
+ d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ fc = (cg - bg) * ca;
+ d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ fc = (cb - bg) * ca;
+ d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
+ d += 3 * width;
+ }
+ dp += 3;
+ start += step;
+ }
+
+ return buf;
+}
+
diff --git a/src/ui/widget/color-slider.h b/src/ui/widget/color-slider.h
new file mode 100644
index 000000000..00cc17ea7
--- /dev/null
+++ b/src/ui/widget/color-slider.h
@@ -0,0 +1,111 @@
+#ifndef __SP_COLOR_SLIDER_H__
+#define __SP_COLOR_SLIDER_H__
+
+/*
+ * A slider with colored background
+ *
+ * Author:
+ * Lauris Kaplinski <lauris@kaplinski.com>
+ *
+ * Copyright (C) 2001-2002 Lauris Kaplinski
+ *
+ * This code is in public domain
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
+#include <gtkmm/widget.h>
+#include <sigc++/signal.h>
+
+namespace Inkscape
+{
+namespace UI
+{
+namespace Widget
+{
+
+/*
+ * A slider with colored background
+ */
+class ColorSlider: public Gtk::Widget {
+public:
+#if GTK_CHECK_VERSION(3,0,0)
+ ColorSlider(Glib::RefPtr<Gtk::Adjustment> adjustment);
+#else
+ ColorSlider(Gtk::Adjustment *adjustment);
+#endif
+ ~ColorSlider();
+
+#if GTK_CHECK_VERSION(3,0,0)
+ void set_adjustment(Glib::RefPtr<Gtk::Adjustment> adjustment);
+#else
+ void set_adjustment(Gtk::Adjustment *adjustment);
+#endif
+
+ void set_colors(guint32 start, guint32 mid, guint32 end);
+
+ void set_map(const guchar* map);
+
+ void set_background(guint dark, guint light, guint size);
+
+ sigc::signal<void> signal_grabbed;
+ sigc::signal<void> signal_dragged;
+ sigc::signal<void> signal_released;
+ sigc::signal<void> signal_value_changed;
+
+protected:
+ void on_size_allocate(Gtk::Allocation& allocation);
+ void on_realize();
+ void on_unrealize();
+ bool on_button_press_event(GdkEventButton *event);
+ bool on_button_release_event(GdkEventButton *event);
+ bool on_motion_notify_event(GdkEventMotion *event);
+ bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr);
+
+#if GTK_CHECK_VERSION(3,0,0)
+ void get_preferred_width_vfunc(int& minimum_width, int& natural_width) const;
+ void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const;
+ void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const;
+ void get_preferred_height_for_width_vfunc(int width, int& minimum_height, int& natural_height) const;
+#else
+ void on_size_request(Gtk::Requisition* requisition);
+ bool on_expose_event(GdkEventExpose* event);
+#endif
+
+private:
+ void _on_adjustment_changed();
+ void _on_adjustment_value_changed();
+
+ bool _dragging;
+
+#if GTK_CHECK_VERSION(3,0,0)
+ Glib::RefPtr<Gtk::Adjustment> _adjustment;
+#else
+ Gtk::Adjustment *_adjustment;
+#endif
+ sigc::connection _adjustment_changed_connection;
+ sigc::connection _adjustment_value_changed_connection;
+
+ gfloat _value;
+ gfloat _oldvalue;
+ guchar _c0[4], _cm[4], _c1[4];
+ guchar _b0, _b1;
+ guchar _bmask;
+
+ gint _mapsize;
+ guchar *_map;
+
+ Glib::RefPtr<Gdk::Window> _refGdkWindow;
+};
+
+}//namespace Widget
+}//namespace UI
+}//namespace Inkscape
+
+#endif
diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index 072b905a2..21c42b79f 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -45,7 +45,6 @@ set(widgets_SRC
sp-color-notebook.cpp
sp-color-scales.cpp
sp-color-selector.cpp
- sp-color-slider.cpp
sp-color-wheel-selector.cpp
sp-widget.cpp
sp-xmlview-attr-list.cpp
@@ -107,7 +106,6 @@ set(widgets_SRC
sp-color-notebook.h
sp-color-scales.h
sp-color-selector.h
- sp-color-slider.h
sp-color-wheel-selector.h
sp-widget.h
sp-xmlview-attr-list.h
diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert
index dc4c12967..7dd7ba407 100644
--- a/src/widgets/Makefile_insert
+++ b/src/widgets/Makefile_insert
@@ -84,8 +84,6 @@ ink_common_sources += \
widgets/sp-color-scales.h \
widgets/sp-color-selector.cpp \
widgets/sp-color-selector.h \
- widgets/sp-color-slider.cpp \
- widgets/sp-color-slider.h \
widgets/sp-color-wheel-selector.cpp \
widgets/sp-color-wheel-selector.h \
widgets/spinbutton-events.cpp \
diff --git a/src/widgets/sp-color-icc-selector.cpp b/src/widgets/sp-color-icc-selector.cpp
index 6e910c582..4d5e94dab 100644
--- a/src/widgets/sp-color-icc-selector.cpp
+++ b/src/widgets/sp-color-icc-selector.cpp
@@ -2,10 +2,15 @@
# include "config.h"
#endif
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
#include "gradient-vector.h"
#include <math.h>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
+#include <gtkmm/adjustment.h>
#include <map>
#include <set>
#include <vector>
@@ -13,7 +18,7 @@
#include "ui/dialog-events.h"
#include "sp-color-icc-selector.h"
#include "sp-color-scales.h"
-#include "sp-color-slider.h"
+#include "ui/widget/color-slider.h"
#include "svg/svg-icc-color.h"
#include "colorspace.h"
#include "document.h"
@@ -101,7 +106,7 @@ public:
colorspace::Component _component;
GtkAdjustment *_adj; // Component adjustment
- GtkWidget *_slider;
+ Inkscape::UI::Widget::ColorSlider *_slider;
GtkWidget *_btn; // spinbutton
GtkWidget *_label; // Label
guchar *_map;
@@ -120,9 +125,9 @@ public:
static void _adjustmentChanged ( GtkAdjustment *adjustment, SPColorICCSelector *cs );
- static void _sliderGrabbed( SPColorSlider *slider, SPColorICCSelector *cs );
- static void _sliderReleased( SPColorSlider *slider, SPColorICCSelector *cs );
- static void _sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs );
+ void _sliderGrabbed();
+ void _sliderReleased();
+ void _sliderChanged();
static void _profileSelected( GtkWidget* src, gpointer data );
static void _fixupHit( GtkWidget* src, gpointer data );
@@ -146,7 +151,7 @@ public:
std::vector<ComponentUI> _compUI;
GtkAdjustment* _adj; // Channel adjustment
- GtkWidget* _slider;
+ Inkscape::UI::Widget::ColorSlider* _slider;
GtkWidget* _sbtn; // Spinbutton
GtkWidget* _label; // Label
@@ -496,15 +501,15 @@ void ColorICCSelector::init()
_impl->_compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, 0.0, scaleValue, step, page, page ) );
// Slider
- _impl->_compUI[i]._slider = sp_color_slider_new( _impl->_compUI[i]._adj );
+ _impl->_compUI[i]._slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_compUI[i]._adj, true)));
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
- gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" );
+ _impl->_compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : "");
#else
- gtk_widget_set_tooltip_text( _impl->_compUI[i]._slider, "." );
+ _impl->_compUI[i]._slider->set_tooltip_text(".");
#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
- gtk_widget_show( _impl->_compUI[i]._slider );
+ _impl->_compUI[i]._slider->show();
- attachToGridOrTable(t, _impl->_compUI[i]._slider, 1, row, 1, 1, true);
+ attachToGridOrTable(t, _impl->_compUI[i]._slider->gobj(), 1, row, 1, 1, true);
_impl->_compUI[i]._btn = gtk_spin_button_new( _impl->_compUI[i]._adj, step, digits );
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
@@ -525,9 +530,9 @@ void ColorICCSelector::init()
// Signals
g_signal_connect( G_OBJECT( _impl->_compUI[i]._adj ), "value_changed", G_CALLBACK( ColorICCSelectorImpl::_adjustmentChanged ), _csel );
- g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "grabbed", G_CALLBACK( ColorICCSelectorImpl::_sliderGrabbed ), _csel );
- g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "released", G_CALLBACK( ColorICCSelectorImpl::_sliderReleased ), _csel );
- g_signal_connect( G_OBJECT( _impl->_compUI[i]._slider ), "changed", G_CALLBACK( ColorICCSelectorImpl::_sliderChanged ), _csel );
+ _impl->_compUI[i]._slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed));
+ _impl->_compUI[i]._slider->signal_released.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased));
+ _impl->_compUI[i]._slider->signal_value_changed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged));
row++;
}
@@ -543,16 +548,15 @@ void ColorICCSelector::init()
_impl->_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0));
// Slider
- _impl->_slider = sp_color_slider_new(_impl->_adj);
- gtk_widget_set_tooltip_text(_impl->_slider, _("Alpha (opacity)"));
- gtk_widget_show(_impl->_slider);
+ _impl->_slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_adj, true)));
+ _impl->_slider->set_tooltip_text(_("Alpha (opacity)"));
+ _impl->_slider->show();
- attachToGridOrTable(t, _impl->_slider, 1, row, 1, 1, true);
+ attachToGridOrTable(t, _impl->_slider->gobj(), 1, row, 1, 1, true);
- sp_color_slider_set_colors( SP_COLOR_SLIDER( _impl->_slider ),
- SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.0 ),
- SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.5 ),
- SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 1.0 ) );
+ _impl->_slider->set_colors(SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.0 ),
+ SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 0.5 ),
+ SP_RGBA32_F_COMPOSE( 1.0, 1.0, 1.0, 1.0 ) );
// Spinbutton
@@ -567,9 +571,9 @@ void ColorICCSelector::init()
// Signals
g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _csel);
- g_signal_connect(G_OBJECT(_impl->_slider), "grabbed", G_CALLBACK(ColorICCSelectorImpl::_sliderGrabbed), _csel);
- g_signal_connect(G_OBJECT(_impl->_slider), "released", G_CALLBACK(ColorICCSelectorImpl::_sliderReleased), _csel);
- g_signal_connect(G_OBJECT(_impl->_slider), "changed", G_CALLBACK(ColorICCSelectorImpl::_sliderChanged), _csel);
+ _impl->_slider->signal_grabbed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderGrabbed));
+ _impl->_slider->signal_released.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderReleased));
+ _impl->_slider->signal_value_changed.connect(sigc::mem_fun(_impl, &ColorICCSelectorImpl::_sliderChanged));
}
static void sp_color_icc_selector_dispose(GObject *object)
@@ -855,7 +859,7 @@ void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile )
for ( size_t i = 0; i < _compUI.size(); i++ ) {
gtk_widget_hide( _compUI[i]._label );
- gtk_widget_hide( _compUI[i]._slider );
+ _compUI[i]._slider->hide();
gtk_widget_hide( _compUI[i]._btn );
}
@@ -878,13 +882,12 @@ void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile )
for ( guint i = 0; i < _profChannelCount; i++ ) {
gtk_label_set_text_with_mnemonic( GTK_LABEL(_compUI[i]._label), (i < things.size()) ? things[i].name.c_str() : "");
- gtk_widget_set_tooltip_text( _compUI[i]._slider, (i < things.size()) ? things[i].tip.c_str() : "" );
+ _compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : "");
gtk_widget_set_tooltip_text( _compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" );
- sp_color_slider_set_colors( SP_COLOR_SLIDER(_compUI[i]._slider),
- SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
- SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
- SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) );
+ _compUI[i]._slider->set_colors(SPColor(0.0, 0.0, 0.0).toRGBA32(0xff),
+ SPColor(0.5, 0.5, 0.5).toRGBA32(0xff),
+ SPColor(1.0, 1.0, 1.0).toRGBA32(0xff) );
/*
_compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( val, 0.0, _fooScales[i], step, page, page ) );
g_signal_connect( G_OBJECT( _compUI[i]._adj ), "value_changed", G_CALLBACK( _adjustmentChanged ), _csel );
@@ -894,14 +897,14 @@ void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile )
gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits );
*/
gtk_widget_show( _compUI[i]._label );
- gtk_widget_show( _compUI[i]._slider );
+ _compUI[i]._slider->show();
gtk_widget_show( _compUI[i]._btn );
//gtk_adjustment_set_value( _compUI[i]._adj, 0.0 );
//gtk_adjustment_set_value( _compUI[i]._adj, val );
}
for ( size_t i = _profChannelCount; i < _compUI.size(); i++ ) {
gtk_widget_hide( _compUI[i]._label );
- gtk_widget_hide( _compUI[i]._slider );
+ _compUI[i]._slider->hide();
gtk_widget_hide( _compUI[i]._btn );
}
}
@@ -958,7 +961,7 @@ void ColorICCSelectorImpl::_updateSliders( gint ignore )
cmsHTRANSFORM trans = _prof->getTransfToSRGB8();
if ( trans ) {
cmsDoTransform( trans, scratch, _compUI[i]._map, 1024 );
- sp_color_slider_set_map( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._map );
+ _compUI[i]._slider->set_map(_compUI[i]._map);
}
}
}
@@ -973,7 +976,7 @@ void ColorICCSelectorImpl::_updateSliders( gint ignore )
guint32 mid = _owner->_color.toRGBA32( 0x7f );
guint32 end = _owner->_color.toRGBA32( 0xff );
- sp_color_slider_set_colors( SP_COLOR_SLIDER(_slider), start, mid, end );
+ _slider->set_colors(start, mid, end);
}
@@ -1066,7 +1069,7 @@ void ColorICCSelectorImpl::_adjustmentChanged( GtkAdjustment *adjustment, SPColo
#endif // DEBUG_LCMS
}
-void ColorICCSelectorImpl::_sliderGrabbed( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
+void ColorICCSelectorImpl::_sliderGrabbed()
{
// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
// if (!iccSelector->_dragging) {
@@ -1076,7 +1079,7 @@ void ColorICCSelectorImpl::_sliderGrabbed( SPColorSlider * /*slider*/, SPColorIC
// }
}
-void ColorICCSelectorImpl::_sliderReleased( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
+void ColorICCSelectorImpl::_sliderReleased()
{
// ColorICCSelector* iccSelector = dynamic_cast<ColorICCSelector*>(SP_COLOR_SELECTOR(cs)->base);
// if (iccSelector->_dragging) {
@@ -1089,7 +1092,7 @@ void ColorICCSelectorImpl::_sliderReleased( SPColorSlider * /*slider*/, SPColorI
#ifdef DEBUG_LCMS
void ColorICCSelectorImpl::_sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs )
#else
-void ColorICCSelectorImpl::_sliderChanged( SPColorSlider * /*slider*/, SPColorICCSelector * /*cs*/ )
+void ColorICCSelectorImpl::_sliderChanged()
#endif // DEBUG_LCMS
{
#ifdef DEBUG_LCMS
diff --git a/src/widgets/sp-color-notebook.cpp b/src/widgets/sp-color-notebook.cpp
index c7fa96efd..b9a8d3475 100644
--- a/src/widgets/sp-color-notebook.cpp
+++ b/src/widgets/sp-color-notebook.cpp
@@ -17,6 +17,10 @@
# include "config.h"
#endif
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
#include "widgets/icon.h"
#include <cstring>
#include <string>
diff --git a/src/widgets/sp-color-scales.cpp b/src/widgets/sp-color-scales.cpp
index 60ba62ec5..87afe76ea 100644
--- a/src/widgets/sp-color-scales.cpp
+++ b/src/widgets/sp-color-scales.cpp
@@ -5,13 +5,22 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
+#include "sp-color-scales.h"
+
#include <math.h>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
-#include "ui/dialog-events.h"
+#include <gtkmm/adjustment.h>
+
#include "sp-color-scales.h"
-#include "sp-color-slider.h"
#include "svg/svg-icc-color.h"
+#include "ui/dialog-events.h"
+#include "ui/widget/color-slider.h"
#define CSC_CHANNEL_R (1 << 0)
#define CSC_CHANNEL_G (1 << 1)
@@ -139,23 +148,23 @@ void ColorScales::init()
/* Adjustment */
_a[i] = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, _rangeLimit, 1.0, 10.0, 10.0));
/* Slider */
- _s[i] = sp_color_slider_new (_a[i]);
- gtk_widget_show (_s[i]);
+ _s[i] = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_a[i], true)));
+ _s[i]->show();
#if GTK_CHECK_VERSION(3,0,0)
#if GTK_CHECK_VERSION(3,12,0)
- gtk_widget_set_margin_start(_s[i], XPAD);
- gtk_widget_set_margin_end(_s[i], XPAD);
+ _s[i]->set_margin_start(XPAD);
+ _s[i]->set_margin_end(XPAD);
#else
- gtk_widget_set_margin_left(_s[i], XPAD);
- gtk_widget_set_margin_right(_s[i], XPAD);
+ _s[i]->set_margin_left(XPAD);
+ _s[i]->set_margin_right(XPAD);
#endif
- gtk_widget_set_margin_top(_s[i], YPAD);
- gtk_widget_set_margin_bottom(_s[i], YPAD);
- gtk_widget_set_hexpand(_s[i], TRUE);
- gtk_grid_attach(GTK_GRID(t), _s[i], 1, i, 1, 1);
+ _s[i]->set_margin_top(YPAD);
+ _s[i]->set_margin_bottom(YPAD);
+ _s[i]->set_hexpand(true);
+ gtk_grid_attach(GTK_GRID(t), _s[i]->gobj(), 1, i, 1, 1);
#else
- gtk_table_attach (GTK_TABLE (t), _s[i], 1, 2, i, i + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, XPAD, YPAD);
+ gtk_table_attach (GTK_TABLE (t), _s[i]->gobj(), 1, 2, i, i + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, XPAD, YPAD);
#endif
/* Spinbutton */
@@ -186,12 +195,9 @@ void ColorScales::init()
/* Signals */
g_signal_connect (G_OBJECT (_a[i]), "value_changed",
G_CALLBACK (_adjustmentAnyChanged), _csel);
- g_signal_connect (G_OBJECT (_s[i]), "grabbed",
- G_CALLBACK (_sliderAnyGrabbed), _csel);
- g_signal_connect (G_OBJECT (_s[i]), "released",
- G_CALLBACK (_sliderAnyReleased), _csel);
- g_signal_connect (G_OBJECT (_s[i]), "changed",
- G_CALLBACK (_sliderAnyChanged), _csel);
+ _s[i]->signal_grabbed.connect(sigc::mem_fun(this, &ColorScales::_sliderAnyGrabbed));
+ _s[i]->signal_released.connect(sigc::mem_fun(this, &ColorScales::_sliderAnyReleased));
+ _s[i]->signal_value_changed.connect(sigc::mem_fun(this, &ColorScales::_sliderAnyChanged));
}
/* Initial mode is none, so it works */
@@ -412,20 +418,20 @@ void ColorScales::setMode(SPColorScalesMode mode)
case SP_COLOR_SCALES_MODE_RGB:
_setRangeLimit(255.0);
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_R:"));
- gtk_widget_set_tooltip_text (_s[0], _("Red"));
+ _s[0]->set_tooltip_text(_("Red"));
gtk_widget_set_tooltip_text (_b[0], _("Red"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[1]), _("_G:"));
- gtk_widget_set_tooltip_text (_s[1], _("Green"));
+ _s[1]->set_tooltip_text(_("Green"));
gtk_widget_set_tooltip_text (_b[1], _("Green"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[2]), _("_B:"));
- gtk_widget_set_tooltip_text (_s[2], _("Blue"));
+ _s[2]->set_tooltip_text(_("Blue"));
gtk_widget_set_tooltip_text (_b[2], _("Blue"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[3]), _("_A:"));
- gtk_widget_set_tooltip_text (_s[3], _("Alpha (opacity)"));
+ _s[3]->set_tooltip_text(_("Alpha (opacity)"));
gtk_widget_set_tooltip_text (_b[3], _("Alpha (opacity)"));
- sp_color_slider_set_map (SP_COLOR_SLIDER (_s[0]), NULL);
+ _s[0]->set_map(NULL);
gtk_widget_hide (_l[4]);
- gtk_widget_hide (_s[4]);
+ _s[4]->hide();
gtk_widget_hide (_b[4]);
_updating = TRUE;
setScaled( _a[0], rgba[0] );
@@ -438,20 +444,20 @@ void ColorScales::setMode(SPColorScalesMode mode)
case SP_COLOR_SCALES_MODE_HSV:
_setRangeLimit(255.0);
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_H:"));
- gtk_widget_set_tooltip_text (_s[0], _("Hue"));
+ _s[0]->set_tooltip_text(_("Hue"));
gtk_widget_set_tooltip_text (_b[0], _("Hue"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[1]), _("_S:"));
- gtk_widget_set_tooltip_text (_s[1], _("Saturation"));
+ _s[1]->set_tooltip_text(_("Saturation"));
gtk_widget_set_tooltip_text (_b[1], _("Saturation"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[2]), _("_L:"));
- gtk_widget_set_tooltip_text (_s[2], _("Lightness"));
+ _s[2]->set_tooltip_text(_("Lightness"));
gtk_widget_set_tooltip_text (_b[2], _("Lightness"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[3]), _("_A:"));
- gtk_widget_set_tooltip_text (_s[3], _("Alpha (opacity)"));
+ _s[3]->set_tooltip_text(_("Alpha (opacity)"));
gtk_widget_set_tooltip_text (_b[3], _("Alpha (opacity)"));
- sp_color_slider_set_map (SP_COLOR_SLIDER (_s[0]), (guchar *)(sp_color_scales_hue_map()));
+ _s[0]->set_map((guchar *)(sp_color_scales_hue_map()));
gtk_widget_hide (_l[4]);
- gtk_widget_hide (_s[4]);
+ _s[4]->hide();
gtk_widget_hide (_b[4]);
_updating = TRUE;
c[0] = 0.0;
@@ -466,23 +472,23 @@ void ColorScales::setMode(SPColorScalesMode mode)
case SP_COLOR_SCALES_MODE_CMYK:
_setRangeLimit(100.0);
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_C:"));
- gtk_widget_set_tooltip_text (_s[0], _("Cyan"));
+ _s[0]->set_tooltip_text(_("Cyan"));
gtk_widget_set_tooltip_text (_b[0], _("Cyan"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[1]), _("_M:"));
- gtk_widget_set_tooltip_text (_s[1], _("Magenta"));
+ _s[1]->set_tooltip_text(_("Magenta"));
gtk_widget_set_tooltip_text (_b[1], _("Magenta"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[2]), _("_Y:"));
- gtk_widget_set_tooltip_text (_s[2], _("Yellow"));
+ _s[2]->set_tooltip_text(_("Yellow"));
gtk_widget_set_tooltip_text (_b[2], _("Yellow"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[3]), _("_K:"));
- gtk_widget_set_tooltip_text (_s[3], _("Black"));
+ _s[3]->set_tooltip_text(_("Black"));
gtk_widget_set_tooltip_text (_b[3], _("Black"));
gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[4]), _("_A:"));
- gtk_widget_set_tooltip_text (_s[4], _("Alpha (opacity)"));
+ _s[4]->set_tooltip_text(_("Alpha (opacity)"));
gtk_widget_set_tooltip_text (_b[4], _("Alpha (opacity)"));
- sp_color_slider_set_map (SP_COLOR_SLIDER (_s[0]), NULL);
+ _s[0]->set_map(NULL);
gtk_widget_show (_l[4]);
- gtk_widget_show (_s[4]);
+ _s[4]->show();
gtk_widget_show (_b[4]);
_updating = TRUE;
@@ -555,34 +561,27 @@ void ColorScales::_adjustmentAnyChanged( GtkAdjustment *adjustment, SPColorScale
_adjustmentChanged(cs, channel);
}
-void ColorScales::_sliderAnyGrabbed( SPColorSlider *slider, SPColorScales *cs )
+void ColorScales::_sliderAnyGrabbed()
{
- (void)slider;
- ColorScales* scales = static_cast<ColorScales*>(SP_COLOR_SELECTOR(cs)->base);
- if (!scales->_dragging) {
- scales->_dragging = TRUE;
- scales->_grabbed();
- scales->_recalcColor( FALSE );
+ if (!_dragging) {
+ _dragging = TRUE;
+ _grabbed();
+ _recalcColor( FALSE );
}
}
-void ColorScales::_sliderAnyReleased( SPColorSlider *slider, SPColorScales *cs )
+void ColorScales::_sliderAnyReleased()
{
- (void)slider;
- ColorScales* scales = static_cast<ColorScales*>(SP_COLOR_SELECTOR(cs)->base);
- if (scales->_dragging) {
- scales->_dragging = FALSE;
- scales->_released();
- scales->_recalcColor( FALSE );
+ if (_dragging) {
+ _dragging = FALSE;
+ _released();
+ _recalcColor( FALSE );
}
}
-void ColorScales::_sliderAnyChanged( SPColorSlider *slider, SPColorScales *cs )
+void ColorScales::_sliderAnyChanged()
{
- (void)slider;
- ColorScales* scales = static_cast<ColorScales*>(SP_COLOR_SELECTOR(cs)->base);
-
- scales->_recalcColor( TRUE );
+ _recalcColor( TRUE );
}
void ColorScales::_adjustmentChanged( SPColorScales *cs, guint channel )
@@ -609,31 +608,27 @@ void ColorScales::_updateSliders( guint channels )
case SP_COLOR_SCALES_MODE_RGB:
if ((channels != CSC_CHANNEL_R) && (channels != CSC_CHANNEL_A)) {
/* Update red */
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[0]),
- SP_RGBA32_F_COMPOSE (0.0, getScaled(_a[1]), getScaled(_a[2]), 1.0),
- SP_RGBA32_F_COMPOSE (0.5, getScaled(_a[1]), getScaled(_a[2]), 1.0),
- SP_RGBA32_F_COMPOSE (1.0, getScaled(_a[1]), getScaled(_a[2]), 1.0));
+ _s[0]->set_colors(SP_RGBA32_F_COMPOSE (0.0, getScaled(_a[1]), getScaled(_a[2]), 1.0),
+ SP_RGBA32_F_COMPOSE (0.5, getScaled(_a[1]), getScaled(_a[2]), 1.0),
+ SP_RGBA32_F_COMPOSE (1.0, getScaled(_a[1]), getScaled(_a[2]), 1.0));
}
if ((channels != CSC_CHANNEL_G) && (channels != CSC_CHANNEL_A)) {
/* Update green */
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[1]),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), 0.0, getScaled(_a[2]), 1.0),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), 0.5, getScaled(_a[2]), 1.0),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), 1.0, getScaled(_a[2]), 1.0));
+ _s[1]->set_colors(SP_RGBA32_F_COMPOSE(getScaled(_a[0]), 0.0, getScaled(_a[2]), 1.0),
+ SP_RGBA32_F_COMPOSE(getScaled(_a[0]), 0.5, getScaled(_a[2]), 1.0),
+ SP_RGBA32_F_COMPOSE(getScaled(_a[0]), 1.0, getScaled(_a[2]), 1.0));
}
if ((channels != CSC_CHANNEL_B) && (channels != CSC_CHANNEL_A)) {
/* Update blue */
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[2]),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 0.0, 1.0),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 0.5, 1.0),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 1.0, 1.0));
+ _s[2]->set_colors(SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 0.0, 1.0),
+ SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 0.5, 1.0),
+ SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), 1.0, 1.0));
}
if (channels != CSC_CHANNEL_A) {
/* Update alpha */
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[3]),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.0),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.5),
- SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 1.0));
+ _s[3]->set_colors(SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.0),
+ SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.5),
+ SP_RGBA32_F_COMPOSE (getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 1.0));
}
break;
case SP_COLOR_SCALES_MODE_HSV:
@@ -643,28 +638,25 @@ void ColorScales::_updateSliders( guint channels )
sp_color_hsl_to_rgb_floatv (rgb0, getScaled(_a[0]), 0.0, getScaled(_a[2]));
sp_color_hsl_to_rgb_floatv (rgbm, getScaled(_a[0]), 0.5, getScaled(_a[2]));
sp_color_hsl_to_rgb_floatv (rgb1, getScaled(_a[0]), 1.0, getScaled(_a[2]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[1]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[1]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if ((channels != CSC_CHANNEL_V) && (channels != CSC_CHANNEL_A)) {
/* Update value */
sp_color_hsl_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), 0.0);
sp_color_hsl_to_rgb_floatv (rgbm, getScaled(_a[0]), getScaled(_a[1]), 0.5);
sp_color_hsl_to_rgb_floatv (rgb1, getScaled(_a[0]), getScaled(_a[1]), 1.0);
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[2]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[2]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if (channels != CSC_CHANNEL_A) {
/* Update alpha */
sp_color_hsl_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[3]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.0),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.5),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0));
+ _s[3]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.0),
+ SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.5),
+ SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0));
}
break;
case SP_COLOR_SCALES_MODE_CMYK:
@@ -673,48 +665,43 @@ void ColorScales::_updateSliders( guint channels )
sp_color_cmyk_to_rgb_floatv (rgb0, 0.0, getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgbm, 0.5, getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgb1, 1.0, getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[0]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[0]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if ((channels != CSC_CHANNEL_M) && (channels != CSC_CHANNEL_CMYKA)) {
/* Update M */
sp_color_cmyk_to_rgb_floatv (rgb0, getScaled(_a[0]), 0.0, getScaled(_a[2]), getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgbm, getScaled(_a[0]), 0.5, getScaled(_a[2]), getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgb1, getScaled(_a[0]), 1.0, getScaled(_a[2]), getScaled(_a[3]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[1]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[1]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if ((channels != CSC_CHANNEL_Y) && (channels != CSC_CHANNEL_CMYKA)) {
/* Update Y */
sp_color_cmyk_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), 0.0, getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgbm, getScaled(_a[0]), getScaled(_a[1]), 0.5, getScaled(_a[3]));
sp_color_cmyk_to_rgb_floatv (rgb1, getScaled(_a[0]), getScaled(_a[1]), 1.0, getScaled(_a[3]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[2]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[2]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if ((channels != CSC_CHANNEL_K) && (channels != CSC_CHANNEL_CMYKA)) {
/* Update K */
sp_color_cmyk_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.0);
sp_color_cmyk_to_rgb_floatv (rgbm, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.5);
sp_color_cmyk_to_rgb_floatv (rgb1, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 1.0);
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[3]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
- SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
+ _s[3]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgbm[0], rgbm[1], rgbm[2], 1.0),
+ SP_RGBA32_F_COMPOSE (rgb1[0], rgb1[1], rgb1[2], 1.0));
}
if (channels != CSC_CHANNEL_CMYKA) {
/* Update alpha */
sp_color_cmyk_to_rgb_floatv (rgb0, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]));
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_s[4]),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.0),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.5),
- SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0));
+ _s[4]->set_colors(SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.0),
+ SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 0.5),
+ SP_RGBA32_F_COMPOSE (rgb0[0], rgb0[1], rgb0[2], 1.0));
}
break;
default:
diff --git a/src/widgets/sp-color-scales.h b/src/widgets/sp-color-scales.h
index 72cbafa2f..4194f9423 100644
--- a/src/widgets/sp-color-scales.h
+++ b/src/widgets/sp-color-scales.h
@@ -7,7 +7,16 @@
struct SPColorScales;
struct SPColorScalesClass;
-struct SPColorSlider;
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class ColorSlider;
+
+}
+}
+}
typedef enum {
SP_COLOR_SCALES_MODE_NONE = 0,
@@ -40,9 +49,9 @@ protected:
virtual void _colorChanged();
static void _adjustmentAnyChanged(GtkAdjustment *adjustment, SPColorScales *cs);
- static void _sliderAnyGrabbed(SPColorSlider *slider, SPColorScales *cs);
- static void _sliderAnyReleased(SPColorSlider *slider, SPColorScales *cs);
- static void _sliderAnyChanged(SPColorSlider *slider, SPColorScales *cs);
+ void _sliderAnyGrabbed();
+ void _sliderAnyReleased();
+ void _sliderAnyChanged();
static void _adjustmentChanged(SPColorScales *cs, guint channel);
void _getRgbaFloatv(gfloat *rgba);
@@ -58,7 +67,7 @@ protected:
gboolean _updating : 1;
gboolean _dragging : 1;
GtkAdjustment *_a[5]; /* Channel adjustments */
- GtkWidget *_s[5]; /* Channel sliders */
+ Inkscape::UI::Widget::ColorSlider *_s[5]; /* Channel sliders */
GtkWidget *_b[5]; /* Spinbuttons */
GtkWidget *_l[5]; /* Labels */
diff --git a/src/widgets/sp-color-selector.cpp b/src/widgets/sp-color-selector.cpp
index e97c36431..e443ca4ab 100644
--- a/src/widgets/sp-color-selector.cpp
+++ b/src/widgets/sp-color-selector.cpp
@@ -6,6 +6,11 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
#include <math.h>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
diff --git a/src/widgets/sp-color-slider.cpp b/src/widgets/sp-color-slider.cpp
deleted file mode 100644
index ab7e2cd84..000000000
--- a/src/widgets/sp-color-slider.cpp
+++ /dev/null
@@ -1,749 +0,0 @@
-/*
- * A slider with colored background
- *
- * Author:
- * Lauris Kaplinski <lauris@kaplinski.com>
- * bulia byak <buliabyak@users.sf.net>
- *
- * Copyright (C) 2001-2002 Lauris Kaplinski
- *
- * This code is in public domain
- */
-
-#include <gtk/gtk.h>
-#include "sp-color-scales.h"
-#include "sp-color-slider.h"
-#include "preferences.h"
-
-#define SLIDER_WIDTH 96
-#define SLIDER_HEIGHT 8
-#define ARROW_SIZE 7
-
-enum {
- GRABBED,
- DRAGGED,
- RELEASED,
- CHANGED,
- LAST_SIGNAL
-};
-
-static void sp_color_slider_dispose(GObject *object);
-
-static void sp_color_slider_realize (GtkWidget *widget);
-static void sp_color_slider_size_request (GtkWidget *widget, GtkRequisition *requisition);
-
-#if GTK_CHECK_VERSION(3,0,0)
-static void sp_color_slider_get_preferred_width(GtkWidget *widget,
- gint *minimal_width,
- gint *natural_width);
-
-static void sp_color_slider_get_preferred_height(GtkWidget *widget,
- gint *minimal_height,
- gint *natural_height);
-#else
-static gboolean sp_color_slider_expose(GtkWidget *widget, GdkEventExpose *event);
-#endif
-
-static void sp_color_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
-
-static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr);
-
-static gint sp_color_slider_button_press (GtkWidget *widget, GdkEventButton *event);
-static gint sp_color_slider_button_release (GtkWidget *widget, GdkEventButton *event);
-static gint sp_color_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event);
-
-static void sp_color_slider_adjustment_changed (GtkAdjustment *adjustment, SPColorSlider *slider);
-static void sp_color_slider_adjustment_value_changed (GtkAdjustment *adjustment, SPColorSlider *slider);
-
-static const guchar *sp_color_slider_render_gradient (gint x0, gint y0, gint width, gint height,
- gint c[], gint dc[], guint b0, guint b1, guint mask);
-static const guchar *sp_color_slider_render_map (gint x0, gint y0, gint width, gint height,
- guchar *map, gint start, gint step, guint b0, guint b1, guint mask);
-
-static guint slider_signals[LAST_SIGNAL] = {0};
-
-G_DEFINE_TYPE(SPColorSlider, sp_color_slider, GTK_TYPE_WIDGET);
-
-static void sp_color_slider_class_init(SPColorSliderClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
-
- slider_signals[GRABBED] = g_signal_new ("grabbed",
- G_TYPE_FROM_CLASS(object_class),
- (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
- G_STRUCT_OFFSET (SPColorSliderClass, grabbed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- slider_signals[DRAGGED] = g_signal_new ("dragged",
- G_TYPE_FROM_CLASS(object_class),
- (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
- G_STRUCT_OFFSET (SPColorSliderClass, dragged),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- slider_signals[RELEASED] = g_signal_new ("released",
- G_TYPE_FROM_CLASS(object_class),
- (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
- G_STRUCT_OFFSET (SPColorSliderClass, released),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- slider_signals[CHANGED] = g_signal_new ("changed",
- G_TYPE_FROM_CLASS(object_class),
- (GSignalFlags)(G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE),
- G_STRUCT_OFFSET (SPColorSliderClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- object_class->dispose = sp_color_slider_dispose;
-
- widget_class->realize = sp_color_slider_realize;
-#if GTK_CHECK_VERSION(3,0,0)
- widget_class->get_preferred_width = sp_color_slider_get_preferred_width;
- widget_class->get_preferred_height = sp_color_slider_get_preferred_height;
- widget_class->draw = sp_color_slider_draw;
-#else
- widget_class->size_request = sp_color_slider_size_request;
- widget_class->expose_event = sp_color_slider_expose;
-#endif
- widget_class->size_allocate = sp_color_slider_size_allocate;
-/* widget_class->draw_focus = sp_color_slider_draw_focus; */
-/* widget_class->draw_default = sp_color_slider_draw_default; */
-
- widget_class->button_press_event = sp_color_slider_button_press;
- widget_class->button_release_event = sp_color_slider_button_release;
- widget_class->motion_notify_event = sp_color_slider_motion_notify;
-}
-
-static void
-sp_color_slider_init (SPColorSlider *slider)
-{
- /* We are widget with window */
- gtk_widget_set_has_window (GTK_WIDGET(slider), TRUE);
-
- slider->dragging = FALSE;
-
- slider->adjustment = NULL;
- slider->value = 0.0;
-
- slider->c0[0] = 0x00;
- slider->c0[1] = 0x00;
- slider->c0[2] = 0x00;
- slider->c0[3] = 0xff;
-
- slider->cm[0] = 0xff;
- slider->cm[1] = 0x00;
- slider->cm[2] = 0x00;
- slider->cm[3] = 0xff;
-
- slider->c1[0] = 0xff;
- slider->c1[1] = 0xff;
- slider->c1[2] = 0xff;
- slider->c1[3] = 0xff;
-
- slider->b0 = 0x5f;
- slider->b1 = 0xa0;
- slider->bmask = 0x08;
-
- slider->map = NULL;
-}
-
-static void sp_color_slider_dispose(GObject *object)
-{
- SPColorSlider *slider = SP_COLOR_SLIDER (object);
-
- if (slider->adjustment) {
- g_signal_handlers_disconnect_matched (G_OBJECT (slider->adjustment), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, slider);
- g_object_unref (slider->adjustment);
- slider->adjustment = NULL;
- }
-
- if (G_OBJECT_CLASS(sp_color_slider_parent_class)->dispose)
- G_OBJECT_CLASS(sp_color_slider_parent_class)->dispose (object);
-}
-
-static void
-sp_color_slider_realize (GtkWidget *widget)
-{
- GdkWindowAttr attributes;
- gint attributes_mask;
- GtkAllocation allocation;
-
- gtk_widget_get_allocation(widget, &allocation);
- gtk_widget_set_realized (widget, TRUE);
-
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = allocation.x;
- attributes.y = allocation.y;
- attributes.width = allocation.width;
- attributes.height = allocation.height;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gdk_screen_get_system_visual(gdk_screen_get_default());
-
-#if !GTK_CHECK_VERSION(3,0,0)
- attributes.colormap = gdk_screen_get_system_colormap(gdk_screen_get_default());
-#endif
-
- attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |= (GDK_EXPOSURE_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK);
-#if GTK_CHECK_VERSION(3,0,0)
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
-#else
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-#endif
-
- gtk_widget_set_window(widget,
- gdk_window_new(gtk_widget_get_parent_window(widget),
- &attributes, attributes_mask));
-
- gdk_window_set_user_data(gtk_widget_get_window(widget), widget);
-
-#if !GTK_CHECK_VERSION(3,0,0)
- // This doesn't do anything in GTK+ 3
- gtk_widget_set_style(widget,
- gtk_style_attach(gtk_widget_get_style(widget),
- gtk_widget_get_window(widget)));
-#endif
-}
-
-static void
-sp_color_slider_size_request (GtkWidget *widget, GtkRequisition *requisition)
-{
- GtkStyle *style = gtk_widget_get_style(widget);
- requisition->width = SLIDER_WIDTH + style->xthickness * 2;
- requisition->height = SLIDER_HEIGHT + style->ythickness * 2;
-}
-
-#if GTK_CHECK_VERSION(3,0,0)
-static void sp_color_slider_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width)
-{
- GtkRequisition requisition;
- sp_color_slider_size_request(widget, &requisition);
- *minimal_width = *natural_width = requisition.width;
-}
-
-static void sp_color_slider_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height)
-{
- GtkRequisition requisition;
- sp_color_slider_size_request(widget, &requisition);
- *minimal_height = *natural_height = requisition.height;
-}
-#endif
-
-static void
-sp_color_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
-{
- gtk_widget_set_allocation(widget, allocation);
-
- if (gtk_widget_get_realized (widget)) {
- /* Resize GdkWindow */
- gdk_window_move_resize(gtk_widget_get_window(widget),
- allocation->x, allocation->y,
- allocation->width, allocation->height);
- }
-}
-
-#if !GTK_CHECK_VERSION(3,0,0)
-static gboolean sp_color_slider_expose(GtkWidget *widget, GdkEventExpose * /*event*/)
-{
- gboolean result = FALSE;
-
- if (gtk_widget_is_drawable(widget)) {
- GdkWindow *window = gtk_widget_get_window(widget);
- cairo_t *cr = gdk_cairo_create(window);
- result = sp_color_slider_draw(widget, cr);
- cairo_destroy(cr);
- }
-
- return result;
-}
-#endif
-
-static gint
-sp_color_slider_button_press (GtkWidget *widget, GdkEventButton *event)
-{
- SPColorSlider *slider;
-
- slider = SP_COLOR_SLIDER (widget);
-
- if (event->button == 1) {
- GtkAllocation allocation;
- gtk_widget_get_allocation(widget, &allocation);
- gint cx, cw;
- cx = gtk_widget_get_style(widget)->xthickness;
- cw = allocation.width - 2 * cx;
- g_signal_emit (G_OBJECT (slider), slider_signals[GRABBED], 0);
- slider->dragging = TRUE;
- slider->oldvalue = slider->value;
- ColorScales::setScaled( slider->adjustment, CLAMP ((gfloat) (event->x - cx) / cw, 0.0, 1.0) );
- g_signal_emit (G_OBJECT (slider), slider_signals[DRAGGED], 0);
-
-#if GTK_CHECK_VERSION(3,0,0)
- gdk_device_grab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)),
- gtk_widget_get_window(widget),
- GDK_OWNERSHIP_NONE,
- FALSE,
- static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK),
- NULL,
- event->time);
-#else
- gdk_pointer_grab(gtk_widget_get_window(widget), FALSE,
- static_cast<GdkEventMask>(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK),
- NULL, NULL, event->time);
-#endif
- }
-
- return FALSE;
-}
-
-static gint
-sp_color_slider_button_release (GtkWidget *widget, GdkEventButton *event)
-{
- SPColorSlider *slider;
-
- slider = SP_COLOR_SLIDER (widget);
-
- if (event->button == 1) {
-
-#if GTK_CHECK_VERSION(3,0,0)
- gdk_device_ungrab(gdk_event_get_device(reinterpret_cast<GdkEvent *>(event)),
- gdk_event_get_time(reinterpret_cast<GdkEvent *>(event)));
-#else
- gdk_pointer_ungrab (event->time);
-#endif
-
- slider->dragging = FALSE;
- g_signal_emit (G_OBJECT (slider), slider_signals[RELEASED], 0);
- if (slider->value != slider->oldvalue) g_signal_emit (G_OBJECT (slider), slider_signals[CHANGED], 0);
- }
-
- return FALSE;
-}
-
-static gint
-sp_color_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event)
-{
- SPColorSlider *slider;
-
- slider = SP_COLOR_SLIDER (widget);
-
- if (slider->dragging) {
- gint cx, cw;
- GtkAllocation allocation;
- gtk_widget_get_allocation(widget, &allocation);
- cx = gtk_widget_get_style(widget)->xthickness;
- cw = allocation.width - 2 * cx;
- ColorScales::setScaled( slider->adjustment, CLAMP ((gfloat) (event->x - cx) / cw, 0.0, 1.0) );
- g_signal_emit (G_OBJECT (slider), slider_signals[DRAGGED], 0);
- }
-
- return FALSE;
-}
-
-GtkWidget *sp_color_slider_new(GtkAdjustment *adjustment)
-{
- SPColorSlider *slider = SP_COLOR_SLIDER(g_object_new(SP_TYPE_COLOR_SLIDER, NULL));
-
- sp_color_slider_set_adjustment (slider, adjustment);
-
- return GTK_WIDGET (slider);
-}
-
-void sp_color_slider_set_adjustment(SPColorSlider *slider, GtkAdjustment *adjustment)
-{
- g_return_if_fail (slider != NULL);
- g_return_if_fail (SP_IS_COLOR_SLIDER (slider));
-
- if (!adjustment) {
- adjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 1.0, 0.01, 0.0, 0.0));
- } else {
- gtk_adjustment_set_page_increment(adjustment, 0.0);
- gtk_adjustment_set_page_size(adjustment, 0.0);
- }
-
- if (slider->adjustment != adjustment) {
- if (slider->adjustment) {
- g_signal_handlers_disconnect_matched (G_OBJECT (slider->adjustment), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, slider);
- g_object_unref (slider->adjustment);
- }
-
- slider->adjustment = adjustment;
- g_object_ref (adjustment);
- g_object_ref_sink (adjustment);
-
- g_signal_connect (G_OBJECT (adjustment), "changed",
- G_CALLBACK (sp_color_slider_adjustment_changed), slider);
- g_signal_connect (G_OBJECT (adjustment), "value_changed",
- G_CALLBACK (sp_color_slider_adjustment_value_changed), slider);
-
- slider->value = ColorScales::getScaled( adjustment );
-
- sp_color_slider_adjustment_changed (adjustment, slider);
- }
-}
-
-void
-sp_color_slider_set_colors (SPColorSlider *slider, guint32 start, guint32 mid, guint32 end)
-{
- g_return_if_fail (slider != NULL);
- g_return_if_fail (SP_IS_COLOR_SLIDER (slider));
-
- // Remove any map, if set
- slider->map = 0;
-
- slider->c0[0] = start >> 24;
- slider->c0[1] = (start >> 16) & 0xff;
- slider->c0[2] = (start >> 8) & 0xff;
- slider->c0[3] = start & 0xff;
-
- slider->cm[0] = mid >> 24;
- slider->cm[1] = (mid >> 16) & 0xff;
- slider->cm[2] = (mid >> 8) & 0xff;
- slider->cm[3] = mid & 0xff;
-
- slider->c1[0] = end >> 24;
- slider->c1[1] = (end >> 16) & 0xff;
- slider->c1[2] = (end >> 8) & 0xff;
- slider->c1[3] = end & 0xff;
-
- gtk_widget_queue_draw (GTK_WIDGET (slider));
-}
-
-void
-sp_color_slider_set_map (SPColorSlider *slider, const guchar *map)
-{
- g_return_if_fail (slider != NULL);
- g_return_if_fail (SP_IS_COLOR_SLIDER (slider));
-
- slider->map = const_cast<guchar *>(map);
-
- gtk_widget_queue_draw (GTK_WIDGET (slider));
-}
-
-void
-sp_color_slider_set_background (SPColorSlider *slider, guint dark, guint light, guint size)
-{
- g_return_if_fail (slider != NULL);
- g_return_if_fail (SP_IS_COLOR_SLIDER (slider));
-
- slider->b0 = dark;
- slider->b1 = light;
- slider->bmask = size;
-
- gtk_widget_queue_draw (GTK_WIDGET (slider));
-}
-
-static void
-sp_color_slider_adjustment_changed (GtkAdjustment */*adjustment*/, SPColorSlider *slider)
-{
- gtk_widget_queue_draw (GTK_WIDGET (slider));
-}
-
-static void
-sp_color_slider_adjustment_value_changed (GtkAdjustment *adjustment, SPColorSlider *slider)
-{
- GtkWidget *widget;
-
- widget = GTK_WIDGET (slider);
-
- if (slider->value != ColorScales::getScaled( adjustment )) {
- gint cx, cy, cw, ch;
- GtkStyle *style = gtk_widget_get_style(widget);
- GtkAllocation allocation;
- gtk_widget_get_allocation(widget, &allocation);
- cx = style->xthickness;
- cy = style->ythickness;
- cw = allocation.width - 2 * cx;
- ch = allocation.height - 2 * cy;
- if ((gint) (ColorScales::getScaled( adjustment ) * cw) != (gint) (slider->value * cw)) {
- gint ax, ay;
- gfloat value;
- value = slider->value;
- slider->value = ColorScales::getScaled( adjustment );
- ax = (int)(cx + value * cw - ARROW_SIZE / 2 - 2);
- ay = cy;
- gtk_widget_queue_draw_area (widget, ax, ay, ARROW_SIZE + 4, ch);
- ax = (int)(cx + slider->value * cw - ARROW_SIZE / 2 - 2);
- ay = cy;
- gtk_widget_queue_draw_area (widget, ax, ay, ARROW_SIZE + 4, ch);
- } else {
- slider->value = ColorScales::getScaled( adjustment );
- }
- }
-}
-
-static gboolean sp_color_slider_draw(GtkWidget *widget, cairo_t *cr)
-{
- SPColorSlider *slider = SP_COLOR_SLIDER(widget);
-
- gboolean colorsOnTop = Inkscape::Preferences::get()->getBool("/options/workarounds/colorsontop", false);
-
- GtkAllocation allocation;
- gtk_widget_get_allocation(widget, &allocation);
-
-#if GTK_CHECK_VERSION(3,0,0)
- GtkStyleContext *context = gtk_widget_get_style_context(widget);
-#else
- GdkWindow *window = gtk_widget_get_window(widget);
- GtkStyle *style = gtk_widget_get_style(widget);
-#endif
-
- // Draw shadow
- if (colorsOnTop) {
-#if GTK_CHECK_VERSION(3,0,0)
- gtk_render_frame(context,
- cr,
- 0, 0,
- allocation.width, allocation.height);
-#else
- gtk_paint_shadow( style, window,
- gtk_widget_get_state(widget), GTK_SHADOW_IN,
- NULL, widget, "colorslider",
- 0, 0,
- allocation.width, allocation.height);
-#endif
- }
-
- /* Paintable part of color gradient area */
- GdkRectangle carea;
-
-#if GTK_CHECK_VERSION(3,0,0)
- GtkBorder padding;
-
- gtk_style_context_get_padding(context,
- gtk_widget_get_state_flags(widget),
- &padding);
-
- carea.x = padding.left;
- carea.y = padding.top;
-#else
- carea.x = style->xthickness;
- carea.y = style->ythickness;
-#endif
-
- carea.width = allocation.width - 2 * carea.x;
- carea.height = allocation.height - 2 * carea.y;
-
- if (slider->map) {
- /* Render map pixelstore */
- gint d = (1024 << 16) / carea.width;
- gint s = 0;
-
- const guchar *b = sp_color_slider_render_map(0, 0, carea.width, carea.height,
- slider->map, s, d,
- slider->b0, slider->b1, slider->bmask);
-
- if (b != NULL && carea.width > 0) {
- GdkPixbuf *pb = gdk_pixbuf_new_from_data (b, GDK_COLORSPACE_RGB,
- 0, 8, carea.width, carea.height, carea.width * 3, NULL, NULL);
-
- gdk_cairo_set_source_pixbuf(cr, pb, carea.x, carea.y);
- cairo_paint(cr);
- g_object_unref(pb);
- }
-
- } else {
- gint c[4], dc[4];
-
- /* Render gradient */
-
- // part 1: from c0 to cm
- if (carea.width > 0) {
- for (gint i = 0; i < 4; i++) {
- c[i] = slider->c0[i] << 16;
- dc[i] = ((slider->cm[i] << 16) - c[i]) / (carea.width/2);
- }
- guint wi = carea.width/2;
- const guchar *b = sp_color_slider_render_gradient(0, 0, wi, carea.height,
- c, dc, slider->b0, slider->b1, slider->bmask);
-
- /* Draw pixelstore 1 */
- if (b != NULL && wi > 0) {
- GdkPixbuf *pb = gdk_pixbuf_new_from_data (b, GDK_COLORSPACE_RGB,
- 0, 8, wi, carea.height, wi * 3, NULL, NULL);
-
- gdk_cairo_set_source_pixbuf(cr, pb, carea.x, carea.y);
- cairo_paint(cr);
- g_object_unref(pb);
- }
- }
-
- // part 2: from cm to c1
- if (carea.width > 0) {
- for (gint i = 0; i < 4; i++) {
- c[i] = slider->cm[i] << 16;
- dc[i] = ((slider->c1[i] << 16) - c[i]) / (carea.width/2);
- }
- guint wi = carea.width/2;
- const guchar *b = sp_color_slider_render_gradient(carea.width/2, 0, wi, carea.height,
- c, dc,
- slider->b0, slider->b1, slider->bmask);
-
- /* Draw pixelstore 2 */
- if (b != NULL && wi > 0) {
- GdkPixbuf *pb = gdk_pixbuf_new_from_data (b, GDK_COLORSPACE_RGB,
- 0, 8, wi, carea.height, wi * 3, NULL, NULL);
-
- gdk_cairo_set_source_pixbuf(cr, pb, carea.width/2 + carea.x, carea.y);
- cairo_paint(cr);
-
- g_object_unref(pb);
- }
- }
- }
-
- /* Draw shadow */
- if (!colorsOnTop) {
-#if GTK_CHECK_VERSION(3,0,0)
- gtk_render_frame(context,
- cr,
- 0, 0,
- allocation.width, allocation.height);
-#else
- gtk_paint_shadow( style, window,
- gtk_widget_get_state(widget), GTK_SHADOW_IN,
- NULL, widget, "colorslider",
- 0, 0,
- allocation.width, allocation.height);
-#endif
- }
-
- /* Draw arrow */
- gint x = (int)(slider->value * (carea.width - 1) - ARROW_SIZE / 2 + carea.x);
- gint y1 = carea.y;
- gint y2 = carea.y + carea.height - 1;
- cairo_set_line_width(cr, 1.0);
-
- // Define top arrow
- cairo_move_to(cr, x - 0.5, y1 + 0.5);
- cairo_line_to(cr, x + ARROW_SIZE - 0.5, y1 + 0.5);
- cairo_line_to(cr, x + (ARROW_SIZE-1)/2.0, y1 + ARROW_SIZE/2.0 + 0.5);
- cairo_line_to(cr, x - 0.5, y1 + 0.5);
-
- // Define bottom arrow
- cairo_move_to(cr, x - 0.5, y2 + 0.5);
- cairo_line_to(cr, x + ARROW_SIZE - 0.5, y2 + 0.5);
- cairo_line_to(cr, x + (ARROW_SIZE-1)/2.0, y2 - ARROW_SIZE/2.0 + 0.5);
- cairo_line_to(cr, x - 0.5, y2 + 0.5);
-
- // Render both arrows
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
- cairo_stroke_preserve(cr);
- cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
- cairo_fill(cr);
-
- return FALSE;
-}
-
-/* Colors are << 16 */
-
-static const guchar *
-sp_color_slider_render_gradient (gint x0, gint y0, gint width, gint height,
- gint c[], gint dc[], guint b0, guint b1, guint mask)
-{
- static guchar *buf = NULL;
- static gint bs = 0;
- guchar *dp;
- gint x, y;
- guint r, g, b, a;
-
- if (buf && (bs < width * height)) {
- g_free (buf);
- buf = NULL;
- }
- if (!buf) {
- buf = g_new (guchar, width * height * 3);
- bs = width * height;
- }
-
- dp = buf;
- r = c[0];
- g = c[1];
- b = c[2];
- a = c[3];
- for (x = x0; x < x0 + width; x++) {
- gint cr, cg, cb, ca;
- guchar *d;
- cr = r >> 16;
- cg = g >> 16;
- cb = b >> 16;
- ca = a >> 16;
- d = dp;
- for (y = y0; y < y0 + height; y++) {
- guint bg, fc;
- /* Background value */
- bg = ((x & mask) ^ (y & mask)) ? b0 : b1;
- fc = (cr - bg) * ca;
- d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- fc = (cg - bg) * ca;
- d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- fc = (cb - bg) * ca;
- d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- d += 3 * width;
- }
- r += dc[0];
- g += dc[1];
- b += dc[2];
- a += dc[3];
- dp += 3;
- }
-
- return buf;
-}
-
-/* Positions are << 16 */
-
-static const guchar *
-sp_color_slider_render_map (gint x0, gint y0, gint width, gint height,
- guchar *map, gint start, gint step, guint b0, guint b1, guint mask)
-{
- static guchar *buf = NULL;
- static gint bs = 0;
- guchar *dp;
- gint x, y;
-
- if (buf && (bs < width * height)) {
- g_free (buf);
- buf = NULL;
- }
- if (!buf) {
- buf = g_new (guchar, width * height * 3);
- bs = width * height;
- }
-
- dp = buf;
- for (x = x0; x < x0 + width; x++) {
- gint cr, cg, cb, ca;
- guchar *d = dp;
- guchar *sp = map + 4 * (start >> 16);
- cr = *sp++;
- cg = *sp++;
- cb = *sp++;
- ca = *sp++;
- for (y = y0; y < y0 + height; y++) {
- guint bg, fc;
- /* Background value */
- bg = ((x & mask) ^ (y & mask)) ? b0 : b1;
- fc = (cr - bg) * ca;
- d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- fc = (cg - bg) * ca;
- d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- fc = (cb - bg) * ca;
- d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
- d += 3 * width;
- }
- dp += 3;
- start += step;
- }
-
- return buf;
-}
-
diff --git a/src/widgets/sp-color-slider.h b/src/widgets/sp-color-slider.h
deleted file mode 100644
index b81d62e41..000000000
--- a/src/widgets/sp-color-slider.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef __SP_COLOR_SLIDER_H__
-#define __SP_COLOR_SLIDER_H__
-
-/*
- * A slider with colored background
- *
- * Author:
- * Lauris Kaplinski <lauris@kaplinski.com>
- *
- * Copyright (C) 2001-2002 Lauris Kaplinski
- *
- * This code is in public domain
- */
-
-#include <gtk/gtk.h>
-
-#define SP_TYPE_COLOR_SLIDER (sp_color_slider_get_type ())
-#define SP_COLOR_SLIDER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_COLOR_SLIDER, SPColorSlider))
-#define SP_COLOR_SLIDER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), SP_TYPE_COLOR_SLIDER, SPColorSliderClass))
-#define SP_IS_COLOR_SLIDER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SP_TYPE_COLOR_SLIDER))
-#define SP_IS_COLOR_SLIDER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SP_TYPE_COLOR_SLIDER))
-
-struct SPColorSlider {
- GtkWidget widget;
-
- guint dragging : 1;
-
- GtkAdjustment *adjustment;
-
- gfloat value;
- gfloat oldvalue;
- guchar c0[4], cm[4], c1[4];
- guchar b0, b1;
- guchar bmask;
-
- gint mapsize;
- guchar *map;
-};
-
-struct SPColorSliderClass {
- GtkWidgetClass parent_class;
-
- void (* grabbed) (SPColorSlider *slider);
- void (* dragged) (SPColorSlider *slider);
- void (* released) (SPColorSlider *slider);
- void (* changed) (SPColorSlider *slider);
-};
-
-GType sp_color_slider_get_type (void);
-
-GtkWidget *sp_color_slider_new (GtkAdjustment *adjustment);
-
-void sp_color_slider_set_adjustment (SPColorSlider *slider, GtkAdjustment *adjustment);
-void sp_color_slider_set_colors (SPColorSlider *slider, guint32 start, guint32 mid, guint32 end);
-void sp_color_slider_set_map (SPColorSlider *slider, const guchar *map);
-void sp_color_slider_set_background (SPColorSlider *slider, guint dark, guint light, guint size);
-
-
-
-#endif
diff --git a/src/widgets/sp-color-wheel-selector.cpp b/src/widgets/sp-color-wheel-selector.cpp
index 6cfa7c14d..f9a6d7ceb 100644
--- a/src/widgets/sp-color-wheel-selector.cpp
+++ b/src/widgets/sp-color-wheel-selector.cpp
@@ -1,15 +1,18 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
+
+#include "sp-color-wheel-selector.h"
+
#include <math.h>
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
+#include <gtkmm/adjustment.h>
#include "ui/dialog-events.h"
-#include "sp-color-wheel-selector.h"
#include "sp-color-scales.h"
-#include "sp-color-slider.h"
#include "sp-color-icc-selector.h"
#include "../svg/svg-icc-color.h"
+#include "ui/widget/color-slider.h"
#include "ui/widget/gimpcolorwheel.h"
G_BEGIN_DECLS
@@ -133,33 +136,31 @@ void ColorWheelSelector::init()
_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, 255.0, 1.0, 10.0, 10.0));
/* Slider */
- _slider = sp_color_slider_new (_adj);
- gtk_widget_set_tooltip_text (_slider, _("Alpha (opacity)"));
- gtk_widget_show (_slider);
+ _slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_adj, true)));
+ _slider->set_tooltip_text(_("Alpha (opacity)"));
+ _slider->show();
#if GTK_CHECK_VERSION(3,0,0)
#if GTK_CHECK_VERSION(3,12,0)
- gtk_widget_set_margin_start(_slider, XPAD);
- gtk_widget_set_margin_end(_slider, XPAD);
+ _slider->set_margin_start(XPAD);
+ _slider->set_margin_end(XPAD);
#else
- gtk_widget_set_margin_left(_slider, XPAD);
- gtk_widget_set_margin_right(_slider, XPAD);
+ _slider->set_margin_left(XPAD);
+ _slider->set_margin_right(XPAD);
#endif
- gtk_widget_set_margin_top(_slider, YPAD);
- gtk_widget_set_margin_bottom(_slider, YPAD);
- gtk_widget_set_hexpand(_slider, TRUE);
- gtk_widget_set_halign(_slider, GTK_ALIGN_FILL);
- gtk_widget_set_valign(_slider, GTK_ALIGN_FILL);
- gtk_grid_attach(GTK_GRID(t), _slider, 1, row, 1, 1);
+ _slider->set_margin_top(YPAD);
+ _slider->set_margin_bottom(YPAD);
+ _slider->set_hexpand(true);
+ _slider->set_halign(Gtk::ALIGN_FILL);
+ _slider->set_valign(Gtk::ALIGN_FILL);
+ gtk_grid_attach(GTK_GRID(t), _slider->gobj(), 1, row, 1, 1);
#else
- gtk_table_attach(GTK_TABLE (t), _slider, 1, 2, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, XPAD, YPAD);
+ gtk_table_attach(GTK_TABLE (t), _slider->gobj(), 1, 2, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_FILL, XPAD, YPAD);
#endif
- sp_color_slider_set_colors (SP_COLOR_SLIDER (_slider),
- SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 0.0),
- SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 0.5),
- SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 1.0));
-
+ _slider->set_colors(SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 0.0),
+ SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 0.5),
+ SP_RGBA32_F_COMPOSE (1.0, 1.0, 1.0, 1.0));
/* Spinbutton */
_sbtn = gtk_spin_button_new (GTK_ADJUSTMENT (_adj), 1.0, 0);
@@ -189,12 +190,9 @@ void ColorWheelSelector::init()
g_signal_connect (G_OBJECT (_adj), "value_changed",
G_CALLBACK (_adjustmentChanged), _csel);
- g_signal_connect (G_OBJECT (_slider), "grabbed",
- G_CALLBACK (_sliderGrabbed), _csel);
- g_signal_connect (G_OBJECT (_slider), "released",
- G_CALLBACK (_sliderReleased), _csel);
- g_signal_connect (G_OBJECT (_slider), "changed",
- G_CALLBACK (_sliderChanged), _csel);
+ _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));
g_signal_connect( G_OBJECT(_wheel), "changed",
G_CALLBACK (_wheelChanged), _csel );
@@ -226,9 +224,8 @@ GtkWidget *sp_color_wheel_selector_new()
/* Helpers for setting color value */
-static void preserve_icc(SPColor *color, SPColorWheelSelector *cs){
- ColorSelector* selector = static_cast<ColorSelector*>(SP_COLOR_SELECTOR(cs)->base);
- color->icc = selector->getColor().icc ? new SVGICCColor(*selector->getColor().icc) : 0;
+void ColorWheelSelector::_preserve_icc(SPColor *color) const {
+ color->icc = getColor().icc ? new SVGICCColor(*getColor().icc) : 0;
}
void ColorWheelSelector::_colorChanged()
@@ -247,7 +244,7 @@ void ColorWheelSelector::_colorChanged()
guint32 mid = _color.toRGBA32( 0x7f );
guint32 end = _color.toRGBA32( 0xff );
- sp_color_slider_set_colors(SP_COLOR_SLIDER(_slider), start, mid, end);
+ _slider->set_colors(start, mid, end);
ColorScales::setScaled(_adj, _alpha);
@@ -270,45 +267,38 @@ void ColorWheelSelector::_adjustmentChanged( GtkAdjustment *adjustment, SPColorW
wheelSelector->_updating = TRUE;
- preserve_icc(&wheelSelector->_color, cs);
+ wheelSelector->_preserve_icc(&wheelSelector->_color);
wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
wheelSelector->_updating = FALSE;
}
-void ColorWheelSelector::_sliderGrabbed( SPColorSlider *slider, SPColorWheelSelector *cs )
+void ColorWheelSelector::_sliderGrabbed()
{
- (void)slider;
- ColorWheelSelector* wheelSelector = static_cast<ColorWheelSelector*>(SP_COLOR_SELECTOR(cs)->base);
- if (!wheelSelector->_dragging) {
- wheelSelector->_dragging = TRUE;
- wheelSelector->_grabbed();
+ if (!_dragging) {
+ _dragging = TRUE;
+ _grabbed();
- preserve_icc(&wheelSelector->_color, cs);
- wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
+ _preserve_icc(&_color);
+ _updateInternals( _color, ColorScales::getScaled( _adj ), _dragging );
}
}
-void ColorWheelSelector::_sliderReleased( SPColorSlider *slider, SPColorWheelSelector *cs )
+void ColorWheelSelector::_sliderReleased()
{
- (void)slider;
- ColorWheelSelector* wheelSelector = static_cast<ColorWheelSelector*>(SP_COLOR_SELECTOR(cs)->base);
- if (wheelSelector->_dragging) {
- wheelSelector->_dragging = FALSE;
- wheelSelector->_released();
+ if (_dragging) {
+ _dragging = FALSE;
+ _released();
- preserve_icc(&wheelSelector->_color, cs);
- wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
+ _preserve_icc(&_color);
+ _updateInternals( _color, ColorScales::getScaled( _adj ), _dragging );
}
}
-void ColorWheelSelector::_sliderChanged( SPColorSlider *slider, SPColorWheelSelector *cs )
+void ColorWheelSelector::_sliderChanged()
{
- (void)slider;
- ColorWheelSelector* wheelSelector = static_cast<ColorWheelSelector*>(SP_COLOR_SELECTOR(cs)->base);
-
- preserve_icc(&wheelSelector->_color, cs);
- wheelSelector->_updateInternals( wheelSelector->_color, ColorScales::getScaled( wheelSelector->_adj ), wheelSelector->_dragging );
+ _preserve_icc(&_color);
+ _updateInternals( _color, ColorScales::getScaled( _adj ), _dragging );
}
void ColorWheelSelector::_wheelChanged( GimpColorWheel *wheel, SPColorWheelSelector *cs )
@@ -329,9 +319,9 @@ void ColorWheelSelector::_wheelChanged( GimpColorWheel *wheel, SPColorWheelSelec
guint32 mid = color.toRGBA32( 0x7f );
guint32 end = color.toRGBA32( 0xff );
- sp_color_slider_set_colors (SP_COLOR_SLIDER(wheelSelector->_slider), start, mid, end);
+ wheelSelector->_slider->set_colors(start, mid, end);
- preserve_icc(&color, cs);
+ wheelSelector->_preserve_icc(&color);
wheelSelector->_updateInternals( color, wheelSelector->_alpha, gimp_color_wheel_is_adjusting(wheel) );
}
diff --git a/src/widgets/sp-color-wheel-selector.h b/src/widgets/sp-color-wheel-selector.h
index 12b060dbe..bb6078906 100644
--- a/src/widgets/sp-color-wheel-selector.h
+++ b/src/widgets/sp-color-wheel-selector.h
@@ -1,15 +1,33 @@
#ifndef SEEN_SP_COLOR_WHEEL_SELECTOR_H
#define SEEN_SP_COLOR_WHEEL_SELECTOR_H
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H
+#include <glibmm/threads.h>
+#endif
+
+#include <glib.h>
#include <gtk/gtk.h>
#include "sp-color-selector.h"
typedef struct _GimpColorWheel GimpColorWheel;
-struct SPColorSlider;
struct SPColorWheelSelector;
struct SPColorWheelSelectorClass;
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class ColorSlider;
+
+}
+}
+}
+
class ColorWheelSelector: public ColorSelector
{
public:
@@ -23,9 +41,9 @@ protected:
static void _adjustmentChanged ( GtkAdjustment *adjustment, SPColorWheelSelector *cs );
- static void _sliderGrabbed( SPColorSlider *slider, SPColorWheelSelector *cs );
- static void _sliderReleased( SPColorSlider *slider, SPColorWheelSelector *cs );
- static void _sliderChanged( SPColorSlider *slider, SPColorWheelSelector *cs );
+ void _sliderGrabbed();
+ void _sliderReleased();
+ void _sliderChanged();
static void _wheelChanged( GimpColorWheel *wheel, SPColorWheelSelector *cs );
static void _fooChanged( GtkWidget foo, SPColorWheelSelector *cs );
@@ -36,7 +54,7 @@ protected:
gboolean _dragging : 1;
GtkAdjustment* _adj; // Channel adjustment
GtkWidget* _wheel;
- GtkWidget* _slider;
+ Inkscape::UI::Widget::ColorSlider* _slider;
GtkWidget* _sbtn; // Spinbutton
GtkWidget* _label; // Label
@@ -44,6 +62,8 @@ private:
// By default, disallow copy constructor and assignment operator
ColorWheelSelector( const ColorWheelSelector& obj );
ColorWheelSelector& operator=( const ColorWheelSelector& obj );
+
+ void _preserve_icc(SPColor *color) const;
};