/*
5 * Authors: see git history
7 * Copyright (C) 2023 Authors
8 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
18#include <glib/gi18n.h>
19#include <glibmm/value.h>
27static const std::vector<Components> color_spaces = {
89 {
"s", _(
"_S<sub>ok</sub>"), _(
"Saturation"),
Unit::Percent },
97 {
"s", _(
"_S<sub>ok</sub>"), _(
"Saturation"),
Unit::Percent },
120 {
"l", _(
"_L<sub>ok</sub>"), _(
"Lightness"),
Unit::Percent },
121 {
"a", _(
"_A<sub>ok</sub>"), _(
"Component A"),
Unit::Percent },
122 {
"b", _(
"_B<sub>ok</sub>"), _(
"Component B"),
Unit::Percent }
128 {
"l", _(
"_L<sub>ok</sub>"), _(
"Lightness"),
Unit::Percent },
181 , tip(
std::move(tip))
201 throw std::logic_error(
"Missing case statement in Component ctor.");
215 return value - std::floor(value);
217 return std::clamp(value, 0.0, 1.0);
225std::map<Type, Components>
_build(
bool alpha)
227 std::map<Type, Components> sets;
229 unsigned int index = 0;
230 for (
auto& component : components.getAll()) {
232 auto& rw =
const_cast<Component&
>(component);
233 rw.
type = components.getType();
236 sets[components.getType()] = components;
240 for (
auto &[
key, val] : sets) {
242 val.add(
"alpha", C_(
"Transparency (alpha)",
"_A"), _(
"Alpha"),
Unit::Percent);
250 static std::map<Type, Components> sets_no_alpha =
_build(
false);
251 static std::map<Type, Components> sets_with_alpha =
_build(
true);
253 auto &lookup_set = alpha ? sets_with_alpha : sets_no_alpha;
254 if (
auto search = lookup_set.find(space); search != lookup_set.end()) {
255 return search->second;
Type get_wheel_type() const
void add(std::string id, std::string name, std::string tip, Unit unit=Unit::EightBit)
std::vector< Component > _components
static Components const & get(Type type, bool alpha=false)
static const std::vector< Components > get_color_spaces()
std::map< Type, Components > _build(bool alpha)
static cairo_user_data_key_t key
Component(Type type, unsigned int index, std::string id, std::string name, std::string tip, Unit unit=Unit::EightBit)
double normalize(double value) const
Clamp the value to between 0.0 and 1.0, except for hue which is wrapped around.