Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Colors::ColorSet Class Reference

#include <color-set.h>

Public Member Functions

 ColorSet (std::shared_ptr< Space::AnySpace > space={}, std::optional< bool > alpha={})
 Construct a new ColorSet object to contain a group of colors which will be modified collectively.
 
 ColorSet (ColorSet const &obj)=delete
 
IdColors::const_iterator begin () const
 
IdColors::const_iterator end () const
 
IdColors::iterator begin ()
 
IdColors::iterator end ()
 
bool isBlocked () const
 
bool isGrabbed () const
 
void grab ()
 Set this color to being grabbed for a continuous set of changes.
 
void release ()
 Set the color as being released from continuous changes.
 
void block ()
 
void unblock ()
 
Space::Components const & getComponents () const
 Get a list of components for the color space set to this color set.
 
std::shared_ptr< Space::AnySpace > const getSpaceConstraint () const
 
std::optional< bool > const getAlphaConstraint () const
 
bool set (Color const &color)
 Remove any other colors and set to just this one color.
 
std::optional< Colorget () const
 Get the color if there is only one color set with set(Color)
 
void clear ()
 Reset the color set and remove all colors from it.
 
std::optional< Colorget (std::string const &id) const
 Return a single color by it's index.
 
bool set (std::string id, Color const &color)
 Set a single color in the color set by its id.
 
unsigned setAll (ColorSet const &other)
 Set each of the colors from the other color set by id.
 
unsigned setAll (Color const &other)
 Overwrite all colors so they equal the the new color.
 
unsigned setAll (Space::Component const &c, double value)
 Set this one component to this specific value for all colors.
 
std::vector< double > getAll (Space::Component const &c) const
 Get a list of all normalized values for this one component.
 
void setAverage (Space::Component const &c, double value)
 Set the average value in this component by taking the average finding the delta and moving all colors by the given delta.
 
double getAverage (Space::Component const &c) const
 Get the average value for this component across all colors.
 
Color getAverage () const
 Return the average color between this set of colors.
 
unsigned size () const
 Return the number of items in the color set.
 
bool isEmpty () const
 
bool isSame () const
 Returns true if all of the colors are the same color.
 
std::shared_ptr< Space::AnySpacegetBestSpace () const
 Return the best color space from this collection of colors.
 
bool isValid (const Space::Component &component) const
 

Public Attributes

sigc::signal< void()> signal_grabbed
 
sigc::signal< void()> signal_released
 
sigc::signal< void()> signal_changed
 
sigc::signal< void()> signal_cleared
 

Private Member Functions

bool _set (std::string id, Color const &color)
 
void colors_changed ()
 Called when the colors change in some way.
 
void colors_cleared ()
 Called when the list of colors changes (add or clear)
 

Private Attributes

IdColors _colors
 
std::shared_ptr< Space::AnySpace > const _space_constraint
 
std::optional< bool > const _alpha_constraint
 
bool _grabbed = false
 
bool _blocked = false
 

Detailed Description

Definition at line 29 of file color-set.h.

Constructor & Destructor Documentation

◆ ColorSet() [1/2]

Inkscape::Colors::ColorSet::ColorSet ( std::shared_ptr< Space::AnySpace space = {},
std::optional< bool >  alpha = {} 
)

Construct a new ColorSet object to contain a group of colors which will be modified collectively.

  • space - optionally contrain each color added to be in this color space
  • alpha - optionally contrain each color to have or not have an alpha channel

Definition at line 26 of file color-set.cpp.

◆ ColorSet() [2/2]

Inkscape::Colors::ColorSet::ColorSet ( ColorSet const &  obj)
delete

Member Function Documentation

◆ _set()

bool Inkscape::Colors::ColorSet::_set ( std::string  id,
Color const &  color 
)
private

Definition at line 203 of file color-set.cpp.

References _alpha_constraint, _colors, and _space_constraint.

Referenced by set(), and setAll().

◆ begin() [1/2]

IdColors::iterator Inkscape::Colors::ColorSet::begin ( )
inline

Definition at line 39 of file color-set.h.

References _colors.

◆ begin() [2/2]

IdColors::const_iterator Inkscape::Colors::ColorSet::begin ( ) const
inline

Definition at line 37 of file color-set.h.

References _colors.

◆ block()

void Inkscape::Colors::ColorSet::block ( )
inline

Definition at line 53 of file color-set.h.

References _blocked.

Referenced by colors_changed(), colors_cleared(), grab(), and release().

◆ clear()

void Inkscape::Colors::ColorSet::clear ( )

Reset the color set and remove all colors from it.

Definition at line 44 of file color-set.cpp.

References _colors, and colors_cleared().

◆ colors_changed()

void Inkscape::Colors::ColorSet::colors_changed ( )
private

Called when the colors change in some way.

