From d58a159e3864bf6664851022bd26a7a98dc7fcf5 Mon Sep 17 00:00:00 2001 From: toger5 Date: Wed, 27 Sep 2017 19:24:05 +0200 Subject: [PATCH 1/3] keep font color on selection as default --- editor/editor_help.cpp | 1 + editor/editor_themes.cpp | 2 +- scene/gui/rich_text_label.cpp | 17 ++++++++++++++++- scene/gui/rich_text_label.h | 4 ++++ scene/gui/text_edit.cpp | 22 +++++++++++++++++----- scene/gui/text_edit.h | 3 +++ 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 6c8bd0f14b5..c4200b330ce 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1903,5 +1903,6 @@ EditorHelpBit::EditorHelpBit() { rich_text->set_area_as_parent_rect(); rich_text->connect("meta_clicked", this, "_meta_clicked"); rich_text->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + rich_text->set_override_selected_font_color(false); set_custom_minimum_size(Size2(0, 70 * EDSCALE)); } diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 3482261c192..1ae898c4711 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -837,7 +837,7 @@ Ref create_editor_theme(const Ref p_theme) { const Color caret_color = mono_color; const Color caret_background_color = mono_color.inverted(); const Color text_selected_color = dark_color_3; - const Color selection_color = alpha3; + const Color selection_color = alpha2; const Color brace_mismatch_color = error_color; const Color current_line_color = alpha1; const Color line_length_guideline_color = warning_color; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 71b9c4ec726..e21bb5aa7cf 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -336,7 +336,7 @@ void RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int cw = font->get_char_size(c[i], c[i + 1]).x; draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg); if (visible) - font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - (fh - ascent)), c[i], c[i + 1], selection_fg); + font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - (fh - ascent)), c[i], c[i + 1], override_selected_font_color ? selection_fg : color); } else { if (visible) @@ -1350,6 +1350,16 @@ 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); @@ -1874,6 +1884,9 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_meta_underline", "enable"), &RichTextLabel::set_meta_underline); ClassDB::bind_method(D_METHOD("is_meta_underlined"), &RichTextLabel::is_meta_underlined); + ClassDB::bind_method(D_METHOD("set_override_selected_font_color", "override"), &RichTextLabel::set_override_selected_font_color); + ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &RichTextLabel::is_overriding_selected_font_color); + ClassDB::bind_method(D_METHOD("set_scroll_active", "active"), &RichTextLabel::set_scroll_active); ClassDB::bind_method(D_METHOD("is_scroll_active"), &RichTextLabel::is_scroll_active); @@ -1913,6 +1926,7 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta"))); @@ -1968,6 +1982,7 @@ RichTextLabel::RichTextLabel() { tab_size = 4; default_align = ALIGN_LEFT; underline_meta = true; + override_selected_font_color = false; scroll_visible = false; scroll_follow = false; diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 4db2c3a8e9f..540bb99c479 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -220,6 +220,7 @@ private: int tab_size; bool underline_meta; + bool override_selected_font_color; Align default_align; @@ -312,6 +313,9 @@ public: void set_meta_underline(bool p_underline); bool is_meta_underlined() const; + void set_override_selected_font_color(bool p_override_selected_font_color); + bool is_overriding_selected_font_color() const; + void set_scroll_active(bool p_active); bool is_scroll_active() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d30e0b9f25b..7138c59c848 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -999,7 +999,7 @@ void TextEdit::_notification(int p_what) { if (brace_open_mismatch) color = cache.brace_mismatch_color; - cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection ? cache.font_selected_color : color); + cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); } if ( @@ -1008,7 +1008,7 @@ void TextEdit::_notification(int p_what) { if (brace_close_mismatch) color = cache.brace_mismatch_color; - cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection ? cache.font_selected_color : color); + cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); } } @@ -1067,15 +1067,15 @@ void TextEdit::_notification(int p_what) { } if (str[j] >= 32) { - int w = cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), str[j], str[j + 1], in_selection ? cache.font_selected_color : color); + int w = cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); if (underlined) { - draw_rect(Rect2(char_ofs + char_margin, ofs_y + ascent + 2, w, 1), in_selection ? cache.font_selected_color : color); + draw_rect(Rect2(char_ofs + char_margin, ofs_y + ascent + 2, w, 1), in_selection && override_selected_font_color ? cache.font_selected_color : color); } } else if (draw_tabs && str[j] == '\t') { int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2; - cache.tab_icon->draw(ci, Point2(char_ofs + char_margin, ofs_y + yofs), in_selection ? cache.font_selected_color : color); + cache.tab_icon->draw(ci, Point2(char_ofs + char_margin, ofs_y + yofs), in_selection && override_selected_font_color ? cache.font_selected_color : color); } char_ofs += char_w; @@ -4257,6 +4257,13 @@ bool TextEdit::is_drawing_tabs() const { return draw_tabs; } +void TextEdit::set_override_selected_font_color(bool p_override_selected_font_color) { + override_selected_font_color = p_override_selected_font_color; +} +bool TextEdit::is_overriding_selected_font_color() const { + return override_selected_font_color; +} + void TextEdit::set_insert_mode(bool p_enabled) { insert_mode = p_enabled; update(); @@ -4814,6 +4821,9 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences); ClassDB::bind_method(D_METHOD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled); + ClassDB::bind_method(D_METHOD("set_override_selected_font_color", "override"), &TextEdit::set_override_selected_font_color); + ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color); + ClassDB::bind_method(D_METHOD("set_syntax_coloring", "enable"), &TextEdit::set_syntax_coloring); ClassDB::bind_method(D_METHOD("is_syntax_coloring_enabled"), &TextEdit::is_syntax_coloring_enabled); @@ -4831,6 +4841,7 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), "set_syntax_coloring", "is_syntax_coloring_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed"); @@ -4861,6 +4872,7 @@ TextEdit::TextEdit() { readonly = false; setting_row = false; draw_tabs = false; + override_selected_font_color = false; draw_caret = true; max_chars = 0; clear(); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 7e61c4e8b1f..03f412729da 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -238,6 +238,7 @@ class TextEdit : public Control { bool setting_row; bool wrap; bool draw_tabs; + bool override_selected_font_color; bool cursor_changed_dirty; bool text_changed_dirty; bool undo_enabled; @@ -482,6 +483,8 @@ public: void set_indent_size(const int p_size); void set_draw_tabs(bool p_draw); bool is_drawing_tabs() const; + void set_override_selected_font_color(bool p_override_selected_font_color); + bool is_overriding_selected_font_color() const; void set_insert_mode(bool p_enabled); bool is_insert_mode() const; From d9272bfdbf9db94f101bdc4c90939288c8df45b2 Mon Sep 17 00:00:00 2001 From: toger5 Date: Wed, 27 Sep 2017 21:27:40 +0200 Subject: [PATCH 2/3] always use the adaptive code theme selection color in help since it wont changed based on the code theme anyways. --- editor/editor_help.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index c4200b330ce..d7c33166644 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1702,7 +1702,7 @@ void EditorHelp::_notification(int p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - class_desc->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); } break; @@ -1792,7 +1792,7 @@ EditorHelp::EditorHelp() { vbc->add_child(class_desc); class_desc->set_area_as_parent_rect(); class_desc->set_v_size_flags(SIZE_EXPAND_FILL); - class_desc->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + class_desc->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); class_desc->connect("meta_clicked", this, "_class_desc_select"); class_desc->connect("gui_input", this, "_class_desc_input"); } @@ -1883,7 +1883,7 @@ void EditorHelpBit::_notification(int p_what) { switch (p_what) { case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - rich_text->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); } break; default: break; @@ -1902,7 +1902,7 @@ EditorHelpBit::EditorHelpBit() { add_child(rich_text); rich_text->set_area_as_parent_rect(); rich_text->connect("meta_clicked", this, "_meta_clicked"); - rich_text->add_color_override("selection_color", EDITOR_DEF("text_editor/highlighting/selection_color", Color(0.2, 0.2, 1))); + rich_text->add_color_override("selection_color", get_color("text_editor/theme/selection_color", "Editor")); rich_text->set_override_selected_font_color(false); set_custom_minimum_size(Size2(0, 70 * EDSCALE)); } From e49ac08c24a9a62c6766fdddcd1f9908002cb013 Mon Sep 17 00:00:00 2001 From: toger5 Date: Thu, 28 Sep 2017 16:10:30 +0200 Subject: [PATCH 3/3] do not overlap current line with selection color --- editor/editor_themes.cpp | 4 ++-- scene/gui/text_edit.cpp | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 1ae898c4711..f6bfd03e116 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -811,8 +811,8 @@ Ref create_editor_theme(const Ref p_theme) { const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5); const float mono_value = mono_color.r; - const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.1); - const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.3); + const Color alpha1 = Color(mono_value, mono_value, mono_value, 0.07); + const Color alpha2 = Color(mono_value, mono_value, mono_value, 0.14); const Color alpha3 = Color(mono_value, mono_value, mono_value, 0.5); const Color alpha4 = Color(mono_value, mono_value, mono_value, 0.7); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7138c59c848..facd272eed4 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -733,10 +733,6 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color); } - if (line == cursor.line) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_end, get_row_height()), cache.current_line_color); - } - if (text.is_breakpoint(line) && !draw_breakpoint_gutter) { #ifdef TOOLS_ENABLED VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y + get_row_height() - EDSCALE, xmargin_end - xmargin_beg, EDSCALE), cache.breakpoint_color); @@ -765,6 +761,7 @@ void TextEdit::_notification(int p_what) { cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width, ofs_y + cache.font->get_ascent()), fc, cache.line_number_color); } + //loop through charcters in one line for (int j = 0; j < str.length(); j++) { //look for keyword @@ -953,10 +950,22 @@ void TextEdit::_notification(int p_what) { } } + //current line highlighting bool in_selection = (selection.active && line >= selection.from_line && line <= selection.to_line && (line > selection.from_line || j >= selection.from_column) && (line < selection.to_line || j < selection.to_column)); + if (line == cursor.line) { + if (j == 0) + //first char + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, (char_ofs + char_margin), get_row_height()), cache.current_line_color); + else if (j == str.length() - 1) + //last char + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(char_ofs + char_margin + char_w, ofs_y, xmargin_end - (char_ofs + char_margin + char_w), get_row_height()), cache.current_line_color); + + if (!in_selection) + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.current_line_color); + } + if (in_selection) { - //inside selection! VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color); }