From 3037b3f6dcaea2de9de058d715a4e3dafc974039 Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Wed, 19 Mar 2014 15:43:56 +0800 Subject: fix render sprite used atlas texture position error --- scene/resources/texture.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index e5ac674784..8dbb73e23d 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -581,9 +581,25 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Vector2 scale = p_rect.size / p_src_rect.size; - Rect2 dr( p_rect.pos+ofs*scale,src_c.size*scale ); - - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); + if(scale.x >= 0 && scale.y >= 0) + { + Rect2 dr(src_c.size*scale,p_rect.pos+ofs*scale); + VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); + } + else + { + Rect2 dr(Point2i(),src_c.size*scale); + if(scale.x > 0) + dr.pos.x = p_rect.pos.x+ofs.x*scale.x; + else + dr.pos.x = p_rect.pos.x-(margin.size.width-margin.pos.x)*scale.x; + if(scale.y > 0) + dr.pos.y = p_rect.pos.y+ofs.y*scale.y; + else + dr.pos.y = p_rect.pos.y-(margin.size.height-margin.pos.y)*scale.y; + + VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); + } } -- cgit v1.2.3 From bc4e37b1322c8fa7c13b40e69d78483bbd6277dc Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Wed, 19 Mar 2014 15:55:12 +0800 Subject: fix a mistake --- scene/resources/texture.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 8dbb73e23d..a29fc5d921 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -583,7 +583,7 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const if(scale.x >= 0 && scale.y >= 0) { - Rect2 dr(src_c.size*scale,p_rect.pos+ofs*scale); + Rect2 dr(p_rect.pos+ofs*scale,src_c.size*scale); VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); } else -- cgit v1.2.3 From 61179e82c7078adab3a6d78ed47184f111db7d62 Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Wed, 19 Mar 2014 21:02:17 +0800 Subject: fix atlas texture algo --- scene/resources/texture.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index a29fc5d921..be3b921bad 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -580,26 +580,21 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item,const Rect2& p_rect, const Vector2 ofs = (src_c.pos-src.pos); Vector2 scale = p_rect.size / p_src_rect.size; - - if(scale.x >= 0 && scale.y >= 0) + if(scale.x < 0) { - Rect2 dr(p_rect.pos+ofs*scale,src_c.size*scale); - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); + float mx = (margin.size.width - margin.pos.x); + mx -= margin.pos.x; + ofs.x = -(ofs.x + mx); } - else + if(scale.y < 0) { - Rect2 dr(Point2i(),src_c.size*scale); - if(scale.x > 0) - dr.pos.x = p_rect.pos.x+ofs.x*scale.x; - else - dr.pos.x = p_rect.pos.x-(margin.size.width-margin.pos.x)*scale.x; - if(scale.y > 0) - dr.pos.y = p_rect.pos.y+ofs.y*scale.y; - else - dr.pos.y = p_rect.pos.y-(margin.size.height-margin.pos.y)*scale.y; - - VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); + float my = margin.size.height - margin.pos.y; + my -= margin.pos.y; + ofs.y = -(ofs.y + my); } + Rect2 dr( p_rect.pos+ofs*scale,src_c.size*scale ); + + VS::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item,dr,atlas->get_rid(),src_c,p_modulate); } -- cgit v1.2.3