Definition at line 81 of file color-set.cpp.

References _blocked, block(), signal_changed, and unblock().

Referenced by set(), setAll(), setAll(), setAll(), and setAverage().

◆ colors_cleared()

void Inkscape::Colors::ColorSet::colors_cleared ( )
private

Called when the list of colors changes (add or clear)

Definition at line 94 of file color-set.cpp.

References _blocked, block(), signal_cleared, and unblock().

Referenced by clear().

◆ end() [1/2]

IdColors::iterator Inkscape::Colors::ColorSet::end ( )
inline

Definition at line 40 of file color-set.h.

References _colors.

◆ end() [2/2]

IdColors::const_iterator Inkscape::Colors::ColorSet::end ( ) const
inline

Definition at line 38 of file color-set.h.

References _colors.

◆ get() [1/2]

std::optional< Color > Inkscape::Colors::ColorSet::get ( ) const

Get the color if there is only one color set with set(Color)

Returns
the available color, normalized

Definition at line 195 of file color-set.cpp.

References get().

Referenced by get().

◆ get() [2/2]

std::optional< Color > Inkscape::Colors::ColorSet::get ( std::string const &  id) const

Return a single color by it's index.

The color will be normalized before returning a copy as some functions can modify colors out of bounds.

Returns
a normalized color object from the given index or none if the id is not found.

Definition at line 236 of file color-set.cpp.

References _colors.

◆ getAll()

std::vector< double > Inkscape::Colors::ColorSet::getAll ( Space::Component const &  c) const

Get a list of all normalized values for this one component.

  • c - The component to collect all the values for.
Returns
a list of normalized values in this component.

Definition at line 318 of file color-set.cpp.

References _colors, c, and isValid().

◆ getAlphaConstraint()

std::optional< bool > const Inkscape::Colors::ColorSet::getAlphaConstraint ( ) const
inline

Definition at line 59 of file color-set.h.

References _alpha_constraint.

◆ getAverage() [1/2]

Color Inkscape::Colors::ColorSet::getAverage ( ) const

Return the average color between this set of colors.

If space is not constrained, it will return the average in the best color space. If alpha is not constrained, the average will always include an alpha channel

Definition at line 361 of file color-set.cpp.

References _alpha_constraint, _colors, getBestSpace(), and isEmpty().

Referenced by setAverage().

◆ getAverage() [2/2]

double Inkscape::Colors::ColorSet::getAverage ( Space::Component const &  c) const

Get the average value for this component across all colors.

  • c - The component to get the average for
Returns
the normalized average value for all colors in this set.

Definition at line 300 of file color-set.cpp.

References _colors, c, and isValid().

Referenced by GrDrag::getColor().

◆ getBestSpace()

std::shared_ptr< Space::AnySpace > Inkscape::Colors::ColorSet::getBestSpace ( ) const

Return the best color space from this collection of colors.

If the color space is constrained then the result will be that space. Otherwise picks the space with the most colors.

Definition at line 334 of file color-set.cpp.

References _colors, and _space_constraint.

Referenced by getAverage().

◆ getComponents()

Space::Components const & Inkscape::Colors::ColorSet::getComponents ( ) const

Get a list of components for the color space set to this color set.

Definition at line 34 of file color-set.cpp.

References _alpha_constraint, and _space_constraint.

◆ getSpaceConstraint()

std::shared_ptr< Space::AnySpace > const Inkscape::Colors::ColorSet::getSpaceConstraint ( ) const
inline

Definition at line 58 of file color-set.h.

References _space_constraint.

◆ grab()

void Inkscape::Colors::ColorSet::grab ( )

Set this color to being grabbed for a continuous set of changes.

Definition at line 55 of file color-set.cpp.

References _blocked, _grabbed, block(), signal_grabbed, and unblock().

◆ isBlocked()

bool Inkscape::Colors::ColorSet::isBlocked ( ) const
inline

Definition at line 43 of file color-set.h.

References _blocked.

◆ isEmpty()

bool Inkscape::Colors::ColorSet::isEmpty ( ) const
inline

Definition at line 84 of file color-set.h.

References _colors.

Referenced by getAverage().

◆ isGrabbed()

bool Inkscape::Colors::ColorSet::isGrabbed ( ) const
inline

Definition at line 44 of file color-set.h.

References _grabbed.

◆ isSame()

bool Inkscape::Colors::ColorSet::isSame ( ) const

Returns true if all of the colors are the same color.

Definition at line 106 of file color-set.cpp.

References _colors.

◆ isValid()

bool Inkscape::Colors::ColorSet::isValid ( const Space::Component component) const

Definition at line 351 of file color-set.cpp.

References _space_constraint, and Inkscape::Colors::Space::Component::type.

Referenced by getAll(), getAverage(), and setAll().

◆ release()

