diff options
-rw-r--r-- | editor/app.hpp | 8 | ||||
-rw-r--r-- | editor/camera.cpp | 19 | ||||
-rw-r--r-- | editor/events.cpp | 27 | ||||
-rw-r--r-- | editor/imgui.cpp | 2 | ||||
-rw-r--r-- | editor/update.cpp | 20 |
5 files changed, 39 insertions, 37 deletions
diff --git a/editor/app.hpp b/editor/app.hpp index 79e0642b..4cdaff60 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -70,11 +70,13 @@ private: void maybe_initialize_chunk_(const chunk_coords& pos, chunk& c); - void do_mouse_move(global_coords pos); - + void do_mouse_move(); + void do_mouse_up_down(std::uint8_t button, bool is_down); void do_camera(float dt); + void do_keys(); + void reset_camera_offset(); - void recalc_cursor_tile(); + void update_cursor_tile(const std::optional<Vector2i>& pixel); void draw_cursor_tile(); void draw_wireframe_quad(global_coords pt); diff --git a/editor/camera.cpp b/editor/camera.cpp index 6762f538..a71bc189 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -9,7 +9,7 @@ namespace floormat { void app::do_camera(float dt) { if (keys[key::camera_reset]) - reset_camera_offset(); + reset_camera_offset(), do_mouse_move(); else { Vector2d dir{}; @@ -38,25 +38,24 @@ void app::do_camera(float dt) camera_offset[1] = std::clamp(camera_offset[1], -max_camera_offset[1], max_camera_offset[1]); shader.set_camera_offset(camera_offset); + + update_cursor_tile(cursor.pixel); + do_mouse_move(); } - else - return; } - recalc_cursor_tile(); - if (cursor.tile) - do_mouse_move(*cursor.tile); } void app::reset_camera_offset() { M->shader().set_camera_offset(tile_shader::project({TILE_MAX_DIM*-.5*dTILE_SIZE[0], TILE_MAX_DIM*-.5*dTILE_SIZE[1], 0})); - recalc_cursor_tile(); + update_cursor_tile(cursor.pixel); } -void app::recalc_cursor_tile() +void app::update_cursor_tile(const std::optional<Vector2i>& pixel) { - if (cursor.pixel && !cursor.in_imgui) - cursor.tile = M->pixel_to_tile(Vector2d(*cursor.pixel)); + cursor.pixel = pixel; + if (pixel) + cursor.tile = M->pixel_to_tile(Vector2d{*pixel}); else cursor.tile = std::nullopt; } diff --git a/editor/events.cpp b/editor/events.cpp index bdaa4c97..513f71c6 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -25,15 +25,8 @@ void app::on_mouse_move(const mouse_move_event& event) noexcept } e = {event.position}; cursor.in_imgui = _imgui.handleMouseMoveEvent(e); - - if (!cursor.in_imgui) - cursor.pixel = event.position; - else - cursor.pixel = std::nullopt; - recalc_cursor_tile(); - - if (cursor.tile) - do_mouse_move(*cursor.tile); + update_cursor_tile(event.position); + do_mouse_move(); } void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept @@ -54,15 +47,9 @@ void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce : _imgui.handleMouseReleaseEvent(e); !cursor.in_imgui) { - cursor.pixel = event.position; - recalc_cursor_tile(); + update_cursor_tile(event.position); if (cursor.tile) - { - if (event.button == mouse_button_left && is_down) - _editor.on_click(M->world(), *cursor.tile); - else - _editor.on_release(); - } + do_mouse_up_down(event.button, is_down); } } @@ -124,15 +111,13 @@ void app::on_viewport_event(const Math::Vector2<int>& size) noexcept void app::on_focus_out() noexcept { - cursor.pixel = std::nullopt; - recalc_cursor_tile(); + update_cursor_tile(std::nullopt); keys = {}; } void app::on_mouse_leave() noexcept { - cursor.pixel = std::nullopt; - recalc_cursor_tile(); + update_cursor_tile(std::nullopt); } } // namespace floormat diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 0052944e..25a76687 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -62,10 +62,10 @@ void app::draw_ui() ImGui::StyleColorsDark(&ImGui::GetStyle()); const float main_menu_height = draw_main_menu(); - draw_editor_pane(_editor.floor(), main_menu_height); draw_fps(); draw_cursor_tile(); draw_cursor_tile_text(); + draw_editor_pane(_editor.floor(), main_menu_height); ImGui::EndFrame(); } diff --git a/editor/update.cpp b/editor/update.cpp index 7e72de5e..28c2ffd3 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -35,9 +35,23 @@ void app::maybe_initialize_chunk([[maybe_unused]] const chunk_coords& pos, [[may //maybe_initialize_chunk_(pos, c); } -void app::do_mouse_move(global_coords pos) +void app::do_mouse_move() { - _editor.on_mouse_move(M->world(), pos); + if (cursor.tile && !cursor.in_imgui) + _editor.on_mouse_move(M->world(), *cursor.tile); +} + +void app::do_mouse_up_down(std::uint8_t button, bool is_down) +{ + if (!cursor.in_imgui && button == mouse_button_left && is_down) + _editor.on_click(M->world(), *cursor.tile); + else + _editor.on_release(); +} + +void app::do_keys() +{ + } void app::update(float dt) @@ -46,6 +60,8 @@ void app::update(float dt) draw_ui(); if (keys[key::quit]) M->quit(0); + if (!keys.any()) + do_keys(); } } // namespace floormat |