/*
5 * Copyright (C) 2024 Authors
6 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
27 : _space_constraint(
std::move(space))
28 , _alpha_constraint(alpha)
37 throw ColorError(
"Components are only available on a color space constrained ColorSet.");
110 for (
auto const &[
id, color] :
_colors) {
111 if (color !=
_colors[0].second)
126 unsigned changed = 0;
127 for (
auto &[
id, color] :
_colors) {
129 color.set(other,
true);
131 changed += (was != color);
148 unsigned changed = 0;
149 for (
auto &[
id, color] : other) {
150 changed +=
_set(
id, color);
168 if (
_set(std::move(
id), other)) {
187 return set(
"single", other);
197 return get(
"single");
205 for (
auto &[cid, color] :
_colors) {
208 color.set(other,
true);
223 _colors.emplace_back(std::move(
id), copy);
238 for (
auto &[cid, color] :
_colors) {
240 return color.normalized();
256 throw ColorError(
"Incompatible color component used in ColorSet::set.");
258 unsigned changed = 0;
259 for (
auto &[
id, color] :
_colors) {
261 color.set(
c.index, value);
263 changed += (was != color);
285 throw ColorError(
"Incompatible color component used in ColorSet::moveAverageTo.");
287 for (
auto &[
id, color] :
_colors) {
288 color.set(
c.index, color[
c.index] +
delta);
302 throw ColorError(
"Incompatible color component used in ColorSet::get.");
305 for (
auto const &[
id, color] :
_colors) {
306 value += color[
c.index];
308 return c.normalize(value /
_colors.size());
321 throw ColorError(
"Incompatible color component used in ColorSet::getAll.");
323 std::vector<double> ret(
_colors.size());
325 [
c](
auto &iter) { return c.normalize(iter.second[c.index]); });
339 unsigned biggest = 0;
340 std::shared_ptr<Space::AnySpace> ret;
341 std::map<std::shared_ptr<Space::AnySpace>,
unsigned> counts;
342 for (
auto const &[
id, color] :
_colors) {
343 if (++counts[color.getSpace()] > biggest) {
344 biggest = counts[color.getSpace()];
345 ret = color.getSpace();
364 throw ColorError(
"Can't get the average color of no colors.");
369 std::vector<double> values(avg_space->getComponentCount() + avg_alpha);
371 for (
auto const &[
id, color] :
_colors) {
373 if (color.getSpace() == avg_space) {
374 for (
unsigned int i = 0; i < values.size(); i++) {
375 values[i] += color[i];
377 }
else if (
auto copy = color.converted(avg_space)) {
378 for (
unsigned int i = 0; i < values.size(); i++) {
379 values[i] += (*copy)[i];
383 for (
double &value : values) {
386 return Color(avg_space, values);
Space::Components const & getComponents() const
Get a list of components for the color space set to this color set.
std::vector< double > getAll(Space::Component const &c) const
Get a list of all normalized values for this one component.
void grab()
Set this color to being grabbed for a continuous set of changes.
std::optional< bool > const _alpha_constraint
bool set(Color const &color)
Remove any other colors and set to just this one color.
sigc::signal< void()> signal_grabbed
sigc::signal< void()> signal_released
sigc::signal< void()> signal_changed
void clear()
Reset the color set and remove all colors from it.
unsigned size() const
Return the number of items in the color set.
std::optional< Color > get() const
Get the color if there is only one color set with set(Color)
unsigned setAll(ColorSet const &other)
Set each of the colors from the other color set by id.
void colors_changed()
Called when the colors change in some way.
void release()
Set the color as being released from continuous changes.
void colors_cleared()
Called when the list of colors changes (add or clear)
std::shared_ptr< Space::AnySpace > getBestSpace() const
Return the best color space from this collection of colors.
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.
bool _set(std::string id, Color const &color)
std::shared_ptr< Space::AnySpace > const _space_constraint
Color getAverage() const
Return the average color between this set of colors.
sigc::signal< void()> signal_cleared
bool isValid(const Space::Component &component) const
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...
bool isSame() const
Returns true if all of the colors are the same color.
A set of colors which can be modified together used for color pickers.
A set of useful color modifying functions which do not fit as generic methods on the color class itse...