Added KeyboardChar event for keyboard text input

This commit is contained in:
2015-12-12 18:07:53 +01:00
parent 6723e71fee
commit 653b4689b5
3 changed files with 37 additions and 0 deletions
+17
View File
@@ -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
+4
View File
@@ -8,6 +8,7 @@
#include "EventBroker.h"
#include "EKeyDown.h"
#include "EKeyUp.h"
#include "EKeyboardChar.h"
#include "EMousePress.h"
#include "EMouseRelease.h"
#include "EMouseMove.h"
@@ -64,6 +65,9 @@ private:
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
static std::vector<unsigned int> CharCallbackQueue;
static void GLFWCharCallback(GLFWwindow* window, unsigned int c);
};
#endif
+16
View File
@@ -1,10 +1,13 @@
#include "Core/InputManager.h"
std::vector<unsigned int> InputManager::CharCallbackQueue;
void InputManager::Initialize()
{
// TODO: Gamepad
//m_LastGamepadAxisState = std::array<GamepadAxisState, 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_EUnlockMouse, &InputManager::OnUnlockMouse);
@@ -73,6 +76,14 @@ void InputManager::Update(double dt)
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
// 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)
{
m_MouseLocked = true;