Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
InputManager.cpp
Go to the documentation of this file.
1#include "input/InputManager.h"
2
3#include "Engine.h"
4#include "Log.h"
5#include "editor/Editor.h"
6
7namespace mnd
8{
9
11{
13}
14
15void InputManager::SetKeyPressed(Key key, bool pressed)
16{
17 const int index = static_cast<int>(key);
18 if (index < 0 || index >= static_cast<int>(m_keys.size()))
19 {
20 LOG_WARN("SetKeyPressed out-of-range key=%d (size=%zu)", index, m_keys.size());
21 return;
22 }
23 m_keys[index] = pressed;
24}
25
27{
28 const int index = static_cast<int>(key);
29 if (index < 0 || index >= static_cast<int>(m_keys.size()))
30 {
31 LOG_WARN("IsKeyPressed out-of-range key=%d (size=%zu)", index, m_keys.size());
32 return false;
33 }
35 {
36 return false;
37 }
38
39 return m_keys[index];
40}
41
43{
44 const int index = static_cast<int>(button);
45 if (index < 0 || index >= static_cast<int>(m_mouseKeys.size()))
46 {
47 return;
48 }
49 m_mouseKeys[index] = pressed;
50}
51
53{
54 const int index = static_cast<int>(button);
55 if (index < 0 || index >= static_cast<int>(m_mouseKeys.size()))
56 {
57 return false;
58 }
60 {
61 return false;
62 }
63
64 return m_mouseKeys[index];
65}
66
68{
69 m_mousePositionOld = pos;
70}
71
73{
74 return m_mousePositionOld;
75}
76
78{
79 m_mousePositionCurrent = pos;
80}
81
83{
84 return m_mousePositionCurrent;
85}
86
88{
89 m_mousePositionChanged = changed;
90}
91
93{
95 {
96 return false;
97 }
98 return m_mousePositionChanged;
99}
100
101} // namespace mnd
In-game ImGui overlay: hierarchy, inspector, console, stats.
Console logging macros for all engine and game code.
#define LOG_WARN(fmt,...)
Definition Log.h:80
bool IsVisible() const
Editor overlay currently shown?
Definition Editor.h:57
Editor & GetEditor()
ImGui-based editor overlay.
Definition Engine.h:149
static Engine & GetInstance()
Returns the single Engine instance (created on first call).
Definition Engine.cpp:59
bool IsKeyPressed(Key key) const
Query whether a key is currently held down.
bool IsMouseButtonPressed(MouseButton button) const
Query whether a mouse button is currently held down.
const vec2 GetMousePositionOld() const
Retrieve the cursor position from the previous frame.
void SetMouseButtonPressed(MouseButton button, bool pressed)
Record a mouse-button press or release event.
void SetMousePositionChanged(bool changed)
const vec2 GetMousePositionCurrent() const
Retrieve the cursor position for the current frame.
bool IsMousePositionChanged() const
void SetMousePositionOld(const vec2 &pos)
Store the cursor position from the previous frame.
void SetKeyPressed(Key key, bool pressed)
Record a key press or release event.
void SetMousePositionCurrent(const vec2 &pos)
Store the cursor position for the current frame.
glm::vec2 vec2
2-component float vector (e.g. UV coordinates, mouse position).
Definition Types.h:50
Key
Keyboard key + mouse button identifier (GLFW-compatible values).
Definition Key.h:29
static bool EditorSwallowsInput()
MouseButton
Definition Key.h:149