From 108f9646f544076708f1b7418960193950cb6208 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Thu, 15 Aug 2019 22:17:08 +0200 Subject: [PATCH] Add an outline to box selection rectangles for better visibility This also refactors selection box color definitions to avoid repetition. --- editor/animation_track_editor.cpp | 7 +++---- editor/editor_themes.cpp | 2 ++ editor/plugins/canvas_item_editor_plugin.cpp | 11 ++++++++--- editor/plugins/spatial_editor_plugin.cpp | 18 ++++++++++++------ scene/gui/graph_edit.cpp | 10 ++++++++-- 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 014bb08144b..bd696d53788 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -5050,10 +5050,9 @@ float AnimationTrackEditor::get_moving_selection_offset() const { void AnimationTrackEditor::_box_selection_draw() { - Color color = get_color("accent_color", "Editor"); - color.a = 0.2; - Rect2 rect = Rect2(Point2(), box_selection->get_size()); - box_selection->draw_rect(rect, color); + const Rect2 selection_rect = Rect2(Point2(), box_selection->get_size()); + box_selection->draw_rect(selection_rect, get_color("box_selection_fill_color", "Editor")); + box_selection->draw_rect(selection_rect, get_color("box_selection_stroke_color", "Editor"), false, Math::round(EDSCALE)); } void AnimationTrackEditor::_scroll_input(const Ref &p_event) { diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 97af0d08eac..9c1e919824f 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -351,6 +351,8 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_color("dark_color_3", "Editor", dark_color_3); theme->set_color("contrast_color_1", "Editor", contrast_color_1); theme->set_color("contrast_color_2", "Editor", contrast_color_2); + theme->set_color("box_selection_fill_color", "Editor", accent_color * Color(1, 1, 1, 0.3)); + theme->set_color("box_selection_stroke_color", "Editor", accent_color * Color(1, 1, 1, 0.8)); theme->set_color("font_color", "Editor", font_color); theme->set_color("highlighted_font_color", "Editor", font_color_hl); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 98c2f21e45d..cc707dbf441 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2918,10 +2918,15 @@ void CanvasItemEditor::_draw_selection() { Point2 bsfrom = transform.xform(drag_from); Point2 bsto = transform.xform(box_selecting_to); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, + viewport->draw_rect( Rect2(bsfrom, bsto - bsfrom), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + get_color("box_selection_fill_color", "Editor")); + + viewport->draw_rect( + Rect2(bsfrom, bsto - bsfrom), + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } if (drag_type == DRAG_ROTATE) { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index f2b1aad59dd..20a06f3ac01 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2373,16 +2373,22 @@ void SpatialEditorViewport::_draw() { get_stylebox("Focus", "EditorStyles")->draw(surface->get_canvas_item(), r); } - RID ci = surface->get_canvas_item(); - if (cursor.region_select) { + const Rect2 selection_rect = Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, - Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + surface->draw_rect( + selection_rect, + get_color("box_selection_fill_color", "Editor")); + + surface->draw_rect( + selection_rect, + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } + RID ci = surface->get_canvas_item(); + if (message_time > 0) { Ref font = get_font("font", "Label"); Point2 msgpos = Point2(5, get_size().y - 20); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 38005f13223..fdffb26cb54 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -776,10 +776,16 @@ void GraphEdit::_top_layer_draw() { _draw_cos_line(top_layer, pos, topos, col, col); } - if (box_selecting) + if (box_selecting) { top_layer->draw_rect( box_selecting_rect, - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + get_color("box_selection_fill_color", "Editor")); + + top_layer->draw_rect( + box_selecting_rect, + get_color("box_selection_stroke_color", "Editor"), + false); + } } void GraphEdit::set_selected(Node *p_child) {