Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::utils::Color Class Referencefinal

Public Member Functions

 Color (const QColor &color) noexcept
 Color (float r, float g, float b, float a=1.0f) noexcept
 Color (std::string_view hex)
 Construct a new Color object by parsing a hex color string.
Color & operator= (const QColor &color)
Color & brighten (float val)
 Brightens the color by the given amount.
Color & brighten_default ()
 Brightens the color by the default amount.
Color & darken (float val)
 Darkens the color by the given amount.
Color & darken_default ()
 Darkens the color by the default amount.
bool is_same (const Color &other) const
 Returns whether the color is the same as another.
bool is_bright () const
 Returns if the color is bright or not.
bool is_very_bright () const
 Returns if the color is very bright or not.
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.
bool is_very_very_dark () const
 Returns if the color is very very dark or not.
Color get_opposite () const
 Gets the opposite color.
float get_brightness () const
 Gets the brightness of the color.
float get_darkness () const
 Gets the darkness of the color.
Color morph (const Color &other, float amt) const
 Morphs from this color to another, depending on the given amount.
Color get_contrast_color () const
 Returns the contrasting color (variation of black or white) based on if the given color is dark enough or not.
QColor to_qcolor () const
std::string to_hex () const
 Converts the color to a hex string (RGB only).

Static Public Member Functions

static Color get_mid_color (const Color &c1, const Color &c2, const float transition=0.5f)
 Returns the color in-between two colors.
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.
static std::string rgb_to_hex (float r, float g, float b)
 Converts RGB float values to a hex string.
static Color from_hex (std::string_view hex)
 Parses a hex color string using QColor.

Data Fields

float red_ = 0.f
 Red.
float green_ = 0.f
 Green.
float blue_ = 0.f
 Blue.
float alpha_ = 1.0f
 Alpha.

Static Public Attributes

static constexpr auto DEFAULT_BRIGHTEN_VAL = 0.1f

Friends

bool operator== (const Color &lhs, const Color &rhs)
void to_json (nlohmann::json &j, const Color &color)
void from_json (const nlohmann::json &j, Color &color)

Detailed Description

Definition at line 14 of file color.h.

Constructor & Destructor Documentation

◆ Color() [1/2]

zrythm::utils::Color::Color ( const QColor & color)
inlinenoexcept

Definition at line 20 of file color.h.

◆ Color() [2/2]

zrythm::utils::Color::Color ( std::string_view hex)

Construct a new Color object by parsing a hex color string.

Parameters
hexHex color string (e.g., "#ff5588" or "#ff5588cc")

Member Function Documentation

◆ from_hex()

Color zrythm::utils::Color::from_hex ( std::string_view hex)
static

Parses a hex color string using QColor.

Supports QColor-compatible formats: #RGB, #RRGGBB Alpha defaults to 1.0.

Parameters
hexHex color string (e.g., "#ff5588")
Returns
Color Parsed color

◆ get_arranger_object_color()

Color zrythm::utils::Color::get_arranger_object_color ( const Color & color,
bool is_hovered,
bool is_selected,
bool is_transient,
bool is_muted )
static

Gets the color the widget should be.

Parameters
colorThe original color.
is_selectedWhether the widget is supposed to be selected or not.

◆ get_mid_color()

Color zrythm::utils::Color::get_mid_color ( const Color & c1,
const Color & c2,
const float transition = 0.5f )
static

Returns the color in-between two colors.

Parameters
transitionHow far to transition (0.5 for half).

◆ morph()

Color zrythm::utils::Color::morph ( const Color & other,
float amt ) const
nodiscard

Morphs from this color to another, depending on the given amount.

Eg, if amt is 0, the resulting color will be this color. If amt is 1, the resulting color will be other.

◆ rgb_to_hex()

std::string zrythm::utils::Color::rgb_to_hex ( float r,
float g,
float b )
static

Converts RGB float values to a hex string.

Parameters
rRed (0.0-1.0)
gGreen (0.0-1.0)
bBlue (0.0-1.0)
Returns
std::string Hex color string (e.g., "#ff5588")

◆ to_hex()

std::string zrythm::utils::Color::to_hex ( ) const

Converts the color to a hex string (RGB only).

Returns
std::string Hex color string (e.g., "#ff5588")

Field Documentation

◆ alpha_

float zrythm::utils::Color::alpha_ = 1.0f

Alpha.

Definition at line 172 of file color.h.

◆ blue_

float zrythm::utils::Color::blue_ = 0.f

Blue.

Definition at line 171 of file color.h.

◆ DEFAULT_BRIGHTEN_VAL

auto zrythm::utils::Color::DEFAULT_BRIGHTEN_VAL = 0.1f
staticconstexpr

Definition at line 17 of file color.h.

◆ green_

float zrythm::utils::Color::green_ = 0.f

Green.

Definition at line 170 of file color.h.

◆ red_

float zrythm::utils::Color::red_ = 0.f

Red.

Definition at line 169 of file color.h.


The documentation for this class was generated from the following file: