diff options
Diffstat (limited to 'scene/gui/rich_text_label.cpp')
-rw-r--r-- | scene/gui/rich_text_label.cpp | 79 |
1 files changed, 39 insertions, 40 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 5fb2243aff..84097eb6a1 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -407,17 +407,16 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & cw = tab_size * font->get_char_size(' ').width; } - if (end > 0 && w + cw + begin > p_width) { + if (end > 0 && fw + cw + begin > p_width) { break; //don't allow lines longer than assigned width } - w += cw; fw += cw; end++; } CHECK_HEIGHT(fh); - ENSURE_WIDTH(w); + ENSURE_WIDTH(fw); line_ascent = MAX(line_ascent, ascent); line_descent = MAX(line_descent, descent); @@ -552,8 +551,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } } - if (visible) + if (visible) { line_is_blank = false; + w += font->get_char_size(c[i], c[i + 1]).x; + } if (c[i] == '\t') visible = false; @@ -582,13 +583,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else { cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); } - } else if (previously_visible) { + } else if (previously_visible && c[i] != '\t') { backtrack += font->get_char_size(fx_char, c[i + 1]).x; } p_char_count++; if (c[i] == '\t') { cw = tab_size * font->get_char_size(' ').width; + backtrack = MAX(0, backtrack - cw); } ofs += cw; @@ -598,8 +600,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & if (underline) { Color uc = color; uc.a *= 0.5; - int uy = y + lh - line_descent + 2; - float underline_width = 1.0; + int uy = y + lh - line_descent + font->get_underline_position(); + float underline_width = font->get_underline_thickness(); #ifdef TOOLS_ENABLED underline_width *= EDSCALE; #endif @@ -607,8 +609,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else if (strikethrough) { Color uc = color; uc.a *= 0.5; - int uy = y + lh / 2 - line_descent + 2; - float strikethrough_width = 1.0; + int uy = y + lh - (line_ascent + line_descent) / 2; + float strikethrough_width = font->get_underline_thickness(); #ifdef TOOLS_ENABLED strikethrough_width *= EDSCALE; #endif @@ -2091,6 +2093,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1); + Vector<String> split_tag_block = tag.split(" ", false); + String bbcode = !split_tag_block.empty() ? split_tag_block[0] : ""; if (tag.begins_with("/") && tag_stack.size()) { bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); @@ -2323,15 +2327,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("font"); - } else if (tag.begins_with("fade")) { - Vector<String> tags = tag.split(" ", false); + } else if (bbcode == "fade") { int startIndex = 0; int length = 10; - if (tags.size() > 1) { - tags.remove(0); - for (int i = 0; i < tags.size(); i++) { - String expr = tags[i]; + if (split_tag_block.size() > 1) { + split_tag_block.remove(0); + for (int i = 0; i < split_tag_block.size(); i++) { + String expr = split_tag_block[i]; if (expr.begins_with("start=")) { String start_str = expr.substr(6, expr.length()); startIndex = start_str.to_int(); @@ -2345,15 +2348,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { push_fade(startIndex, length); pos = brk_end + 1; tag_stack.push_front("fade"); - } else if (tag.begins_with("shake")) { - Vector<String> tags = tag.split(" ", false); + } else if (bbcode == "shake") { int strength = 5; float rate = 20.0f; - if (tags.size() > 1) { - tags.remove(0); - for (int i = 0; i < tags.size(); i++) { - String expr = tags[i]; + if (split_tag_block.size() > 1) { + split_tag_block.remove(0); + for (int i = 0; i < split_tag_block.size(); i++) { + String expr = split_tag_block[i]; if (expr.begins_with("level=")) { String str_str = expr.substr(6, expr.length()); strength = str_str.to_int(); @@ -2368,15 +2370,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("shake"); set_process_internal(true); - } else if (tag.begins_with("wave")) { - Vector<String> tags = tag.split(" ", false); + } else if (bbcode == "wave") { float amplitude = 20.0f; float period = 5.0f; - if (tags.size() > 1) { - tags.remove(0); - for (int i = 0; i < tags.size(); i++) { - String expr = tags[i]; + if (split_tag_block.size() > 1) { + split_tag_block.remove(0); + for (int i = 0; i < split_tag_block.size(); i++) { + String expr = split_tag_block[i]; if (expr.begins_with("amp=")) { String amp_str = expr.substr(4, expr.length()); amplitude = amp_str.to_float(); @@ -2391,15 +2392,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("wave"); set_process_internal(true); - } else if (tag.begins_with("tornado")) { - Vector<String> tags = tag.split(" ", false); + } else if (bbcode == "tornado") { float radius = 10.0f; float frequency = 1.0f; - if (tags.size() > 1) { - tags.remove(0); - for (int i = 0; i < tags.size(); i++) { - String expr = tags[i]; + if (split_tag_block.size() > 1) { + split_tag_block.remove(0); + for (int i = 0; i < split_tag_block.size(); i++) { + String expr = split_tag_block[i]; if (expr.begins_with("radius=")) { String amp_str = expr.substr(7, expr.length()); radius = amp_str.to_float(); @@ -2414,16 +2414,15 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("tornado"); set_process_internal(true); - } else if (tag.begins_with("rainbow")) { - Vector<String> tags = tag.split(" ", false); + } else if (bbcode == "rainbow") { float saturation = 0.8f; float value = 0.8f; float frequency = 1.0f; - if (tags.size() > 1) { - tags.remove(0); - for (int i = 0; i < tags.size(); i++) { - String expr = tags[i]; + if (split_tag_block.size() > 1) { + split_tag_block.remove(0); + for (int i = 0; i < split_tag_block.size(); i++) { + String expr = split_tag_block[i]; if (expr.begins_with("sat=")) { String sat_str = expr.substr(4, expr.length()); saturation = sat_str.to_float(); @@ -2442,7 +2441,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front("rainbow"); set_process_internal(true); } else { - Vector<String> expr = tag.split(" ", false); + Vector<String> &expr = split_tag_block; if (expr.size() < 1) { add_text("["); pos = brk_pos + 1; |