From 653b4689b550c6bb2720e59c27b0f5ba11663f6e Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Sat, 12 Dec 2015 18:07:53 +0100 Subject: [PATCH] Added KeyboardChar event for keyboard text input --- include/Engine/Core/EKeyboardChar.h | 17 +++++++++++++++++ include/Engine/Core/InputManager.h | 4 ++++ src/Engine/Core/InputManager.cpp | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 include/Engine/Core/EKeyboardChar.h diff --git a/include/Engine/Core/EKeyboardChar.h b/include/Engine/Core/EKeyboardChar.h new file mode 100644 index 00000000..8c1654ce --- /dev/null +++ b/include/Engine/Core/EKeyboardChar.h @@ -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 \ No newline at end of file diff --git a/include/Engine/Core/InputManager.h b/include/Engine/Core/InputManager.h index b8fe7f7a..063e691e 100644 --- a/include/Engine/Core/InputManager.h +++ b/include/Engine/Core/InputManager.h @@ -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 CharCallbackQueue; + static void GLFWCharCallback(GLFWwindow* window, unsigned int c); }; #endif diff --git a/src/Engine/Core/InputManager.cpp b/src/Engine/Core/InputManager.cpp index 597fd7f6..4fd2e2a5 100644 --- a/src/Engine/Core/InputManager.cpp +++ b/src/Engine/Core/InputManager.cpp @@ -1,10 +1,13 @@ #include "Core/InputManager.h" +std::vector InputManager::CharCallbackQueue; + void InputManager::Initialize() { // TODO: Gamepad //m_LastGamepadAxisState = std::array(); //m_LastGamepadButtonState = std::array(); + 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;