From d41a1b907e503a5e6c587c35607a5fa2015eb0ae Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Sun, 3 May 2015 11:42:05 +0200 Subject: Reformatted refactored files (bzr r14059.1.18) --- src/ui/widget/color-entry.cpp | 18 +- src/ui/widget/color-entry.h | 3 +- src/ui/widget/color-icc-selector.cpp | 784 +++++++++++++++-------------- src/ui/widget/color-icc-selector.h | 27 +- src/ui/widget/color-notebook.cpp | 200 ++++---- src/ui/widget/color-notebook.h | 16 +- src/ui/widget/color-scales.cpp | 888 ++++++++++++++++----------------- src/ui/widget/color-scales.h | 27 +- src/ui/widget/color-slider.cpp | 491 +++++++++--------- src/ui/widget/color-slider.h | 43 +- src/ui/widget/color-wheel-selector.cpp | 96 ++-- src/ui/widget/color-wheel-selector.h | 22 +- 12 files changed, 1291 insertions(+), 1324 deletions(-) (limited to 'src') diff --git a/src/ui/widget/color-entry.cpp b/src/ui/widget/color-entry.cpp index a1fabf181..473d7de65 100644 --- a/src/ui/widget/color-entry.cpp +++ b/src/ui/widget/color-entry.cpp @@ -30,12 +30,14 @@ ColorEntry::ColorEntry(SelectedColor &color) set_tooltip_text(_("Hexadecimal RGBA value of the color")); } -ColorEntry::~ColorEntry() { +ColorEntry::~ColorEntry() +{ _color_changed_connection.disconnect(); _color_dragged_connection.disconnect(); } -void ColorEntry::on_changed() { +void ColorEntry::on_changed() +{ if (_updating) { return; } @@ -43,7 +45,7 @@ void ColorEntry::on_changed() { Glib::ustring text = get_text(); bool changed = false; - //Coerce the value format to eight hex digits + // Coerce the value format to eight hex digits if (!text.empty() && text[0] == '#') { changed = true; text.erase(0, 1); @@ -54,8 +56,8 @@ void ColorEntry::on_changed() { } } - gchar* str = g_strdup(text.c_str()); - gchar* end = 0; + gchar *str = g_strdup(text.c_str()); + gchar *end = 0; guint64 rgba = g_ascii_strtoull(str, &end, 16); if (end != str) { ptrdiff_t len = end - str; @@ -72,11 +74,12 @@ void ColorEntry::on_changed() { } -void ColorEntry::_onColorChanged() { +void ColorEntry::_onColorChanged() +{ SPColor color = _color.color(); gdouble alpha = _color.alpha(); - guint32 rgba = color.toRGBA32( alpha ); + guint32 rgba = color.toRGBA32(alpha); Glib::ustring text = Glib::ustring::format(std::hex, std::setw(8), std::setfill(L'0'), rgba); Glib::ustring old_text = get_text(); @@ -86,7 +89,6 @@ void ColorEntry::_onColorChanged() { _updating = false; } } - } } } diff --git a/src/ui/widget/color-entry.h b/src/ui/widget/color-entry.h index ecb0518b1..cd7d6164a 100644 --- a/src/ui/widget/color-entry.h +++ b/src/ui/widget/color-entry.h @@ -18,7 +18,8 @@ namespace Inkscape { namespace UI { namespace Widget { -class ColorEntry: public Gtk::Entry { +class ColorEntry : public Gtk::Entry +{ public: ColorEntry(SelectedColor &color); virtual ~ColorEntry(); diff --git a/src/ui/widget/color-icc-selector.cpp b/src/ui/widget/color-icc-selector.cpp index 48c098604..a7e75bfc5 100644 --- a/src/ui/widget/color-icc-selector.cpp +++ b/src/ui/widget/color-icc-selector.cpp @@ -1,5 +1,5 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -36,40 +36,30 @@ #ifdef DEBUG_LCMS extern guint update_in_progress; -#define DEBUG_MESSAGE(key, ...) \ -{\ - Inkscape::Preferences *prefs = Inkscape::Preferences::get();\ - bool dump = prefs->getBool("/options/scislac/" #key);\ - bool dumpD = prefs->getBool("/options/scislac/" #key "D");\ - bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2");\ - dumpD &&= ( (update_in_progress == 0) || dumpD2 );\ - if ( dump )\ - {\ - g_message( __VA_ARGS__ );\ -\ - }\ - if ( dumpD )\ - {\ - GtkWidget *dialog = gtk_message_dialog_new(NULL,\ - GTK_DIALOG_DESTROY_WITH_PARENT, \ - GTK_MESSAGE_INFO, \ - GTK_BUTTONS_OK, \ - __VA_ARGS__ \ - );\ - g_signal_connect_swapped(dialog, "response",\ - G_CALLBACK(gtk_widget_destroy), \ - dialog); \ - gtk_widget_show_all( dialog );\ - }\ -} +#define DEBUG_MESSAGE(key, ...) \ + { \ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); \ + bool dump = prefs->getBool("/options/scislac/" #key); \ + bool dumpD = prefs->getBool("/options/scislac/" #key "D"); \ + bool dumpD2 = prefs->getBool("/options/scislac/" #key "D2"); \ + dumpD && = ((update_in_progress == 0) || dumpD2); \ + if (dump) { \ + g_message(__VA_ARGS__); \ + } \ + if (dumpD) { \ + GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, \ + GTK_BUTTONS_OK, __VA_ARGS__); \ + g_signal_connect_swapped(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog); \ + gtk_widget_show_all(dialog); \ + } \ + } #endif // DEBUG_LCMS #define XPAD 4 #define YPAD 1 -namespace -{ +namespace { size_t maxColorspaceComponentCount = 0; @@ -94,41 +84,35 @@ GtkAttachOptions operator|(GtkAttachOptions lhs, GtkAttachOptions rhs) /** * Helper function to handle GTK2/GTK3 attachment #ifdef code. */ -void attachToGridOrTable(GtkWidget *parent, - GtkWidget *child, - guint left, - guint top, - guint width, - guint height, - bool hexpand = false, - bool centered = false, - guint xpadding = XPAD, - guint ypadding = YPAD) +void attachToGridOrTable(GtkWidget *parent, GtkWidget *child, guint left, guint top, guint width, guint height, + bool hexpand = false, bool centered = false, guint xpadding = XPAD, guint ypadding = YPAD) { -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) - gtk_widget_set_margin_start( child, xpadding ); - gtk_widget_set_margin_end( child, xpadding ); - #else - gtk_widget_set_margin_left( child, xpadding ); - gtk_widget_set_margin_right( child, xpadding ); - #endif - - gtk_widget_set_margin_top( child, ypadding ); - gtk_widget_set_margin_bottom( child, ypadding ); +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) + gtk_widget_set_margin_start(child, xpadding); + gtk_widget_set_margin_end(child, xpadding); + #else + gtk_widget_set_margin_left(child, xpadding); + gtk_widget_set_margin_right(child, xpadding); + #endif + + gtk_widget_set_margin_top(child, ypadding); + gtk_widget_set_margin_bottom(child, ypadding); if (hexpand) { gtk_widget_set_hexpand(child, TRUE); } if (centered) { - gtk_widget_set_halign( child, GTK_ALIGN_CENTER ); - gtk_widget_set_valign( child, GTK_ALIGN_CENTER ); + gtk_widget_set_halign(child, GTK_ALIGN_CENTER); + gtk_widget_set_valign(child, GTK_ALIGN_CENTER); } - gtk_grid_attach( GTK_GRID(parent), child, left, top, width, height ); + gtk_grid_attach(GTK_GRID(parent), child, left, top, width, height); #else - GtkAttachOptions xoptions = centered ? static_cast(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL; + GtkAttachOptions xoptions = + centered ? static_cast(0) : hexpand ? (GTK_EXPAND | GTK_FILL) : GTK_FILL; GtkAttachOptions yoptions = centered ? static_cast(0) : GTK_FILL; - gtk_table_attach( GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding, ypadding ); + gtk_table_attach(GTK_TABLE(parent), child, left, left + width, top, top + height, xoptions, yoptions, xpadding, + ypadding); #endif } @@ -145,32 +129,32 @@ icSigCmyData #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -static cmsUInt16Number* getScratch() { +static cmsUInt16Number *getScratch() +{ // bytes per pixel * input channels * width - static cmsUInt16Number* scritch = static_cast(g_new(cmsUInt16Number, 4 * 1024)); + static cmsUInt16Number *scritch = static_cast(g_new(cmsUInt16Number, 4 * 1024)); return scritch; } -colorspace::Component::Component() : - name(), - tip(), - scale(1) +colorspace::Component::Component() + : name() + , tip() + , scale(1) { } -colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale) : - name(name), - tip(tip), - scale(scale) +colorspace::Component::Component(std::string const &name, std::string const &tip, guint scale) + : name(name) + , tip(tip) + , scale(scale) { } -std::vector colorspace::getColorSpaceInfo( uint32_t space ) +std::vector colorspace::getColorSpaceInfo(uint32_t space) { static std::map > sets; - if (sets.empty()) - { + if (sets.empty()) { sets[cmsSigXYZData].push_back(Component("_X", "X", 2)); // TYPE_XYZ_16 sets[cmsSigXYZData].push_back(Component("_Y", "Y", 1)); sets[cmsSigXYZData].push_back(Component("_Z", "Z", 2)); @@ -179,7 +163,7 @@ std::vector colorspace::getColorSpaceInfo( uint32_t space sets[cmsSigLabData].push_back(Component("_a", "a", 256)); sets[cmsSigLabData].push_back(Component("_b", "b", 256)); - //cmsSigLuvData + // cmsSigLuvData sets[cmsSigYCbCrData].push_back(Component("_Y", "Y", 1)); // TYPE_YCbCr_16 sets[cmsSigYCbCrData].push_back(Component("C_b", "Cb", 1)); @@ -212,8 +196,7 @@ std::vector colorspace::getColorSpaceInfo( uint32_t space sets[cmsSigCmyData].push_back(Component(_("_M:"), _("Magenta"), 1)); sets[cmsSigCmyData].push_back(Component(_("_Y:"), _("Yellow"), 1)); - for (std::map >::iterator it = sets.begin(); it != sets.end(); ++it) - { + for (std::map >::iterator it = sets.begin(); it != sets.end(); ++it) { knownColorspaces.insert(it->first); maxColorspaceComponentCount = std::max(maxColorspaceComponentCount, it->second.size()); } @@ -221,17 +204,16 @@ std::vector colorspace::getColorSpaceInfo( uint32_t space std::vector target; - if (sets.find(space) != sets.end()) - { + if (sets.find(space) != sets.end()) { target = sets[space]; } return target; } -std::vector colorspace::getColorSpaceInfo( Inkscape::ColorProfile *prof ) +std::vector colorspace::getColorSpaceInfo(Inkscape::ColorProfile *prof) { - return getColorSpaceInfo( asICColorSpaceSig(prof->getColorSpace()) ); + return getColorSpaceInfo(asICColorSpaceSig(prof->getColorSpace())); } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -243,9 +225,8 @@ namespace Widget { /** * Class containing the parts for a single color component's UI presence. */ -class ComponentUI -{ -public: +class ComponentUI { + public: ComponentUI() : _component() , _adj(0) @@ -269,37 +250,35 @@ public: colorspace::Component _component; GtkAdjustment *_adj; // Component adjustment Inkscape::UI::Widget::ColorSlider *_slider; - GtkWidget *_btn; // spinbutton - GtkWidget *_label; // Label - guchar *_map; + GtkWidget *_btn; // spinbutton + GtkWidget *_label; // Label + guchar *_map; }; /** * Class that implements the internals of the selector. */ -class ColorICCSelectorImpl -{ -public: - +class ColorICCSelectorImpl { + public: ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color); ~ColorICCSelectorImpl(); - static void _adjustmentChanged ( GtkAdjustment *adjustment, ColorICCSelectorImpl *cs ); + static void _adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs); void _sliderGrabbed(); void _sliderReleased(); void _sliderChanged(); - static void _profileSelected( GtkWidget* src, gpointer data ); - static void _fixupHit( GtkWidget* src, gpointer data ); + static void _profileSelected(GtkWidget *src, gpointer data); + static void _fixupHit(GtkWidget *src, gpointer data); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - void _setProfile( SVGICCColor* profile ); - void _switchToProfile( gchar const* name ); + void _setProfile(SVGICCColor *profile); + void _switchToProfile(gchar const *name); #endif - void _updateSliders( gint ignore ); - void _profilesChanged( std::string const & name ); + void _updateSliders(gint ignore); + void _profilesChanged(std::string const &name); ColorICCSelector *_owner; SelectedColor &_color; @@ -308,19 +287,19 @@ public: gboolean _dragging : 1; guint32 _fixupNeeded; - GtkWidget* _fixupBtn; - GtkWidget* _profileSel; + GtkWidget *_fixupBtn; + GtkWidget *_profileSel; std::vector _compUI; - GtkAdjustment* _adj; // Channel adjustment - Inkscape::UI::Widget::ColorSlider* _slider; - GtkWidget* _sbtn; // Spinbutton - GtkWidget* _label; // Label + GtkAdjustment *_adj; // Channel adjustment + Inkscape::UI::Widget::ColorSlider *_slider; + GtkWidget *_sbtn; // Spinbutton + GtkWidget *_label; // Label #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) std::string _profileName; - Inkscape::ColorProfile* _prof; + Inkscape::ColorProfile *_prof; guint _profChannelCount; gulong _profChangedID; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) @@ -328,8 +307,7 @@ public: - -const gchar* ColorICCSelector::MODE_NAME = N_("CMS"); +const gchar *ColorICCSelector::MODE_NAME = N_("CMS"); ColorICCSelector::ColorICCSelector(SelectedColor &color) : _impl(NULL) @@ -337,13 +315,12 @@ ColorICCSelector::ColorICCSelector(SelectedColor &color) _impl = new ColorICCSelectorImpl(this, color); init(); color.signal_changed.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged)); - //color.signal_dragged.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged)); + // color.signal_dragged.connect(sigc::mem_fun(this, &ColorICCSelector::_colorChanged)); } ColorICCSelector::~ColorICCSelector() { - if (_impl) - { + if (_impl) { delete _impl; _impl = 0; } @@ -351,25 +328,24 @@ ColorICCSelector::~ColorICCSelector() -ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color) : - _owner(owner), - _color(color), - _updating( FALSE ), - _dragging( FALSE ), - _fixupNeeded(0), - _fixupBtn(0), - _profileSel(0), - _compUI(), - _adj(0), - _slider(0), - _sbtn(0), - _label(0) +ColorICCSelectorImpl::ColorICCSelectorImpl(ColorICCSelector *owner, SelectedColor &color) + : _owner(owner) + , _color(color) + , _updating(FALSE) + , _dragging(FALSE) + , _fixupNeeded(0) + , _fixupBtn(0) + , _profileSel(0) + , _compUI() + , _adj(0) + , _slider(0) + , _sbtn(0) + , _label(0) #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - , - _profileName(), - _prof(0), - _profChannelCount(0), - _profChangedID(0) + , _profileName() + , _prof(0) + , _profChannelCount(0) + , _profChangedID(0) #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) { } @@ -388,9 +364,9 @@ void ColorICCSelector::init() _impl->_updating = FALSE; _impl->_dragging = FALSE; - GtkWidget* t = GTK_WIDGET(gobj()); + GtkWidget *t = GTK_WIDGET(gobj()); - gtk_widget_show (t); + gtk_widget_show(t); _impl->_compUI.clear(); @@ -399,50 +375,53 @@ void ColorICCSelector::init() _impl->_fixupBtn = gtk_button_new_with_label(_("Fix")); - g_signal_connect( G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit), (gpointer)_impl ); - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE ); - gtk_widget_set_tooltip_text( _impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value.") ); - //gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 ); - gtk_widget_show( _impl->_fixupBtn ); + g_signal_connect(G_OBJECT(_impl->_fixupBtn), "clicked", G_CALLBACK(ColorICCSelectorImpl::_fixupHit), + (gpointer)_impl); + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE); + gtk_widget_set_tooltip_text(_impl->_fixupBtn, _("Fix RGB fallback to match icc-color() value.")); + // gtk_misc_set_alignment( GTK_MISC (_impl->_fixupBtn), 1.0, 0.5 ); + gtk_widget_show(_impl->_fixupBtn); attachToGridOrTable(t, _impl->_fixupBtn, 0, row, 1, 1); // Combobox and store with 2 columns : label (0) and full name (1) - GtkListStore *store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - _impl->_profileSel = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); + GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); + _impl->_profileSel = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); - GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); + GtkCellRenderer *renderer = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(_impl->_profileSel), renderer, "text", 0, NULL); GtkTreeIter iter; - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, _(""), 1, _(""), -1); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, _(""), 1, _(""), -1); - gtk_widget_show( _impl->_profileSel ); - gtk_combo_box_set_active( GTK_COMBO_BOX(_impl->_profileSel), 0 ); + gtk_widget_show(_impl->_profileSel); + gtk_combo_box_set_active(GTK_COMBO_BOX(_impl->_profileSel), 0); attachToGridOrTable(t, _impl->_profileSel, 1, row, 1, 1); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - _impl->_profChangedID = g_signal_connect( G_OBJECT(_impl->_profileSel), "changed", G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl ); + _impl->_profChangedID = g_signal_connect(G_OBJECT(_impl->_profileSel), "changed", + G_CALLBACK(ColorICCSelectorImpl::_profileSelected), (gpointer)_impl); #else - gtk_widget_set_sensitive( _impl->_profileSel, false ); + gtk_widget_set_sensitive(_impl->_profileSel, false); #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) row++; - // populate the data for colorspaces and channels: +// populate the data for colorspaces and channels: #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - std::vector things = colorspace::getColorSpaceInfo( cmsSigRgbData ); + std::vector things = colorspace::getColorSpaceInfo(cmsSigRgbData); #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - for ( size_t i = 0; i < maxColorspaceComponentCount; i++ ) { + for (size_t i = 0; i < maxColorspaceComponentCount; i++) { #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) if (i < things.size()) { _impl->_compUI.push_back(ComponentUI(things[i])); - } else { + } + else { _impl->_compUI.push_back(ComponentUI()); } @@ -453,9 +432,9 @@ void ColorICCSelector::init() std::string labelStr = "."; #endif - _impl->_compUI[i]._label = gtk_label_new_with_mnemonic( labelStr.c_str() ); - gtk_misc_set_alignment( GTK_MISC (_impl->_compUI[i]._label), 1.0, 0.5 ); - gtk_widget_show( _impl->_compUI[i]._label ); + _impl->_compUI[i]._label = gtk_label_new_with_mnemonic(labelStr.c_str()); + gtk_misc_set_alignment(GTK_MISC(_impl->_compUI[i]._label), 1.0, 0.5); + gtk_widget_show(_impl->_compUI[i]._label); attachToGridOrTable(t, _impl->_compUI[i]._label, 0, row, 1, 1); @@ -464,10 +443,11 @@ void ColorICCSelector::init() gdouble step = static_cast(scaleValue) / 100.0; gdouble page = static_cast(scaleValue) / 10.0; gint digits = (step > 0.9) ? 0 : 2; - _impl->_compUI[i]._adj = GTK_ADJUSTMENT( gtk_adjustment_new( 0.0, 0.0, scaleValue, step, page, page ) ); + _impl->_compUI[i]._adj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, scaleValue, step, page, page)); // Slider - _impl->_compUI[i]._slider = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_impl->_compUI[i]._adj, true))); + _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) _impl->_compUI[i]._slider->set_tooltip_text((i < things.size()) ? things[i].tip.c_str() : ""); #else @@ -477,28 +457,31 @@ void ColorICCSelector::init() 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 ); + _impl->_compUI[i]._btn = gtk_spin_button_new(_impl->_compUI[i]._adj, step, digits); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : "" ); + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, (i < things.size()) ? things[i].tip.c_str() : ""); #else - gtk_widget_set_tooltip_text( _impl->_compUI[i]._btn, "." ); + gtk_widget_set_tooltip_text(_impl->_compUI[i]._btn, "."); #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - sp_dialog_defocus_on_enter( _impl->_compUI[i]._btn ); - gtk_label_set_mnemonic_widget( GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn ); - gtk_widget_show( _impl->_compUI[i]._btn ); + sp_dialog_defocus_on_enter(_impl->_compUI[i]._btn); + gtk_label_set_mnemonic_widget(GTK_LABEL(_impl->_compUI[i]._label), _impl->_compUI[i]._btn); + gtk_widget_show(_impl->_compUI[i]._btn); attachToGridOrTable(t, _impl->_compUI[i]._btn, 2, row, 1, 1, false, true); - _impl->_compUI[i]._map = g_new( guchar, 4 * 1024 ); - memset( _impl->_compUI[i]._map, 0x0ff, 1024 * 4 ); + _impl->_compUI[i]._map = g_new(guchar, 4 * 1024); + memset(_impl->_compUI[i]._map, 0x0ff, 1024 * 4); // Signals - g_signal_connect( G_OBJECT( _impl->_compUI[i]._adj ), "value_changed", G_CALLBACK( ColorICCSelectorImpl::_adjustmentChanged ), _impl ); + g_signal_connect(G_OBJECT(_impl->_compUI[i]._adj), "value_changed", + G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _impl); _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)); + _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++; } @@ -520,9 +503,8 @@ void ColorICCSelector::init() attachToGridOrTable(t, _impl->_slider->gobj(), 1, row, 1, 1, true); - _impl->_slider->setColors(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->setColors(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 @@ -535,66 +517,69 @@ void ColorICCSelector::init() attachToGridOrTable(t, _impl->_sbtn, 2, row, 1, 1, false, true); // Signals - g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), _impl); + g_signal_connect(G_OBJECT(_impl->_adj), "value_changed", G_CALLBACK(ColorICCSelectorImpl::_adjustmentChanged), + _impl); _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)); } -void ColorICCSelectorImpl::_fixupHit( GtkWidget* /*src*/, gpointer data ) +void ColorICCSelectorImpl::_fixupHit(GtkWidget * /*src*/, gpointer data) { - ColorICCSelectorImpl* self = reinterpret_cast(data); - gtk_widget_set_sensitive( self->_fixupBtn, FALSE ); - self->_adjustmentChanged( self->_compUI[0]._adj, self ); + ColorICCSelectorImpl *self = reinterpret_cast(data); + gtk_widget_set_sensitive(self->_fixupBtn, FALSE); + self->_adjustmentChanged(self->_compUI[0]._adj, self); } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -void ColorICCSelectorImpl::_profileSelected( GtkWidget* /*src*/, gpointer data ) +void ColorICCSelectorImpl::_profileSelected(GtkWidget * /*src*/, gpointer data) { - ColorICCSelectorImpl* self = reinterpret_cast(data); + ColorICCSelectorImpl *self = reinterpret_cast(data); - GtkTreeIter iter; + GtkTreeIter iter; if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(self->_profileSel), &iter)) { GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(self->_profileSel)); - gchar* name = 0; + gchar *name = 0; gtk_tree_model_get(store, &iter, 1, &name, -1); - self->_switchToProfile( name ); - gtk_widget_set_tooltip_text(self->_profileSel, name ); + self->_switchToProfile(name); + gtk_widget_set_tooltip_text(self->_profileSel, name); - if ( name ) { - g_free( name ); + if (name) { + g_free(name); } } } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -void ColorICCSelectorImpl::_switchToProfile( gchar const* name ) +void ColorICCSelectorImpl::_switchToProfile(gchar const *name) { bool dirty = false; - SPColor tmp( _color.color() ); + SPColor tmp(_color.color()); - if ( name ) { - if ( tmp.icc && tmp.icc->colorProfile == name ) { + if (name) { + if (tmp.icc && tmp.icc->colorProfile == name) { #ifdef DEBUG_LCMS - g_message("Already at name [%s]", name ); + g_message("Already at name [%s]", name); #endif // DEBUG_LCMS - } else { + } + else { #ifdef DEBUG_LCMS - g_message("Need to switch to profile [%s]", name ); + g_message("Need to switch to profile [%s]", name); #endif // DEBUG_LCMS - if ( tmp.icc ) { + if (tmp.icc) { tmp.icc->colors.clear(); - } else { + } + else { tmp.icc = new SVGICCColor(); } tmp.icc->colorProfile = name; - Inkscape::ColorProfile* newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name); - if ( newProf ) { + Inkscape::ColorProfile *newProf = SP_ACTIVE_DOCUMENT->profileManager->find(name); + if (newProf) { cmsHTRANSFORM trans = newProf->getTransfFromSRGB8(); - if ( trans ) { + if (trans) { guint32 val = _color.color().toRGBA32(0); guchar pre[4] = { static_cast(SP_RGBA32_R_U(val)), @@ -604,29 +589,31 @@ void ColorICCSelectorImpl::_switchToProfile( gchar const* name ) #ifdef DEBUG_LCMS g_message("Shoving in [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]); #endif // DEBUG_LCMS - cmsUInt16Number post[4] = {0,0,0,0}; - cmsDoTransform( trans, pre, post, 1 ); + cmsUInt16Number post[4] = { 0, 0, 0, 0 }; + cmsDoTransform(trans, pre, post, 1); #ifdef DEBUG_LCMS g_message("got on out [%04x] [%04x] [%04x] [%04x]", post[0], post[1], post[2], post[3]); #endif // DEBUG_LCMS #if HAVE_LIBLCMS1 - guint count = _cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) ); + guint count = _cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace())); #elif HAVE_LIBLCMS2 - guint count = cmsChannelsOf( asICColorSpaceSig(newProf->getColorSpace()) ); + guint count = cmsChannelsOf(asICColorSpaceSig(newProf->getColorSpace())); #endif - std::vector things = colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace())); + std::vector things = + colorspace::getColorSpaceInfo(asICColorSpaceSig(newProf->getColorSpace())); - for ( guint i = 0; i < count; i++ ) { - gdouble val = (((gdouble)post[i])/65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1); + for (guint i = 0; i < count; i++) { + gdouble val = + (((gdouble)post[i]) / 65535.0) * (gdouble)((i < things.size()) ? things[i].scale : 1); #ifdef DEBUG_LCMS g_message(" scaled %d by %d to be %f", i, ((i < things.size()) ? things[i].scale : 1), val); #endif // DEBUG_LCMS tmp.icc->colors.push_back(val); } cmsHTRANSFORM retrans = newProf->getTransfToSRGB8(); - if ( retrans ) { - cmsDoTransform( retrans, post, pre, 1 ); + if (retrans) { + cmsDoTransform(retrans, post, pre, 1); #ifdef DEBUG_LCMS g_message(" back out [%02x] [%02x] [%02x]", pre[0], pre[1], pre[2]); #endif // DEBUG_LCMS @@ -636,28 +623,30 @@ void ColorICCSelectorImpl::_switchToProfile( gchar const* name ) } dirty = true; } - } else { + } + else { #ifdef DEBUG_LCMS - g_message("NUKE THE ICC"); + g_message("NUKE THE ICC"); #endif // DEBUG_LCMS - if ( tmp.icc ) { + if (tmp.icc) { delete tmp.icc; tmp.icc = 0; dirty = true; - _fixupHit( 0, this ); - } else { + _fixupHit(0, this); + } + else { #ifdef DEBUG_LCMS - g_message("No icc to nuke"); + g_message("No icc to nuke"); #endif // DEBUG_LCMS } } - if ( dirty ) { + if (dirty) { #ifdef DEBUG_LCMS g_message("+----------------"); g_message("+ new color is [%s]", tmp.toString().c_str()); #endif // DEBUG_LCMS - _setProfile( tmp.icc ); + _setProfile(tmp.icc); //_adjustmentChanged( _compUI[0]._adj, SP_COLOR_ICC_SELECTOR(_csel) ); _color.setColor(tmp); #ifdef DEBUG_LCMS @@ -668,45 +657,43 @@ void ColorICCSelectorImpl::_switchToProfile( gchar const* name ) #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -void ColorICCSelectorImpl::_profilesChanged( std::string const & name ) +void ColorICCSelectorImpl::_profilesChanged(std::string const &name) { - GtkComboBox* combo = GTK_COMBO_BOX(_profileSel); + GtkComboBox *combo = GTK_COMBO_BOX(_profileSel); - g_signal_handler_block( G_OBJECT(_profileSel), _profChangedID ); + g_signal_handler_block(G_OBJECT(_profileSel), _profChangedID); GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(combo)); gtk_list_store_clear(store); GtkTreeIter iter; - gtk_list_store_append (store, &iter); + gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, _(""), 1, _(""), -1); - gtk_combo_box_set_active( combo, 0 ); + gtk_combo_box_set_active(combo, 0); int index = 1; - const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" ); - while ( current ) { - SPObject* obj = SP_OBJECT(current->data); - Inkscape::ColorProfile* prof = reinterpret_cast(obj); + const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList("iccprofile"); + while (current) { + SPObject *obj = SP_OBJECT(current->data); + Inkscape::ColorProfile *prof = reinterpret_cast(obj); - gtk_list_store_append (store, &iter); + gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, gr_ellipsize_text(prof->name, 25).c_str(), 1, prof->name, -1); - if ( name == prof->name ) { - gtk_combo_box_set_active( combo, index ); - gtk_widget_set_tooltip_text(_profileSel, prof->name ); + if (name == prof->name) { + gtk_combo_box_set_active(combo, index); + gtk_widget_set_tooltip_text(_profileSel, prof->name); } index++; current = g_slist_next(current); } - g_signal_handler_unblock( G_OBJECT(_profileSel), _profChangedID ); + g_signal_handler_unblock(G_OBJECT(_profileSel), _profChangedID); } #else -void ColorICCSelectorImpl::_profilesChanged( std::string const & /*name*/ ) -{ -} +void ColorICCSelectorImpl::_profilesChanged(std::string const & /*name*/) {} #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) // Helpers for setting color value @@ -714,190 +701,199 @@ void ColorICCSelectorImpl::_profilesChanged( std::string const & /*name*/ ) void ColorICCSelector::_colorChanged() { _impl->_updating = TRUE; - //sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color ); +// sp_color_icc_set_color( SP_COLOR_ICC( _icc ), &color ); #ifdef DEBUG_LCMS - g_message( "/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this, - _impl->_color.color().toRGBA32(_impl->_color.alpha()), ( (_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile.c_str(): "" ) - ); + g_message("/^^^^^^^^^ %p::_colorChanged(%08x:%s)", this, _impl->_color.color().toRGBA32(_impl->_color.alpha()), + ((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile.c_str() : "")); #endif // DEBUG_LCMS #ifdef DEBUG_LCMS - g_message("FLIPPIES!!!! %p '%s'", _impl->_color.color().icc, (_impl->_color.color().icc ? _impl->_color.color().icc->colorProfile.c_str():"")); + g_message("FLIPPIES!!!! %p '%s'", _impl->_color.color().icc, + (_impl->_color.color().icc ? _impl->_color.color().icc->colorProfile.c_str() : "")); #endif // DEBUG_LCMS - _impl->_profilesChanged( (_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile : std::string("") ); - ColorScales::setScaled( _impl->_adj, _impl->_color.alpha() ); + _impl->_profilesChanged((_impl->_color.color().icc) ? _impl->_color.color().icc->colorProfile : std::string("")); + ColorScales::setScaled(_impl->_adj, _impl->_color.alpha()); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - _impl->_setProfile( _impl->_color.color().icc ); + _impl->_setProfile(_impl->_color.color().icc); _impl->_fixupNeeded = 0; - gtk_widget_set_sensitive( _impl->_fixupBtn, FALSE ); + gtk_widget_set_sensitive(_impl->_fixupBtn, FALSE); if (_impl->_prof) { - if (_impl->_prof->getTransfToSRGB8() ) { + if (_impl->_prof->getTransfToSRGB8()) { cmsUInt16Number tmp[4]; - for ( guint i = 0; i < _impl->_profChannelCount; i++ ) { + for (guint i = 0; i < _impl->_profChannelCount; i++) { gdouble val = 0.0; - if ( _impl->_color.color().icc->colors.size() > i ) { - if ( _impl->_compUI[i]._component.scale == 256 ) { - val = (_impl->_color.color().icc->colors[i] + 128.0) / static_cast(_impl->_compUI[i]._component.scale); - } else { - val = _impl->_color.color().icc->colors[i] / static_cast(_impl->_compUI[i]._component.scale); + if (_impl->_color.color().icc->colors.size() > i) { + if (_impl->_compUI[i]._component.scale == 256) { + val = (_impl->_color.color().icc->colors[i] + 128.0) / + static_cast(_impl->_compUI[i]._component.scale); + } + else { + val = _impl->_color.color().icc->colors[i] / + static_cast(_impl->_compUI[i]._component.scale); } } tmp[i] = val * 0x0ffff; } - guchar post[4] = {0,0,0,0}; + guchar post[4] = { 0, 0, 0, 0 }; cmsHTRANSFORM trans = _impl->_prof->getTransfToSRGB8(); - if ( trans ) { - cmsDoTransform( trans, tmp, post, 1 ); - guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255 ); - if ( other != _impl->_color.color().toRGBA32(255) ) { + if (trans) { + cmsDoTransform(trans, tmp, post, 1); + guint32 other = SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255); + if (other != _impl->_color.color().toRGBA32(255)) { _impl->_fixupNeeded = other; - gtk_widget_set_sensitive( _impl->_fixupBtn, TRUE ); + gtk_widget_set_sensitive(_impl->_fixupBtn, TRUE); #ifdef DEBUG_LCMS - g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8 ); + g_message("Color needs to change 0x%06x to 0x%06x", _color.toRGBA32(255) >> 8, other >> 8); #endif // DEBUG_LCMS } } } } #else - //(void)color; +//(void)color; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - _impl->_updateSliders( -1 ); + _impl->_updateSliders(-1); _impl->_updating = FALSE; #ifdef DEBUG_LCMS - g_message( "\\_________ %p::_colorChanged()", this ); + g_message("\\_________ %p::_colorChanged()", this); #endif // DEBUG_LCMS } #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -void ColorICCSelectorImpl::_setProfile( SVGICCColor* profile ) +void ColorICCSelectorImpl::_setProfile(SVGICCColor *profile) { #ifdef DEBUG_LCMS - g_message( "/^^^^^^^^^ %p::_setProfile(%s)", this, - ( (profile) ? profile->colorProfile.c_str() : "") - ); + g_message("/^^^^^^^^^ %p::_setProfile(%s)", this, ((profile) ? profile->colorProfile.c_str() : "")); #endif // DEBUG_LCMS bool profChanged = false; - if ( _prof && (!profile || (_profileName != profile->colorProfile) ) ) { + if (_prof && (!profile || (_profileName != profile->colorProfile))) { // Need to clear out the prior one profChanged = true; _profileName.clear(); _prof = 0; _profChannelCount = 0; - } else if ( profile && !_prof ) { + } + else if (profile && !_prof) { profChanged = true; } - for ( size_t i = 0; i < _compUI.size(); i++ ) { - gtk_widget_hide( _compUI[i]._label ); + for (size_t i = 0; i < _compUI.size(); i++) { + gtk_widget_hide(_compUI[i]._label); _compUI[i]._slider->hide(); - gtk_widget_hide( _compUI[i]._btn ); + gtk_widget_hide(_compUI[i]._btn); } - if ( profile ) { + if (profile) { _prof = SP_ACTIVE_DOCUMENT->profileManager->find(profile->colorProfile.c_str()); - if ( _prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass) ) { + if (_prof && (asICColorProfileClassSig(_prof->getProfileClass()) != cmsSigNamedColorClass)) { #if HAVE_LIBLCMS1 - _profChannelCount = _cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) ); + _profChannelCount = _cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace())); #elif HAVE_LIBLCMS2 - _profChannelCount = cmsChannelsOf( asICColorSpaceSig(_prof->getColorSpace()) ); + _profChannelCount = cmsChannelsOf(asICColorSpaceSig(_prof->getColorSpace())); #endif - if ( profChanged ) { - std::vector things = colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace())); - for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i) - { + if (profChanged) { + std::vector things = + colorspace::getColorSpaceInfo(asICColorSpaceSig(_prof->getColorSpace())); + for (size_t i = 0; (i < things.size()) && (i < _profChannelCount); ++i) { _compUI[i]._component = things[i]; } - 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() : ""); + 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() : ""); - _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() : "" ); + _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() : ""); _compUI[i]._slider->setColors(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 ); - - sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider), _compUI[i]._adj ); - gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn), _compUI[i]._adj ); - gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits ); -*/ - gtk_widget_show( _compUI[i]._label ); + 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 ); + + sp_color_slider_set_adjustment( SP_COLOR_SLIDER(_compUI[i]._slider), + _compUI[i]._adj ); + gtk_spin_button_set_adjustment( GTK_SPIN_BUTTON(_compUI[i]._btn), + _compUI[i]._adj ); + gtk_spin_button_set_digits( GTK_SPIN_BUTTON(_compUI[i]._btn), digits ); + */ + gtk_widget_show(_compUI[i]._label); _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 ); + 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 ); + for (size_t i = _profChannelCount; i < _compUI.size(); i++) { + gtk_widget_hide(_compUI[i]._label); _compUI[i]._slider->hide(); - gtk_widget_hide( _compUI[i]._btn ); + gtk_widget_hide(_compUI[i]._btn); } } - } else { + } + else { // Give up for now on named colors _prof = 0; } } #ifdef DEBUG_LCMS - g_message( "\\_________ %p::_setProfile()", this ); + g_message("\\_________ %p::_setProfile()", this); #endif // DEBUG_LCMS } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -void ColorICCSelectorImpl::_updateSliders( gint ignore ) +void ColorICCSelectorImpl::_updateSliders(gint ignore) { #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if ( _color.color().icc ) - { - for ( guint i = 0; i < _profChannelCount; i++ ) { + if (_color.color().icc) { + for (guint i = 0; i < _profChannelCount; i++) { gdouble val = 0.0; - if ( _color.color().icc->colors.size() > i ) { - if ( _compUI[i]._component.scale == 256 ) { + if (_color.color().icc->colors.size() > i) { + if (_compUI[i]._component.scale == 256) { val = (_color.color().icc->colors[i] + 128.0) / static_cast(_compUI[i]._component.scale); - } else { + } + else { val = _color.color().icc->colors[i] / static_cast(_compUI[i]._component.scale); } } - gtk_adjustment_set_value( _compUI[i]._adj, val ); + gtk_adjustment_set_value(_compUI[i]._adj, val); } - if ( _prof ) { - if ( _prof->getTransfToSRGB8() ) { - for ( guint i = 0; i < _profChannelCount; i++ ) { - if ( static_cast(i) != ignore ) { - cmsUInt16Number* scratch = getScratch(); - cmsUInt16Number filler[4] = {0, 0, 0, 0}; - for ( guint j = 0; j < _profChannelCount; j++ ) { - filler[j] = 0x0ffff * ColorScales::getScaled( _compUI[j]._adj ); + if (_prof) { + if (_prof->getTransfToSRGB8()) { + for (guint i = 0; i < _profChannelCount; i++) { + if (static_cast(i) != ignore) { + cmsUInt16Number *scratch = getScratch(); + cmsUInt16Number filler[4] = { 0, 0, 0, 0 }; + for (guint j = 0; j < _profChannelCount; j++) { + filler[j] = 0x0ffff * ColorScales::getScaled(_compUI[j]._adj); } - - cmsUInt16Number* p = scratch; - for ( guint x = 0; x < 1024; x++ ) { - for ( guint j = 0; j < _profChannelCount; j++ ) { - if ( j == i ) { + + cmsUInt16Number *p = scratch; + for (guint x = 0; x < 1024; x++) { + for (guint j = 0; j < _profChannelCount; j++) { + if (j == i) { *p++ = x * 0x0ffff / 1024; - } else { + } + else { *p++ = filler[j]; } } } - + cmsHTRANSFORM trans = _prof->getTransfToSRGB8(); - if ( trans ) { - cmsDoTransform( trans, scratch, _compUI[i]._map, 1024 ); + if (trans) { + cmsDoTransform(trans, scratch, _compUI[i]._map, 1024); _compUI[i]._slider->setMap(_compUI[i]._map); } } @@ -909,15 +905,15 @@ void ColorICCSelectorImpl::_updateSliders( gint ignore ) (void)ignore; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - guint32 start = _color.color().toRGBA32( 0x00 ); - guint32 mid = _color.color().toRGBA32( 0x7f ); - guint32 end = _color.color().toRGBA32( 0xff ); + guint32 start = _color.color().toRGBA32(0x00); + guint32 mid = _color.color().toRGBA32(0x7f); + guint32 end = _color.color().toRGBA32(0xff); _slider->setColors(start, mid, end); } -void ColorICCSelectorImpl::_adjustmentChanged( GtkAdjustment *adjustment, ColorICCSelectorImpl *cs ) +void ColorICCSelectorImpl::_adjustmentChanged(GtkAdjustment *adjustment, ColorICCSelectorImpl *cs) { // // TODO check this. It looks questionable: // // if a value is entered between 0 and 1 exclusive, normalize it to (int) 0..255 or 0..100 @@ -926,130 +922,132 @@ void ColorICCSelectorImpl::_adjustmentChanged( GtkAdjustment *adjustment, ColorI // } #ifdef DEBUG_LCMS - g_message( "/^^^^^^^^^ %p::_adjustmentChanged()", cs ); + g_message("/^^^^^^^^^ %p::_adjustmentChanged()", cs); #endif // DEBUG_LCMS - ColorICCSelector* iccSelector = cs->_owner; - if (iccSelector->_impl->_updating) { - return; - } + ColorICCSelector *iccSelector = cs->_owner; + if (iccSelector->_impl->_updating) { + return; + } - iccSelector->_impl->_updating = TRUE; + iccSelector->_impl->_updating = TRUE; - gint match = -1; + gint match = -1; - SPColor newColor( iccSelector->_impl->_color.color() ); - gfloat scaled = ColorScales::getScaled( iccSelector->_impl->_adj ); - if ( iccSelector->_impl->_adj == adjustment ) { + SPColor newColor(iccSelector->_impl->_color.color()); + gfloat scaled = ColorScales::getScaled(iccSelector->_impl->_adj); + if (iccSelector->_impl->_adj == adjustment) { #ifdef DEBUG_LCMS - g_message("ALPHA"); + g_message("ALPHA"); #endif // DEBUG_LCMS - } else { + } + else { #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - for ( size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++ ) { - if ( iccSelector->_impl->_compUI[i]._adj == adjustment ) { - match = i; - break; - } - } - if ( match >= 0 ) { + for (size_t i = 0; i < iccSelector->_impl->_compUI.size(); i++) { + if (iccSelector->_impl->_compUI[i]._adj == adjustment) { + match = i; + break; + } + } + if (match >= 0) { #ifdef DEBUG_LCMS - g_message(" channel %d", match ); + g_message(" channel %d", match); #endif // DEBUG_LCMS - } + } - cmsUInt16Number tmp[4]; - for ( guint i = 0; i < 4; i++ ) { - tmp[i] = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj ) * 0x0ffff; - } - guchar post[4] = {0,0,0,0}; + cmsUInt16Number tmp[4]; + for (guint i = 0; i < 4; i++) { + tmp[i] = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj) * 0x0ffff; + } + guchar post[4] = { 0, 0, 0, 0 }; - cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8(); - if ( trans ) { - cmsDoTransform( trans, tmp, post, 1 ); - } + cmsHTRANSFORM trans = iccSelector->_impl->_prof->getTransfToSRGB8(); + if (trans) { + cmsDoTransform(trans, tmp, post, 1); + } - SPColor other( SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255) ); - other.icc = new SVGICCColor(); - if ( iccSelector->_impl->_color.color().icc ) { - other.icc->colorProfile = iccSelector->_impl->_color.color().icc->colorProfile; - } + SPColor other(SP_RGBA32_U_COMPOSE(post[0], post[1], post[2], 255)); + other.icc = new SVGICCColor(); + if (iccSelector->_impl->_color.color().icc) { + other.icc->colorProfile = iccSelector->_impl->_color.color().icc->colorProfile; + } - guint32 prior = iccSelector->_impl->_color.color().toRGBA32(255); - guint32 newer = other.toRGBA32(255); + guint32 prior = iccSelector->_impl->_color.color().toRGBA32(255); + guint32 newer = other.toRGBA32(255); - if ( prior != newer ) { + if (prior != newer) { #ifdef DEBUG_LCMS - g_message("Transformed color from 0x%08x to 0x%08x", prior, newer ); - g_message(" ~~~~ FLIP"); + g_message("Transformed color from 0x%08x to 0x%08x", prior, newer); + g_message(" ~~~~ FLIP"); #endif // DEBUG_LCMS - newColor = other; - newColor.icc->colors.clear(); - for ( guint i = 0; i < iccSelector->_impl->_profChannelCount; i++ ) { - gdouble val = ColorScales::getScaled( iccSelector->_impl->_compUI[i]._adj ); - val *= iccSelector->_impl->_compUI[i]._component.scale; - if ( iccSelector->_impl->_compUI[i]._component.scale == 256 ) { - val -= 128; - } - newColor.icc->colors.push_back( val ); - } - } + newColor = other; + newColor.icc->colors.clear(); + for (guint i = 0; i < iccSelector->_impl->_profChannelCount; i++) { + gdouble val = ColorScales::getScaled(iccSelector->_impl->_compUI[i]._adj); + val *= iccSelector->_impl->_compUI[i]._component.scale; + if (iccSelector->_impl->_compUI[i]._component.scale == 256) { + val -= 128; + } + newColor.icc->colors.push_back(val); + } + } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - } - iccSelector->_impl->_color.setColorAlpha(newColor, scaled); - //iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging ); - iccSelector->_impl->_updateSliders( match ); + } + iccSelector->_impl->_color.setColorAlpha(newColor, scaled); + // iccSelector->_updateInternals( newColor, scaled, iccSelector->_impl->_dragging ); + iccSelector->_impl->_updateSliders(match); - iccSelector->_impl->_updating = FALSE; + iccSelector->_impl->_updating = FALSE; #ifdef DEBUG_LCMS - g_message( "\\_________ %p::_adjustmentChanged()", cs ); + g_message("\\_________ %p::_adjustmentChanged()", cs); #endif // DEBUG_LCMS } void ColorICCSelectorImpl::_sliderGrabbed() { -// ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); -// if (!iccSelector->_dragging) { -// iccSelector->_dragging = TRUE; -// iccSelector->_grabbed(); -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ), iccSelector->_dragging ); -// } + // ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); + // if (!iccSelector->_dragging) { + // iccSelector->_dragging = TRUE; + // iccSelector->_grabbed(); + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_impl->_adj ), + // iccSelector->_dragging ); + // } } void ColorICCSelectorImpl::_sliderReleased() { -// ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); -// if (iccSelector->_dragging) { -// iccSelector->_dragging = FALSE; -// iccSelector->_released(); -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging ); -// } + // ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); + // if (iccSelector->_dragging) { + // iccSelector->_dragging = FALSE; + // iccSelector->_released(); + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), + // iccSelector->_dragging ); + // } } #ifdef DEBUG_LCMS -void ColorICCSelectorImpl::_sliderChanged( SPColorSlider *slider, SPColorICCSelector *cs ) +void ColorICCSelectorImpl::_sliderChanged(SPColorSlider *slider, SPColorICCSelector *cs) #else void ColorICCSelectorImpl::_sliderChanged() #endif // DEBUG_LCMS { #ifdef DEBUG_LCMS - g_message("Changed %p and %p", slider, cs ); + g_message("Changed %p and %p", slider, cs); #endif // DEBUG_LCMS -// ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); + // ColorICCSelector* iccSelector = dynamic_cast(SP_COLOR_SELECTOR(cs)->base); -// iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), iccSelector->_dragging ); + // iccSelector->_updateInternals( iccSelector->_color, ColorScales::getScaled( iccSelector->_adj ), + // iccSelector->_dragging ); } -Gtk::Widget *ColorICCSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const { +Gtk::Widget *ColorICCSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const +{ Gtk::Widget *w = Gtk::manage(new ColorICCSelector(color)); return w; } -Glib::ustring ColorICCSelectorFactory::modeName() const { - return gettext(ColorICCSelector::MODE_NAME); -} - +Glib::ustring ColorICCSelectorFactory::modeName() const { return gettext(ColorICCSelector::MODE_NAME); } } } } diff --git a/src/ui/widget/color-icc-selector.h b/src/ui/widget/color-icc-selector.h index 6066586f5..37201de3b 100644 --- a/src/ui/widget/color-icc-selector.h +++ b/src/ui/widget/color-icc-selector.h @@ -2,7 +2,7 @@ #define SEEN_SP_COLOR_ICC_SELECTOR_H #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -24,42 +24,41 @@ namespace Widget { class ColorICCSelectorImpl; class ColorICCSelector -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : public Gtk::Grid #else : public Gtk::Table #endif -{ -public: - static const gchar* MODE_NAME; + { + public: + static const gchar *MODE_NAME; ColorICCSelector(SelectedColor &color); virtual ~ColorICCSelector(); virtual void init(); -protected: + protected: virtual void _colorChanged(); - void _recalcColor( gboolean changing ); + void _recalcColor(gboolean changing); -private: + private: friend class ColorICCSelectorImpl; // By default, disallow copy constructor and assignment operator - ColorICCSelector( const ColorICCSelector& obj ); - ColorICCSelector& operator=( const ColorICCSelector& obj ); + ColorICCSelector(const ColorICCSelector &obj); + ColorICCSelector &operator=(const ColorICCSelector &obj); ColorICCSelectorImpl *_impl; }; -class ColorICCSelectorFactory: public ColorSelectorFactory { -public: - Gtk::Widget* createWidget(SelectedColor &color) const; +class ColorICCSelectorFactory : public ColorSelectorFactory { + public: + Gtk::Widget *createWidget(SelectedColor &color) const; Glib::ustring modeName() const; }; - } } } diff --git a/src/ui/widget/color-notebook.cpp b/src/ui/widget/color-notebook.cpp index 92b1d7086..0150f2ca2 100644 --- a/src/ui/widget/color-notebook.cpp +++ b/src/ui/widget/color-notebook.cpp @@ -16,7 +16,7 @@ #define noDUMP_CHANGE_INFO #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include "widgets/icon.h" @@ -56,7 +56,7 @@ namespace Widget { ColorNotebook::ColorNotebook(SelectedColor &color) -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : Gtk::Grid() #else : Gtk::Table(2, 3, false) @@ -87,12 +87,10 @@ ColorNotebook::ColorNotebook(SelectedColor &color) ColorNotebook::~ColorNotebook() { - if ( _buttons ) - { - delete [] _buttons; + if (_buttons) { + delete[] _buttons; _buttons = 0; } - } ColorNotebook::Page::Page(Inkscape::UI::ColorSelectorFactory *selector_factory, bool enabled_full) @@ -112,57 +110,57 @@ void ColorNotebook::_initUI() notebook->set_show_tabs(false); _book = GTK_WIDGET(notebook->gobj()); -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) _buttonbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2); gtk_box_set_homogeneous(GTK_BOX(_buttonbox), TRUE); #else - _buttonbox = gtk_hbox_new (TRUE, 2); + _buttonbox = gtk_hbox_new(TRUE, 2); #endif - gtk_widget_show (_buttonbox); + gtk_widget_show(_buttonbox); _buttons = new GtkWidget *[_available_pages.size()]; - for (int i = 0; static_cast(i) < _available_pages.size(); i++ ) - { + for (int i = 0; static_cast(i) < _available_pages.size(); i++) { _addPage(_available_pages[i]); } - sp_set_font_size_smaller (_buttonbox); + sp_set_font_size_smaller(_buttonbox); -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) gtk_widget_set_margin_start(_buttonbox, XPAD); gtk_widget_set_margin_end(_buttonbox, XPAD); - #else + #else gtk_widget_set_margin_left(_buttonbox, XPAD); gtk_widget_set_margin_right(_buttonbox, XPAD); - #endif + #endif gtk_widget_set_margin_top(_buttonbox, YPAD); gtk_widget_set_margin_bottom(_buttonbox, YPAD); gtk_widget_set_hexpand(_buttonbox, TRUE); gtk_widget_set_valign(_buttonbox, GTK_ALIGN_CENTER); attach(*Glib::wrap(_buttonbox), 0, row, 2, 1); #else - attach(*Glib::wrap(_buttonbox), 0, 2, row, row+1, Gtk::EXPAND | Gtk::FILL, static_cast(0), XPAD, YPAD); + attach(*Glib::wrap(_buttonbox), 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, static_cast(0), + XPAD, YPAD); #endif row++; -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) - gtk_widget_set_margin_start(_book, XPAD*2); - gtk_widget_set_margin_end(_book, XPAD*2); - #else - gtk_widget_set_margin_left(_book, XPAD*2); - gtk_widget_set_margin_right(_book, XPAD*2); - #endif +#if GTK_CHECK_VERSION(3, 0, 0) +#if GTK_CHECK_VERSION(3, 12, 0) + gtk_widget_set_margin_start(_book, XPAD * 2); + gtk_widget_set_margin_end(_book, XPAD * 2); +#else + gtk_widget_set_margin_left(_book, XPAD * 2); + gtk_widget_set_margin_right(_book, XPAD * 2); +#endif gtk_widget_set_margin_top(_book, YPAD); gtk_widget_set_margin_bottom(_book, YPAD); gtk_widget_set_hexpand(_book, TRUE); gtk_widget_set_vexpand(_book, TRUE); attach(*notebook, 0, row, 2, 1); #else - attach(*notebook, 0, 2, row, row+1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, XPAD * 2, YPAD); + attach(*notebook, 0, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::EXPAND | Gtk::FILL, XPAD * 2, YPAD); #endif // restore the last active page @@ -170,72 +168,72 @@ void ColorNotebook::_initUI() _setCurrentPage(prefs->getInt("/colorselector/page", 0)); row++; -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) GtkWidget *rgbabox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); #else - GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0); + GtkWidget *rgbabox = gtk_hbox_new(FALSE, 0); #endif #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) /* Create color management icons */ - _box_colormanaged = gtk_event_box_new (); - GtkWidget *colormanaged = gtk_image_new_from_icon_name ("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_container_add (GTK_CONTAINER (_box_colormanaged), colormanaged); - gtk_widget_set_tooltip_text (_box_colormanaged, _("Color Managed")); - gtk_widget_set_sensitive (_box_colormanaged, false); + _box_colormanaged = gtk_event_box_new(); + GtkWidget *colormanaged = gtk_image_new_from_icon_name("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_container_add(GTK_CONTAINER(_box_colormanaged), colormanaged); + gtk_widget_set_tooltip_text(_box_colormanaged, _("Color Managed")); + gtk_widget_set_sensitive(_box_colormanaged, false); gtk_box_pack_start(GTK_BOX(rgbabox), _box_colormanaged, FALSE, FALSE, 2); - _box_outofgamut = gtk_event_box_new (); - GtkWidget *outofgamut = gtk_image_new_from_icon_name ("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_container_add (GTK_CONTAINER (_box_outofgamut), outofgamut); - gtk_widget_set_tooltip_text (_box_outofgamut, _("Out of gamut!")); - gtk_widget_set_sensitive (_box_outofgamut, false); + _box_outofgamut = gtk_event_box_new(); + GtkWidget *outofgamut = gtk_image_new_from_icon_name("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_container_add(GTK_CONTAINER(_box_outofgamut), outofgamut); + gtk_widget_set_tooltip_text(_box_outofgamut, _("Out of gamut!")); + gtk_widget_set_sensitive(_box_outofgamut, false); gtk_box_pack_start(GTK_BOX(rgbabox), _box_outofgamut, FALSE, FALSE, 2); - _box_toomuchink = gtk_event_box_new (); - GtkWidget *toomuchink = gtk_image_new_from_icon_name ("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); - gtk_container_add (GTK_CONTAINER (_box_toomuchink), toomuchink); - gtk_widget_set_tooltip_text (_box_toomuchink, _("Too much ink!")); - gtk_widget_set_sensitive (_box_toomuchink, false); + _box_toomuchink = gtk_event_box_new(); + GtkWidget *toomuchink = gtk_image_new_from_icon_name("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR); + gtk_container_add(GTK_CONTAINER(_box_toomuchink), toomuchink); + gtk_widget_set_tooltip_text(_box_toomuchink, _("Too much ink!")); + gtk_widget_set_sensitive(_box_toomuchink, false); gtk_box_pack_start(GTK_BOX(rgbabox), _box_toomuchink, FALSE, FALSE, 2); -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) /* Color picker */ - GtkWidget *picker = gtk_image_new_from_icon_name ("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR); - _btn_picker = gtk_button_new (); + GtkWidget *picker = gtk_image_new_from_icon_name("color-picker", GTK_ICON_SIZE_SMALL_TOOLBAR); + _btn_picker = gtk_button_new(); gtk_button_set_relief(GTK_BUTTON(_btn_picker), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (_btn_picker), picker); - gtk_widget_set_tooltip_text (_btn_picker, _("Pick colors from image")); + gtk_container_add(GTK_CONTAINER(_btn_picker), picker); + gtk_widget_set_tooltip_text(_btn_picker, _("Pick colors from image")); gtk_box_pack_start(GTK_BOX(rgbabox), _btn_picker, FALSE, FALSE, 2); g_signal_connect(G_OBJECT(_btn_picker), "clicked", G_CALLBACK(ColorNotebook::_onPickerClicked), this); /* Create RGBA entry and color preview */ - _rgbal = gtk_label_new_with_mnemonic (_("RGBA_:")); - gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5); + _rgbal = gtk_label_new_with_mnemonic(_("RGBA_:")); + gtk_misc_set_alignment(GTK_MISC(_rgbal), 1.0, 0.5); gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2); - ColorEntry* rgba_entry = Gtk::manage(new ColorEntry(_selected_color)); - sp_dialog_defocus_on_enter (GTK_WIDGET(rgba_entry->gobj())); + ColorEntry *rgba_entry = Gtk::manage(new ColorEntry(_selected_color)); + sp_dialog_defocus_on_enter(GTK_WIDGET(rgba_entry->gobj())); gtk_box_pack_start(GTK_BOX(rgbabox), GTK_WIDGET(rgba_entry->gobj()), FALSE, FALSE, 0); - gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), GTK_WIDGET(rgba_entry->gobj())); + gtk_label_set_mnemonic_widget(GTK_LABEL(_rgbal), GTK_WIDGET(rgba_entry->gobj())); - sp_set_font_size_smaller (rgbabox); - gtk_widget_show_all (rgbabox); + sp_set_font_size_smaller(rgbabox); + gtk_widget_show_all(rgbabox); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - //the "too much ink" icon is initially hidden + // the "too much ink" icon is initially hidden gtk_widget_hide(GTK_WIDGET(_box_toomuchink)); -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) gtk_widget_set_margin_start(rgbabox, XPAD); gtk_widget_set_margin_end(rgbabox, XPAD); - #else + #else gtk_widget_set_margin_left(rgbabox, XPAD); gtk_widget_set_margin_right(rgbabox, XPAD); - #endif + #endif gtk_widget_set_margin_top(rgbabox, YPAD); gtk_widget_set_margin_bottom(rgbabox, YPAD); attach(*Glib::wrap(rgbabox), 0, row, 2, 1); @@ -244,13 +242,12 @@ void ColorNotebook::_initUI() #endif #ifdef SPCS_PREVIEW - _p = sp_color_preview_new (0xffffffff); - gtk_widget_show (_p); + _p = sp_color_preview_new(0xffffffff); + gtk_widget_show(_p); attach(*Glib::wrap(_p), 2, 3, row, row + 1, Gtk::FILL, Gtk::FILL, XPAD, YPAD); #endif - g_signal_connect(G_OBJECT (_book), "switch-page", - G_CALLBACK (ColorNotebook::_onPageSwitched), this); + g_signal_connect(G_OBJECT(_book), "switch-page", G_CALLBACK(ColorNotebook::_onPageSwitched), this); } void ColorNotebook::_onPickerClicked(GtkWidget * /*widget*/, ColorNotebook * /*colorbook*/) @@ -261,27 +258,22 @@ void ColorNotebook::_onPickerClicked(GtkWidget * /*widget*/, ColorNotebook * /*c Inkscape::UI::Tools::sp_toggle_dropper(SP_ACTIVE_DESKTOP); } -void ColorNotebook::_onButtonClicked(GtkWidget *widget, ColorNotebook *nb) +void ColorNotebook::_onButtonClicked(GtkWidget *widget, ColorNotebook *nb) { - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) { + if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { return; } - for(gint i = 0; i < gtk_notebook_get_n_pages (GTK_NOTEBOOK (nb->_book)); i++) { + for (gint i = 0; i < gtk_notebook_get_n_pages(GTK_NOTEBOOK(nb->_book)); i++) { if (nb->_buttons[i] == widget) { - gtk_notebook_set_current_page (GTK_NOTEBOOK (nb->_book), i); + gtk_notebook_set_current_page(GTK_NOTEBOOK(nb->_book), i); } } } -void ColorNotebook::_onSelectedColorChanged() { - _updateICCButtons(); -} +void ColorNotebook::_onSelectedColorChanged() { _updateICCButtons(); } -void ColorNotebook::_onPageSwitched(GtkNotebook *notebook, - GtkWidget *page, - guint page_num, - ColorNotebook *colorbook) +void ColorNotebook::_onPageSwitched(GtkNotebook *notebook, GtkWidget *page, guint page_num, ColorNotebook *colorbook) { if (colorbook) { // remember the page we switched to @@ -297,41 +289,45 @@ void ColorNotebook::_updateICCButtons() SPColor color = _selected_color.color(); gfloat alpha = _selected_color.alpha(); - g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); + g_return_if_fail((0.0 <= alpha) && (alpha <= 1.0)); #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) /* update color management icon*/ - gtk_widget_set_sensitive (_box_colormanaged, color.icc != NULL); + gtk_widget_set_sensitive(_box_colormanaged, color.icc != NULL); /* update out-of-gamut icon */ - gtk_widget_set_sensitive (_box_outofgamut, false); - if (color.icc){ - Inkscape::ColorProfile* target_profile = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); - if ( target_profile ) + gtk_widget_set_sensitive(_box_outofgamut, false); + if (color.icc) { + Inkscape::ColorProfile *target_profile = + SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); + if (target_profile) gtk_widget_set_sensitive(_box_outofgamut, target_profile->GamutCheck(color)); } /* update too-much-ink icon */ - gtk_widget_set_sensitive (_box_toomuchink, false); - if (color.icc){ - Inkscape::ColorProfile* prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); - if ( prof && CMSSystem::isPrintColorSpace(prof) ) { + gtk_widget_set_sensitive(_box_toomuchink, false); + if (color.icc) { + Inkscape::ColorProfile *prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str()); + if (prof && CMSSystem::isPrintColorSpace(prof)) { gtk_widget_show(GTK_WIDGET(_box_toomuchink)); double ink_sum = 0; - for (unsigned int i=0; icolors.size(); i++){ + for (unsigned int i = 0; i < color.icc->colors.size(); i++) { ink_sum += color.icc->colors[i]; } - /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured color, - which means the paper can get too wet due to an excessive ammount of ink. This may lead to several issues + /* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured + color, + which means the paper can get too wet due to an excessive ammount of ink. This may lead to several + issues such as misalignment and poor quality of printing in general.*/ - if ( ink_sum > 3.2 ) - gtk_widget_set_sensitive (_box_toomuchink, true); - } else { + if (ink_sum > 3.2) + gtk_widget_set_sensitive(_box_toomuchink, true); + } + else { gtk_widget_hide(GTK_WIDGET(_box_toomuchink)); } } -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) } void ColorNotebook::_setCurrentPage(int i) @@ -343,7 +339,8 @@ void ColorNotebook::_setCurrentPage(int i) } } -void ColorNotebook::_addPage(Page& page) { +void ColorNotebook::_addPage(Page &page) +{ Gtk::Widget *selector_widget; selector_widget = page.selector_factory->createWidget(_selected_color); @@ -351,22 +348,21 @@ void ColorNotebook::_addPage(Page& page) { selector_widget->show(); Glib::ustring mode_name = page.selector_factory->modeName(); - Gtk::Widget* tab_label = Gtk::manage(new Gtk::Label(mode_name)); - gint page_num = gtk_notebook_append_page( GTK_NOTEBOOK(_book), selector_widget->gobj(), tab_label->gobj()); + Gtk::Widget *tab_label = Gtk::manage(new Gtk::Label(mode_name)); + gint page_num = gtk_notebook_append_page(GTK_NOTEBOOK(_book), selector_widget->gobj(), tab_label->gobj()); _buttons[page_num] = gtk_radio_button_new_with_label(NULL, mode_name.c_str()); gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(_buttons[page_num]), FALSE); if (page_num > 0) { - GSList *group = gtk_radio_button_get_group (GTK_RADIO_BUTTON(_buttons[0])); - gtk_radio_button_set_group (GTK_RADIO_BUTTON(_buttons[page_num]), group); + GSList *group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(_buttons[0])); + gtk_radio_button_set_group(GTK_RADIO_BUTTON(_buttons[page_num]), group); } - gtk_widget_show (_buttons[page_num]); - gtk_box_pack_start (GTK_BOX (_buttonbox), _buttons[page_num], TRUE, TRUE, 0); + gtk_widget_show(_buttons[page_num]); + gtk_box_pack_start(GTK_BOX(_buttonbox), _buttons[page_num], TRUE, TRUE, 0); - g_signal_connect (G_OBJECT (_buttons[page_num]), "clicked", G_CALLBACK (_onButtonClicked), this); + g_signal_connect(G_OBJECT(_buttons[page_num]), "clicked", G_CALLBACK(_onButtonClicked), this); } } - } } } diff --git a/src/ui/widget/color-notebook.h b/src/ui/widget/color-notebook.h index 9909aa39c..d28028c72 100644 --- a/src/ui/widget/color-notebook.h +++ b/src/ui/widget/color-notebook.h @@ -15,7 +15,7 @@ #define SEEN_SP_COLOR_NOTEBOOK_H #ifdef HAVE_CONFIG_H -# include +#include #endif #include @@ -35,7 +35,7 @@ namespace UI { namespace Widget { class ColorNotebook -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : public Gtk::Grid #else : public Gtk::Table @@ -54,12 +54,11 @@ protected: }; virtual void _initUI(); - void _addPage(Page& page); + void _addPage(Page &page); static void _onButtonClicked(GtkWidget *widget, ColorNotebook *colorbook); static void _onPickerClicked(GtkWidget *widget, ColorNotebook *colorbook); - static void _onPageSwitched(GtkNotebook *notebook, GtkWidget *page, - guint page_num, ColorNotebook *colorbook); + static void _onPageSwitched(GtkNotebook *notebook, GtkWidget *page, guint page_num, ColorNotebook *colorbook); virtual void _onSelectedColorChanged(); void _updateICCButtons(); @@ -73,17 +72,16 @@ protected: GtkWidget *_rgbal; /* RGBA entry */ #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) GtkWidget *_box_outofgamut, *_box_colormanaged, *_box_toomuchink; -#endif //defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) GtkWidget *_btn_picker; GtkWidget *_p; /* Color preview */ boost::ptr_vector _available_pages; private: // By default, disallow copy constructor and assignment operator - ColorNotebook( const ColorNotebook& obj ); - ColorNotebook& operator=( const ColorNotebook& obj ); + ColorNotebook(const ColorNotebook &obj); + ColorNotebook &operator=(const ColorNotebook &obj); }; - } } } diff --git a/src/ui/widget/color-scales.cpp b/src/ui/widget/color-scales.cpp index 9f18b2d96..5fa5af902 100644 --- a/src/ui/widget/color-scales.cpp +++ b/src/ui/widget/color-scales.cpp @@ -3,7 +3,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -41,26 +41,20 @@ namespace UI { namespace Widget { -static const gchar * sp_color_scales_hue_map (); +static const gchar *sp_color_scales_hue_map(); -const gchar* ColorScales::SUBMODE_NAMES[] = { - N_("None"), - N_("RGB"), - N_("HSL"), - N_("CMYK") -}; +const gchar *ColorScales::SUBMODE_NAMES[] = { N_("None"), N_("RGB"), N_("HSL"), N_("CMYK") }; ColorScales::ColorScales(SelectedColor &color, SPColorScalesMode mode) -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : Gtk::Grid() #else : Gtk::Table(5, 3, false) #endif , _color(color) - , - _rangeLimit( 255.0 ), - _updating( FALSE ), - _dragging( FALSE ) + , _rangeLimit(255.0) + , _updating(FALSE) + , _dragging(FALSE) { for (gint i = 0; i < 5; i++) { _l[i] = 0; @@ -73,7 +67,6 @@ ColorScales::ColorScales(SelectedColor &color, SPColorScalesMode mode) _color.signal_changed.connect(sigc::mem_fun(this, &ColorScales::_onColorChanged)); _color.signal_dragged.connect(sigc::mem_fun(this, &ColorScales::_onColorChanged)); - } ColorScales::~ColorScales() @@ -88,92 +81,92 @@ ColorScales::~ColorScales() void ColorScales::_initUI(SPColorScalesMode mode) { - gint i; + gint i; - _updating = FALSE; - _dragging = FALSE; + _updating = FALSE; + _dragging = FALSE; - GtkWidget *t = GTK_WIDGET(gobj()); + GtkWidget *t = GTK_WIDGET(gobj()); - /* Create components */ - for (i = 0; i < static_cast< gint > (G_N_ELEMENTS(_a)) ; i++) { - /* Label */ - _l[i] = gtk_label_new(""); - gtk_misc_set_alignment (GTK_MISC (_l[i]), 1.0, 0.5); - gtk_widget_show (_l[i]); + /* Create components */ + for (i = 0; i < static_cast(G_N_ELEMENTS(_a)); i++) { + /* Label */ + _l[i] = gtk_label_new(""); + gtk_misc_set_alignment(GTK_MISC(_l[i]), 1.0, 0.5); + gtk_widget_show(_l[i]); -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) - gtk_widget_set_margin_start(_l[i], XPAD); - gtk_widget_set_margin_end(_l[i], XPAD); +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) + gtk_widget_set_margin_start(_l[i], XPAD); + gtk_widget_set_margin_end(_l[i], XPAD); #else - gtk_widget_set_margin_left(_l[i], XPAD); - gtk_widget_set_margin_right(_l[i], XPAD); + gtk_widget_set_margin_left(_l[i], XPAD); + gtk_widget_set_margin_right(_l[i], XPAD); #endif - gtk_widget_set_margin_top(_l[i], YPAD); - gtk_widget_set_margin_bottom(_l[i], YPAD); - gtk_grid_attach(GTK_GRID(t), _l[i], 0, i, 1, 1); + gtk_widget_set_margin_top(_l[i], YPAD); + gtk_widget_set_margin_bottom(_l[i], YPAD); + gtk_grid_attach(GTK_GRID(t), _l[i], 0, i, 1, 1); #else - gtk_table_attach (GTK_TABLE (t), _l[i], 0, 1, i, i + 1, GTK_FILL, GTK_FILL, XPAD, YPAD); + gtk_table_attach(GTK_TABLE(t), _l[i], 0, 1, i, i + 1, GTK_FILL, GTK_FILL, XPAD, YPAD); #endif - /* Adjustment */ - _a[i] = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, _rangeLimit, 1.0, 10.0, 10.0)); - /* Slider */ - _s[i] = Gtk::manage(new Inkscape::UI::Widget::ColorSlider(Glib::wrap(_a[i], true))); - _s[i]->show(); + /* Adjustment */ + _a[i] = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, 0.0, _rangeLimit, 1.0, 10.0, 10.0)); + /* Slider */ + _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) - _s[i]->set_margin_start(XPAD); - _s[i]->set_margin_end(XPAD); +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) + _s[i]->set_margin_start(XPAD); + _s[i]->set_margin_end(XPAD); #else - _s[i]->set_margin_left(XPAD); - _s[i]->set_margin_right(XPAD); + _s[i]->set_margin_left(XPAD); + _s[i]->set_margin_right(XPAD); #endif - _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); + _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]->gobj(), 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 */ - _b[i] = gtk_spin_button_new (GTK_ADJUSTMENT (_a[i]), 1.0, 0); - sp_dialog_defocus_on_enter (_b[i]); - gtk_label_set_mnemonic_widget (GTK_LABEL(_l[i]), _b[i]); - gtk_widget_show (_b[i]); + /* Spinbutton */ + _b[i] = gtk_spin_button_new(GTK_ADJUSTMENT(_a[i]), 1.0, 0); + sp_dialog_defocus_on_enter(_b[i]); + gtk_label_set_mnemonic_widget(GTK_LABEL(_l[i]), _b[i]); + gtk_widget_show(_b[i]); -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) - gtk_widget_set_margin_start(_b[i], XPAD); - gtk_widget_set_margin_end(_b[i], XPAD); +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) + gtk_widget_set_margin_start(_b[i], XPAD); + gtk_widget_set_margin_end(_b[i], XPAD); #else - gtk_widget_set_margin_left(_b[i], XPAD); - gtk_widget_set_margin_right(_b[i], XPAD); + gtk_widget_set_margin_left(_b[i], XPAD); + gtk_widget_set_margin_right(_b[i], XPAD); #endif - gtk_widget_set_margin_top(_b[i], YPAD); - gtk_widget_set_margin_bottom(_b[i], YPAD); - gtk_widget_set_halign(_b[i], GTK_ALIGN_CENTER); - gtk_widget_set_valign(_b[i], GTK_ALIGN_CENTER); - gtk_grid_attach(GTK_GRID(t), _b[i], 2, i, 1, 1); + gtk_widget_set_margin_top(_b[i], YPAD); + gtk_widget_set_margin_bottom(_b[i], YPAD); + gtk_widget_set_halign(_b[i], GTK_ALIGN_CENTER); + gtk_widget_set_valign(_b[i], GTK_ALIGN_CENTER); + gtk_grid_attach(GTK_GRID(t), _b[i], 2, i, 1, 1); #else - gtk_table_attach (GTK_TABLE (t), _b[i], 2, 3, i, i + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, XPAD, YPAD); + gtk_table_attach(GTK_TABLE(t), _b[i], 2, 3, i, i + 1, (GtkAttachOptions)0, (GtkAttachOptions)0, XPAD, YPAD); #endif - /* Attach channel value to adjustment */ - g_object_set_data (G_OBJECT (_a[i]), "channel", GINT_TO_POINTER (i)); - /* Signals */ - g_signal_connect (G_OBJECT (_a[i]), "value_changed", - G_CALLBACK (_adjustmentAnyChanged), this); - _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 */ - setMode(mode); + /* Attach channel value to adjustment */ + g_object_set_data(G_OBJECT(_a[i]), "channel", GINT_TO_POINTER(i)); + /* Signals */ + g_signal_connect(G_OBJECT(_a[i]), "value_changed", G_CALLBACK(_adjustmentAnyChanged), this); + _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 */ + setMode(mode); } void ColorScales::_recalcColor() @@ -183,25 +176,24 @@ void ColorScales::_recalcColor() gfloat c[5]; switch (_mode) { - case SP_COLOR_SCALES_MODE_RGB: - case SP_COLOR_SCALES_MODE_HSV: - _getRgbaFloatv(c); - color.set( c[0], c[1], c[2] ); - alpha = c[3]; - break; - case SP_COLOR_SCALES_MODE_CMYK: - { - _getCmykaFloatv( c ); - - float rgb[3]; - sp_color_cmyk_to_rgb_floatv( rgb, c[0], c[1], c[2], c[3] ); - color.set( rgb[0], rgb[1], rgb[2] ); - alpha = c[4]; - break; - } - default: - g_warning ("file %s: line %d: Illegal color selector mode %d", __FILE__, __LINE__, _mode); - break; + case SP_COLOR_SCALES_MODE_RGB: + case SP_COLOR_SCALES_MODE_HSV: + _getRgbaFloatv(c); + color.set(c[0], c[1], c[2]); + alpha = c[3]; + break; + case SP_COLOR_SCALES_MODE_CMYK: { + _getCmykaFloatv(c); + + float rgb[3]; + sp_color_cmyk_to_rgb_floatv(rgb, c[0], c[1], c[2], c[3]); + color.set(rgb[0], rgb[1], rgb[2]); + alpha = c[4]; + break; + } + default: + g_warning("file %s: line %d: Illegal color selector mode %d", __FILE__, __LINE__, _mode); + break; } _color.preserveICC(); @@ -209,25 +201,25 @@ void ColorScales::_recalcColor() } /* Helpers for setting color value */ -gfloat ColorScales::getScaled( const GtkAdjustment *a ) +gfloat ColorScales::getScaled(const GtkAdjustment *a) { - gfloat val = gtk_adjustment_get_value (const_cast(a)) - / gtk_adjustment_get_upper (const_cast(a)); + gfloat val = gtk_adjustment_get_value(const_cast(a)) / + gtk_adjustment_get_upper(const_cast(a)); return val; } -void ColorScales::setScaled( GtkAdjustment *a, gfloat v ) +void ColorScales::setScaled(GtkAdjustment *a, gfloat v) { - gfloat val = v * gtk_adjustment_get_upper (a); - gtk_adjustment_set_value( a, val ); + gfloat val = v * gtk_adjustment_get_upper(a); + gtk_adjustment_set_value(a, val); } -void ColorScales::_setRangeLimit( gdouble upper ) +void ColorScales::_setRangeLimit(gdouble upper) { _rangeLimit = upper; - for ( gint i = 0; i < static_cast(G_N_ELEMENTS(_a)); i++ ) { - gtk_adjustment_set_upper (_a[i], upper); - gtk_adjustment_changed( _a[i] ); + for (gint i = 0; i < static_cast(G_N_ELEMENTS(_a)); i++) { + gtk_adjustment_set_upper(_a[i], upper); + gtk_adjustment_changed(_a[i]); } } @@ -237,231 +229,230 @@ void ColorScales::_onColorChanged() return; } #ifdef DUMP_CHANGE_INFO - g_message("ColorScales::_onColorChanged( this=%p, %f, %f, %f, %f)", this, _color.color().v.c[0], _color.color().v.c[1], _color.color().v.c[2], _color.alpha() ); + g_message("ColorScales::_onColorChanged( this=%p, %f, %f, %f, %f)", this, _color.color().v.c[0], + _color.color().v.c[1], _color.color().v.c[2], _color.alpha()); #endif gfloat tmp[3]; - gfloat c[5] = {0.0, 0.0, 0.0, 0.0}; + gfloat c[5] = { 0.0, 0.0, 0.0, 0.0 }; SPColor color = _color.color(); switch (_mode) { - case SP_COLOR_SCALES_MODE_RGB: - sp_color_get_rgb_floatv( &color, c ); - c[3] = _color.alpha(); - c[4] = 0.0; - break; - case SP_COLOR_SCALES_MODE_HSV: - sp_color_get_rgb_floatv( &color, tmp ); - sp_color_rgb_to_hsl_floatv (c, tmp[0], tmp[1], tmp[2]); - c[3] = _color.alpha(); - c[4] = 0.0; - break; - case SP_COLOR_SCALES_MODE_CMYK: - sp_color_get_cmyk_floatv( &color, c ); - c[4] = _color.alpha(); - break; - default: - g_warning ("file %s: line %d: Illegal color selector mode %d", __FILE__, __LINE__, _mode); - break; + case SP_COLOR_SCALES_MODE_RGB: + sp_color_get_rgb_floatv(&color, c); + c[3] = _color.alpha(); + c[4] = 0.0; + break; + case SP_COLOR_SCALES_MODE_HSV: + sp_color_get_rgb_floatv(&color, tmp); + sp_color_rgb_to_hsl_floatv(c, tmp[0], tmp[1], tmp[2]); + c[3] = _color.alpha(); + c[4] = 0.0; + break; + case SP_COLOR_SCALES_MODE_CMYK: + sp_color_get_cmyk_floatv(&color, c); + c[4] = _color.alpha(); + break; + default: + g_warning("file %s: line %d: Illegal color selector mode %d", __FILE__, __LINE__, _mode); + break; } _updating = TRUE; - setScaled( _a[0], c[0] ); - setScaled( _a[1], c[1] ); - setScaled( _a[2], c[2] ); - setScaled( _a[3], c[3] ); - setScaled( _a[4], c[4] ); - _updateSliders( CSC_CHANNELS_ALL ); + setScaled(_a[0], c[0]); + setScaled(_a[1], c[1]); + setScaled(_a[2], c[2]); + setScaled(_a[3], c[3]); + setScaled(_a[4], c[4]); + _updateSliders(CSC_CHANNELS_ALL); _updating = FALSE; } -void ColorScales::_getRgbaFloatv( gfloat *rgba ) +void ColorScales::_getRgbaFloatv(gfloat *rgba) { - g_return_if_fail (rgba != NULL); - - switch (_mode) { - case SP_COLOR_SCALES_MODE_RGB: - rgba[0] = getScaled(_a[0]); - rgba[1] = getScaled(_a[1]); - rgba[2] = getScaled(_a[2]); - rgba[3] = getScaled(_a[3]); - break; - case SP_COLOR_SCALES_MODE_HSV: - sp_color_hsl_to_rgb_floatv (rgba, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); - rgba[3] = getScaled(_a[3]); - break; - case SP_COLOR_SCALES_MODE_CMYK: - sp_color_cmyk_to_rgb_floatv (rgba, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3])); - rgba[3] = getScaled(_a[4]); - break; - default: - g_warning ("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); - break; - } + g_return_if_fail(rgba != NULL); + + switch (_mode) { + case SP_COLOR_SCALES_MODE_RGB: + rgba[0] = getScaled(_a[0]); + rgba[1] = getScaled(_a[1]); + rgba[2] = getScaled(_a[2]); + rgba[3] = getScaled(_a[3]); + break; + case SP_COLOR_SCALES_MODE_HSV: + sp_color_hsl_to_rgb_floatv(rgba, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); + rgba[3] = getScaled(_a[3]); + break; + case SP_COLOR_SCALES_MODE_CMYK: + sp_color_cmyk_to_rgb_floatv(rgba, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3])); + rgba[3] = getScaled(_a[4]); + break; + default: + g_warning("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); + break; + } } -void ColorScales::_getCmykaFloatv( gfloat *cmyka ) +void ColorScales::_getCmykaFloatv(gfloat *cmyka) { - gfloat rgb[3]; - - g_return_if_fail (cmyka != NULL); - - switch (_mode) { - case SP_COLOR_SCALES_MODE_RGB: - sp_color_rgb_to_cmyk_floatv (cmyka, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); - cmyka[4] = getScaled(_a[3]); - break; - case SP_COLOR_SCALES_MODE_HSV: - sp_color_hsl_to_rgb_floatv (rgb, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); - sp_color_rgb_to_cmyk_floatv (cmyka, rgb[0], rgb[1], rgb[2]); - cmyka[4] = getScaled(_a[3]); - break; - case SP_COLOR_SCALES_MODE_CMYK: - cmyka[0] = getScaled(_a[0]); - cmyka[1] = getScaled(_a[1]); - cmyka[2] = getScaled(_a[2]); - cmyka[3] = getScaled(_a[3]); - cmyka[4] = getScaled(_a[4]); - break; - default: - g_warning ("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); - break; - } + gfloat rgb[3]; + + g_return_if_fail(cmyka != NULL); + + switch (_mode) { + case SP_COLOR_SCALES_MODE_RGB: + sp_color_rgb_to_cmyk_floatv(cmyka, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); + cmyka[4] = getScaled(_a[3]); + break; + case SP_COLOR_SCALES_MODE_HSV: + sp_color_hsl_to_rgb_floatv(rgb, getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2])); + sp_color_rgb_to_cmyk_floatv(cmyka, rgb[0], rgb[1], rgb[2]); + cmyka[4] = getScaled(_a[3]); + break; + case SP_COLOR_SCALES_MODE_CMYK: + cmyka[0] = getScaled(_a[0]); + cmyka[1] = getScaled(_a[1]); + cmyka[2] = getScaled(_a[2]); + cmyka[3] = getScaled(_a[3]); + cmyka[4] = getScaled(_a[4]); + break; + default: + g_warning("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); + break; + } } guint32 ColorScales::_getRgba32() { - gfloat c[4]; - guint32 rgba; + gfloat c[4]; + guint32 rgba; - _getRgbaFloatv(c); + _getRgbaFloatv(c); - rgba = SP_RGBA32_F_COMPOSE (c[0], c[1], c[2], c[3]); + rgba = SP_RGBA32_F_COMPOSE(c[0], c[1], c[2], c[3]); - return rgba; + return rgba; } void ColorScales::setMode(SPColorScalesMode mode) { - gfloat rgba[4]; - gfloat c[4]; - - if (_mode == mode) return; - - if ((_mode == SP_COLOR_SCALES_MODE_RGB) || - (_mode == SP_COLOR_SCALES_MODE_HSV) || - (_mode == SP_COLOR_SCALES_MODE_CMYK)) { - _getRgbaFloatv(rgba); - } else { - rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0; - } - - _mode = mode; - - switch (mode) { - case SP_COLOR_SCALES_MODE_RGB: - _setRangeLimit(255.0); - gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_R:")); - _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:")); - _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:")); - _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:")); - _s[3]->set_tooltip_text(_("Alpha (opacity)")); - gtk_widget_set_tooltip_text (_b[3], _("Alpha (opacity)")); - _s[0]->setMap(NULL); - gtk_widget_hide (_l[4]); - _s[4]->hide(); - gtk_widget_hide (_b[4]); - _updating = TRUE; - setScaled( _a[0], rgba[0] ); - setScaled( _a[1], rgba[1] ); - setScaled( _a[2], rgba[2] ); - setScaled( _a[3], rgba[3] ); - _updating = FALSE; - _updateSliders( CSC_CHANNELS_ALL ); - break; - case SP_COLOR_SCALES_MODE_HSV: - _setRangeLimit(255.0); - gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_H:")); - _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:")); - _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:")); - _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:")); - _s[3]->set_tooltip_text(_("Alpha (opacity)")); - gtk_widget_set_tooltip_text (_b[3], _("Alpha (opacity)")); - _s[0]->setMap((guchar *)(sp_color_scales_hue_map())); - gtk_widget_hide (_l[4]); - _s[4]->hide(); - gtk_widget_hide (_b[4]); - _updating = TRUE; - c[0] = 0.0; - sp_color_rgb_to_hsl_floatv (c, rgba[0], rgba[1], rgba[2]); - setScaled( _a[0], c[0] ); - setScaled( _a[1], c[1] ); - setScaled( _a[2], c[2] ); - setScaled( _a[3], rgba[3] ); - _updating = FALSE; - _updateSliders( CSC_CHANNELS_ALL ); - break; - case SP_COLOR_SCALES_MODE_CMYK: - _setRangeLimit(100.0); - gtk_label_set_markup_with_mnemonic (GTK_LABEL (_l[0]), _("_C:")); - _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:")); - _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:")); - _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:")); - _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:")); - _s[4]->set_tooltip_text(_("Alpha (opacity)")); - gtk_widget_set_tooltip_text (_b[4], _("Alpha (opacity)")); - _s[0]->setMap(NULL); - gtk_widget_show (_l[4]); - _s[4]->show(); - gtk_widget_show (_b[4]); - _updating = TRUE; - - sp_color_rgb_to_cmyk_floatv (c, rgba[0], rgba[1], rgba[2]); - setScaled( _a[0], c[0] ); - setScaled( _a[1], c[1] ); - setScaled( _a[2], c[2] ); - setScaled( _a[3], c[3] ); - - setScaled( _a[4], rgba[3] ); - _updating = FALSE; - _updateSliders( CSC_CHANNELS_ALL ); - break; - default: - g_warning ("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); - break; - } -} + gfloat rgba[4]; + gfloat c[4]; -SPColorScalesMode ColorScales::getMode() const -{ - return _mode; + if (_mode == mode) + return; + + if ((_mode == SP_COLOR_SCALES_MODE_RGB) || (_mode == SP_COLOR_SCALES_MODE_HSV) || + (_mode == SP_COLOR_SCALES_MODE_CMYK)) { + _getRgbaFloatv(rgba); + } + else { + rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0; + } + + _mode = mode; + + switch (mode) { + case SP_COLOR_SCALES_MODE_RGB: + _setRangeLimit(255.0); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(_l[0]), _("_R:")); + _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:")); + _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:")); + _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:")); + _s[3]->set_tooltip_text(_("Alpha (opacity)")); + gtk_widget_set_tooltip_text(_b[3], _("Alpha (opacity)")); + _s[0]->setMap(NULL); + gtk_widget_hide(_l[4]); + _s[4]->hide(); + gtk_widget_hide(_b[4]); + _updating = TRUE; + setScaled(_a[0], rgba[0]); + setScaled(_a[1], rgba[1]); + setScaled(_a[2], rgba[2]); + setScaled(_a[3], rgba[3]); + _updating = FALSE; + _updateSliders(CSC_CHANNELS_ALL); + break; + case SP_COLOR_SCALES_MODE_HSV: + _setRangeLimit(255.0); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(_l[0]), _("_H:")); + _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:")); + _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:")); + _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:")); + _s[3]->set_tooltip_text(_("Alpha (opacity)")); + gtk_widget_set_tooltip_text(_b[3], _("Alpha (opacity)")); + _s[0]->setMap((guchar *)(sp_color_scales_hue_map())); + gtk_widget_hide(_l[4]); + _s[4]->hide(); + gtk_widget_hide(_b[4]); + _updating = TRUE; + c[0] = 0.0; + sp_color_rgb_to_hsl_floatv(c, rgba[0], rgba[1], rgba[2]); + setScaled(_a[0], c[0]); + setScaled(_a[1], c[1]); + setScaled(_a[2], c[2]); + setScaled(_a[3], rgba[3]); + _updating = FALSE; + _updateSliders(CSC_CHANNELS_ALL); + break; + case SP_COLOR_SCALES_MODE_CMYK: + _setRangeLimit(100.0); + gtk_label_set_markup_with_mnemonic(GTK_LABEL(_l[0]), _("_C:")); + _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:")); + _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:")); + _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:")); + _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:")); + _s[4]->set_tooltip_text(_("Alpha (opacity)")); + gtk_widget_set_tooltip_text(_b[4], _("Alpha (opacity)")); + _s[0]->setMap(NULL); + gtk_widget_show(_l[4]); + _s[4]->show(); + gtk_widget_show(_b[4]); + _updating = TRUE; + + sp_color_rgb_to_cmyk_floatv(c, rgba[0], rgba[1], rgba[2]); + setScaled(_a[0], c[0]); + setScaled(_a[1], c[1]); + setScaled(_a[2], c[2]); + setScaled(_a[3], c[3]); + + setScaled(_a[4], rgba[3]); + _updating = FALSE; + _updateSliders(CSC_CHANNELS_ALL); + break; + default: + g_warning("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); + break; + } } -void ColorScales::_adjustmentAnyChanged( GtkAdjustment *adjustment, ColorScales *cs ) +SPColorScalesMode ColorScales::getMode() const { return _mode; } + +void ColorScales::_adjustmentAnyChanged(GtkAdjustment *adjustment, ColorScales *cs) { - gint channel = GPOINTER_TO_INT (g_object_get_data(G_OBJECT (adjustment), "channel")); + gint channel = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(adjustment), "channel")); - _adjustmentChanged(cs, channel); + _adjustmentChanged(cs, channel); } void ColorScales::_sliderAnyGrabbed() @@ -469,10 +460,10 @@ void ColorScales::_sliderAnyGrabbed() if (_updating) { return; } - if (!_dragging) { - _dragging = TRUE; + if (!_dragging) { + _dragging = TRUE; _color.setHeld(true); - } + } } void ColorScales::_sliderAnyReleased() @@ -480,10 +471,10 @@ void ColorScales::_sliderAnyReleased() if (_updating) { return; } - if (_dragging) { - _dragging = FALSE; + if (_dragging) { + _dragging = FALSE; _color.setHeld(false); - } + } } void ColorScales::_sliderAnyChanged() @@ -494,160 +485,159 @@ void ColorScales::_sliderAnyChanged() _recalcColor(); } -void ColorScales::_adjustmentChanged( ColorScales *scales, guint channel ) +void ColorScales::_adjustmentChanged(ColorScales *scales, guint channel) { - if (scales->_updating) { - return; - } + if (scales->_updating) { + return; + } - scales->_updateSliders( (1 << channel) ); - scales->_recalcColor(); + scales->_updateSliders((1 << channel)); + scales->_recalcColor(); } -void ColorScales::_updateSliders( guint channels ) +void ColorScales::_updateSliders(guint channels) { - gfloat rgb0[3], rgbm[3], rgb1[3]; + gfloat rgb0[3], rgbm[3], rgb1[3]; #ifdef SPCS_PREVIEW - guint32 rgba; + guint32 rgba; #endif - switch (_mode) { - case SP_COLOR_SCALES_MODE_RGB: - if ((channels != CSC_CHANNEL_R) && (channels != CSC_CHANNEL_A)) { - /* Update red */ - _s[0]->setColors(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 */ - _s[1]->setColors(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 */ - _s[2]->setColors(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 */ - _s[3]->setColors(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: - /* Hue is never updated */ - if ((channels != CSC_CHANNEL_S) && (channels != CSC_CHANNEL_A)) { - /* Update saturation */ - 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])); - _s[1]->setColors(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); - _s[2]->setColors(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])); - _s[3]->setColors(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: - if ((channels != CSC_CHANNEL_C) && (channels != CSC_CHANNEL_CMYKA)) { - /* Update C */ - 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])); - _s[0]->setColors(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])); - _s[1]->setColors(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])); - _s[2]->setColors(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); - _s[3]->setColors(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])); - _s[4]->setColors(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: - g_warning ("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); - break; - } - - // Force the internal color to be updated - if ( !_updating ) - { + switch (_mode) { + case SP_COLOR_SCALES_MODE_RGB: + if ((channels != CSC_CHANNEL_R) && (channels != CSC_CHANNEL_A)) { + /* Update red */ + _s[0]->setColors(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 */ + _s[1]->setColors(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 */ + _s[2]->setColors(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 */ + _s[3]->setColors(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: + /* Hue is never updated */ + if ((channels != CSC_CHANNEL_S) && (channels != CSC_CHANNEL_A)) { + /* Update saturation */ + 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])); + _s[1]->setColors(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); + _s[2]->setColors(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])); + _s[3]->setColors(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: + if ((channels != CSC_CHANNEL_C) && (channels != CSC_CHANNEL_CMYKA)) { + /* Update C */ + 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])); + _s[0]->setColors(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])); + _s[1]->setColors(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])); + _s[2]->setColors(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); + _s[3]->setColors(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])); + _s[4]->setColors(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: + g_warning("file %s: line %d: Illegal color selector mode", __FILE__, __LINE__); + break; + } + + // Force the internal color to be updated + if (!_updating) { _recalcColor(); } #ifdef SPCS_PREVIEW - rgba = sp_color_scales_get_rgba32 (cs); - sp_color_preview_set_rgba32 (SP_COLOR_PREVIEW (_p), rgba); + rgba = sp_color_scales_get_rgba32(cs); + sp_color_preview_set_rgba32(SP_COLOR_PREVIEW(_p), rgba); #endif } -static const gchar * -sp_color_scales_hue_map (void) +static const gchar *sp_color_scales_hue_map(void) { - static gchar *map = NULL; - - if (!map) { - gchar *p; - gint h; - map = g_new (gchar, 4 * 1024); - p = map; - for (h = 0; h < 1024; h++) { - gfloat rgb[3]; - sp_color_hsl_to_rgb_floatv (rgb, h / 1024.0, 1.0, 0.5); - *p++ = SP_COLOR_F_TO_U (rgb[0]); - *p++ = SP_COLOR_F_TO_U (rgb[1]); - *p++ = SP_COLOR_F_TO_U (rgb[2]); - *p++ = 255; - } - } - - return map; + static gchar *map = NULL; + + if (!map) { + gchar *p; + gint h; + map = g_new(gchar, 4 * 1024); + p = map; + for (h = 0; h < 1024; h++) { + gfloat rgb[3]; + sp_color_hsl_to_rgb_floatv(rgb, h / 1024.0, 1.0, 0.5); + *p++ = SP_COLOR_F_TO_U(rgb[0]); + *p++ = SP_COLOR_F_TO_U(rgb[1]); + *p++ = SP_COLOR_F_TO_U(rgb[2]); + *p++ = 255; + } + } + + return map; } ColorScalesFactory::ColorScalesFactory(SPColorScalesMode submode) @@ -655,10 +645,10 @@ ColorScalesFactory::ColorScalesFactory(SPColorScalesMode submode) { } -ColorScalesFactory::~ColorScalesFactory() { -} +ColorScalesFactory::~ColorScalesFactory() {} -Gtk::Widget *ColorScalesFactory::createWidget(Inkscape::UI::SelectedColor &color) const { +Gtk::Widget *ColorScalesFactory::createWidget(Inkscape::UI::SelectedColor &color) const +{ Gtk::Widget *w = Gtk::manage(new ColorScales(color, _submode)); return w; } diff --git a/src/ui/widget/color-scales.h b/src/ui/widget/color-scales.h index 0744a645c..025f92e2d 100644 --- a/src/ui/widget/color-scales.h +++ b/src/ui/widget/color-scales.h @@ -2,7 +2,7 @@ #define SEEN_SP_COLOR_SCALES_H #ifdef HAVE_CONFIG_H -# include +#include #endif #if WITH_GTKMM_3_0 @@ -19,7 +19,6 @@ namespace Widget { class ColorSlider; - typedef enum { SP_COLOR_SCALES_MODE_NONE = 0, SP_COLOR_SCALES_MODE_RGB = 1, @@ -27,20 +26,18 @@ typedef enum { SP_COLOR_SCALES_MODE_CMYK = 3 } SPColorScalesMode; - - class ColorScales -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : public Gtk::Grid #else : public Gtk::Table #endif { public: - static const gchar* SUBMODE_NAMES[]; + static const gchar *SUBMODE_NAMES[]; - static gfloat getScaled( const GtkAdjustment *a ); - static void setScaled( GtkAdjustment *a, gfloat v); + static gfloat getScaled(const GtkAdjustment *a); + static void setScaled(GtkAdjustment *a, gfloat v); ColorScales(SelectedColor &color, SPColorScalesMode mode); virtual ~ColorScales(); @@ -65,26 +62,26 @@ protected: void _updateSliders(guint channels); void _recalcColor(); - void _setRangeLimit( gdouble upper ); + void _setRangeLimit(gdouble upper); SelectedColor &_color; SPColorScalesMode _mode; gdouble _rangeLimit; gboolean _updating : 1; gboolean _dragging : 1; - GtkAdjustment *_a[5]; /* Channel adjustments */ + GtkAdjustment *_a[5]; /* Channel adjustments */ Inkscape::UI::Widget::ColorSlider *_s[5]; /* Channel sliders */ - GtkWidget *_b[5]; /* Spinbuttons */ - GtkWidget *_l[5]; /* Labels */ + GtkWidget *_b[5]; /* Spinbuttons */ + GtkWidget *_l[5]; /* Labels */ private: // By default, disallow copy constructor and assignment operator ColorScales(ColorScales const &obj); - ColorScales &operator=(ColorScales const &obj ); + ColorScales &operator=(ColorScales const &obj); }; - -class ColorScalesFactory: public Inkscape::UI::ColorSelectorFactory { +class ColorScalesFactory : public Inkscape::UI::ColorSelectorFactory +{ public: ColorScalesFactory(SPColorScalesMode submode); ~ColorScalesFactory(); diff --git a/src/ui/widget/color-slider.cpp b/src/ui/widget/color-slider.cpp index bf8b85dbd..0c9586a67 100644 --- a/src/ui/widget/color-slider.cpp +++ b/src/ui/widget/color-slider.cpp @@ -12,7 +12,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -34,20 +34,20 @@ 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); +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) +#if GTK_CHECK_VERSION(3, 0, 0) ColorSlider::ColorSlider(Glib::RefPtr adjustment) : _dragging(false) #else -ColorSlider::ColorSlider(Gtk::Adjustment* adjustment) +ColorSlider::ColorSlider(Gtk::Adjustment *adjustment) : _dragging(false) , _adjustment(NULL) #endif @@ -78,11 +78,12 @@ ColorSlider::ColorSlider(Gtk::Adjustment* adjustment) setAdjustment(adjustment); } -ColorSlider::~ColorSlider() { +ColorSlider::~ColorSlider() +{ if (_adjustment) { _adjustment_changed_connection.disconnect(); _adjustment_value_changed_connection.disconnect(); -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) _adjustment.reset(); #else _adjustment->unreference(); @@ -91,103 +92,102 @@ ColorSlider::~ColorSlider() { } } -void ColorSlider::on_realize() { +void ColorSlider::on_realize() +{ set_realized(); - if(!_gdk_window) - { - 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()); + if (!_gdk_window) { + 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; + 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; + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; #endif - _gdk_window = Gdk::Window::create(get_parent_window(), &attributes, - attributes_mask); - set_window(_gdk_window); - _gdk_window->set_user_data(gobj()); + _gdk_window = Gdk::Window::create(get_parent_window(), &attributes, attributes_mask); + set_window(_gdk_window); + _gdk_window->set_user_data(gobj()); -#if !GTK_CHECK_VERSION(3,0,0) - style_attach(); +#if !GTK_CHECK_VERSION(3, 0, 0) + style_attach(); #endif } } -void ColorSlider::on_unrealize() { +void ColorSlider::on_unrealize() +{ _gdk_window.reset(); Gtk::Widget::on_unrealize(); } -void ColorSlider::on_size_allocate(Gtk::Allocation& allocation) { +void ColorSlider::on_size_allocate(Gtk::Allocation &allocation) +{ set_allocation(allocation); if (get_realized()) { - _gdk_window->move_resize(allocation.get_x(), allocation.get_y(), - allocation.get_width(), allocation.get_height()); + _gdk_window->move_resize(allocation.get_x(), allocation.get_y(), allocation.get_width(), + allocation.get_height()); } } -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) -void ColorSlider::get_preferred_width_vfunc(int& minimum_width, int& natural_width) const +void ColorSlider::get_preferred_width_vfunc(int &minimum_width, int &natural_width) const { - Glib::RefPtrstyle_context = get_style_context(); + Glib::RefPtr 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 +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 +void ColorSlider::get_preferred_height_vfunc(int &minimum_height, int &natural_height) const { - Glib::RefPtrstyle_context = get_style_context(); + Glib::RefPtr 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 +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) { +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 ColorSlider::on_expose_event(GdkEventExpose *event) +{ bool result = false; if (get_is_drawable()) { @@ -199,11 +199,12 @@ bool ColorSlider::on_expose_event(GdkEventExpose* event) { #endif -bool ColorSlider::on_button_press_event(GdkEventButton *event) { +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) +#if GTK_CHECK_VERSION(3, 0, 0) cx = get_style_context()->get_padding(get_state_flags()).get_left(); #else cx = get_style()->get_xthickness(); @@ -212,33 +213,30 @@ bool ColorSlider::on_button_press_event(GdkEventButton *event) { signal_grabbed.emit(); _dragging = true; _oldvalue = _value; - ColorScales::setScaled( _adjustment->gobj(), CLAMP ((gfloat) (event->x - cx) / cw, 0.0, 1.0) ); + 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(event)), - _gdk_window->gobj(), - GDK_OWNERSHIP_NONE, - FALSE, - static_cast(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), - NULL, - event->time); +#if GTK_CHECK_VERSION(3, 0, 0) + gdk_device_grab( + gdk_event_get_device(reinterpret_cast(event)), _gdk_window->gobj(), GDK_OWNERSHIP_NONE, FALSE, + static_cast(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, event->time); #else gdk_pointer_grab(get_window()->gobj(), FALSE, - static_cast(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), - NULL, NULL, event->time); + static_cast(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, NULL, + event->time); #endif } return false; } -bool ColorSlider::on_button_release_event(GdkEventButton *event) { +bool ColorSlider::on_button_release_event(GdkEventButton *event) +{ if (event->button == 1) { -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) gdk_device_ungrab(gdk_event_get_device(reinterpret_cast(event)), - gdk_event_get_time(reinterpret_cast(event))); + gdk_event_get_time(reinterpret_cast(event))); #else get_window()->pointer_ungrab(event->time); #endif @@ -253,35 +251,39 @@ bool ColorSlider::on_button_release_event(GdkEventButton *event) { return false; } -bool ColorSlider::on_motion_notify_event(GdkEventMotion *event) { +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) +#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) ); + 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::setAdjustment(Glib::RefPtr adjustment) { +#if GTK_CHECK_VERSION(3, 0, 0) +void ColorSlider::setAdjustment(Glib::RefPtr adjustment) +{ #else -void ColorSlider::setAdjustment(Gtk::Adjustment *adjustment) { +void ColorSlider::setAdjustment(Gtk::Adjustment *adjustment) +{ #endif if (!adjustment) { -#if GTK_CHECK_VERSION(3,0,0) +#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 { + } + else { adjustment->set_page_increment(0.0); adjustment->set_page_size(0.0); } @@ -290,16 +292,16 @@ void ColorSlider::setAdjustment(Gtk::Adjustment *adjustment) { if (_adjustment) { _adjustment_changed_connection.disconnect(); _adjustment_value_changed_connection.disconnect(); -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) _adjustment->unreference(); #endif } _adjustment = adjustment; - _adjustment_changed_connection = _adjustment->signal_changed().connect( - sigc::mem_fun(this, &ColorSlider::_onAdjustmentChanged)); - _adjustment_value_changed_connection = _adjustment->signal_value_changed().connect( - sigc::mem_fun(this, &ColorSlider::_onAdjustmentValueChanged)); + _adjustment_changed_connection = + _adjustment->signal_changed().connect(sigc::mem_fun(this, &ColorSlider::_onAdjustmentChanged)); + _adjustment_value_changed_connection = + _adjustment->signal_value_changed().connect(sigc::mem_fun(this, &ColorSlider::_onAdjustmentValueChanged)); _value = ColorScales::getScaled(_adjustment->gobj()); @@ -307,15 +309,14 @@ void ColorSlider::setAdjustment(Gtk::Adjustment *adjustment) { } } -void ColorSlider::_onAdjustmentChanged() { - queue_draw(); -} +void ColorSlider::_onAdjustmentChanged() { queue_draw(); } -void ColorSlider::_onAdjustmentValueChanged() { - if (_value != ColorScales::getScaled( _adjustment->gobj() )) { +void ColorSlider::_onAdjustmentValueChanged() +{ + if (_value != ColorScales::getScaled(_adjustment->gobj())) { gint cx, cy, cw, ch; -#if GTK_CHECK_VERSION(3,0,0) - Glib::RefPtrstyle_context = get_style_context(); +#if GTK_CHECK_VERSION(3, 0, 0) + Glib::RefPtr style_context = get_style_context(); Gtk::Allocation allocation = get_allocation(); Gtk::Border padding = style_context->get_padding(get_state_flags()); cx = padding.get_left(); @@ -328,24 +329,26 @@ void ColorSlider::_onAdjustmentValueChanged() { #endif cw = allocation.get_width() - 2 * cx; ch = allocation.get_height() - 2 * cy; - if ((gint) (ColorScales::getScaled( _adjustment->gobj() ) * cw) != (gint) (_value * cw)) { + if ((gint)(ColorScales::getScaled(_adjustment->gobj()) * cw) != (gint)(_value * cw)) { gint ax, ay; gfloat value; value = _value; - _value = ColorScales::getScaled( _adjustment->gobj() ); + _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() ); + } + else { + _value = ColorScales::getScaled(_adjustment->gobj()); } } } -void ColorSlider::setColors(guint32 start, guint32 mid, guint32 end) { +void ColorSlider::setColors(guint32 start, guint32 mid, guint32 end) +{ // Remove any map, if set _map = 0; @@ -367,13 +370,15 @@ void ColorSlider::setColors(guint32 start, guint32 mid, guint32 end) { queue_draw(); } -void ColorSlider::setMap(const guchar *map) { +void ColorSlider::setMap(const guchar *map) +{ _map = const_cast(map); queue_draw(); } -void ColorSlider::setBackground(guint dark, guint light, guint size) { +void ColorSlider::setBackground(guint dark, guint light, guint size) +{ _b0 = dark; _b1 = light; _bmask = size; @@ -381,12 +386,13 @@ void ColorSlider::setBackground(guint dark, guint light, guint size) { queue_draw(); } -bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { +bool ColorSlider::on_draw(const Cairo::RefPtr &cr) +{ gboolean colorsOnTop = Inkscape::Preferences::get()->getBool("/options/workarounds/colorsontop", false); Gtk::Allocation allocation = get_allocation(); -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) Glib::RefPtr style_context = get_style_context(); #else Glib::RefPtr window = get_window(); @@ -395,28 +401,25 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { // Draw shadow if (colorsOnTop) { -#if GTK_CHECK_VERSION(3,0,0) - style_context->render_frame(cr, 0, 0, - allocation.get_width(), allocation.get_height()); +#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()); + 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) +#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());; + carea.set_y(padding.get_top()); + ; #else carea.set_x(style->get_xthickness()); carea.set_y(style->get_ythickness()); @@ -430,19 +433,18 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { 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); + 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 pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB, - false, 8, carea.get_width(), carea.get_height(), carea.get_width() * 3); + Glib::RefPtr 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 { + } + else { gint c[4], dc[4]; /* Render gradient */ @@ -451,16 +453,15 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { 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); + 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); + 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 pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB, - false, 8, wi, carea.get_height(), wi * 3); + Glib::RefPtr 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(); @@ -471,37 +472,32 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { 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); + 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); + 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 pb = Gdk::Pixbuf::create_from_data(b, Gdk::COLORSPACE_RGB, - false, 8, wi, carea.get_height(), wi * 3); + Glib::RefPtr 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()); + 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()); + /* 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()); + 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()); @@ -510,16 +506,16 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { 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); + 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); + 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); @@ -530,111 +526,108 @@ bool ColorSlider::on_draw(const Cairo::RefPtr& cr) { return false; } -}//namespace Widget -}//namespace UI -}//namespace Inkscape +} // 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 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; + 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 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; -} + 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 index 2f2e7b2db..253f3123c 100644 --- a/src/ui/widget/color-slider.h +++ b/src/ui/widget/color-slider.h @@ -15,26 +15,23 @@ #include #include -namespace Inkscape -{ -namespace UI -{ -namespace Widget -{ +namespace Inkscape { +namespace UI { +namespace Widget { /* * A slider with colored background */ -class ColorSlider: public Gtk::Widget { +class ColorSlider : public Gtk::Widget { public: -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) ColorSlider(Glib::RefPtr adjustment); #else ColorSlider(Gtk::Adjustment *adjustment); #endif ~ColorSlider(); -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) void setAdjustment(Glib::RefPtr adjustment); #else void setAdjustment(Gtk::Adjustment *adjustment); @@ -42,7 +39,7 @@ public: void setColors(guint32 start, guint32 mid, guint32 end); - void setMap(const guchar* map); + void setMap(const guchar *map); void setBackground(guint dark, guint light, guint size); @@ -52,22 +49,22 @@ public: sigc::signal signal_value_changed; protected: - void on_size_allocate(Gtk::Allocation& allocation); + 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& cr); + bool on_draw(const Cairo::RefPtr &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; +#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); + void on_size_request(Gtk::Requisition *requisition); + bool on_expose_event(GdkEventExpose *event); #endif private: @@ -76,7 +73,7 @@ private: bool _dragging; -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) Glib::RefPtr _adjustment; #else Gtk::Adjustment *_adjustment; @@ -96,9 +93,9 @@ private: Glib::RefPtr _gdk_window; }; -}//namespace Widget -}//namespace UI -}//namespace Inkscape +} // namespace Widget +} // namespace UI +} // namespace Inkscape #endif /* diff --git a/src/ui/widget/color-wheel-selector.cpp b/src/ui/widget/color-wheel-selector.cpp index e00fb2fab..8c6402d90 100644 --- a/src/ui/widget/color-wheel-selector.cpp +++ b/src/ui/widget/color-wheel-selector.cpp @@ -1,5 +1,5 @@ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include "color-wheel-selector.h" @@ -26,17 +26,17 @@ namespace Widget { #define YPAD 1 -const gchar* ColorWheelSelector::MODE_NAME = N_("Wheel"); +const gchar *ColorWheelSelector::MODE_NAME = N_("Wheel"); ColorWheelSelector::ColorWheelSelector(SelectedColor &color) -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : Gtk::Grid() #else : Gtk::Table(5, 3, false) #endif , _color(color) , _updating(false) -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) , _alpha_adjustment(NULL) #endif , _wheel(0) @@ -45,13 +45,12 @@ ColorWheelSelector::ColorWheelSelector(SelectedColor &color) _initUI(); _color_changed_connection = color.signal_changed.connect(sigc::mem_fun(this, &ColorWheelSelector::_colorChanged)); _color_dragged_connection = color.signal_dragged.connect(sigc::mem_fun(this, &ColorWheelSelector::_colorChanged)); - } ColorWheelSelector::~ColorWheelSelector() { _wheel = 0; -#if !GTK_CHECK_VERSION(3,0,0) +#if !GTK_CHECK_VERSION(3, 0, 0) delete _alpha_adjustment; #endif @@ -59,32 +58,34 @@ ColorWheelSelector::~ColorWheelSelector() _color_dragged_connection.disconnect(); } -void ColorWheelSelector::_initUI() { +void ColorWheelSelector::_initUI() +{ /* Create components */ gint row = 0; _wheel = gimp_color_wheel_new(); - gtk_widget_show( _wheel ); + gtk_widget_show(_wheel); -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) 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); #else - gtk_table_attach(GTK_TABLE(gobj()), _wheel, 0, 3, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); + gtk_table_attach(GTK_TABLE(gobj()), _wheel, 0, 3, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); #endif row++; /* Label */ - Gtk::Label* label = Gtk::manage(new Gtk::Label(_("_A:"), true)); + Gtk::Label *label = Gtk::manage(new Gtk::Label(_("_A:"), true)); label->set_alignment(1.0, 0.5); label->show(); -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) label->set_margin_start(XPAD); label->set_margin_end(XPAD); #else @@ -100,8 +101,8 @@ void ColorWheelSelector::_initUI() { attach(*label, 0, 1, row, row + 1, Gtk::FILL, Gtk::FILL, XPAD, YPAD); #endif - /* Adjustment */ -#if GTK_CHECK_VERSION(3,0,0) +/* Adjustment */ +#if GTK_CHECK_VERSION(3, 0, 0) _alpha_adjustment = Gtk::Adjustment::create(0.0, 0.0, 255.0, 1.0, 10.0, 10.0); #else _alpha_adjustment = new Gtk::Adjustment(0.0, 0.0, 255.0, 1.0, 10.0, 10.0); @@ -111,8 +112,8 @@ void ColorWheelSelector::_initUI() { _slider->set_tooltip_text(_("Alpha (opacity)")); _slider->show(); -#if GTK_CHECK_VERSION(3,0,0) - #if GTK_CHECK_VERSION(3,12,0) +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) _slider->set_margin_start(XPAD); _slider->set_margin_end(XPAD); #else @@ -126,26 +127,25 @@ void ColorWheelSelector::_initUI() { _slider->set_valign(Gtk::ALIGN_FILL); attach(*_slider, 1, row, 1, 1); #else - attach(*_slider, 1, 2, row, row+1, Gtk::EXPAND | Gtk::FILL, Gtk::FILL, XPAD, YPAD); + attach(*_slider, 1, 2, row, row + 1, Gtk::EXPAND | Gtk::FILL, Gtk::FILL, XPAD, YPAD); #endif - _slider->setColors(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->setColors(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 */ -#if GTK_CHECK_VERSION(3,0,0) - Gtk::SpinButton* spin_button = Gtk::manage(new Gtk::SpinButton(_alpha_adjustment, 1.0, 0)); - #else - Gtk::SpinButton* spin_button = Gtk::manage(new Gtk::SpinButton(*_alpha_adjustment, 1.0, 0)); +/* Spinbutton */ +#if GTK_CHECK_VERSION(3, 0, 0) + Gtk::SpinButton *spin_button = Gtk::manage(new Gtk::SpinButton(_alpha_adjustment, 1.0, 0)); +#else + Gtk::SpinButton *spin_button = Gtk::manage(new Gtk::SpinButton(*_alpha_adjustment, 1.0, 0)); #endif 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,0,0) - #if GTK_CHECK_VERSION(3,12,0) +#if GTK_CHECK_VERSION(3, 0, 0) + #if GTK_CHECK_VERSION(3, 12, 0) spin_button->set_margin_start(XPAD); spin_button->set_margin_end(XPAD); #else @@ -167,27 +167,27 @@ void ColorWheelSelector::_initUI() { _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), this ); + g_signal_connect(G_OBJECT(_wheel), "changed", G_CALLBACK(_wheelChanged), this); } void ColorWheelSelector::_colorChanged() { #ifdef DUMP_CHANGE_INFO - g_message("ColorWheelSelector::_colorChanged( this=%p, %f, %f, %f, %f)", this, _color.color().v.c[0], _color.color().v.c[1], _color.color().v.c[2], alpha ); + g_message("ColorWheelSelector::_colorChanged( this=%p, %f, %f, %f, %f)", this, _color.color().v.c[0], + _color.color().v.c[1], _color.color().v.c[2], alpha); #endif bool oldval = _updating; _updating = true; { - float hsv[3] = {0,0,0}; + float hsv[3] = { 0, 0, 0 }; sp_color_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] ); + gimp_color_wheel_set_color(GIMP_COLOR_WHEEL(_wheel), hsv[0], hsv[1], hsv[2]); } - guint32 start = _color.color().toRGBA32( 0x00 ); - guint32 mid = _color.color().toRGBA32( 0x7f ); - guint32 end = _color.color().toRGBA32( 0xff ); + guint32 start = _color.color().toRGBA32(0x00); + guint32 mid = _color.color().toRGBA32(0x7f); + guint32 end = _color.color().toRGBA32(0xff); _slider->setColors(start, mid, end); @@ -238,23 +238,23 @@ void ColorWheelSelector::_sliderChanged() void ColorWheelSelector::_wheelChanged(GimpColorWheel *wheel, ColorWheelSelector *wheelSelector) { - if (wheelSelector->_updating){ + if (wheelSelector->_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}; - sp_color_hsv_to_rgb_floatv (rgb, h, s, v); + gimp_color_wheel_get_color(wheel, &h, &s, &v); + + float rgb[3] = { 0, 0, 0 }; + sp_color_hsv_to_rgb_floatv(rgb, h, s, v); SPColor color(rgb[0], rgb[1], rgb[2]); - guint32 start = color.toRGBA32( 0x00 ); - guint32 mid = color.toRGBA32( 0x7f ); - guint32 end = color.toRGBA32( 0xff ); + guint32 start = color.toRGBA32(0x00); + guint32 mid = color.toRGBA32(0x7f); + guint32 end = color.toRGBA32(0xff); wheelSelector->_slider->setColors(start, mid, end); @@ -265,15 +265,13 @@ void ColorWheelSelector::_wheelChanged(GimpColorWheel *wheel, ColorWheelSelector } -Gtk::Widget *ColorWheelSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const { +Gtk::Widget *ColorWheelSelectorFactory::createWidget(Inkscape::UI::SelectedColor &color) const +{ Gtk::Widget *w = Gtk::manage(new ColorWheelSelector(color)); return w; } -Glib::ustring ColorWheelSelectorFactory::modeName() const { - return gettext(ColorWheelSelector::MODE_NAME); -} - +Glib::ustring ColorWheelSelectorFactory::modeName() const { return gettext(ColorWheelSelector::MODE_NAME); } } } } diff --git a/src/ui/widget/color-wheel-selector.h b/src/ui/widget/color-wheel-selector.h index ec30cc7c5..f97f70f6a 100644 --- a/src/ui/widget/color-wheel-selector.h +++ b/src/ui/widget/color-wheel-selector.h @@ -13,7 +13,7 @@ #define SEEN_SP_COLOR_WHEEL_SELECTOR_H #ifdef HAVE_CONFIG_H -# include +#include #endif #if WITH_GTKMM_3_0 @@ -33,14 +33,14 @@ namespace Widget { class ColorSlider; class ColorWheelSelector -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) : public Gtk::Grid #else : public Gtk::Table #endif { public: - static const gchar* MODE_NAME; + static const gchar *MODE_NAME; ColorWheelSelector(SelectedColor &color); virtual ~ColorWheelSelector(); @@ -59,30 +59,28 @@ protected: SelectedColor &_color; bool _updating; -#if GTK_CHECK_VERSION(3,0,0) +#if GTK_CHECK_VERSION(3, 0, 0) Glib::RefPtr _alpha_adjustment; #else - Gtk::Adjustment* _alpha_adjustment; + Gtk::Adjustment *_alpha_adjustment; #endif - GtkWidget* _wheel; - Inkscape::UI::Widget::ColorSlider* _slider; + GtkWidget *_wheel; + Inkscape::UI::Widget::ColorSlider *_slider; private: // By default, disallow copy constructor and assignment operator - ColorWheelSelector( const ColorWheelSelector& obj ); - ColorWheelSelector& operator=( const ColorWheelSelector& obj ); + ColorWheelSelector(const ColorWheelSelector &obj); + ColorWheelSelector &operator=(const ColorWheelSelector &obj); sigc::connection _color_changed_connection; sigc::connection _color_dragged_connection; }; - -class ColorWheelSelectorFactory: public ColorSelectorFactory { +class ColorWheelSelectorFactory : public ColorSelectorFactory { public: Gtk::Widget *createWidget(SelectedColor &color) const; Glib::ustring modeName() const; }; - } } } -- cgit v1.2.3