diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-07-09 15:22:01 +0200 |
---|---|---|
committer | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2019-07-09 20:30:18 +0200 |
commit | 2491c87f8658696509c58985c3c075d32e585305 (patch) | |
tree | 2e2b1800b92f7146cf51f7467bd0e90138a97a9b /editor/plugins | |
parent | 7f80c1dca8892cab4f4fe7a2daf6699755024f09 (diff) |
Add `width` and `antialiased` parameters to CanvasItem `draw_rect()`
This also removes some duplicated editor code which is now obsoleted
by the new parameters in `draw_rect()`.
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/curve_editor_plugin.cpp | 19 | ||||
-rw-r--r-- | editor/plugins/curve_editor_plugin.h | 2 | ||||
-rw-r--r-- | editor/plugins/spatial_editor_plugin.cpp | 21 |
3 files changed, 3 insertions, 39 deletions
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index d2d2b8f130..33f685892c 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -715,7 +715,7 @@ void CurveEditor::_draw() { if (_hover_point != -1) { const Color hover_color = line_color; Vector2 pos = curve.get_point_position(_hover_point); - stroke_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(_hover_radius), hover_color); + draw_rect(Rect2(get_view_pos(pos), Vector2(1, 1)).grow(_hover_radius), hover_color, false, Math::round(EDSCALE)); } // Help text @@ -726,23 +726,6 @@ void CurveEditor::_draw() { } } -// TODO That should be part of the drawing API... -void CurveEditor::stroke_rect(Rect2 rect, Color color) { - - // a---b - // | | - // c---d - Vector2 a(rect.position); - Vector2 b(rect.position.x + rect.size.x, rect.position.y); - Vector2 c(rect.position.x, rect.position.y + rect.size.y); - Vector2 d(rect.position + rect.size); - - draw_line(a, b, color, Math::round(EDSCALE)); - draw_line(b, d, color, Math::round(EDSCALE)); - draw_line(d, c, color, Math::round(EDSCALE)); - draw_line(c, a, color, Math::round(EDSCALE)); -} - void CurveEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &CurveEditor::on_gui_input); ClassDB::bind_method(D_METHOD("_on_preset_item_selected"), &CurveEditor::on_preset_item_selected); diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h index be774a9696..2e2bf1c26f 100644 --- a/editor/plugins/curve_editor_plugin.h +++ b/editor/plugins/curve_editor_plugin.h @@ -97,8 +97,6 @@ private: void _draw(); - void stroke_rect(Rect2 rect, Color color); - private: Transform2D _world_to_view; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index fc72f25b04..66663d0cd9 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2348,23 +2348,6 @@ void SpatialEditorViewport::_notification(int p_what) { } } -// TODO That should be part of the drawing API... -static void stroke_rect(CanvasItem &ci, Rect2 rect, Color color, real_t width = 1.0) { - - // a---b - // | | - // c---d - Vector2 a(rect.position); - Vector2 b(rect.position.x + rect.size.x, rect.position.y); - Vector2 c(rect.position.x, rect.position.y + rect.size.y); - Vector2 d(rect.position + rect.size); - - ci.draw_line(a, b, color, width); - ci.draw_line(b, d, color, width); - ci.draw_line(d, c, color, width); - ci.draw_line(c, a, color, width); -} - static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon) { // Adjust bar size from control height @@ -2379,7 +2362,7 @@ static void draw_indicator_bar(Control &surface, real_t fill, Ref<Texture> icon) // Draw both neutral dark and bright colors to account this surface.draw_rect(r, Color(1, 1, 1, 0.2)); surface.draw_rect(Rect2(r.position.x, r.position.y + r.size.y - sy, r.size.x, sy), Color(1, 1, 1, 0.6)); - stroke_rect(surface, r.grow(1), Color(0, 0, 0, 0.7)); + surface.draw_rect(r.grow(1), Color(0, 0, 0, 0.7), false, Math::round(EDSCALE)); Vector2 icon_size = icon->get_size(); Vector2 icon_pos = Vector2(r.position.x - (icon_size.x - r.size.x) / 2, r.position.y + r.size.y + 2); @@ -2460,7 +2443,7 @@ void SpatialEditorViewport::_draw() { draw_rect = Rect2(Vector2(), s).clip(draw_rect); - stroke_rect(*surface, draw_rect, Color(0.6, 0.6, 0.1, 0.5), 2.0); + surface->draw_rect(draw_rect, Color(0.6, 0.6, 0.1, 0.5), false, Math::round(2 * EDSCALE)); } else { |