mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Backends: move io.AddKeyModsEvent() next to io.AddKeyEvent() submission, rely on mods from platform/source. (#4858) + fix #2622 again broken by 746c9f7
				
					
				
			Amended to submit modifiers before.
This commit is contained in:
		| @@ -16,6 +16,7 @@ | ||||
|  | ||||
| // CHANGELOG | ||||
| // (minor and older changes stripped away, please see git history for details) | ||||
| //  2022-01-17: Inputs: always calling io.AddKeyModsEvent() next and before key event (not in NewFrame) to fix input queue with very low framerates. | ||||
| //  2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback(). | ||||
| //  2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range. | ||||
| //  2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API. | ||||
| @@ -238,12 +239,24 @@ static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key) | ||||
|     } | ||||
| } | ||||
|  | ||||
| static void ImGui_ImplGlfw_UpdateKeyModifiers(int mods) | ||||
| { | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
|     ImGuiKeyModFlags key_mods = | ||||
|         ((mods & GLFW_MOD_CONTROL) ? ImGuiKeyModFlags_Ctrl : 0) | | ||||
|         ((mods & GLFW_MOD_SHIFT) ? ImGuiKeyModFlags_Shift : 0) | | ||||
|         ((mods & GLFW_MOD_ALT) ? ImGuiKeyModFlags_Alt : 0) | | ||||
|         ((mods & GLFW_MOD_SUPER) ? ImGuiKeyModFlags_Super : 0); | ||||
|     io.AddKeyModsEvent(key_mods); | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) | ||||
| { | ||||
|     ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); | ||||
|     if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window) | ||||
|         bd->PrevUserCallbackMousebutton(window, button, action, mods); | ||||
|  | ||||
|     ImGui_ImplGlfw_UpdateKeyModifiers(mods); | ||||
|     if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(bd->MouseJustPressed)) | ||||
|         bd->MouseJustPressed[button] = true; | ||||
| } | ||||
| @@ -293,6 +306,8 @@ void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, i | ||||
|     if (action != GLFW_PRESS && action != GLFW_RELEASE) | ||||
|         return; | ||||
|  | ||||
|     ImGui_ImplGlfw_UpdateKeyModifiers(mods); | ||||
|  | ||||
|     keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode); | ||||
|  | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
| @@ -557,18 +572,6 @@ static void ImGui_ImplGlfw_UpdateGamepads() | ||||
|         io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; | ||||
| } | ||||
|  | ||||
| static void ImGui_ImplGlfw_UpdateKeyModifiers() | ||||
| { | ||||
|     ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData(); | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
|     ImGuiKeyModFlags key_mods = | ||||
|         (((glfwGetKey(bd->Window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) ? ImGuiKeyModFlags_Ctrl : 0) | | ||||
|         (((glfwGetKey(bd->Window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS)) ? ImGuiKeyModFlags_Shift : 0) | | ||||
|         (((glfwGetKey(bd->Window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS)) ? ImGuiKeyModFlags_Alt : 0) | | ||||
|         (((glfwGetKey(bd->Window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(bd->Window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS)) ? ImGuiKeyModFlags_Super : 0); | ||||
|     io.AddKeyModsEvent(key_mods); | ||||
| } | ||||
|  | ||||
| void ImGui_ImplGlfw_NewFrame() | ||||
| { | ||||
|     ImGuiIO& io = ImGui::GetIO(); | ||||
| @@ -589,7 +592,6 @@ void ImGui_ImplGlfw_NewFrame() | ||||
|     io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f); | ||||
|     bd->Time = current_time; | ||||
|  | ||||
|     ImGui_ImplGlfw_UpdateKeyModifiers(); | ||||
|     ImGui_ImplGlfw_UpdateMouseData(); | ||||
|     ImGui_ImplGlfw_UpdateMouseCursor(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user