diff options
author | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-01-04 15:28:11 +0100 |
---|---|---|
committer | Ignacio Etcheverry <ignalfonsore@gmail.com> | 2016-01-04 15:28:11 +0100 |
commit | a9dbe83155ec707f87f5eb6fae782e4947d84aa5 (patch) | |
tree | a1856aa52e4775efc666da698e947d0412323496 /tools/editor/plugins | |
parent | e22e0cecf7bdf7f16956e4657df4b6de77bdee24 (diff) |
TileMap: Properly flip/rotate tiles with non-square region
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r-- | tools/editor/plugins/tile_map_editor_plugin.cpp | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index 5ee0259d56..29326a2222 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -680,26 +680,39 @@ void TileMapEditor::_canvas_draw() { Rect2 r = ts->tile_get_region(st); Size2 sc = xform.get_scale(); - if (transpose->is_pressed()) + Rect2 rect; + if (r==Rect2()) { + rect=Rect2(from,t->get_size()); + } else { + + rect=Rect2(from,r.get_size()); + } + + bool transp = transpose->is_pressed(); + bool flip_h = mirror_x->is_pressed(); + bool flip_v = mirror_y->is_pressed(); + + if (rect.size.y > rect.size.x) { + if ((flip_h && (flip_v || transp)) || (flip_v && !transp)) + tile_ofs.y += rect.size.y - rect.size.x; + } else if (rect.size.y < rect.size.x) { + if ((flip_v && (flip_h || transp)) || (flip_h && !transp)) + tile_ofs.x += rect.size.x - rect.size.y; + } + + if (transp) { SWAP(tile_ofs.x, tile_ofs.y); + } - if (mirror_x->is_pressed()) { + if (flip_h) { sc.x*=-1.0; tile_ofs.x*=-1.0; } - if (mirror_y->is_pressed()) { + if (flip_v) { sc.y*=-1.0; tile_ofs.y*=-1.0; } - Rect2 rect; - if (r==Rect2()) { - rect=Rect2(from,t->get_size()); - } else { - - rect=Rect2(from,r.get_size()); - } - if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { rect.pos+=tile_ofs; @@ -710,12 +723,12 @@ void TileMapEditor::_canvas_draw() { Vector2 center = (s/2) - tile_ofs; - if (mirror_x->is_pressed()) + if (flip_h) rect.pos.x-=s.x-center.x; else rect.pos.x-=center.x; - if (mirror_y->is_pressed()) + if (flip_v) rect.pos.y-=s.y-center.y; else rect.pos.y-=center.y; @@ -726,10 +739,10 @@ void TileMapEditor::_canvas_draw() { if (r==Rect2()) { - canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transpose->is_pressed()); + canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transp); } else { - canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transpose->is_pressed()); + canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transp); } } } |