Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
components.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Authors:
4 * Jon A. Cruz <jon@joncruz.org>
5 * Martin Owens <doctormo@geek-2.com>
6 *
7 * Copyright (C) 2013-2023 Authors
8 *
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11
12#ifndef SEEN_COLORS_COMPONENTS_H
13#define SEEN_COLORS_COMPONENTS_H
14
15#include <lcms2.h>
16#include <map>
17#include <string>
18#include <vector>
19
20#include "enum.h"
21
23
24enum class Type;
25
26enum class Traits {
27 None = 0,
28 Picker = 1, // show color picker of this type in UI
29 Internal = 2, // internal use only, has converters and tests, or is supported by CSS toString
30 CMS = 4, // CMS use only, no conversion math available
31};
32inline Traits operator & (const Traits lhs, const Traits rhs) {
33 using underlying = std::underlying_type_t<Traits>;
34 return static_cast<Traits>(static_cast<underlying>(lhs) & static_cast<underlying>(rhs));
35}
36inline Traits operator | (const Traits lhs, const Traits rhs) {
37 using underlying = std::underlying_type_t<Traits>;
38 return static_cast<Traits>(static_cast<underlying>(lhs) | static_cast<underlying>(rhs));
39}
40
41// Unit impacts component presentation in the UI and dictates what its scale is
42enum class Unit {
43 EightBit, // one byte, values from 0..255, unitless
44 Percent, // 0..100%
45 Degree, // 0..360 degree
46 Linear1024, // 0..1024 for linear RGB
47 Chroma40 // an oddball 0..40 for OkLch hue encoding
48};
49
51{
52 Component(Type type, unsigned int index, std::string id, std::string name, std::string tip, Unit unit = Unit::EightBit);
53 Component(std::string id, std::string name, std::string tip, Unit unit = Unit::EightBit);
54
56 unsigned int index;
57 std::string id;
58 std::string name;
59 std::string tip;
60 unsigned scale;
62
63 double normalize(double value) const;
64};
65
67{
68public:
69 Components() = default;
70 Components(Type type, Type wheel, Traits traits, std::vector<Component> components):
71 _type(type), _wheel_type(wheel), _components(std::move(components)), _traits(traits) {}
72
73 static Components const &get(Type type, bool alpha = false);
74
75 const std::vector<Component>& getAll() const { return _components; }
76
77 std::vector<Component>::const_iterator begin() const { return std::begin(_components); }
78 std::vector<Component>::const_iterator end() const { return std::end(_components); }
79 Component const &operator[](const unsigned int index) const { return _components[index]; }
80
81 Type getType() const { return _type; }
82 unsigned size() const { return _components.size(); }
83
84 void add(std::string id, std::string name, std::string tip, Unit unit = Unit::EightBit);
85 void setType(Type type, Type color_wheel = Type::NONE) { _type = type; _wheel_type = color_wheel; }
86 // Says which space the color wheel should be in when picking this color space
87 Type get_wheel_type() const;
88 // Trait(s) of those components
89 Traits traits() const { return _traits; }
90
91private:
93 std::vector<Component> _components;
96};
97
98} // namespace Inkscape::Colors::Space
99
100#endif // SEEN_COLORS_COMPONENTS_H
std::vector< Component >::const_iterator begin() const
Definition components.h:77
Component const & operator[](const unsigned int index) const
Definition components.h:79
std::vector< Component > _components
Definition components.h:93
void setType(Type type, Type color_wheel=Type::NONE)
Definition components.h:85
Components(Type type, Type wheel, Traits traits, std::vector< Component > components)
Definition components.h:70
const std::vector< Component > & getAll() const
Definition components.h:75
static Components const & get(Type type, bool alpha=false)
std::vector< Component >::const_iterator end() const
Definition components.h:78
Traits operator|(const Traits lhs, const Traits rhs)
Definition components.h:36
Traits operator&(const Traits lhs, const Traits rhs)
Definition components.h:32
STL namespace.
double normalize(double value) const
Clamp the value to between 0.0 and 1.0, except for hue which is wrapped around.
int index
Glib::ustring name
Definition toolbars.cpp:55