From a7c1272a331692b1af44455b4fedc3ff7984bb99 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sat, 21 Sep 2024 17:19:16 -0500 Subject: [PATCH] Allow RichTextEffect to modify outline/shadow color. Adjust pulse and rainbow effects so they keep their previous behavior of not modifying the color of the outline or shadow. (Pulse still affects the alpha value for the color.) --- scene/gui/rich_text_label.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index e302927692d..b32c4dbf149 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -1041,8 +1041,10 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o bool txt_visible = false; if (step == DRAW_STEP_OUTLINE) { txt_visible = (font_outline_color.a != 0 && outline_size > 0); + font_color = font_outline_color * Color(1, 1, 1, font_color.a); } else if (step == DRAW_STEP_SHADOW) { txt_visible = (font_shadow_color.a != 0); + font_color = font_shadow_color * Color(1, 1, 1, font_color.a); } else if (step == DRAW_STEP_TEXT) { txt_visible = (font_color.a != 0); bool has_ul = _find_underline(it); @@ -1245,12 +1247,18 @@ 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(item_rainbow->frequency * (item_rainbow->elapsed_time + ((p_ofs.x + off_step.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a); + if (step == DRAW_STEP_TEXT) { + font_color = font_color.from_hsv(item_rainbow->frequency * (item_rainbow->elapsed_time + ((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); const float sined_time = (Math::ease(Math::pingpong(item_pulse->elapsed_time, 1.0 / item_pulse->frequency) * item_pulse->frequency, item_pulse->ease)); - font_color = font_color.lerp(font_color * item_pulse->color, sined_time); + if (step == DRAW_STEP_TEXT) { + font_color = font_color.lerp(font_color * item_pulse->color, sined_time); + } else { + font_color.a = Math::lerp(font_color.a, font_color.a * item_pulse->color.a, sined_time); + } } } @@ -1269,15 +1277,11 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o Transform2D char_final_xform = char_xform * char_reverse_xform; draw_set_transform_matrix(char_final_xform); } else if (step == DRAW_STEP_SHADOW) { - font_color = font_shadow_color * Color(1, 1, 1, font_color.a); - char_reverse_xform.set_origin(-char_off - p_shadow_ofs); Transform2D char_final_xform = char_xform * char_reverse_xform; char_final_xform.columns[2] += p_shadow_ofs; draw_set_transform_matrix(char_final_xform); } else if (step == DRAW_STEP_OUTLINE) { - font_color = font_outline_color * Color(1, 1, 1, font_color.a); - char_reverse_xform.set_origin(-char_off); Transform2D char_final_xform = char_xform * char_reverse_xform; draw_set_transform_matrix(char_final_xform);