Orange/include/Orange/Render/Input.h

167 lines
3.6 KiB
C++

#pragma once
#include <Orange/Core/Bitset.h>
namespace orange::Input
{
namespace ButtonCodes
{
enum ButtonCode
{
Invalid = -1,
None = 0,
Key_0,
Key_1,
Key_2,
Key_3,
Key_4,
Key_5,
Key_6,
Key_7,
Key_8,
Key_9,
Key_A,
Key_B,
Key_C,
Key_D,
Key_E,
Key_F,
Key_G,
Key_H,
Key_I,
Key_J,
Key_K,
Key_L,
Key_M,
Key_N,
Key_O,
Key_P,
Key_Q,
Key_R,
Key_S,
Key_T,
Key_U,
Key_V,
Key_W,
Key_X,
Key_Y,
Key_Z,
Key_Numpad_0,
Key_Numpad_1,
Key_Numpad_2,
Key_Numpad_3,
Key_Numpad_4,
Key_Numpad_5,
Key_Numpad_6,
Key_Numpad_7,
Key_Numpad_8,
Key_Numpad_9,
Key_Numpad_Divide,
Key_Numpad_Multiply,
Key_Numpad_Minus,
Key_Numpad_Plus,
Key_Numpad_Enter,
Key_Numpad_Decimal,
Key_LBracket,
Key_RBracket,
Key_Semicolon,
Key_Apostrophe,
Key_Backquote,
Key_Comma,
Key_Period,
Key_Slash,
Key_Backslash,
Key_Minus,
Key_Equal,
Key_Enter,
Key_Space,
Key_Backspace,
Key_Tab,
Key_CapsLock,
Key_NumLock,
Key_Escape,
Key_ScrollLock,
Key_Insert,
Key_Delete,
Key_Home,
Key_End,
Key_PageUp,
Key_PageDown,
Key_Break,
Key_LShift,
Key_RShift,
Key_LAlt,
Key_RAlt,
Key_LControl,
Key_RControl,
Key_LSuper,
Key_RSuper,
Key_App,
Key_Up,
Key_Left,
Key_Down,
Key_Right,
Key_F1,
Key_F2,
Key_F3,
Key_F4,
Key_F5,
Key_F6,
Key_F7,
Key_F8,
Key_F9,
Key_F10,
Key_F11,
Key_F12,
Key_CapsLockToggle,
Key_NumLockToggle,
Key_ScrollLockToggle,
Mouse_1, // Left Click
Mouse_2, // Right Click
Mouse_3, // Middle Click
Mouse_4,
Mouse_5,
Mouse_WheelUp,
Mouse_WheelDown,
Count,
};
}
using ButtonCode = ButtonCodes::ButtonCode;
class InputHandler
{
public:
bool get(ButtonCode code)
{
return m_pressed.get(code);
}
// Returns true for first window update
// it was pressed on, not if held.
// For like, shooting, etc.
bool getFirst(ButtonCode code)
{
return m_firstPressed.get(code);
}
void set(ButtonCode code, bool pressed)
{
m_firstPressed.set(code, pressed);
m_pressed.set(code, pressed);
}
void flushKeys()
{
m_firstPressed.clearAll();
}
private:
Bitset<ButtonCodes::Count> m_pressed;
Bitset<ButtonCodes::Count> m_firstPressed;
};
ButtonCode SDLScancodeToButton(int scancode);
}