Browse Source

Merge pull request #8211 from robertdhernandez/NinePatch-Fix

[3.0] Fixed NinePatchRect/StyleBoxTexture incorrectly drawing AtlasTexture
Rémi Verschelde 8 years ago
parent
commit
1bd3648bb0

+ 13 - 13
drivers/gles3/rasterizer_canvas_gles3.cpp

@@ -535,49 +535,49 @@ void RasterizerCanvasGLES3::_canvas_item_render_commands(Item *p_item, Item *cur
 
 
 				//top left
 				//top left
 				DSTRECT(np->rect.pos.x, np->rect.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
 				DSTRECT(np->rect.pos.x, np->rect.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
-				SRCRECT(0, 0, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
+				SRCRECT(np->source.pos.x, np->source.pos.y, np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//top right
 				//top right
-				DSTRECT(np->rect.pos.x + np->rect.size.x - np->margin[MARGIN_RIGHT], np->rect.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
-				SRCRECT(texture->width - np->margin[MARGIN_RIGHT], 0, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+				DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+				SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y, np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//bottom right
 				//bottom right
-				DSTRECT(np->rect.pos.x + np->rect.size.x - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
-				SRCRECT(texture->width - np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
+				DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
+				SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_RIGHT], np->margin[MARGIN_BOTTOM]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//bottom left
 				//bottom left
-				DSTRECT(np->rect.pos.x, np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
-				SRCRECT(0, texture->height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
+				DSTRECT(np->rect.pos.x, np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
+				SRCRECT(np->source.pos.x, np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->margin[MARGIN_LEFT], np->margin[MARGIN_BOTTOM]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//top
 				//top
 				DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
 				DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y, np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
-				SRCRECT(np->margin[MARGIN_LEFT], 0, texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+				SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y, np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//bottom
 				//bottom
-				DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->rect.size.y - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
-				SRCRECT(np->margin[MARGIN_LEFT], texture->height - np->margin[MARGIN_BOTTOM], texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
+				DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->rect.size.height - np->margin[MARGIN_BOTTOM], np->rect.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP]);
+				SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->source.size.height - np->margin[MARGIN_BOTTOM], np->source.size.width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//left
 				//left
 				DSTRECT(np->rect.pos.x, np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 				DSTRECT(np->rect.pos.x, np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
-				SRCRECT(0, np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+				SRCRECT(np->source.pos.x, np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_LEFT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				//right
 				//right
 				DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 				DSTRECT(np->rect.pos.x + np->rect.size.width - np->margin[MARGIN_RIGHT], np->rect.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
-				SRCRECT(texture->width - np->margin[MARGIN_RIGHT], np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+				SRCRECT(np->source.pos.x + np->source.size.width - np->margin[MARGIN_RIGHT], np->source.pos.y + np->margin[MARGIN_TOP], np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 
 
 				if (np->draw_center) {
 				if (np->draw_center) {
 
 
 					//center
 					//center
 					DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 					DSTRECT(np->rect.pos.x + np->margin[MARGIN_LEFT], np->rect.pos.y + np->margin[MARGIN_TOP], np->rect.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->rect.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
-					SRCRECT(np->margin[MARGIN_LEFT], np->margin[MARGIN_TOP], texture->width - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], texture->height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
+					SRCRECT(np->source.pos.x + np->margin[MARGIN_LEFT], np->source.pos.y + np->margin[MARGIN_TOP], np->source.size.x - np->margin[MARGIN_LEFT] - np->margin[MARGIN_RIGHT], np->source.size.height - np->margin[MARGIN_TOP] - np->margin[MARGIN_BOTTOM]);
 					glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 					glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 				}
 				}
 
 

+ 12 - 1
scene/gui/dialogs.cpp

@@ -177,7 +177,18 @@ void WindowDialog::_notification(int p_what) {
 			Size2 size = get_size();
 			Size2 size = get_size();
 
 
 			Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
 			Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog");
-			panel->draw(canvas, Rect2(Point2(), size));
+			int margin_left = static_cast<int>(panel->get_margin(MARGIN_LEFT));
+			int margin_top = static_cast<int>(panel->get_margin(MARGIN_TOP));
+			int margin_right = static_cast<int>(panel->get_margin(MARGIN_RIGHT));
+			int margin_bottom = static_cast<int>(panel->get_margin(MARGIN_BOTTOM));
+
+			Rect2 rect;
+			rect.pos.x = -margin_left;
+			rect.pos.y = -margin_top;
+			rect.size.width = size.width + margin_left + margin_right;
+			rect.size.height = size.height + margin_top + margin_bottom;
+
+			panel->draw(canvas, rect);
 
 
 			int title_height = get_constant("title_height", "WindowDialog");
 			int title_height = get_constant("title_height", "WindowDialog");
 			Color title_color = get_color("title_color", "WindowDialog");
 			Color title_color = get_color("title_color", "WindowDialog");

+ 6 - 20
scene/gui/patch_9_rect.cpp

@@ -37,27 +37,13 @@ void NinePatchRect::_notification(int p_what) {
 		if (texture.is_null())
 		if (texture.is_null())
 			return;
 			return;
 
 
-		Size2 s = get_size();
+		Rect2 rect = Rect2(Point2(), get_size());
+		Rect2 src_rect = region_rect;
+
+		texture->get_rect_region(rect, src_rect, rect, src_rect);
+
 		RID ci = get_canvas_item();
 		RID ci = get_canvas_item();
-		VS::get_singleton()->canvas_item_add_nine_patch(ci, Rect2(Point2(), s), region_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center);
-		//draw_texture_rect(texture,Rect2(Point2(),s),false,modulate);
-
-		/*
-		Vector<Point2> points;
-		points.resize(4);
-		points[0]=Point2(0,0);
-		points[1]=Point2(s.x,0);
-		points[2]=Point2(s.x,s.y);
-		points[3]=Point2(0,s.y);
-		Vector<Point2> uvs;
-		uvs.resize(4);
-		uvs[0]=Point2(0,0);
-		uvs[1]=Point2(1,0);
-		uvs[2]=Point2(1,1);
-		uvs[3]=Point2(0,1);
-
-		VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid());
-*/
+		VS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center);
 	}
 	}
 }
 }
 
 

+ 1 - 1
scene/resources/default_theme/default_theme.cpp

@@ -544,7 +544,7 @@ void fill_default_theme(Ref<Theme> &t, const Ref<Font> &default_font, const Ref<
 
 
 	t->set_font("title_font", "WindowDialog", large_font);
 	t->set_font("title_font", "WindowDialog", large_font);
 	t->set_color("title_color", "WindowDialog", Color(0, 0, 0));
 	t->set_color("title_color", "WindowDialog", Color(0, 0, 0));
-	t->set_constant("title_height", "WindowDialog", 18 * scale);
+	t->set_constant("title_height", "WindowDialog", 20 * scale);
 
 
 	t->set_icon("close", "WindowDialog", make_icon(close_png));
 	t->set_icon("close", "WindowDialog", make_icon(close_png));
 	t->set_icon("close_hilite", "WindowDialog", make_icon(close_hl_png));
 	t->set_icon("close_hilite", "WindowDialog", make_icon(close_hl_png));

+ 8 - 6
scene/resources/style_box.cpp

@@ -103,9 +103,11 @@ void StyleBoxTexture::set_texture(RES p_texture) {
 	if (texture == p_texture)
 	if (texture == p_texture)
 		return;
 		return;
 	texture = p_texture;
 	texture = p_texture;
+	region_rect = Rect2(Point2(), texture->get_size());
 	emit_signal("texture_changed");
 	emit_signal("texture_changed");
 	emit_changed();
 	emit_changed();
 }
 }
+
 RES StyleBoxTexture::get_texture() const {
 RES StyleBoxTexture::get_texture() const {
 
 
 	return texture;
 	return texture;
@@ -130,12 +132,12 @@ void StyleBoxTexture::draw(RID p_canvas_item, const Rect2 &p_rect) const {
 	if (texture.is_null())
 	if (texture.is_null())
 		return;
 		return;
 
 
-	Rect2 r = p_rect;
-	r.pos.x -= expand_margin[MARGIN_LEFT];
-	r.pos.y -= expand_margin[MARGIN_TOP];
-	r.size.x += expand_margin[MARGIN_LEFT] + expand_margin[MARGIN_RIGHT];
-	r.size.y += expand_margin[MARGIN_TOP] + expand_margin[MARGIN_BOTTOM];
-	VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, r, region_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
+	Rect2 rect = p_rect;
+	Rect2 src_rect = region_rect;
+
+	texture->get_rect_region(rect, src_rect, rect, src_rect);
+
+	VisualServer::get_singleton()->canvas_item_add_nine_patch(p_canvas_item, rect, src_rect, texture->get_rid(), Vector2(margin[MARGIN_LEFT], margin[MARGIN_TOP]), Vector2(margin[MARGIN_RIGHT], margin[MARGIN_BOTTOM]), VS::NINE_PATCH_STRETCH, VS::NINE_PATCH_STRETCH, draw_center, modulate);
 }
 }
 
 
 void StyleBoxTexture::set_draw_center(bool p_draw) {
 void StyleBoxTexture::set_draw_center(bool p_draw) {