1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

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()`.
This commit is contained in:
Hugo Locurcio
2019-07-09 15:22:01 +02:00
parent 7f80c1dca8
commit 2491c87f86
6 changed files with 56 additions and 47 deletions

View File

@@ -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 {