mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(gx): translate SDL_TextInput events into OS_INPUT_CHAR events
This commit is contained in:
parent
c0d5e2a0c8
commit
a336165cef
2 changed files with 38 additions and 6 deletions
|
|
@ -199,6 +199,8 @@ void GLSDLWindow::Create(const char* title, const GLSDLWindowRect& rect, GLTextu
|
||||||
);
|
);
|
||||||
|
|
||||||
BLIZZARD_ASSERT(this->m_sdlWindow != nullptr);
|
BLIZZARD_ASSERT(this->m_sdlWindow != nullptr);
|
||||||
|
|
||||||
|
SDL_StartTextInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSDLWindow::Swap() {
|
void GLSDLWindow::Swap() {
|
||||||
|
|
@ -210,7 +212,6 @@ void GLSDLWindow::Swap() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLSDLWindow::Destroy() {
|
void GLSDLWindow::Destroy() {
|
||||||
SDL_DestroyWindow(this->m_sdlWindow);
|
SDL_DestroyWindow(this->m_sdlWindow);
|
||||||
this->m_sdlWindow = nullptr;
|
this->m_sdlWindow = nullptr;
|
||||||
|
|
@ -282,6 +283,9 @@ void GLSDLWindow::DispatchSDLEvent(const SDL_Event& event) {
|
||||||
case SDL_EVENT_MOUSE_MOTION:
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
this->DispatchSDLMouseMotionEvent(event);
|
this->DispatchSDLMouseMotionEvent(event);
|
||||||
break;
|
break;
|
||||||
|
case SDL_EVENT_TEXT_INPUT:
|
||||||
|
this->DispatchSDLTextInputEvent(event);
|
||||||
|
break;
|
||||||
case SDL_EVENT_QUIT:
|
case SDL_EVENT_QUIT:
|
||||||
EventPostClose();
|
EventPostClose();
|
||||||
break;
|
break;
|
||||||
|
|
@ -296,14 +300,15 @@ void GLSDLWindow::DispatchSDLKeyboardEvent(const SDL_Event& event) {
|
||||||
|
|
||||||
// What key does this SDL scancode correspond to?
|
// What key does this SDL scancode correspond to?
|
||||||
auto lookup = s_keyConversion.find(event.key.keysym.scancode);
|
auto lookup = s_keyConversion.find(event.key.keysym.scancode);
|
||||||
if (lookup == s_keyConversion.end()) {
|
if (lookup != s_keyConversion.end()) {
|
||||||
// No corresponding KEY to this scancode
|
// Scancode was found
|
||||||
|
KEY key = lookup->second;
|
||||||
|
|
||||||
|
// Push key event into input queue
|
||||||
|
OsQueuePut(inputclass, key, 0, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KEY key = lookup->second;
|
|
||||||
|
|
||||||
// Push key event into input queue
|
|
||||||
OsQueuePut(inputclass, key, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLSDLWindow::DispatchSDLMouseMotionEvent(const SDL_Event& event) {
|
void GLSDLWindow::DispatchSDLMouseMotionEvent(const SDL_Event& event) {
|
||||||
|
|
@ -331,3 +336,29 @@ void GLSDLWindow::DispatchSDLMouseButtonEvent(const SDL_Event& event) {
|
||||||
// Push mousebutton event into input queue
|
// Push mousebutton event into input queue
|
||||||
OsQueuePut(inputclass, button, x, y, 0);
|
OsQueuePut(inputclass, button, x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLSDLWindow::DispatchSDLTextInputEvent(const SDL_Event& event) {
|
||||||
|
// text input string holding one or more UTF-8 characters
|
||||||
|
auto text = reinterpret_cast<const uint8_t*>(event.text.text);
|
||||||
|
|
||||||
|
// Because SDL_TextInputEvent can hold multiple UTF-8 characters
|
||||||
|
// explode variable number of these characters into
|
||||||
|
// individual OS_INPUT_CHAR events
|
||||||
|
while (*text != '\0') {
|
||||||
|
// byte size of current UTF-8 character
|
||||||
|
uint32_t charactersize = 0;
|
||||||
|
|
||||||
|
// Read UTF-8 character
|
||||||
|
auto character = static_cast<int32_t>(SUniGetUTF8(text, &charactersize));
|
||||||
|
if (character < 0) {
|
||||||
|
// Cancel in case of invalid input
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push character to input queue
|
||||||
|
OsQueuePut(OS_INPUT_CHAR, character, 1, 0, 0);
|
||||||
|
|
||||||
|
// Advance text pointer
|
||||||
|
text += charactersize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class GLSDLWindow {
|
||||||
void DispatchSDLKeyboardEvent(const SDL_Event& event);
|
void DispatchSDLKeyboardEvent(const SDL_Event& event);
|
||||||
void DispatchSDLMouseMotionEvent(const SDL_Event& event);
|
void DispatchSDLMouseMotionEvent(const SDL_Event& event);
|
||||||
void DispatchSDLMouseButtonEvent(const SDL_Event& event);
|
void DispatchSDLMouseButtonEvent(const SDL_Event& event);
|
||||||
|
void DispatchSDLTextInputEvent(const SDL_Event& event);
|
||||||
void Resize(const GLSDLWindowRect& rect);
|
void Resize(const GLSDLWindowRect& rect);
|
||||||
|
|
||||||
GLSDLWindowRect GetRect();
|
GLSDLWindowRect GetRect();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue