76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include "../../Base/ITickable.hpp"
|
|
#include "../../Input/InputDeviceKeyboard.hpp"
|
|
#include "../../Input/InputDeviceMouse.hpp"
|
|
#include "../../Input/InputDeviceController.hpp"
|
|
#include <GLFW/glfw3.h>
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
class KeyboardGLFW final : public Input::InputDeviceKeyboard
|
|
{
|
|
public:
|
|
KeyboardGLFW() = default;
|
|
|
|
using Input::InputDeviceKeyboard::Init;
|
|
using Input::InputDeviceKeyboard::PreTick;
|
|
using Input::InputDeviceKeyboard::UpdateKey;
|
|
using Input::InputDeviceKeyboard::UpdateActiveWindow;
|
|
};
|
|
|
|
class MouseGLFW final : public Input::InputDeviceMouse
|
|
{
|
|
public:
|
|
MouseGLFW() = default;
|
|
|
|
using Input::InputDeviceMouse::Init;
|
|
using Input::InputDeviceMouse::ClearAxes;
|
|
using Input::InputDeviceMouse::UpdateButtons;
|
|
using Input::InputDeviceMouse::UpdatePosition;
|
|
using Input::InputDeviceMouse::UpdateWheel;
|
|
using Input::InputDeviceMouse::UpdateActiveWindow;
|
|
};
|
|
|
|
class ControllerGLFW final : public Input::InputDeviceController, public ITickable
|
|
{
|
|
bool gamepad = false;;
|
|
public:
|
|
ControllerGLFW() = default;
|
|
|
|
void Init(int joystickId)
|
|
{
|
|
if (GetIndex() != -1) return;
|
|
gamepad = glfwJoystickIsGamepad(joystickId);
|
|
std::string name = glfwGetJoystickName(joystickId);
|
|
if (gamepad) name += " - " + std::string(glfwGetGamepadName(joystickId));
|
|
InputDeviceController::Init(joystickId, name);
|
|
if (!gamepad) Logger::INPUT->warn("Joysticks currently are not supported");
|
|
}
|
|
|
|
void Tick() override
|
|
{
|
|
if (GetIndex() == -1) return;
|
|
if (gamepad)
|
|
{
|
|
GLFWgamepadstate state;
|
|
glfwGetGamepadState(GetIndex(), &state);
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
SetAxis(static_cast<Input::InputKey::Controller::Axis>(i), state.axes[i]);
|
|
}
|
|
|
|
uint32_t buttonStates = 0;
|
|
for (int i = 0; i < 15; i++)
|
|
{
|
|
buttonStates |= static_cast<uint32_t>(state.buttons[i] != 0) << i;
|
|
}
|
|
SetButtons(buttonStates);
|
|
}
|
|
else
|
|
{
|
|
// Joysticks currently are not supported
|
|
}
|
|
}
|
|
};
|
|
} |