diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-26 19:16:25 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-26 19:16:25 +0100 |
| commit | 90d388665cfdb048a71fcadf0e142bb679f160ef (patch) | |
| tree | ef5c8a5c01619a244cf6ebccfe806ae2a5c45baa /editor | |
| parent | e8dc8c27155afade10310c84678959f2d7456641 (diff) | |
bbox rotation work
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.hpp | 1 | ||||
| -rw-r--r-- | editor/scenery-editor.cpp | 20 | ||||
| -rw-r--r-- | editor/update.cpp | 44 |
3 files changed, 33 insertions, 32 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index 64fdb587..d12a7001 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -108,6 +108,7 @@ private: void do_key(key k, int mods); void do_key(key k); + void do_rotate(bool backward); void apply_commands(const key_set& k); int get_key_modifiers(); void clear_keys(key min_inclusive, key max_exclusive); diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp index d8f74f7d..f9a0678e 100644 --- a/editor/scenery-editor.cpp +++ b/editor/scenery-editor.cpp @@ -21,11 +21,7 @@ scenery_editor::scenery_editor() noexcept void scenery_editor::set_rotation(rotation_ r) { - if (_selected.proto.atlas) - { - (void)_selected.proto.atlas->group(r); - _selected.proto.frame.r = r; - } + _selected.proto.frame.rotate(r); } rotation_ scenery_editor::rotation() const @@ -35,23 +31,21 @@ rotation_ scenery_editor::rotation() const void scenery_editor::next_rotation() { - if (_selected) - set_rotation(_selected.proto.atlas->next_rotation_from(_selected.proto.frame.r)); + set_rotation(_selected.proto.atlas->next_rotation_from(_selected.proto.frame.r)); } void scenery_editor::prev_rotation() { - if (_selected) - set_rotation(_selected.proto.atlas->next_rotation_from(_selected.proto.frame.r)); + set_rotation(_selected.proto.atlas->prev_rotation_from(_selected.proto.frame.r)); } void scenery_editor::select_tile(const scenery_& s) { - const auto rot = s.proto.atlas && s.proto.atlas->check_rotation(_selected.proto.frame.r) - ? _selected.proto.frame.r - : s.proto.frame.r; + const auto r = s.proto.atlas && s.proto.atlas->check_rotation(_selected.proto.frame.r) + ? _selected.proto.frame.r + : s.proto.frame.r; _selected = s; - _selected.proto.frame.r = rot; + set_rotation(r); } void scenery_editor::clear_selection() diff --git a/editor/update.cpp b/editor/update.cpp index 7423ef76..3481ea3b 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -83,6 +83,30 @@ void app::do_mouse_up_down(std::uint8_t button, bool is_down, int mods) _editor.on_release(); } +void app::do_rotate(bool backward) +{ + if (auto* ed = _editor.current_tile_editor()) + ed->toggle_rotation(); + else if (auto* ed = _editor.current_scenery_editor()) + { + if (ed->is_anything_selected()) + backward ? ed->prev_rotation() : ed->next_rotation(); + else if (cursor.tile) + { + auto [c, t] = M->world()[*cursor.tile]; + if (auto [atlas, s] = t.scenery(); atlas) + { + auto r = backward ? atlas->prev_rotation_from(s.r) : atlas->next_rotation_from(s.r); + if (r != s.r) + { + s.rotate(r); + c.mark_scenery_modified(); + } + } + } + } +} + void app::do_key(key k, int mods) { (void)mods; @@ -93,25 +117,7 @@ void app::do_key(key k, int mods) fm_warn("unhandled key: '%zu'", std::size_t(k)); return; case key_rotate_tile: - if (auto* ed = _editor.current_tile_editor()) - ed->toggle_rotation(); - else if (auto* ed = _editor.current_scenery_editor()) - { - if (ed->is_anything_selected()) - ed->next_rotation(); - else if (cursor.tile) - { - auto [c, t] = M->world()[*cursor.tile]; - if (auto [atlas, s] = t.scenery(); atlas) - { - auto old_r = s.r; - s.r = atlas->next_rotation_from(s.r); - if (s.r != old_r) - c.mark_scenery_modified(); - } - } - } - return; + return do_rotate(false); case key_mode_none: return _editor.set_mode(editor_mode::none); case key_mode_floor: |
