diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-23 04:40:15 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-23 04:40:15 +0200 |
commit | 630e16296276eacec4fea22519b8610b88847a1a (patch) | |
tree | 61de3c427a459cd6d303b4c4654edf25e1e85575 | |
parent | 264c759ce2cdc53df28248394f40400d6dcf9ace (diff) |
fix snap-drag tile display
-rw-r--r-- | editor/draw.cpp | 20 | ||||
-rw-r--r-- | editor/editor.cpp | 8 | ||||
-rw-r--r-- | editor/editor.hpp | 1 |
3 files changed, 23 insertions, 6 deletions
diff --git a/editor/draw.cpp b/editor/draw.cpp index f482d373..09f9c490 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -25,9 +25,17 @@ void app::draw_cursor() auto& w = M->world(); const auto inactive_color = 0xff00ffff_rgbaf; - if (cursor.tile && !cursor.in_imgui) + global_coords tile; + if (auto pos = _editor.mouse_drag_pos()) + tile = *pos; + else if (cursor.tile) + tile = *cursor.tile; + else + return; + + if (!cursor.in_imgui) { - const auto draw = [&, pos = *cursor.tile](auto& mesh, const auto& size) { + const auto draw = [&, pos = tile](auto& mesh, const auto& size) { const auto center = Vector3(pos) * TILE_SIZE; mesh.draw(shader, {center, size, LINE_WIDTH}); }; @@ -58,9 +66,9 @@ void app::draw_cursor() shader.set_tint({1, 1, 1, 0.75f}); auto [_f, _w, anim_mesh] = M->meshes(); const auto offset = Vector3i(Vector2i(sel.offset), 0); - const auto pos = Vector3i(*cursor.tile)*iTILE_SIZE + offset; - auto [ch, t] = w[*cursor.tile]; - if (!ch.can_place_object(sel, cursor.tile->local())) + const auto pos = Vector3i(tile)*iTILE_SIZE + offset; + auto [ch, t] = w[tile]; + if (!ch.can_place_object(sel, tile.local())) shader.set_tint({1, 0, 1, 0.5f}); anim_mesh.draw(shader, *sel.atlas, sel.r, sel.frame, Vector3(pos), 1); } @@ -75,7 +83,7 @@ void app::draw_cursor() draw(_wireframe_quad, TILE_SIZE2); shader.set_tint({1, 1, 1, 0.75f}); auto [_f, _w, anim_mesh] = M->meshes(); - const auto pos = Vector3i(*cursor.tile)*iTILE_SIZE; + const auto pos = Vector3i(tile)*iTILE_SIZE; anim_mesh.draw(shader, *atlas, rotation::N, 0, Vector3(pos), 1); } } diff --git a/editor/editor.cpp b/editor/editor.cpp index 028e02fe..a1561081 100644 --- a/editor/editor.cpp +++ b/editor/editor.cpp @@ -89,6 +89,14 @@ void editor::on_mouse_move(world& world, global_coords& pos, int mods) on_release(); } +Optional<global_coords> editor::mouse_drag_pos() +{ + if (_last_pos) + return _last_pos->draw_coord; + else + return NullOpt; +} + void editor::on_click_(world& world, global_coords pos, button b) { // todo make template diff --git a/editor/editor.hpp b/editor/editor.hpp index 8fa3a859..1ae983de 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -40,6 +40,7 @@ struct editor final void on_mouse_move(world& world, global_coords& pos, int modifiers); void on_release(); void clear_selection(); + Optional<global_coords> mouse_drag_pos(); editor(app* a); editor(editor&&) noexcept = default; |