diff options
| author | Tomasz Boczkowski <penginsbacon@gmail.com> | 2015-04-25 13:36:15 +0000 |
|---|---|---|
| committer | Tomasz Boczkowski <penginsbacon@gmail.com> | 2015-04-25 13:36:15 +0000 |
| commit | 29a14487f0e02a7a0e74c9f2bd02262b86c17b66 (patch) | |
| tree | f695adf494de8a1eb73f8669c0256fbd91e5aade /src/ui | |
| parent | fixed possible bug SPPattern::_get_children (diff) | |
| parent | SPColorSelector c++-sification: added ColorSelectorFactory (diff) | |
| download | inkscape-29a14487f0e02a7a0e74c9f2bd02262b86c17b66.tar.gz inkscape-29a14487f0e02a7a0e74c9f2bd02262b86c17b66.zip | |
merged SPSelected color implementation from svgpaints branch
(bzr r14059.1.4)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/ui/selected-color.cpp | 106 | ||||
| -rw-r--r-- | src/ui/selected-color.h | 71 |
3 files changed, 179 insertions, 0 deletions
diff --git a/src/ui/Makefile_insert b/src/ui/Makefile_insert index f94cba4e9..bbfdb532c 100644 --- a/src/ui/Makefile_insert +++ b/src/ui/Makefile_insert @@ -19,6 +19,8 @@ ink_common_sources += \ ui/previewfillable.h \ ui/previewholder.cpp \ ui/previewholder.h \ + ui/selected-color.h \ + ui/selected-color.cpp \ ui/shape-editor.cpp \ ui/shape-editor.h \ ui/tool-factory.cpp \ diff --git a/src/ui/selected-color.cpp b/src/ui/selected-color.cpp new file mode 100644 index 000000000..0da2139cd --- /dev/null +++ b/src/ui/selected-color.cpp @@ -0,0 +1,106 @@ +/** @file + * Color selected in color selector widget. + * This file was created during the refactoring of SPColorSelector + *//* + * Authors: + * bulia byak <buliabyak@users.sf.net> + * Jon A. Cruz <jon@joncruz.org> + * Tomasz Boczkowski <penginsbacon@gmail.com> + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#if GLIBMM_DISABLE_DEPRECATED && HAVE_GLIBMM_THREADS_H +#include <glibmm/threads.h> +#endif + +#include <cmath> +#include <glib.h> + +#include "selected-color.h" + +namespace Inkscape { +namespace UI { + +double SelectedColor::_epsilon = 1e-4; + +SelectedColor::SelectedColor() + : _color(0) + , _alpha(1.0) + , _virgin(true) +{ + +} + +SelectedColor::~SelectedColor() { + +} + +void SelectedColor::set_color(const SPColor& color) +{ + set_color_alpha( color, _alpha ); +} + +SPColor SelectedColor::get_color() const +{ + return _color; +} + +void SelectedColor::set_alpha(gfloat alpha) +{ + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); + set_color_alpha( _color, alpha ); +} + +gfloat SelectedColor::get_alpha() const +{ + return _alpha; +} + +void SelectedColor::set_color_alpha(const SPColor& color, gfloat alpha, bool emit) +{ +#ifdef DUMP_CHANGE_INFO + g_message("SelectedColor::setColorAlpha( this=%p, %f, %f, %f, %s, %f, %s) in %s", this, color.v.c[0], color.v.c[1], color.v.c[2], (color.icc?color.icc->colorProfile.c_str():"<null>"), alpha, (emit?"YES":"no"), FOO_NAME(_csel)); +#endif + g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) ); + +#ifdef DUMP_CHANGE_INFO + g_message("---- SelectedColor::setColorAlpha virgin:%s !close:%s alpha is:%s in %s", + (_virgin?"YES":"no"), + (!color.isClose( _color, _epsilon )?"YES":"no"), + ((fabs((_alpha) - (alpha)) >= _epsilon )?"YES":"no"), + FOO_NAME(_csel) + ); +#endif + + if ( _virgin || !color.isClose( _color, _epsilon ) || + (fabs((_alpha) - (alpha)) >= _epsilon )) { + + _virgin = false; + + _color = color; + _alpha = alpha; + + if (emit) { + signal_changed.emit(); + } +#ifdef DUMP_CHANGE_INFO + } else { + g_message("++++ SelectedColor::setColorAlpha color:%08x ==> _color:%08X isClose:%s in %s", color.toRGBA32(alpha), _color.toRGBA32(_alpha), + (color.isClose( _color, _epsilon )?"YES":"no"), FOO_NAME(_csel)); +#endif + } +} + +void SelectedColor::get_color_alpha(SPColor &color, gfloat &alpha) const { + color = _color; + alpha = _alpha; +} + +} +} + diff --git a/src/ui/selected-color.h b/src/ui/selected-color.h new file mode 100644 index 000000000..db2f2f68c --- /dev/null +++ b/src/ui/selected-color.h @@ -0,0 +1,71 @@ +/** @file + * Color selected in color selector widget. + * This file was created during the refactoring of SPColorSelector + *//* + * Authors: + * bulia byak <buliabyak@users.sf.net> + * Jon A. Cruz <jon@joncruz.org> + * Tomasz Boczkowski <penginsbacon@gmail.com> + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#ifndef SEEN_SELECTED_COLOR +#define SEEN_SELECTED_COLOR + +#include <sigc++/signal.h> +#include <gtkmm/widget.h> +#include "color.h" + +namespace Inkscape { +namespace UI { + +class SelectedColor { +public: + SelectedColor(); + virtual ~SelectedColor(); + + void set_color( const SPColor& color ); + SPColor get_color() const; + + void set_alpha( gfloat alpha ); + gfloat get_alpha() const; + + void set_color_alpha( const SPColor& color, gfloat alpha, bool emit = false ); + void get_color_alpha( SPColor &color, gfloat &alpha ) const; + + sigc::signal<void> signal_changed; +private: + // By default, disallow copy constructor and assignment operator + SelectedColor( const SelectedColor& obj ); + SelectedColor& operator=( const SelectedColor& obj ); + + SPColor _color; + /** + * Color alpha value guaranteed to be in [0, 1]. + */ + gfloat _alpha; + + /** + * This flag is true if no color is set yet + */ + bool _virgin; + + static double _epsilon; +}; + + +class ColorSelectorFactory { +public: + virtual ~ColorSelectorFactory() {} + + virtual Gtk::Widget* createWidget(SelectedColor& color) const = 0; + virtual Glib::ustring modeName() const = 0; +}; + + +} +} + +#endif + |
