From 19daf844f7493ca05ce7b427664f7345a85752b1 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 19 Mar 2023 20:15:48 +0100 Subject: main: don't set cursor when not needed --- main/events.cpp | 5 +++-- main/main-impl.cpp | 6 +++++- main/main-impl.hpp | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'main') diff --git a/main/events.cpp b/main/events.cpp index 6888132a..1f1c81a2 100644 --- a/main/events.cpp +++ b/main/events.cpp @@ -91,15 +91,16 @@ void main_impl::anyEvent(SDL_Event& event) case SDL_WINDOWEVENT_FOCUS_LOST: return app.on_focus_out(); case SDL_WINDOWEVENT_FOCUS_GAINED: + _mouse_cursor = (uint32_t)-1; return app.on_focus_in(); case SDL_WINDOWEVENT_LEAVE: return app.on_mouse_leave(); case SDL_WINDOWEVENT_ENTER: + _mouse_cursor = (uint32_t)-1; return app.on_mouse_enter(); - default: { + default: return app.on_any_event(make_any_event(event)); } - } } else return app.on_any_event(make_any_event(event)); diff --git a/main/main-impl.cpp b/main/main-impl.cpp index 8cde3e2f..f6a3dff0 100644 --- a/main/main-impl.cpp +++ b/main/main-impl.cpp @@ -48,7 +48,11 @@ Vector2i floormat_main::window_size() const noexcept void main_impl::set_cursor(uint32_t cursor) noexcept { - setCursor(Cursor(cursor)); + if (cursor != _mouse_cursor || _mouse_cursor == (uint32_t)-1) + { + _mouse_cursor = cursor; + setCursor(Cursor(cursor)); + } } uint32_t main_impl::cursor() const noexcept diff --git a/main/main-impl.hpp b/main/main-impl.hpp index e968951e..dae4286e 100644 --- a/main/main-impl.hpp +++ b/main/main-impl.hpp @@ -82,6 +82,7 @@ private: std::vector _clickable_scenery; struct world _world{}; Magnum::Timeline timeline; + uint32_t _mouse_cursor = (uint32_t)-1; floor_mesh _floor_mesh; wall_mesh _wall_mesh; anim_mesh _anim_mesh; -- cgit v1.2.3