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 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include "utils/serialization.h"
7
8#include <QColor>
9
10#include <boost/describe.hpp>
11
12namespace zrythm::utils
13{
14
15class Color final
16{
17public:
18 static constexpr auto DEFAULT_BRIGHTEN_VAL = 0.1f;
19
20 Color () noexcept = default;
21 Color (const QColor &color) noexcept { *this = color; }
22 Color (float r, float g, float b, float a = 1.0f) noexcept;
23
29 Color (const std::string &str);
30
31 Color &operator= (const QColor &color);
32
36 Color &brighten (float val);
37
42
46 Color &darken (float val);
47
51 Color &darken_default ();
52
56 [[nodiscard]] bool is_same (const Color &other) const;
57
61 [[nodiscard]] bool is_bright () const;
62
66 [[nodiscard]] bool is_very_bright () const;
67
71 [[nodiscard]] bool is_very_very_bright () const;
72
76 [[nodiscard]] bool is_very_dark () const;
77
81 [[nodiscard]] bool is_very_very_dark () const;
82
86 [[nodiscard]] Color get_opposite () const;
87
91 [[nodiscard]] float get_brightness () const;
92
96 [[nodiscard]] float get_darkness () const;
97
105 [[nodiscard]] Color morph (const Color &other, float amt) const;
106
112 static Color
113 get_mid_color (const Color &c1, const Color &c2, const float transition = 0.5f);
114
119 Color get_contrast_color () const;
120
121 QColor to_qcolor () const;
122
130 const Color &color,
131 bool is_hovered,
132 bool is_selected,
133 bool is_transient,
134 bool is_muted);
135
141 std::string to_hex () const;
142
143 static std::string rgb_to_hex (float r, float g, float b);
144
145 friend bool operator== (const Color &lhs, const Color &rhs);
146
147 NLOHMANN_DEFINE_TYPE_INTRUSIVE (Color, red_, green_, blue_, alpha_)
148
149public:
150 float red_ = 0.f;
151 float green_ = 0.f;
152 float blue_ = 0.f;
153 float alpha_ = 1.0f;
154
155 BOOST_DESCRIBE_CLASS (Color, (), (red_, green_, blue_, alpha_), (), ())
156};
157
158}; // 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:153
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:152
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.
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.
Color(const std::string &str)
Construct a new Color object by parsing the color string.
bool is_same(const Color &other) const
Returns whether the color is the same as another.
float red_
Red.
Definition color.h:150
std::string to_hex() const
Converts the color to a hex string.
bool is_very_very_dark() const
Returns if the color is very very dark or not.
float green_
Green.
Definition color.h:151
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