Skip to content

Commit 955744f

Browse files
committed
Merge pull request godotengine#106733 from Ivorforce/ok-rainbows
Use OkHSV for `RichTextLabel` rainbows
2 parents 50aa801 + ea6fbd6 commit 955744f

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

core/math/color.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,19 @@ void Color::set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) {
246246
a = c.a;
247247
}
248248

249+
void Color::set_ok_hsv(float p_h, float p_s, float p_v, float p_alpha) {
250+
ok_color::HSV hsv;
251+
hsv.h = p_h;
252+
hsv.s = p_s;
253+
hsv.v = p_v;
254+
ok_color::RGB rgb = ok_color::okhsv_to_srgb(hsv);
255+
Color c = Color(rgb.r, rgb.g, rgb.b, p_alpha).clamp();
256+
r = c.r;
257+
g = c.g;
258+
b = c.b;
259+
a = c.a;
260+
}
261+
249262
bool Color::is_equal_approx(const Color &p_color) const {
250263
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);
251264
}
@@ -476,6 +489,12 @@ Color Color::from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) {
476489
return c;
477490
}
478491

492+
Color Color::from_ok_hsv(float p_h, float p_s, float p_l, float p_alpha) {
493+
Color c;
494+
c.set_ok_hsv(p_h, p_s, p_l, p_alpha);
495+
return c;
496+
}
497+
479498
float Color::get_ok_hsl_h() const {
480499
ok_color::RGB rgb;
481500
rgb.r = r;

core/math/color.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct [[nodiscard]] Color {
6262
float get_ok_hsl_s() const;
6363
float get_ok_hsl_l() const;
6464
void set_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f);
65+
void set_ok_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f);
6566

6667
_FORCE_INLINE_ float &operator[](int p_idx) {
6768
return components[p_idx];
@@ -214,6 +215,7 @@ struct [[nodiscard]] Color {
214215
static Color from_string(const String &p_string, const Color &p_default);
215216
static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0f);
216217
static Color from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha = 1.0f);
218+
static Color from_ok_hsv(float p_h, float p_s, float p_l, float p_alpha = 1.0f);
217219
static Color from_rgbe9995(uint32_t p_rgbe);
218220
static Color from_rgba8(int64_t p_r8, int64_t p_g8, int64_t p_b8, int64_t p_a8 = 255);
219221

scene/gui/rich_text_label.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
12961296
} else if (item_fx->type == ITEM_RAINBOW) {
12971297
ItemRainbow *item_rainbow = static_cast<ItemRainbow *>(item_fx);
12981298

1299-
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);
1299+
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);
13001300
} else if (item_fx->type == ITEM_PULSE) {
13011301
ItemPulse *item_pulse = static_cast<ItemPulse *>(item_fx);
13021302

scene/gui/rich_text_label.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,8 @@ class RichTextLabel : public Control {
454454
};
455455

456456
struct ItemRainbow : public ItemFX {
457-
float saturation = 0.8f;
458-
float value = 0.8f;
457+
float saturation = 0.9f;
458+
float value = 1.0f;
459459
float frequency = 1.0f;
460460
float speed = 1.0f;
461461

0 commit comments

Comments
 (0)