Browse Source

Fix proper handling of numpad inputs in text fields when using GLFW and SDL backends

Michael Ragazzon 3 years ago
parent
commit
9cd0fac5de

+ 3 - 0
Backends/RmlUi_Backend_GLFW_GL2.cpp

@@ -98,6 +98,9 @@ bool Backend::Initialize(const char* name, int width, int height, bool allow_res
 	glfwGetFramebufferSize(window, &width, &height);
 	glfwGetFramebufferSize(window, &width, &height);
 	data->render_interface.SetViewport(width, height);
 	data->render_interface.SetViewport(width, height);
 
 
+	// Receive num lock and caps lock modifiers for proper handling of numpad inputs in text fields.
+	glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
+
 	// Setup the input and window event callback functions.
 	// Setup the input and window event callback functions.
 	SetupCallbacks(window);
 	SetupCallbacks(window);
 
 

+ 3 - 0
Backends/RmlUi_Backend_GLFW_GL3.cpp

@@ -109,6 +109,9 @@ bool Backend::Initialize(const char* name, int width, int height, bool allow_res
 	glfwGetFramebufferSize(window, &width, &height);
 	glfwGetFramebufferSize(window, &width, &height);
 	data->render_interface.SetViewport(width, height);
 	data->render_interface.SetViewport(width, height);
 
 
+	// Receive num lock and caps lock modifiers for proper handling of numpad inputs in text fields.
+	glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
+
 	// Setup the input and window event callback functions.
 	// Setup the input and window event callback functions.
 	SetupCallbacks(window);
 	SetupCallbacks(window);
 
 

+ 3 - 0
Backends/RmlUi_Backend_GLFW_VK.cpp

@@ -102,6 +102,9 @@ bool Backend::Initialize(const char* window_name, int width, int height, bool al
 	data->system_interface.SetWindow(window);
 	data->system_interface.SetWindow(window);
 	data->render_interface.SetViewport(width, height);
 	data->render_interface.SetViewport(width, height);
 
 
+	// Receive num lock and caps lock modifiers for proper handling of numpad inputs in text fields.
+	glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
+
 	SetupCallbacks(window);
 	SetupCallbacks(window);
 
 
 	return true;
 	return true;

+ 10 - 4
Backends/RmlUi_Platform_SDL.cpp

@@ -295,18 +295,24 @@ int RmlSDL::ConvertMouseButton(int button)
 
 
 int RmlSDL::GetKeyModifierState()
 int RmlSDL::GetKeyModifierState()
 {
 {
-	SDL_Keymod sdlMods = SDL_GetModState();
+	SDL_Keymod sdl_mods = SDL_GetModState();
 
 
 	int retval = 0;
 	int retval = 0;
 
 
-	if (sdlMods & KMOD_CTRL)
+	if (sdl_mods & KMOD_CTRL)
 		retval |= Rml::Input::KM_CTRL;
 		retval |= Rml::Input::KM_CTRL;
 
 
-	if (sdlMods & KMOD_SHIFT)
+	if (sdl_mods & KMOD_SHIFT)
 		retval |= Rml::Input::KM_SHIFT;
 		retval |= Rml::Input::KM_SHIFT;
 
 
-	if (sdlMods & KMOD_ALT)
+	if (sdl_mods & KMOD_ALT)
 		retval |= Rml::Input::KM_ALT;
 		retval |= Rml::Input::KM_ALT;
 
 
+	if (sdl_mods & KMOD_NUM)
+		retval |= Rml::Input::KM_NUMLOCK;
+
+	if (sdl_mods & KMOD_CAPS)
+		retval |= Rml::Input::KM_CAPSLOCK;
+
 	return retval;
 	return retval;
 }
 }