diff --git a/core/math/color.cpp b/core/math/color.cpp index d032a3fec718..68f71ccfa646 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -246,6 +246,19 @@ void Color::set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) { a = c.a; } +void Color::set_ok_hsv(float p_h, float p_s, float p_v, float p_alpha) { + ok_color::HSV hsv; + hsv.h = p_h; + hsv.s = p_s; + hsv.v = p_v; + ok_color::RGB rgb = ok_color::okhsv_to_srgb(hsv); + Color c = Color(rgb.r, rgb.g, rgb.b, p_alpha).clamp(); + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + bool Color::is_equal_approx(const Color &p_color) const { return Math::is_equal_approx(r, p_color.r) && Math::is_equal_approx(g, p_color.g) && Math::is_equal_approx(b, p_color.b) && Math::is_equal_approx(a, p_color.a); } @@ -476,6 +489,12 @@ Color Color::from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) { return c; } +Color Color::from_ok_hsv(float p_h, float p_s, float p_l, float p_alpha) { + Color c; + c.set_ok_hsv(p_h, p_s, p_l, p_alpha); + return c; +} + float Color::get_ok_hsl_h() const { ok_color::RGB rgb; rgb.r = r; diff --git a/core/math/color.h b/core/math/color.h index ae91677d258a..5d3ec4b5ec08 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -62,6 +62,7 @@ struct [[nodiscard]] Color { float get_ok_hsl_s() const; float get_ok_hsl_l() const; void set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f); + void set_ok_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f); _FORCE_INLINE_ float &operator[](int p_idx) { return components[p_idx]; @@ -214,6 +215,7 @@ struct [[nodiscard]] Color { static Color from_string(const String &p_string, const Color &p_default); static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f); static Color from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f); + static Color from_ok_hsv(float p_h, float p_s, float p_l, float p_alpha = 1.0f); static Color from_rgbe9995(uint32_t p_rgbe); static Color from_rgba8(int64_t p_r8, int64_t p_g8, int64_t p_b8, int64_t p_a8 = 255); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 692f018f297b..705a1d414ef4 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1296,7 +1296,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } else if (item_fx->type == ITEM_RAINBOW) { ItemRainbow *item_rainbow = static_cast(item_fx); - font_color = font_color.from_hsv(MAX(item_rainbow->frequency, 0) * Math::abs(item_rainbow->elapsed_time * item_rainbow->speed + ((p_ofs.x + off_step.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a); + font_color = font_color.from_ok_hsv(MAX(item_rainbow->frequency, 0) * Math::abs(item_rainbow->elapsed_time * item_rainbow->speed + ((p_ofs.x + off_step.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a); } else if (item_fx->type == ITEM_PULSE) { ItemPulse *item_pulse = static_cast(item_fx); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 156e972b3651..79331c527e8c 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -454,8 +454,8 @@ class RichTextLabel : public Control { }; struct ItemRainbow : public ItemFX { - float saturation = 0.8f; - float value = 0.8f; + float saturation = 0.9f; + float value = 1.0f; float frequency = 1.0f; float speed = 1.0f;