mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-24 08:00:14 +00:00
Initial commit: wowee native WoW 3.3.5a client
This commit is contained in:
commit
ce6cb8f38e
147 changed files with 32347 additions and 0 deletions
81
src/core/input.cpp
Normal file
81
src/core/input.cpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#include "core/input.hpp"
|
||||
|
||||
namespace wowee {
|
||||
namespace core {
|
||||
|
||||
Input& Input::getInstance() {
|
||||
static Input instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void Input::update() {
|
||||
// Copy current state to previous
|
||||
previousKeyState = currentKeyState;
|
||||
previousMouseState = currentMouseState;
|
||||
previousMousePosition = mousePosition;
|
||||
|
||||
// Get current keyboard state
|
||||
const Uint8* keyState = SDL_GetKeyboardState(nullptr);
|
||||
for (int i = 0; i < NUM_KEYS; ++i) {
|
||||
currentKeyState[i] = keyState[i];
|
||||
}
|
||||
|
||||
// Get current mouse state
|
||||
int mouseX, mouseY;
|
||||
Uint32 mouseState = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
mousePosition = glm::vec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
|
||||
|
||||
for (int i = 0; i < NUM_MOUSE_BUTTONS; ++i) {
|
||||
currentMouseState[i] = (mouseState & SDL_BUTTON(i)) != 0;
|
||||
}
|
||||
|
||||
// Calculate mouse delta
|
||||
mouseDelta = mousePosition - previousMousePosition;
|
||||
|
||||
// Reset wheel delta (will be set by handleEvent)
|
||||
mouseWheelDelta = 0.0f;
|
||||
}
|
||||
|
||||
void Input::handleEvent(const SDL_Event& event) {
|
||||
if (event.type == SDL_MOUSEWHEEL) {
|
||||
mouseWheelDelta = static_cast<float>(event.wheel.y);
|
||||
}
|
||||
}
|
||||
|
||||
bool Input::isKeyPressed(SDL_Scancode key) const {
|
||||
if (key < 0 || key >= NUM_KEYS) return false;
|
||||
return currentKeyState[key];
|
||||
}
|
||||
|
||||
bool Input::isKeyJustPressed(SDL_Scancode key) const {
|
||||
if (key < 0 || key >= NUM_KEYS) return false;
|
||||
return currentKeyState[key] && !previousKeyState[key];
|
||||
}
|
||||
|
||||
bool Input::isKeyJustReleased(SDL_Scancode key) const {
|
||||
if (key < 0 || key >= NUM_KEYS) return false;
|
||||
return !currentKeyState[key] && previousKeyState[key];
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonPressed(int button) const {
|
||||
if (button < 0 || button >= NUM_MOUSE_BUTTONS) return false;
|
||||
return currentMouseState[button];
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonJustPressed(int button) const {
|
||||
if (button < 0 || button >= NUM_MOUSE_BUTTONS) return false;
|
||||
return currentMouseState[button] && !previousMouseState[button];
|
||||
}
|
||||
|
||||
bool Input::isMouseButtonJustReleased(int button) const {
|
||||
if (button < 0 || button >= NUM_MOUSE_BUTTONS) return false;
|
||||
return !currentMouseState[button] && previousMouseState[button];
|
||||
}
|
||||
|
||||
void Input::setMouseLocked(bool locked) {
|
||||
mouseLocked = locked;
|
||||
SDL_SetRelativeMouseMode(locked ? SDL_TRUE : SDL_FALSE);
|
||||
}
|
||||
|
||||
} // namespace core
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue