Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
color.h
1// SPDX-FileCopyrightText: © 2020-2022, 2024-2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <QColor>
7
8#include <boost/describe.hpp>
9#include <nlohmann/json_fwd.hpp>
10
11namespace zrythm::utils
12{
13
14class Color final
15{
16public:
17 static constexpr auto DEFAULT_BRIGHTEN_VAL = 0.1f;
18
19 Color () noexcept = default;
20 Color (const QColor &color) noexcept { *this = color; }
21 Color (float r, float g, float b, float a = 1.0f) noexcept;
22
28 Color (std::string_view hex);
29
30 Color &operator= (const QColor &color);
31
35 Color &brighten (float val);
36
41
45 Color &darken (float val);
46
50 Color &darken_default ();
51
55 [[nodiscard]] bool is_same (const Color &other) const;
56
60 [[nodiscard]] bool is_bright () const;
61
65 [[nodiscard]] bool is_very_bright () const;
66
70 [[nodiscard]] bool is_very_very_bright () const;
71
75 [[nodiscard]] bool is_very_dark () const;
76
80 [[nodiscard]] bool is_very_very_dark () const;
81
85 [[nodiscard]] Color get_opposite () const;
86
90 [[nodiscard]] float get_brightness () const;
91
95 [[nodiscard]] float get_darkness () const;
96
104 [[nodiscard]] Color morph (const Color &other, float amt) const;
105
111 static Color
112 get_mid_color (const Color &c1, const Color &c2, const float transition = 0.5f);
113
118 Color get_contrast_color () const;
119
120 QColor to_qcolor () const;
121
129 const Color &color,
130 bool is_hovered,
131 bool is_selected,
132 bool is_transient,
133 bool is_muted);
134
140 std::string to_hex () const;
141
150 static std::string rgb_to_hex (float r, float g, float b);
151
161 static Color from_hex (std::string_view hex);
162
163 friend bool operator== (const Color &lhs, const Color &rhs);
164
165 friend void to_json (nlohmann::json &j, const Color &color);
166 friend void from_json (const nlohmann::json &j, Color &color);
167
168public:
169 float red_ = 0.f;
170 float green_ = 0.f;
171 float blue_ = 0.f;
172 float alpha_ = 1.0f;
173
174 BOOST_DESCRIBE_CLASS (Color, (), (red_, green_, blue_, alpha_), (), ())
175};
176
177}; // namespace zrythm::utils
float get_brightness() const
Gets the brightness of the color.
Color & darken_default()
Darkens the color by the default amount.
float alpha_
Alpha.
Definition color.h:172
static Color get_mid_color(const Color &c1, const Color &c2, const float transition=0.5f)
Returns the color in-between two colors.
bool is_bright() const
Returns if the color is bright or not.
float blue_
Blue.
Definition color.h:171
float get_darkness() const
Gets the darkness of the color.
Color get_contrast_color() const
Returns the contrasting color (variation of black or white) based on if the given color is dark enoug...
Color & darken(float val)
Darkens the color by the given amount.
bool is_very_bright() const
Returns if the color is very bright or not.
Color get_opposite() const
Gets the opposite color.
static Color from_hex(std::string_view hex)
Parses a hex color string using QColor.
Color & brighten(float val)
Brightens the color by the given amount.
Color morph(const Color &other, float amt) const
Morphs from this color to another, depending on the given amount.
static std::string rgb_to_hex(float r, float g, float b)
Converts RGB float values to a hex string.
Color(std::string_view hex)
Construct a new Color object by parsing a hex color string.
bool is_same(const Color &other) const
Returns whether the color is the same as another.
float red_
Red.
Definition color.h:169
std::string to_hex() const
Converts the color to a hex string (RGB only).
bool is_very_very_dark() const
Returns if the color is very very dark or not.
float green_
Green.
Definition color.h:170
Color & brighten_default()
Brightens the color by the default amount.
bool is_very_very_bright() const
Returns if the color is very very bright or not.
bool is_very_dark() const
Returns if the color is very dark or not.
static Color get_arranger_object_color(const Color &color, bool is_hovered, bool is_selected, bool is_transient, bool is_muted)
Gets the color the widget should be.
String utilities.
Definition algorithms.h:12