From 51eab9e9fdc5a520f91cb90ba101cedd62fd3eb4 Mon Sep 17 00:00:00 2001 From: Tomasz Boczkowski Date: Thu, 29 May 2014 18:21:29 +0200 Subject: SPColorSelector c++-sification: added SelectedColor class (bzr r13341.6.26) --- src/ui/selected-color.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++ src/ui/selected-color.h | 55 ++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/ui/selected-color.cpp create mode 100644 src/ui/selected-color.h (limited to 'src') 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 + * Jon A. Cruz + * Tomasz Boczkowski + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#include +#include + +#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():""), 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 + * Jon A. Cruz + * Tomasz Boczkowski + * + * Copyright (C) 2014 Authors + * Released under GNU GPL, read the file 'COPYING' for more information + */ +#ifndef SEEN_SELECTED_COLOR +#define SEEN_SELECTED_COLOR + +#include +#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 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 + -- cgit v1.2.3