87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
#pragma once
|
|
#include "InputDevice.hpp"
|
|
#include <bitset>
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
class IWindow;
|
|
|
|
namespace Input
|
|
{
|
|
class InputDeviceKeyboard : public InputDevice
|
|
{
|
|
std::bitset<InputKey::Keyboard::KEY_LAST + 1> keyState;
|
|
std::bitset<InputKey::Keyboard::KEY_LAST + 1> lastKeyState;
|
|
IWindow* lastWindow;
|
|
|
|
protected:
|
|
InputDeviceKeyboard() = default;
|
|
|
|
void Init(int index, const std::string& name)
|
|
{
|
|
InputDevice::Init(InputDeviceType::KEYBOARD, index, name);
|
|
}
|
|
|
|
void PreTick()
|
|
{
|
|
lastKeyState = keyState;
|
|
}
|
|
|
|
void UpdateKey(InputKey::Keyboard::Key key, bool state)
|
|
{
|
|
keyState[key] = state;
|
|
}
|
|
|
|
void UpdateActiveWindow(IWindow* window)
|
|
{
|
|
lastWindow = window;
|
|
}
|
|
|
|
float ReadAxis(int16_t key) const override final
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
bool ReadButton(int16_t key) const override final
|
|
{
|
|
return GetButton(static_cast<InputKey::Keyboard::Key>(key));
|
|
}
|
|
|
|
bool ReadButtonUp(int16_t key) const override final
|
|
{
|
|
return GetButtonUp(static_cast<InputKey::Keyboard::Key>(key));
|
|
}
|
|
|
|
bool ReadButtonDown(int16_t key) const override final
|
|
{
|
|
return GetButtonDown(static_cast<InputKey::Keyboard::Key>(key));
|
|
}
|
|
|
|
public:
|
|
bool GetButton(const InputKey::Keyboard::Key button) const
|
|
{
|
|
return keyState[button] > 0;
|
|
}
|
|
|
|
bool GetButtonUp(const InputKey::Keyboard::Key button) const
|
|
{
|
|
return !keyState[button] && lastKeyState[button];
|
|
}
|
|
|
|
bool GetButtonDown(const InputKey::Keyboard::Key button) const
|
|
{
|
|
return keyState[button] && !lastKeyState[button];
|
|
}
|
|
|
|
IWindow* GetActiveWindow() const
|
|
{
|
|
return lastWindow;
|
|
}
|
|
|
|
bool IsInWindow(const IWindow* window) const
|
|
{
|
|
return window == lastWindow;
|
|
}
|
|
};
|
|
}
|
|
} |