summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--main/app.cpp32
-rw-r--r--main/app.hpp13
-rw-r--r--main/camera.cpp4
-rw-r--r--main/draw.cpp2
-rw-r--r--main/imgui.cpp (renamed from main/gui.cpp)0
-rw-r--r--main/keyboard.cpp14
6 files changed, 32 insertions, 33 deletions
diff --git a/main/app.cpp b/main/app.cpp
index f60b1287..84831978 100644
--- a/main/app.cpp
+++ b/main/app.cpp
@@ -81,10 +81,8 @@ void app::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
void app::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
{
- if (_imgui.handleMouseMoveEvent(event) && false)
- return _cursor_tile = std::nullopt, event.setAccepted();
-
- _cursor_pos = event.position();
+ _cursor_in_imgui = _imgui.handleMouseMoveEvent(event);
+ _cursor_pixel = event.position();
recalc_cursor_tile();
}
@@ -100,15 +98,29 @@ void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
return keys = {}, event.setAccepted();
}
+void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ if (_imgui.handleKeyPressEvent(event))
+ return event.setAccepted();
+ do_key(event.key(), event.modifiers(), true, event.isRepeated());
+}
+
+void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
+{
+ if (_imgui.handleKeyReleaseEvent(event))
+ return keys = {}, event.setAccepted();
+ do_key(event.key(), event.modifiers(), false, false);
+}
+
void app::anyEvent(SDL_Event& event)
{
if (event.type == SDL_WINDOWEVENT)
switch (event.window.event)
{
case SDL_WINDOWEVENT_FOCUS_LOST:
- return event_leave();
+ return event_focus_out();
case SDL_WINDOWEVENT_FOCUS_GAINED:
- return event_enter();
+ return event_focus_in();
case SDL_WINDOWEVENT_LEAVE:
return event_mouse_leave();
case SDL_WINDOWEVENT_ENTER:
@@ -118,19 +130,19 @@ void app::anyEvent(SDL_Event& event)
}
}
-void app::event_leave()
+void app::event_focus_out()
{
- _cursor_pos = std::nullopt;
+ _cursor_pixel = std::nullopt;
_cursor_tile = std::nullopt;
}
-void app::event_enter()
+void app::event_focus_in()
{
}
void app::event_mouse_leave()
{
- _cursor_pos = std::nullopt;
+ _cursor_pixel = std::nullopt;
_cursor_tile = std::nullopt;
}
diff --git a/main/app.hpp b/main/app.hpp
index 89439dc0..7417962e 100644
--- a/main/app.hpp
+++ b/main/app.hpp
@@ -37,18 +37,18 @@ struct app final : Platform::Application
void update_window_scale(Vector2i window_size);
void recalc_cursor_tile();
- void keyPressEvent(KeyEvent& event) override;
- void keyReleaseEvent(KeyEvent& event) override;
+ void viewportEvent(ViewportEvent& event) override;
void mousePressEvent(MouseEvent& event) override;
void mouseReleaseEvent(MouseEvent& event) override;
void mouseMoveEvent(MouseMoveEvent& event) override;
void mouseScrollEvent(MouseScrollEvent& event) override;
void textInputEvent(TextInputEvent& event) override;
- void viewportEvent(ViewportEvent& event) override;
+ void keyPressEvent(KeyEvent& event) override;
+ void keyReleaseEvent(KeyEvent& event) override;
void anyEvent(SDL_Event& event) override;
- void event_leave();
- void event_enter();
+ void event_focus_out();
+ void event_focus_in();
void event_mouse_enter();
void event_mouse_leave();
@@ -97,9 +97,10 @@ struct app final : Platform::Application
enum_bitset<key> keys;
Magnum::Timeline timeline;
editor _editor;
- std::optional<Vector2i> _cursor_pos;
+ std::optional<Vector2i> _cursor_pixel;
std::optional<global_coords> _cursor_tile;
float _frame_time = 0;
+ bool _cursor_in_imgui = false;
static constexpr std::int16_t BASE_X = 0, BASE_Y = 0;
};
diff --git a/main/camera.cpp b/main/camera.cpp
index 7086b562..c3a3b2f7 100644
--- a/main/camera.cpp
+++ b/main/camera.cpp
@@ -48,8 +48,8 @@ void app::update_window_scale(Vector2i sz)
void app::recalc_cursor_tile()
{
- if (_cursor_pos)
- _cursor_tile = pixel_to_tile(Vector2d(*_cursor_pos));
+ if (_cursor_pixel)
+ _cursor_tile = pixel_to_tile(Vector2d(*_cursor_pixel));
else
_cursor_tile = std::nullopt;
}
diff --git a/main/draw.cpp b/main/draw.cpp
index 6d165c89..85cabb90 100644
--- a/main/draw.cpp
+++ b/main/draw.cpp
@@ -94,7 +94,7 @@ void app::draw_wireframe_box(local_coords pt)
void app::draw_cursor_tile()
{
- if (_cursor_tile)
+ if (_cursor_tile && !_cursor_in_imgui)
draw_wireframe_quad(*_cursor_tile);
}
diff --git a/main/gui.cpp b/main/imgui.cpp
index 8d2cb97e..8d2cb97e 100644
--- a/main/gui.cpp
+++ b/main/imgui.cpp
diff --git a/main/keyboard.cpp b/main/keyboard.cpp
index 66dafa7e..b40daec4 100644
--- a/main/keyboard.cpp
+++ b/main/keyboard.cpp
@@ -32,18 +32,4 @@ app::~app()
loader_::destroy();
}
-void app::keyPressEvent(Platform::Sdl2Application::KeyEvent& event)
-{
- if (_imgui.handleKeyPressEvent(event))
- return event.setAccepted();
- do_key(event.key(), event.modifiers(), true, event.isRepeated());
-}
-
-void app::keyReleaseEvent(Platform::Sdl2Application::KeyEvent& event)
-{
- if (_imgui.handleKeyReleaseEvent(event))
- return keys = {}, event.setAccepted();
- do_key(event.key(), event.modifiers(), false, false);
-}
-
} // namespace floormat