diff options
Diffstat (limited to 'scene/gui/rich_text_label.cpp')
-rw-r--r-- | scene/gui/rich_text_label.cpp | 175 |
1 files changed, 0 insertions, 175 deletions
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index a6c0c99bdb..baf8c53fef 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -46,16 +46,12 @@ #endif RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { - if (p_free) { - if (p_item->subitems.size()) { - return p_item->subitems.front()->get(); } else if (!p_item->parent) { return nullptr; } else if (p_item->E->next()) { - return p_item->E->next()->get(); } else { //go up until something with a next is found @@ -71,12 +67,10 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { } else { if (p_item->subitems.size() && p_item->type != ITEM_TABLE) { - return p_item->subitems.front()->get(); } else if (p_item->type == ITEM_FRAME) { return nullptr; } else if (p_item->E->next()) { - return p_item->E->next()->get(); } else { //go up until something with a next is found @@ -96,14 +90,11 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { if (p_free) { - if (p_item->subitems.size()) { - return p_item->subitems.back()->get(); } else if (!p_item->parent) { return nullptr; } else if (p_item->E->prev()) { - return p_item->E->prev()->get(); } else { //go back until something with a prev is found @@ -119,12 +110,10 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { } else { if (p_item->subitems.size() && p_item->type != ITEM_TABLE) { - return p_item->subitems.back()->get(); } else if (p_item->type == ITEM_FRAME) { return nullptr; } else if (p_item->E->prev()) { - return p_item->E->prev()->get(); } else { //go back until something with a prev is found @@ -148,7 +137,6 @@ Rect2 RichTextLabel::_get_text_rect() { } int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) { - ERR_FAIL_INDEX_V((int)p_mode, 3, 0); RID ci; @@ -172,7 +160,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int height = get_size().y; if (p_mode != PROCESS_CACHE) { - ERR_FAIL_INDEX_V(line, l.offset_caches.size(), 0); line_ofs = l.offset_caches[line]; } @@ -328,18 +315,14 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int fh = 0; while (it) { - switch (it->type) { - case ITEM_ALIGN: { - ItemAlign *align_it = static_cast<ItemAlign *>(it); align = align_it->align; } break; case ITEM_INDENT: { - if (it != l.from) { ItemIndent *indent_it = static_cast<ItemIndent *>(it); @@ -351,7 +334,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } break; case ITEM_TEXT: { - ItemText *text = static_cast<ItemText *>(it); Ref<Font> font = _find_font(it); @@ -399,7 +381,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & rchar = 0; FontDrawer drawer(font, Color(1, 1, 1)); while (*c) { - int end = 0; int w = 0; int fw = 0; @@ -412,7 +393,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; } while (c[end] != 0 && !(end && c[end - 1] == ' ' && c[end] != ' ')) { - int cw = font->get_char_size(c[end], c[end + 1]).width; if (c[end] == '\t') { cw = tab_size * font->get_char_size(' ').width; @@ -446,14 +426,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } { - int ofs = 0 - backtrack; for (int i = 0; i < end; i++) { int pofs = wofs + ofs; if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) { - int cw = font->get_char_size(c[i], c[i + 1]).x; if (c[i] == '\t') { @@ -461,7 +439,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } if (p_click_pos.x - cw / 2 > p_ofs.x + align_ofs + pofs) { - rchar = int((&c[i]) - cf); } @@ -473,7 +450,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & CharType fx_char = c[i]; if (selection.active) { - int cofs = (&c[i]) - cf; if ((text->index > selection.from->index || (text->index == selection.from->index && cofs >= selection.from_char)) && (text->index < selection.to->index || (text->index == selection.to->index && cofs <= selection.to_char))) { selected = true; @@ -498,7 +474,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & const bool previously_visible = visible; for (int j = 0; j < fx_stack.size(); j++) { - ItemFX *item_fx = fx_stack[j]; if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) { @@ -571,7 +546,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & visible = false; if (visible) { - if (selected) { cw = font->get_char_size(fx_char, c[i + 1]).x; draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg); @@ -636,7 +610,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } break; case ITEM_IMAGE: { - lh = 0; if (p_mode != PROCESS_CACHE) lh = line < l.height_caches.size() ? l.height_caches[line] : 1; @@ -668,7 +641,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } break; case ITEM_NEWLINE: { - lh = 0; if (p_mode != PROCESS_CACHE) { @@ -678,7 +650,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } break; case ITEM_TABLE: { - lh = 0; ItemTable *table = static_cast<ItemTable *>(it); int hseparation = get_theme_constant("table_hseparation"); @@ -690,7 +661,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Point2 shadow_ofs2(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); if (p_mode == PROCESS_CACHE) { - int idx = 0; //set minimums to zero for (int i = 0; i < table->columns.size(); i++) { @@ -710,7 +680,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int ly = 0; for (int i = 0; i < frame->lines.size(); i++) { - _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2); table->columns.write[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width); table->columns.write[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].maximum_width); @@ -782,7 +751,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int column = idx % table->columns.size(); for (int i = 0; i < frame->lines.size(); i++) { - int ly = 0; _process_line(frame, Point2(), ly, table->columns[column].width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2); frame->lines.write[i].height_cache = ly; //actual height @@ -814,7 +782,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & line_is_blank = false; for (int i = 0; i < frame->lines.size(); i++) { - if (visible) { if (p_mode == PROCESS_DRAW) { nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2); @@ -836,7 +803,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & offset.x += table->columns[column].width + hseparation; if (column == table->columns.size() - 1) { - offset.y += row_height + vseparation; offset.x = hseparation; row_height = 0; @@ -863,7 +829,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & it = _get_next_item(it); if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) { - if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) { //went to next line, but pointer was on the previous one if (r_outside) @@ -888,7 +853,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } void RichTextLabel::_scroll_changed(double) { - if (updating_scroll || !scroll_active) return; @@ -903,13 +867,11 @@ void RichTextLabel::_scroll_changed(double) { } void RichTextLabel::_update_scroll() { - int total_height = get_content_height(); bool exceeds = total_height > get_size().height && scroll_active; if (exceeds != scroll_visible) { - if (exceeds) { scroll_visible = true; scroll_w = vscroll->get_combined_minimum_size().width; @@ -961,9 +923,7 @@ void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, float p_delta_ } void RichTextLabel::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_MOUSE_EXIT: { if (meta_hovering) { meta_hovering = nullptr; @@ -973,13 +933,11 @@ void RichTextLabel::_notification(int p_what) { } } break; case NOTIFICATION_RESIZED: { - main->first_invalid_line = 0; //invalidate ALL update(); } break; case NOTIFICATION_ENTER_TREE: { - if (bbcode != "") set_bbcode(bbcode); @@ -988,12 +946,10 @@ void RichTextLabel::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - update(); } break; case NOTIFICATION_DRAW: { - _validate_line_caches(main); _update_scroll(); @@ -1017,7 +973,6 @@ void RichTextLabel::_notification(int p_what) { int from_line = 0; int total_chars = 0; while (from_line < main->lines.size()) { - if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) break; total_chars += main->lines[from_line].char_count; @@ -1035,7 +990,6 @@ void RichTextLabel::_notification(int p_what) { visible_line_count = 0; while (y < size.height && from_line < main->lines.size()) { - visible_line_count += _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), nullptr, nullptr, nullptr, total_chars); total_chars += main->lines[from_line].char_count; @@ -1052,7 +1006,6 @@ void RichTextLabel::_notification(int p_what) { } void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) { - if (r_click_item) *r_click_item = nullptr; @@ -1066,7 +1019,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item int from_line = 0; while (from_line < p_frame->lines.size()) { - if (p_frame->lines[from_line].height_accum_cache >= ofs) break; from_line++; @@ -1080,7 +1032,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item Color base_color = get_theme_color("default_color"); while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) { - _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, p_click, r_click_item, r_click_char, r_outside); if (r_click_item && *r_click_item) return; @@ -1089,7 +1040,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item } Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const { - if (!underline_meta) return CURSOR_ARROW; @@ -1111,7 +1061,6 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const } void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { - Ref<InputEventMouseButton> b = p_event; if (b.is_valid()) { @@ -1128,9 +1077,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { _find_click(main, b->get_position(), &item, &line, &outside); if (item) { - if (selection.enabled) { - selection.click = item; selection.click_char = line; @@ -1147,7 +1094,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } } } else if (b->is_pressed() && b->is_doubleclick() && selection.enabled) { - //doubleclick: select word int line = 0; Item *item = nullptr; @@ -1156,17 +1102,14 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { _find_click(main, b->get_position(), &item, &line, &outside); while (item && item->type != ITEM_TEXT) { - item = _get_next_item(item, true); } if (item && item->type == ITEM_TEXT) { - String itext = static_cast<ItemText *>(item)->text; int beg, end; if (select_word(itext, line, beg, end)) { - selection.from = item; selection.to = item; selection.from_char = beg; @@ -1176,7 +1119,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } } } else if (!b->is_pressed()) { - selection.click = nullptr; if (!b->is_doubleclick() && !scroll_updated) { @@ -1187,7 +1129,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { _find_click(main, b->get_position(), &item, &line, &outside); if (item) { - Variant meta; if (!outside && _find_meta(item, &meta)) { //meta clicked @@ -1211,7 +1152,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (scroll_active) vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8); @@ -1226,42 +1166,36 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { bool handled = false; switch (k->get_keycode()) { case KEY_PAGEUP: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() - vscroll->get_page()); handled = true; } } break; case KEY_PAGEDOWN: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() + vscroll->get_page()); handled = true; } } break; case KEY_UP: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height()); handled = true; } } break; case KEY_DOWN: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height()); handled = true; } } break; case KEY_HOME: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(0); handled = true; } } break; case KEY_END: { - if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_max()); handled = true; @@ -1269,7 +1203,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } break; case KEY_INSERT: case KEY_C: { - if (k->get_command()) { selection_copy(); handled = true; @@ -1295,7 +1228,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { _find_click(main, m->get_position(), &item, &line, &outside); if (selection.click) { - if (!item) return; // do not update @@ -1312,7 +1244,6 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { if (selection.from_char > selection.to_char) swap = true; else if (selection.from_char == selection.to_char) { - selection.active = false; return; } @@ -1347,13 +1278,10 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { } Ref<Font> RichTextLabel::_find_font(Item *p_item) { - Item *fontitem = p_item; while (fontitem) { - if (fontitem->type == ITEM_FONT) { - ItemFont *fi = static_cast<ItemFont *>(fontitem); return fi->font; } @@ -1365,15 +1293,12 @@ Ref<Font> RichTextLabel::_find_font(Item *p_item) { } int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) { - Item *item = p_item; int margin = 0; while (item) { - if (item->type == ITEM_INDENT) { - Ref<Font> font = _find_font(item); if (font.is_null()) font = p_base_font; @@ -1383,7 +1308,6 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) { margin += indent->level * tab_size * font->get_char_size(' ').width; } else if (item->type == ITEM_LIST) { - Ref<Font> font = _find_font(item); if (font.is_null()) font = p_base_font; @@ -1396,13 +1320,10 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) { } RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) { - Item *item = p_item; while (item) { - if (item->type == ITEM_ALIGN) { - ItemAlign *align = static_cast<ItemAlign *>(item); return align->align; } @@ -1414,13 +1335,10 @@ RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) { } Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) { - Item *item = p_item; while (item) { - if (item->type == ITEM_COLOR) { - ItemColor *color = static_cast<ItemColor *>(item); return color->color; } @@ -1432,13 +1350,10 @@ Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) { } bool RichTextLabel::_find_underline(Item *p_item) { - Item *item = p_item; while (item) { - if (item->type == ITEM_UNDERLINE) { - return true; } @@ -1449,13 +1364,10 @@ bool RichTextLabel::_find_underline(Item *p_item) { } bool RichTextLabel::_find_strikethrough(Item *p_item) { - Item *item = p_item; while (item) { - if (item->type == ITEM_STRIKETHROUGH) { - return true; } @@ -1466,7 +1378,6 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) { } bool RichTextLabel::_find_by_type(Item *p_item, ItemType p_type) { - ERR_FAIL_INDEX_V((int)p_type, 19, false); Item *item = p_item; @@ -1495,9 +1406,7 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) Item *item = p_item; while (item) { - if (item->type == ITEM_META) { - ItemMeta *meta = static_cast<ItemMeta *>(item); if (r_meta) *r_meta = meta->meta; @@ -1513,7 +1422,6 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) } bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { - if (from && from != to) { if (from->type != ITEM_FONT && from->type != ITEM_COLOR && from->type != ITEM_UNDERLINE && from->type != ITEM_STRIKETHROUGH) return true; @@ -1530,7 +1438,6 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) { } void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { - if (p_frame->first_invalid_line == p_frame->lines.size()) return; @@ -1547,7 +1454,6 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { Ref<Font> base_font = get_theme_font("normal_font"); for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) { - int y = 0; _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, i, PROCESS_CACHE, base_font, Color(), font_color_shadow, use_outline, shadow_ofs); p_frame->lines.write[i].height_cache = y; @@ -1573,31 +1479,25 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { } void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) { - if (p_frame->lines.size() - 1 <= p_frame->first_invalid_line) { - p_frame->first_invalid_line = p_frame->lines.size() - 1; update(); } } void RichTextLabel::add_text(const String &p_text) { - if (current->type == ITEM_TABLE) return; //can't add anything here int pos = 0; while (pos < p_text.length()) { - int end = p_text.find("\n", pos); String line; bool eol = false; if (end == -1) { - end = p_text.length(); } else { - eol = true; } @@ -1607,7 +1507,6 @@ void RichTextLabel::add_text(const String &p_text) { line = p_text.substr(pos, end - pos); if (line.length() > 0) { - if (current->subitems.size() && current->subitems.back()->get()->type == ITEM_TEXT) { //append text condition! ItemText *ti = static_cast<ItemText *>(current->subitems.back()->get()); @@ -1623,7 +1522,6 @@ void RichTextLabel::add_text(const String &p_text) { } if (eol) { - ItemNewline *item = memnew(ItemNewline); item->line = current_frame->lines.size(); _add_item(item, false); @@ -1638,7 +1536,6 @@ void RichTextLabel::add_text(const String &p_text) { } void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) { - p_item->parent = current; p_item->E = current->subitems.push_back(p_item); p_item->index = current_idx++; @@ -1668,7 +1565,6 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) } void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_subitem_line) { - int size = p_item->subitems.size(); if (size == 0) { p_item->parent->subitems.erase(p_item); @@ -1687,7 +1583,6 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub } void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) { - if (current->type == ITEM_TABLE) return; @@ -1723,7 +1618,6 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, } void RichTextLabel::add_newline() { - if (current->type == ITEM_TABLE) return; ItemNewline *item = memnew(ItemNewline); @@ -1734,7 +1628,6 @@ void RichTextLabel::add_newline() { } bool RichTextLabel::remove_line(const int p_line) { - if (p_line >= current_frame->lines.size() || p_line < 0) return false; @@ -1767,7 +1660,6 @@ bool RichTextLabel::remove_line(const int p_line) { } void RichTextLabel::push_font(const Ref<Font> &p_font) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ERR_FAIL_COND(p_font.is_null()); ItemFont *item = memnew(ItemFont); @@ -1812,7 +1704,6 @@ void RichTextLabel::push_mono() { } void RichTextLabel::push_color(const Color &p_color) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ItemColor *item = memnew(ItemColor); @@ -1821,7 +1712,6 @@ void RichTextLabel::push_color(const Color &p_color) { } void RichTextLabel::push_underline() { - ERR_FAIL_COND(current->type == ITEM_TABLE); ItemUnderline *item = memnew(ItemUnderline); @@ -1829,7 +1719,6 @@ void RichTextLabel::push_underline() { } void RichTextLabel::push_strikethrough() { - ERR_FAIL_COND(current->type == ITEM_TABLE); ItemStrikethrough *item = memnew(ItemStrikethrough); @@ -1837,7 +1726,6 @@ void RichTextLabel::push_strikethrough() { } void RichTextLabel::push_align(Align p_align) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ItemAlign *item = memnew(ItemAlign); @@ -1846,7 +1734,6 @@ void RichTextLabel::push_align(Align p_align) { } void RichTextLabel::push_indent(int p_level) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ERR_FAIL_COND(p_level < 0); @@ -1856,7 +1743,6 @@ void RichTextLabel::push_indent(int p_level) { } void RichTextLabel::push_list(ListType p_list) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ERR_FAIL_INDEX(p_list, 3); @@ -1867,7 +1753,6 @@ void RichTextLabel::push_list(ListType p_list) { } void RichTextLabel::push_meta(const Variant &p_meta) { - ERR_FAIL_COND(current->type == ITEM_TABLE); ItemMeta *item = memnew(ItemMeta); @@ -1876,7 +1761,6 @@ void RichTextLabel::push_meta(const Variant &p_meta) { } void RichTextLabel::push_table(int p_columns) { - ERR_FAIL_COND(p_columns < 1); ItemTable *item = memnew(ItemTable); @@ -1933,7 +1817,6 @@ void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionar } void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) { - ERR_FAIL_COND(current->type != ITEM_TABLE); ItemTable *table = static_cast<ItemTable *>(current); ERR_FAIL_INDEX(p_column, table->columns.size()); @@ -1942,7 +1825,6 @@ void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_r } void RichTextLabel::push_cell() { - ERR_FAIL_COND(current->type != ITEM_TABLE); ItemFrame *item = memnew(ItemFrame); @@ -1957,7 +1839,6 @@ void RichTextLabel::push_cell() { } int RichTextLabel::get_current_table_column() const { - ERR_FAIL_COND_V(current->type != ITEM_TABLE, -1); ItemTable *table = static_cast<ItemTable *>(current); @@ -1966,7 +1847,6 @@ int RichTextLabel::get_current_table_column() const { } void RichTextLabel::pop() { - ERR_FAIL_COND(!current->parent); if (current->type == ITEM_FRAME) { current_frame = static_cast<ItemFrame *>(current)->parent_frame; @@ -1975,7 +1855,6 @@ void RichTextLabel::pop() { } void RichTextLabel::clear() { - main->_clear_children(); current = main; current_frame = main; @@ -1993,45 +1872,37 @@ void RichTextLabel::clear() { } void RichTextLabel::set_tab_size(int p_spaces) { - tab_size = p_spaces; main->first_invalid_line = 0; update(); } int RichTextLabel::get_tab_size() const { - return tab_size; } void RichTextLabel::set_meta_underline(bool p_underline) { - underline_meta = p_underline; update(); } bool RichTextLabel::is_meta_underlined() const { - return underline_meta; } void RichTextLabel::set_override_selected_font_color(bool p_override_selected_font_color) { - override_selected_font_color = p_override_selected_font_color; } bool RichTextLabel::is_overriding_selected_font_color() const { - return override_selected_font_color; } void RichTextLabel::set_offset(int p_pixel) { - vscroll->set_value(p_pixel); } void RichTextLabel::set_scroll_active(bool p_active) { - if (scroll_active == p_active) return; @@ -2040,30 +1911,25 @@ void RichTextLabel::set_scroll_active(bool p_active) { } bool RichTextLabel::is_scroll_active() const { - return scroll_active; } void RichTextLabel::set_scroll_follow(bool p_follow) { - scroll_follow = p_follow; if (!vscroll->is_visible_in_tree() || vscroll->get_value() >= (vscroll->get_max() - vscroll->get_page())) scroll_following = true; } bool RichTextLabel::is_scroll_following() const { - return scroll_follow; } Error RichTextLabel::parse_bbcode(const String &p_bbcode) { - clear(); return append_bbcode(p_bbcode); } Error RichTextLabel::append_bbcode(const String &p_bbcode) { - int pos = 0; List<String> tag_stack; @@ -2083,7 +1949,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { set_process_internal(false); while (pos < p_bbcode.length()) { - int brk_pos = p_bbcode.find("[", pos); if (brk_pos < 0) @@ -2108,7 +1973,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { 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()); if (tag_stack.front()->get() == "b") @@ -2130,7 +1994,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pop(); } else if (tag == "b") { - //use bold font in_bold = true; if (in_italics) @@ -2140,7 +2003,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "i") { - //use italics font in_italics = true; if (in_bold) @@ -2150,13 +2012,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "code") { - //use monospace font push_font(mono_font); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag.begins_with("table=")) { - int columns = tag.substr(6, tag.length()).to_int(); if (columns < 1) columns = 1; @@ -2165,12 +2025,10 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("table"); } else if (tag == "cell") { - push_cell(); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag.begins_with("cell=")) { - int ratio = tag.substr(5, tag.length()).to_int(); if (ratio < 1) ratio = 1; @@ -2180,51 +2038,42 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = brk_end + 1; tag_stack.push_front("cell"); } else if (tag == "u") { - //use underline push_underline(); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "s") { - //use strikethrough push_strikethrough(); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "center") { - push_align(ALIGN_CENTER); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "fill") { - push_align(ALIGN_FILL); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "right") { - push_align(ALIGN_RIGHT); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "ul") { - push_list(LIST_DOTS); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "ol") { - push_list(LIST_NUMBERS); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "indent") { - indent_level++; push_indent(indent_level); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "url") { - int end = p_bbcode.find("[", brk_end); if (end == -1) end = p_bbcode.length(); @@ -2235,13 +2084,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front(tag); } else if (tag.begins_with("url=")) { - String url = tag.substr(4, tag.length()); push_meta(url); pos = brk_end + 1; tag_stack.push_front("url"); } else if (tag == "img") { - int end = p_bbcode.find("[", brk_end); if (end == -1) end = p_bbcode.length(); @@ -2255,7 +2102,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = end; tag_stack.push_front(tag); } else if (tag.begins_with("img=")) { - int width = 0; int height = 0; @@ -2281,7 +2127,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { pos = end; tag_stack.push_front("img"); } else if (tag.begins_with("color=")) { - String col = tag.substr(6, tag.length()); Color color; @@ -2327,7 +2172,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front("color"); } else if (tag.begins_with("font=")) { - String fnt = tag.substr(5, tag.length()); Ref<Font> font = ResourceLoader::load(fnt, "Font"); @@ -2480,14 +2324,12 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } void RichTextLabel::scroll_to_line(int p_line) { - ERR_FAIL_INDEX(p_line, main->lines.size()); _validate_line_caches(main); vscroll->set_value(main->lines[p_line].height_accum_cache - main->lines[p_line].height_cache); } int RichTextLabel::get_line_count() const { - return current_frame->lines.size(); } @@ -2498,7 +2340,6 @@ int RichTextLabel::get_visible_line_count() const { } void RichTextLabel::set_selection_enabled(bool p_enabled) { - selection.enabled = p_enabled; if (!p_enabled) { if (selection.active) { @@ -2512,7 +2353,6 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) { } bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) { - ERR_FAIL_COND_V(!selection.enabled, false); Item *it = main; int charidx = 0; @@ -2523,9 +2363,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p } while (it) { - if (it->type == ITEM_TEXT) { - ItemText *t = static_cast<ItemText *>(it); int sp = t->text.findn(p_string, charidx); if (sp != -1) { @@ -2571,7 +2409,6 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p } void RichTextLabel::selection_copy() { - if (!selection.active || !selection.enabled) return; @@ -2580,9 +2417,7 @@ void RichTextLabel::selection_copy() { RichTextLabel::Item *item = selection.from; while (item) { - if (item->type == ITEM_TEXT) { - String itext = static_cast<ItemText *>(item)->text; if (item == selection.from && item == selection.to) { text += itext.substr(selection.from_char, selection.to_char - selection.from_char + 1); @@ -2609,7 +2444,6 @@ void RichTextLabel::selection_copy() { } bool RichTextLabel::is_selection_enabled() const { - return selection.enabled; } @@ -2624,7 +2458,6 @@ void RichTextLabel::set_bbcode(const String &p_bbcode) { } String RichTextLabel::get_bbcode() const { - return bbcode; } @@ -2636,7 +2469,6 @@ void RichTextLabel::set_use_bbcode(bool p_enable) { } bool RichTextLabel::is_using_bbcode() const { - return use_bbcode; } @@ -2663,14 +2495,11 @@ void RichTextLabel::set_text(const String &p_string) { } void RichTextLabel::set_percent_visible(float p_percent) { - if (p_percent < 0 || p_percent >= 1) { - visible_characters = -1; percent_visible = 1; } else { - visible_characters = get_total_character_count() * p_percent; percent_visible = p_percent; } @@ -2717,7 +2546,6 @@ int RichTextLabel::get_content_height() { } void RichTextLabel::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input); ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text); ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text); @@ -2857,7 +2685,6 @@ int RichTextLabel::get_visible_characters() const { return visible_characters; } int RichTextLabel::get_total_character_count() const { - int tc = 0; for (int i = 0; i < current_frame->lines.size(); i++) tc += current_frame->lines[i].char_count; @@ -2871,7 +2698,6 @@ void RichTextLabel::set_fixed_size_to_width(int p_width) { } Size2 RichTextLabel::get_minimum_size() const { - if (fixed_width != -1) { const_cast<RichTextLabel *>(this)->_validate_line_caches(main); return Size2(fixed_width, const_cast<RichTextLabel *>(this)->get_content_height()); @@ -2953,7 +2779,6 @@ Dictionary RichTextLabel::parse_expressions_for_values(Vector<String> p_expressi } RichTextLabel::RichTextLabel() { - main = memnew(ItemFrame); main->index = 0; current = main; |