Early exit when nothing to draw in style box flat (fixes #27764)

This commit is contained in:
PouleyKetchoupp 2019-04-07 22:23:44 +02:00
parent 3dabe862af
commit cb3842833a

View file

@ -669,11 +669,15 @@ inline void adapt_values(int p_index_a, int p_index_b, int *adapted_values, cons
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
//PREPARATIONS //PREPARATIONS
bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0);
bool draw_shadow = (shadow_size > 0);
if (!draw_border && !draw_center && !draw_shadow) {
return;
}
bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0); bool rounded_corners = (corner_radius[0] > 0) || (corner_radius[1] > 0) || (corner_radius[2] > 0) || (corner_radius[3] > 0);
bool aa_on = rounded_corners && anti_aliased; bool aa_on = rounded_corners && anti_aliased;
bool draw_border = (border_width[0] > 0) || (border_width[1] > 0) || (border_width[2] > 0) || (border_width[3] > 0);
Color border_color_alpha = Color(border_color.r, border_color.g, border_color.b, 0); Color border_color_alpha = Color(border_color.r, border_color.g, border_color.b, 0);
bool blend_on = blend_border && draw_border; bool blend_on = blend_border && draw_border;
@ -710,11 +714,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
Vector<int> indices; Vector<int> indices;
Vector<Color> colors; Vector<Color> colors;
//DRAWING
VisualServer *vs = VisualServer::get_singleton();
//DRAW SHADOW //DRAW SHADOW
if (shadow_size > 0) { if (draw_shadow) {
int shadow_width[4] = { shadow_size, shadow_size, shadow_size, shadow_size }; int shadow_width[4] = { shadow_size, shadow_size, shadow_size, shadow_size };
Rect2 shadow_inner_rect = style_rect; Rect2 shadow_inner_rect = style_rect;
@ -798,6 +799,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
} }
} }
//DRAWING
VisualServer *vs = VisualServer::get_singleton();
vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors); vs->canvas_item_add_triangle_array(p_canvas_item, indices, verts, colors);
} }