38 lines
687 B
C++
38 lines
687 B
C++
|
|
#include "iwa/input.hpp"
|
|
|
|
#include "iwa/log.hpp"
|
|
|
|
namespace iwa
|
|
{
|
|
KeyState getKeyState(ScanCode scanCode) noexcept
|
|
{
|
|
const int index = static_cast<int>(scanCode);
|
|
int numKeys = 0;
|
|
const Uint8* keys = SDL_GetKeyboardState(&numKeys);
|
|
if (index >= numKeys) {
|
|
return {};
|
|
}
|
|
return {
|
|
.pressed = keys[index] > 0
|
|
};
|
|
}
|
|
|
|
void captureMouse() noexcept
|
|
{
|
|
SDL_CaptureMouse(SDL_TRUE);
|
|
}
|
|
|
|
void uncaptureMouse() noexcept
|
|
{
|
|
SDL_CaptureMouse(SDL_FALSE);
|
|
}
|
|
|
|
std::pair<int, int> getMouseScreenPosition() noexcept
|
|
{
|
|
std::pair<int, int> position;
|
|
SDL_GetGlobalMouseState(&position.first, &position.second);
|
|
return position;
|
|
}
|
|
} // namespace iwa
|