void Inkscape::Colors::ColorSet::release ( )

Set the color as being released from continuous changes.

Definition at line 68 of file color-set.cpp.

References _blocked, _grabbed, block(), signal_released, and unblock().

◆ set() [1/2]

bool Inkscape::Colors::ColorSet::set ( Color const &  other)

Remove any other colors and set to just this one color.

  • color - The color to set this color-set to.
Returns
true if the color was new or changed.

Definition at line 182 of file color-set.cpp.

References _colors, and set.

Referenced by Inkscape::UI::Dialog::collect_object_colors(), and GrDrag::getColor().

◆ set() [2/2]

bool Inkscape::Colors::ColorSet::set ( std::string  id,
Color const &  other 
)

Set a single color in the color set by its id.

  • id - The id to use, if this id isn't set a new item is created.
  • other - The other color to replace all colors in this set with.
Returns
true if this color was changed.

Definition at line 166 of file color-set.cpp.

References _set(), and colors_changed().

◆ setAll() [1/3]

unsigned Inkscape::Colors::ColorSet::setAll ( Color const &  other)

Overwrite all colors so they equal the the new color.

  • other - The other color to replace all colors in this set with.
Returns
the number of colors changed.

Definition at line 124 of file color-set.cpp.

References _colors, and colors_changed().

◆ setAll() [2/3]

unsigned Inkscape::Colors::ColorSet::setAll ( ColorSet const &  other)

Set each of the colors from the other color set by id.

Creating new entries where the id is not found.

  • other - The other color set to find colors from.
Returns
the number of colors changed or added

Definition at line 146 of file color-set.cpp.

References _set(), and colors_changed().

◆ setAll() [3/3]

unsigned Inkscape::Colors::ColorSet::setAll ( Space::Component const &  c,
double  value 
)

Set this one component to this specific value for all colors.

  • index - The index to replace, will cause an error if out of bounds.
  • other - The other color to replace all colors in this set with.
Returns
the number of colors changed.

Definition at line 253 of file color-set.cpp.

References _colors, c, colors_changed(), and isValid().

◆ setAverage()

void Inkscape::Colors::ColorSet::setAverage ( Space::Component const &  c,
double  value 
)

Set the average value in this component by taking the average finding the delta and moving all colors by the given delta.

This will not run normalization so out of bound changes can remember their values until the mutation period is finished and normalization is run on the returned colors. see ColorSet::get().

  • c - The component to change the average for
  • value - The new average value that the set will calculate to

Definition at line 282 of file color-set.cpp.

References _colors, _space_constraint, c, colors_changed(), delta, and getAverage().

◆ size()

unsigned Inkscape::Colors::ColorSet::size ( ) const

Return the number of items in the color set.

Definition at line 392 of file color-set.cpp.

References _colors.

◆ unblock()

void Inkscape::Colors::ColorSet::unblock ( )
inline

Definition at line 54 of file color-set.h.

References _blocked.

Referenced by colors_changed(), colors_cleared(), grab(), and release().

Member Data Documentation

◆ _alpha_constraint

std::optional<bool> const Inkscape::Colors::ColorSet::_alpha_constraint
private

Definition at line 98 of file color-set.h.

Referenced by _set(), getAlphaConstraint(), getAverage(), and getComponents().

◆ _blocked

bool Inkscape::Colors::ColorSet::_blocked = false
private

Definition at line 102 of file color-set.h.

Referenced by block(), colors_changed(), colors_cleared(), grab(), isBlocked(), release(), and unblock().

◆ _colors

IdColors Inkscape::Colors::ColorSet::_colors
private

◆ _grabbed

bool Inkscape::Colors::ColorSet::_grabbed = false
private

Definition at line 101 of file color-set.h.

Referenced by grab(), isGrabbed(), and release().

◆ _space_constraint

std::shared_ptr<Space::AnySpace> const Inkscape::Colors::ColorSet::_space_constraint
private

Definition at line 97 of file color-set.h.

Referenced by _set(), getBestSpace(), getComponents(), getSpaceConstraint(), isValid(), and setAverage().

◆ signal_changed

sigc::signal<void()> Inkscape::Colors::ColorSet::signal_changed

Definition at line 48 of file color-set.h.

Referenced by colors_changed().

◆ signal_cleared

sigc::signal<void()> Inkscape::Colors::ColorSet::signal_cleared

Definition at line 49 of file color-set.h.

Referenced by colors_cleared().

◆ signal_grabbed

sigc::signal<void()> Inkscape::Colors::ColorSet::signal_grabbed

Definition at line 46 of file color-set.h.

Referenced by grab().

◆ signal_released

sigc::signal<void()> Inkscape::Colors::ColorSet::signal_released

Definition at line 47 of file color-set.h.

Referenced by release().


The documentation for this class was generated from the following files: