rework API
This commit is contained in:
@@ -33,6 +33,8 @@ namespace OpenVulkano::Input
|
||||
{
|
||||
axes[InputKey::Mouse::AXIS_X] = static_cast<float>(posX - mousePosX);
|
||||
axes[InputKey::Mouse::AXIS_Y] = static_cast<float>(posY - mousePosY);
|
||||
axes[InputKey::Mouse::AXIS_X_ABS] = posX;
|
||||
axes[InputKey::Mouse::AXIS_Y_ABS] = posY;
|
||||
mousePosX = posX;
|
||||
mousePosY = posY;
|
||||
Logger::INPUT->trace("Mouse moved posX: {0} posY: {1}, relativeX: {2}, relativeY: {3}", posX, posY, axes[InputKey::Mouse::AXIS_X], axes[InputKey::Mouse::AXIS_Y]);
|
||||
@@ -53,9 +55,9 @@ namespace OpenVulkano::Input
|
||||
|
||||
void InputDeviceMouse::ClearAxes()
|
||||
{
|
||||
for (float& axis : axes)
|
||||
for (int i = 2; i < AXES_SIZE; i++)
|
||||
{
|
||||
axis = 0;
|
||||
axes[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "InputDevice.hpp"
|
||||
#include "Math/Math.hpp"
|
||||
#include "Base/Event.hpp"
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
@@ -18,7 +17,8 @@ namespace OpenVulkano
|
||||
{
|
||||
class InputDeviceMouse : public InputDevice
|
||||
{
|
||||
float axes[InputKey::Mouse::Axis::AXIS_LAST + 2] = { 0 };
|
||||
static constexpr int AXES_SIZE = InputKey::Mouse::Axis::AXIS_LAST + 2;
|
||||
float axes[AXES_SIZE] = { 0 };
|
||||
uint8_t pressedButtons = 0, lastPressedButtons = 0;
|
||||
double mousePosX = 0, mousePosY = 0;
|
||||
IWindow* lastWindow = nullptr;
|
||||
@@ -144,9 +144,6 @@ namespace OpenVulkano
|
||||
{
|
||||
return window == lastWindow;
|
||||
}
|
||||
|
||||
Event<Math::Vector2i> onLeftButtonClick;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,9 @@ namespace OpenVulkano::Input
|
||||
|
||||
enum Axis : int16_t
|
||||
{
|
||||
AXIS_X = 0,
|
||||
AXIS_X_ABS = 0,
|
||||
AXIS_Y_ABS,
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
AXIS_WHEEL_X,
|
||||
AXIS_WHEEL_Y,
|
||||
|
||||
@@ -75,6 +75,23 @@ namespace OpenVulkano::Input
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputManager::GetButtonDown(InputAction* action) const
|
||||
{
|
||||
const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices();
|
||||
for (const InputDevice* device : testDevices)
|
||||
{
|
||||
for (const KeyBinding binding : action->GetKeys())
|
||||
{
|
||||
if (binding.key.GetInputDeviceType() != device->GetType())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
return device->GetButtonDown(binding.key);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputManager::GetButton(InputKey key) const
|
||||
{
|
||||
for(const InputDevice* device : devices)
|
||||
@@ -87,9 +104,13 @@ namespace OpenVulkano::Input
|
||||
|
||||
InputDevice* InputManager::GetDevice(InputDeviceType type) const
|
||||
{
|
||||
for (InputDevice* device: devices)
|
||||
if (type == InputDeviceType::UNKNOWN)
|
||||
{
|
||||
if (device->GetType() == type && type != InputDeviceType::UNKNOWN)
|
||||
return nullptr;
|
||||
}
|
||||
for (InputDevice* device : devices)
|
||||
{
|
||||
if (device->GetType() == type)
|
||||
{
|
||||
return device;
|
||||
}
|
||||
@@ -97,6 +118,24 @@ namespace OpenVulkano::Input
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<InputDevice*> InputManager::GetDevices(InputDeviceType type) const
|
||||
{
|
||||
if (type == InputDeviceType::UNKNOWN)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
std::vector<InputDevice*> devices;
|
||||
devices.reserve(this->devices.size());
|
||||
for (InputDevice* device : this->devices)
|
||||
{
|
||||
if (device->GetType() == type)
|
||||
{
|
||||
devices.push_back(device);
|
||||
}
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
void InputManager::Tick()
|
||||
{
|
||||
for(InputDevice* device : devices)
|
||||
|
||||
@@ -40,10 +40,14 @@ namespace OpenVulkano::Input
|
||||
|
||||
[[nodiscard]] bool GetButton(InputAction* action) const;
|
||||
|
||||
[[nodiscard]] bool GetButtonDown(InputAction* action) const;
|
||||
|
||||
[[nodiscard]] bool GetButton(InputKey key) const;
|
||||
|
||||
[[nodiscard]] InputDevice* GetDevice(InputDeviceType type) const;
|
||||
|
||||
[[nodiscard]] std::vector<InputDevice*> GetDevices(InputDeviceType type) const;
|
||||
|
||||
[[nodiscard]] InputDevice* GetLastActiveDevice() const
|
||||
{
|
||||
return lastActiveDevice;
|
||||
|
||||
@@ -84,6 +84,5 @@ namespace OpenVulkano::Input
|
||||
[[nodiscard]] bool IsMultiTouch() const { return m_multiTouch; }
|
||||
|
||||
Event<Touch&> OnTouchAdded, OnTouchDown, OnTouchUp, OnTouchMoved, OnTouchRemoved;
|
||||
Event<Math::Vector2i> OnTap;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user