102 lines
3.6 KiB
C++
102 lines
3.6 KiB
C++
#pragma once
|
|
#include "Core/Event.h"
|
|
#include "InputTypes.h"
|
|
#include "InputEvent.h"
|
|
#include "InputAxis.h"
|
|
#include <XCEngine/Core/Math/Vector2.h>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
namespace XCEngine {
|
|
namespace Input {
|
|
|
|
class InputManager {
|
|
public:
|
|
static InputManager& Get();
|
|
|
|
void Initialize(void* platformWindowHandle);
|
|
void Shutdown();
|
|
void Update(float deltaTime);
|
|
|
|
bool IsKeyDown(KeyCode key) const;
|
|
bool IsKeyUp(KeyCode key) const;
|
|
bool IsKeyPressed(KeyCode key) const;
|
|
bool IsKeyReleased(KeyCode key) const;
|
|
|
|
Math::Vector2 GetMousePosition() const;
|
|
Math::Vector2 GetMouseDelta() const;
|
|
float GetMouseScrollDelta() const;
|
|
bool IsMouseButtonDown(MouseButton button) const;
|
|
bool IsMouseButtonUp(MouseButton button) const;
|
|
bool IsMouseButtonClicked(MouseButton button) const;
|
|
bool IsMouseButtonReleased(MouseButton button) const;
|
|
|
|
int GetTouchCount() const;
|
|
TouchState GetTouch(int index) const;
|
|
|
|
float GetAxis(const Containers::String& axisName) const;
|
|
float GetAxisRaw(const Containers::String& axisName) const;
|
|
|
|
bool GetButton(const Containers::String& buttonName) const;
|
|
bool GetButtonDown(const Containers::String& buttonName) const;
|
|
bool GetButtonUp(const Containers::String& buttonName) const;
|
|
bool IsAnyKeyDown() const;
|
|
bool IsAnyKeyPressed() const;
|
|
|
|
void RegisterAxis(const InputAxis& axis);
|
|
void RegisterButton(const Containers::String& name, KeyCode key);
|
|
void ClearAxes();
|
|
|
|
Core::Event<const KeyEvent&>& OnKeyEvent() { return m_onKeyEvent; }
|
|
Core::Event<const MouseButtonEvent&>& OnMouseButton() { return m_onMouseButton; }
|
|
Core::Event<const MouseMoveEvent&>& OnMouseMove() { return m_onMouseMove; }
|
|
Core::Event<const MouseWheelEvent&>& OnMouseWheel() { return m_onMouseWheel; }
|
|
Core::Event<const TextInputEvent&>& OnTextInput() { return m_onTextInput; }
|
|
|
|
void ProcessKeyDown(KeyCode key, bool repeat, bool alt, bool ctrl, bool shift, bool meta);
|
|
void ProcessKeyUp(KeyCode key, bool alt, bool ctrl, bool shift, bool meta);
|
|
void ProcessMouseMove(int x, int y, int deltaX, int deltaY);
|
|
void ProcessMouseButton(MouseButton button, bool pressed, int x, int y);
|
|
void ProcessMouseWheel(float delta, int x, int y);
|
|
void ProcessTextInput(char c);
|
|
|
|
private:
|
|
InputManager() = default;
|
|
~InputManager() = default;
|
|
|
|
size_t GetKeyIndex(KeyCode key) const;
|
|
size_t GetMouseButtonIndex(MouseButton button) const;
|
|
|
|
void* m_platformWindowHandle = nullptr;
|
|
bool m_initialized = false;
|
|
|
|
std::vector<bool> m_keyDownThisFrame;
|
|
std::vector<bool> m_keyDownLastFrame;
|
|
std::vector<bool> m_keyUpThisFrame;
|
|
std::vector<bool> m_keyDown;
|
|
|
|
Math::Vector2 m_mousePosition;
|
|
Math::Vector2 m_mouseDelta;
|
|
float m_mouseScrollDelta = 0.0f;
|
|
std::vector<bool> m_mouseButtonDownThisFrame;
|
|
std::vector<bool> m_mouseButtonDownLastFrame;
|
|
std::vector<bool> m_mouseButtonUpThisFrame;
|
|
std::vector<bool> m_mouseButtonDown;
|
|
|
|
std::vector<TouchState> m_touches;
|
|
|
|
std::unordered_map<Containers::String, InputAxis> m_axes;
|
|
std::unordered_map<Containers::String, KeyCode> m_buttons;
|
|
std::vector<bool> m_buttonDownThisFrame;
|
|
std::vector<bool> m_buttonDownLastFrame;
|
|
|
|
Core::Event<const KeyEvent&> m_onKeyEvent;
|
|
Core::Event<const MouseButtonEvent&> m_onMouseButton;
|
|
Core::Event<const MouseMoveEvent&> m_onMouseMove;
|
|
Core::Event<const MouseWheelEvent&> m_onMouseWheel;
|
|
Core::Event<const TextInputEvent&> m_onTextInput;
|
|
};
|
|
|
|
} // namespace Input
|
|
} // namespace XCEngine
|