Skip to content

Commit

Permalink
Fix RichTextLabel bbcode rainbow play reversed and paused
Browse files Browse the repository at this point in the history
  • Loading branch information
havi05 committed Dec 16, 2024
1 parent 4364ed6 commit b905014
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions scene/gui/rich_text_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,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<ItemRainbow *>(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);
font_color = font_color.from_hsv(MAX(item_rainbow->frequency, 0) * 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<ItemPulse *>(item_fx);

Expand Down Expand Up @@ -3906,14 +3906,15 @@ void RichTextLabel::push_tornado(float p_frequency = 1.0f, float p_radius = 10.0
_add_item(item, true);
}

void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_frequency) {
void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_frequency, float p_speed) {
_stop_thread();
MutexLock data_lock(data_mutex);

ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemRainbow *item = memnew(ItemRainbow);
item->owner = get_instance_id();
item->rid = items.make_rid(item);
item->speed = p_speed;
item->frequency = p_frequency;
item->saturation = p_saturation;
item->value = p_value;
Expand Down Expand Up @@ -5379,7 +5380,13 @@ void RichTextLabel::append_text(const String &p_bbcode) {
frequency = frequency_option->value.to_float();
}

push_rainbow(saturation, value, frequency);
float speed = 1.0f;
OptionMap::Iterator speed_option = bbcode_options.find("speed");
if (speed_option) {
speed = speed_option->value.to_float();
}

push_rainbow(saturation, value, frequency, speed);
pos = brk_end + 1;
tag_stack.push_front("rainbow");
set_process_internal(true);
Expand Down
3 changes: 2 additions & 1 deletion scene/gui/rich_text_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class RichTextLabel : public Control {
float saturation = 0.8f;
float value = 0.8f;
float frequency = 1.0f;
float speed = 1.0f;

ItemRainbow() { type = ITEM_RAINBOW; }
};
Expand Down Expand Up @@ -716,7 +717,7 @@ class RichTextLabel : public Control {
void push_shake(int p_strength, float p_rate, bool p_connected);
void push_wave(float p_frequency, float p_amplitude, bool p_connected);
void push_tornado(float p_frequency, float p_radius, bool p_connected);
void push_rainbow(float p_saturation, float p_value, float p_frequency);
void push_rainbow(float p_saturation, float p_value, float p_frequency, float p_speed);
void push_pulse(const Color &p_color, float p_frequency, float p_ease);
void push_bgcolor(const Color &p_color);
void push_fgcolor(const Color &p_color);
Expand Down

0 comments on commit b905014

Please sign in to comment.