61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#include "InputProviderGLFW.hpp"
|
|
#include "InputMappingGLFW.hpp"
|
|
#include "../../Input/InputManager.hpp"
|
|
|
|
namespace openVulkanoCpp
|
|
{
|
|
namespace GLFW
|
|
{
|
|
constexpr KeyboardInputMapping keyboardMapping = KeyboardInputMapping();
|
|
|
|
InputProviderGLFW* InputProviderGLFW::INSTANCE = nullptr;
|
|
|
|
void InputProviderGLFW::Init()
|
|
{
|
|
if (INSTANCE) throw PlatformInitFailedException("An instance of the GLFW input provider has already been initialized!");
|
|
INSTANCE = this;
|
|
glfwSetJoystickCallback(&JoystickCallback);
|
|
|
|
// register already connected controller
|
|
for (int i = 0; i < GLFW_JOYSTICK_LAST; i++)
|
|
{
|
|
if (glfwJoystickPresent(i) == GLFW_TRUE)
|
|
{
|
|
OnJoystickConnect(i);
|
|
}
|
|
}
|
|
mouseButtons = 0;
|
|
|
|
keyboard.Init(0, "Keyboard");
|
|
mouse.Init(0, "Mouse");
|
|
Input::InputManager::GetInstace()->RegisterInputDevice(&mouse);
|
|
Input::InputManager::GetInstace()->RegisterInputDevice(&keyboard);
|
|
}
|
|
|
|
void InputProviderGLFW::OnJoystickConnect(int joystickId)
|
|
{
|
|
controllers[joystickId].Init(joystickId);
|
|
Input::InputManager::GetInstace()->RegisterInputDevice(&controllers[joystickId]);
|
|
}
|
|
|
|
void InputProviderGLFW::OnJoystickDisconnect(int joystickId)
|
|
{
|
|
Input::InputManager::GetInstace()->UnregisterInputDevice(&controllers[joystickId]);
|
|
|
|
controllers[joystickId].Close();
|
|
}
|
|
|
|
void InputProviderGLFW::SetKeyboardKey(IWindow* window, int key, int scanCode, int action, int mods)
|
|
{
|
|
if (action == GLFW_REPEAT)
|
|
{
|
|
//TODO handle repeat for text inputs
|
|
}
|
|
else
|
|
{
|
|
keyboard.UpdateKey(static_cast<Input::InputKey::Keyboard::Key>(keyboardMapping.Map(key)), action == GLFW_PRESS);
|
|
}
|
|
//TODO handle keyboard notifications
|
|
}
|
|
}
|
|
} |