Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
color-set.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Copyright (C) 2024 Authors
6 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
7 */
8#ifndef SEEN_COLORS_COLOR_SET
9#define SEEN_COLORS_COLOR_SET
10
11#include <memory>
12#include <optional>
13#include <sigc++/signal.h>
14#include <vector>
15
16#include "colors/color.h"
17#include <sigc++/scoped_connection.h>
18
19namespace Inkscape::Colors {
20class Color;
21namespace Space {
22class AnySpace;
23class Components;
24class Component;
25} // namespace Space
26
27using IdColors = std::vector<std::pair<std::string, Color>>;
28
30{
31public:
32 ColorSet(std::shared_ptr<Space::AnySpace> space = {}, std::optional<bool> alpha = {});
33
34 // By default, disallow copy constructor
35 ColorSet(ColorSet const &obj) = delete;
36
37 IdColors::const_iterator begin() const { return std::begin(_colors); }
38 IdColors::const_iterator end() const { return std::end(_colors); }
39 IdColors::iterator begin() { return std::begin(_colors); }
40 IdColors::iterator end() { return std::end(_colors); }
41
42 // Signals allow the set to be tied into various interfaces
43 bool isBlocked() const { return _blocked; }
44 bool isGrabbed() const { return _grabbed; }
45
46 sigc::signal<void()> signal_grabbed;
47 sigc::signal<void()> signal_released;
48 sigc::signal<void()> signal_changed;
49 sigc::signal<void()> signal_cleared;
50
51 void grab();
52 void release();
53 void block() { _blocked = true; }
54 void unblock() { _blocked = false; }
55
56 // Information about the color set's meta data
57 Space::Components const &getComponents() const;
58 std::shared_ptr<Space::AnySpace> const getSpaceConstraint() const { return _space_constraint; }
59 std::optional<bool> const getAlphaConstraint() const { return _alpha_constraint; }
60
61 // Set and get a single color (i.e. not a list of colors)
62 bool set(Color const &color);
63 std::optional<Color> get() const;
64 void clear();
65
66 // Control the list of colors by id
67 std::optional<Color> get(std::string const &id) const;
68 bool set(std::string id, Color const &color);
69
70 // Change the colors in some way and send signals
71 unsigned setAll(ColorSet const &other);
72 unsigned setAll(Color const &other);
73 unsigned setAll(Space::Component const &c, double value);
74 std::vector<double> getAll(Space::Component const &c) const;
75
76 // Set and get specific color components
77 void setAverage(Space::Component const &c, double value);
78 double getAverage(Space::Component const &c) const;
79 Color getAverage() const;
80
81 // Ask for information about the whole set of colors
82 unsigned size() const;
83
84 bool isEmpty() const { return _colors.empty(); }
85 bool isSame() const;
86 std::shared_ptr<Space::AnySpace> getBestSpace() const;
87
88 bool isValid(const Space::Component& component) const;
89private:
90 bool _set(std::string id, Color const &color);
91 void colors_changed();
92 void colors_cleared();
93
95
96 // Constraints can only be set up at construction so are immutable.
97 std::shared_ptr<Space::AnySpace> const _space_constraint;
98 std::optional<bool> const _alpha_constraint;
99
100 // States which are set during the lifetime of the set
101 bool _grabbed = false;
102 bool _blocked = false;
103};
104
105} // namespace Inkscape::Colors
106
107#endif
108/*
109 Local Variables:
110 mode:c++
111 c-file-style:"stroustrup"
112 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
113 indent-tabs-mode:nil
114 fill-column:99
115 End:
116*/
117// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
uint32_t Color
IdColors::iterator begin()
Definition color-set.h:39
Space::Components const & getComponents() const
Get a list of components for the color space set to this color set.
Definition color-set.cpp:34
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.
Definition color-set.cpp:55
std::optional< bool > const _alpha_constraint
Definition color-set.h:98
sigc::signal< void()> signal_grabbed
Definition color-set.h:46
sigc::signal< void()> signal_released
Definition color-set.h:47
IdColors::const_iterator end() const
Definition color-set.h:38
sigc::signal< void()> signal_changed
Definition color-set.h:48
void clear()
Reset the color set and remove all colors from it.
Definition color-set.cpp:44
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.
IdColors::iterator end()
Definition color-set.h:40
std::shared_ptr< Space::AnySpace > const getSpaceConstraint() const
Definition color-set.h:58
void colors_changed()
Called when the colors change in some way.
Definition color-set.cpp:81
void release()
Set the color as being released from continuous changes.
Definition color-set.cpp:68
void colors_cleared()
Called when the list of colors changes (add or clear)
Definition color-set.cpp:94
std::shared_ptr< Space::AnySpace > getBestSpace() const
Return the best color space from this collection of colors.
ColorSet(ColorSet const &obj)=delete
bool _set(std::string id, Color const &color)
IdColors::const_iterator begin() const
Definition color-set.h:37
std::shared_ptr< Space::AnySpace > const _space_constraint
Definition color-set.h:97
Color getAverage() const
Return the average color between this set of colors.
sigc::signal< void()> signal_cleared
Definition color-set.h:49
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.
std::optional< bool > const getAlphaConstraint() const
Definition color-set.h:59
double c[8][4]
A set of useful color modifying functions which do not fit as generic methods on the color class itse...
Definition profile.cpp:24
std::vector< std::pair< std::string, Color > > IdColors
Definition color-set.h:27