diff options
| author | Tomasz Boczkowski <penginsbacon@gmail.com> | 2014-05-29 16:21:29 +0000 |
|---|---|---|
| committer | Tomasz Boczkowski <penginsbacon@gmail.com> | 2014-05-29 16:21:29 +0000 |
| commit | 51eab9e9fdc5a520f91cb90ba101cedd62fd3eb4 (patch) | |
| tree | 8f59e6692b60687b777426dc892beba00023b64c /src/ui | |
| parent | SPColorSelector c++-sification: added SelectedColor class (diff) | |
| download | inkscape-51eab9e9fdc5a520f91cb90ba101cedd62fd3eb4.tar.gz inkscape-51eab9e9fdc5a520f91cb90ba101cedd62fd3eb4.zip | |
SPColorSelector c++-sification: added SelectedColor class
(bzr r13341.6.26)
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/selected-color.cpp | 92 | ||||
| -rw-r--r-- | src/ui/selected-color.h | 55 |
2 files changed, 147 insertions, 0 deletions
diff --git a/src/ui/selected-color.cpp b/src/ui/selected-color.cpp new file mode 100644 index 000000000..246c51ebd --- /dev/null +++ b/src/ui/selected-color.cpp @@ -0,0 +1,92 @@ +/** @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 + */ +#include <cmath> +#include <glib.h> + +#include "selected-color.h" + +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..f7f0d6ad0 --- /dev/null +++ b/src/ui/selected-color.h @@ -0,0 +1,55 @@ +/** @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 "color.h" + +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; +}; + +#endif + |
