Added KeyboardChar event for keyboard text input
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef Events_KeyboardChar_h__
|
||||||
|
#define Events_KeyboardChar_h__
|
||||||
|
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct KeyboardChar : Event
|
||||||
|
{
|
||||||
|
double Timestamp = 0.f;
|
||||||
|
unsigned int Char = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "EventBroker.h"
|
#include "EventBroker.h"
|
||||||
#include "EKeyDown.h"
|
#include "EKeyDown.h"
|
||||||
#include "EKeyUp.h"
|
#include "EKeyUp.h"
|
||||||
|
#include "EKeyboardChar.h"
|
||||||
#include "EMousePress.h"
|
#include "EMousePress.h"
|
||||||
#include "EMouseRelease.h"
|
#include "EMouseRelease.h"
|
||||||
#include "EMouseMove.h"
|
#include "EMouseMove.h"
|
||||||
@@ -64,6 +65,9 @@ private:
|
|||||||
|
|
||||||
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
|
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
|
||||||
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
|
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
|
||||||
|
|
||||||
|
static std::vector<unsigned int> CharCallbackQueue;
|
||||||
|
static void GLFWCharCallback(GLFWwindow* window, unsigned int c);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
#include "Core/InputManager.h"
|
#include "Core/InputManager.h"
|
||||||
|
|
||||||
|
std::vector<unsigned int> InputManager::CharCallbackQueue;
|
||||||
|
|
||||||
void InputManager::Initialize()
|
void InputManager::Initialize()
|
||||||
{
|
{
|
||||||
// TODO: Gamepad
|
// TODO: Gamepad
|
||||||
//m_LastGamepadAxisState = std::array<GamepadAxisState, XUSER_MAX_COUNT>();
|
//m_LastGamepadAxisState = std::array<GamepadAxisState, XUSER_MAX_COUNT>();
|
||||||
//m_LastGamepadButtonState = std::array<GamepadButtonState, XUSER_MAX_COUNT>();
|
//m_LastGamepadButtonState = std::array<GamepadButtonState, XUSER_MAX_COUNT>();
|
||||||
|
glfwSetCharCallback(m_GLFWWindow, &InputManager::GLFWCharCallback);
|
||||||
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ELockMouse, &InputManager::OnLockMouse);
|
EVENT_SUBSCRIBE_MEMBER(m_ELockMouse, &InputManager::OnLockMouse);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &InputManager::OnUnlockMouse);
|
EVENT_SUBSCRIBE_MEMBER(m_EUnlockMouse, &InputManager::OnUnlockMouse);
|
||||||
@@ -73,6 +76,14 @@ void InputManager::Update(double dt)
|
|||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (unsigned int& c : CharCallbackQueue) {
|
||||||
|
Events::KeyboardChar e;
|
||||||
|
e.Timestamp = glfwGetTime();
|
||||||
|
e.Char = c;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
CharCallbackQueue.clear();
|
||||||
|
|
||||||
// // Lock mouse while holding LMB
|
// // Lock mouse while holding LMB
|
||||||
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
// if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||||
// {
|
// {
|
||||||
@@ -196,6 +207,11 @@ void InputManager::PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputManager::GLFWCharCallback(GLFWwindow* window, unsigned int c)
|
||||||
|
{
|
||||||
|
CharCallbackQueue.push_back(c);
|
||||||
|
}
|
||||||
|
|
||||||
bool InputManager::OnLockMouse(const Events::LockMouse &event)
|
bool InputManager::OnLockMouse(const Events::LockMouse &event)
|
||||||
{
|
{
|
||||||
m_MouseLocked = true;
|
m_MouseLocked = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user