From dcce4eae31bf798949a7991cac165bcd6d0a0eef Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Wed, 21 May 2014 18:03:59 +0200 Subject: SPColorSlider c++-sification: added ColorSlider class (bzr r13341.6.1) --- src/widgets/sp-color-scales.cpp | 4 +- src/widgets/sp-color-scales.h | 8 ++ src/widgets/sp-color-slider.cpp | 202 ++++++++++++++++++++++++++++++-- src/widgets/sp-color-slider.h | 81 ++++++++++++- src/widgets/sp-color-wheel-selector.cpp | 4 +- src/widgets/sp-color-wheel-selector.h | 8 ++ 6 files changed, 294 insertions(+), 13 deletions(-) diff --git a/src/widgets/sp-color-scales.cpp b/src/widgets/sp-color-scales.cpp index c3f9d511c..a7d458561 100644 --- a/src/widgets/sp-color-scales.cpp +++ b/src/widgets/sp-color-scales.cpp @@ -5,11 +5,13 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif + +#include "sp-color-scales.h" + #include #include #include #include "../dialogs/dialog-events.h" -#include "sp-color-scales.h" #include "svg/svg-icc-color.h" #define CSC_CHANNEL_R (1 << 0) diff --git a/src/widgets/sp-color-scales.h b/src/widgets/sp-color-scales.h index 3b11bc05e..cd3900f85 100644 --- a/src/widgets/sp-color-scales.h +++ b/src/widgets/sp-color-scales.h @@ -1,6 +1,14 @@ #ifndef SEEN_SP_COLOR_SCALES_H #define SEEN_SP_COLOR_SCALES_H +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + #include #include diff --git a/src/widgets/sp-color-slider.cpp b/src/widgets/sp-color-slider.cpp index 9b13ba1c5..07e1d79fb 100644 --- a/src/widgets/sp-color-slider.cpp +++ b/src/widgets/sp-color-slider.cpp @@ -1,7 +1,8 @@ -/* - * A slider with colored background - * - * Author: +/** + * @file + * A slider with colored background - implementation. + */ +/* Author: * Lauris Kaplinski * bulia byak * @@ -10,13 +11,200 @@ * This code is in public domain */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "sp-color-slider.h" + #include +#include +#include +#include + #include "sp-color-scales.h" #include "preferences.h" -#define SLIDER_WIDTH 96 -#define SLIDER_HEIGHT 8 -#define ARROW_SIZE 7 +static const gint SLIDER_WIDTH = 96; +static const gint SLIDER_HEIGHT = 8; +static const gint ARROW_SIZE = 7; + + +ColorSlider::ColorSlider(Gtk::Adjustment* adjustment) + : _dragging(false) + , _adjustment(NULL) + , _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) { + //TODO: disconnect all connections + delete _adjustment; + _adjustment = NULL; + } +} + +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()); + + style_attach(); + } +} + +void ColorSlider::on_unrealize() { + _refGdkWindow.reset(); + + Gtk::Widget::on_unrealize(); +} + +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; +} + +//TODO: GTK3 prefferred width/height + +void ColorSlider::on_size_allocate(Gtk::Allocation& allocation) { + if (get_realized()) { + _refGdkWindow->move_resize(allocation.get_x(), allocation.get_y(), + allocation.get_width(), allocation.get_height()); + } +} + +//TODO: if not GTK3 +bool ColorSlider::on_expose_event(GdkEventExpose* event) { + bool result = false; + + if (get_is_drawable()) { + Cairo::RefPtr cr = _refGdkWindow->create_cairo_context(); + result = on_draw(cr); + } + return result; +} + +bool ColorSlider::on_button_press_event(GdkEventButton *event) { + //TODO: implementation + return false; +} + +bool ColorSlider::on_button_release_event(GdkEventButton *event) { + //TODO: implementation + return false; +} + +bool ColorSlider::on_motion_notify_event(GdkEventMotion *event) { + //TODO: implementation + return false; +} + +void ColorSlider::set_adjustment(Gtk::Adjustment* /*adjustment*/) { + //TODO: implementation +} + +void ColorSlider::set_colors(guint32 start, guint32 min, guint32 end) { + +} + +void ColorSlider::set_map(const guchar *map) { + +} + +void ColorSlider::set_background(guint dark, guint light, guint size) { + +} + +bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { + return false; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + enum { GRABBED, diff --git a/src/widgets/sp-color-slider.h b/src/widgets/sp-color-slider.h index 591d8368a..6821c8fe4 100644 --- a/src/widgets/sp-color-slider.h +++ b/src/widgets/sp-color-slider.h @@ -1,10 +1,7 @@ #ifndef __SP_COLOR_SLIDER_H__ #define __SP_COLOR_SLIDER_H__ -/* - * A slider with colored background - * - * Author: +/* Author: * Lauris Kaplinski * * Copyright (C) 2001-2002 Lauris Kaplinski @@ -12,6 +9,82 @@ * This code is in public domain */ +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + +#include + +#include + + +/* + * A slider with colored background + */ +class ColorSlider: public Gtk::Widget { +public: + //if GTK2 + ColorSlider(Gtk::Adjustment *adjustment); + ~ColorSlider(); + + void set_adjustment(Gtk::Adjustment *adjustment); + + 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 signal_grabbed; + sigc::signal signal_dragged; + sigc::signal signal_released; + sigc::signal 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); + + //if GTK2 + void on_size_request(Gtk::Requisition* requisition); + bool on_expose_event(GdkEventExpose* event); + //if GTK3 + //request mode, get preffered width/height vfunc + //endif + + bool on_draw(const Cairo::RefPtr& cr); + + //TODO: on_adjustment_changed method + //TODO: on_adjustment value changed method + connection + +private: + bool _dragging; + + Gtk::Adjustment *_adjustment; + + gfloat _value; + gfloat _oldvalue; + guchar _c0[4], _cm[4], _c1[4]; + guchar _b0, _b1; + guchar _bmask; + + gint _mapsize; + guchar *_map; + + Glib::RefPtr _refGdkWindow; +}; + + + + + #include #include diff --git a/src/widgets/sp-color-wheel-selector.cpp b/src/widgets/sp-color-wheel-selector.cpp index 7c8bb1df7..1cc2e06d6 100644 --- a/src/widgets/sp-color-wheel-selector.cpp +++ b/src/widgets/sp-color-wheel-selector.cpp @@ -1,11 +1,13 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif + +#include "sp-color-wheel-selector.h" + #include #include #include #include "../dialogs/dialog-events.h" -#include "sp-color-wheel-selector.h" #include "sp-color-scales.h" #include "sp-color-icc-selector.h" #include "../svg/svg-icc-color.h" diff --git a/src/widgets/sp-color-wheel-selector.h b/src/widgets/sp-color-wheel-selector.h index bbd377422..6f45b6bba 100644 --- a/src/widgets/sp-color-wheel-selector.h +++ b/src/widgets/sp-color-wheel-selector.h @@ -1,6 +1,14 @@ #ifndef SEEN_SP_COLOR_WHEEL_SELECTOR_H #define SEEN_SP_COLOR_WHEEL_SELECTOR_H +#ifdef HAVE_CONFIG_H +# include +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include +#endif + #include #include -- cgit v1.2.3