Simplified glfw keyboard callbacks.

docking
Dale Kim 10 years ago
parent 4b7be31197
commit fe15756129

@ -134,50 +134,24 @@ void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yo
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
} }
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods) void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int, int action, int mods)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
{ io.KeysDown[key] = true;
switch (key)
{
case GLFW_KEY_LEFT_CONTROL:
case GLFW_KEY_RIGHT_CONTROL:
io.KeyCtrl = true;
break;
case GLFW_KEY_LEFT_SHIFT:
case GLFW_KEY_RIGHT_SHIFT:
io.KeyShift = true;
break;
case GLFW_KEY_LEFT_ALT:
case GLFW_KEY_RIGHT_ALT:
io.KeyAlt = true;
break;
default:
io.KeysDown[key] = true;
}
}
if (action == GLFW_RELEASE) if (action == GLFW_RELEASE)
{ io.KeysDown[key] = false;
switch (key)
{ bool leftCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS;
case GLFW_KEY_LEFT_CONTROL: bool rightCtrl = glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS;
case GLFW_KEY_RIGHT_CONTROL: bool leftShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
io.KeyCtrl = false; bool rightShift = glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;
break; bool leftAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS;
case GLFW_KEY_LEFT_SHIFT: bool rightAlt = glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS;
case GLFW_KEY_RIGHT_SHIFT:
io.KeyShift = false; io.KeyCtrl = leftCtrl || rightCtrl;
break; io.KeyShift = leftShift || rightShift;
case GLFW_KEY_LEFT_ALT: io.KeyAlt = leftAlt || rightAlt;
case GLFW_KEY_RIGHT_ALT:
io.KeyAlt = false;
break;
default:
io.KeysDown[key] = false;
}
}
} }
void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c) void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c)

@ -115,50 +115,24 @@ void ImGui_ImplGlfw_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffs
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines. g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
} }
void ImGui_ImplGlFw_KeyCallback(GLFWwindow*, int key, int, int action, int mods) void ImGui_ImplGlFw_KeyCallback(GLFWwindow* window, int key, int, int action, int mods)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
{ io.KeysDown[key] = true;
switch (key)
{
case GLFW_KEY_LEFT_CONTROL:
case GLFW_KEY_RIGHT_CONTROL:
io.KeyCtrl = true;
break;
case GLFW_KEY_LEFT_SHIFT:
case GLFW_KEY_RIGHT_SHIFT:
io.KeyShift = true;
break;
case GLFW_KEY_LEFT_ALT:
case GLFW_KEY_RIGHT_ALT:
io.KeyAlt = true;
break;
default:
io.KeysDown[key] = true;
}
}
if (action == GLFW_RELEASE) if (action == GLFW_RELEASE)
{ io.KeysDown[key] = false;
switch (key)
{ bool leftCtrl = glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS;
case GLFW_KEY_LEFT_CONTROL: bool rightCtrl = glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS;
case GLFW_KEY_RIGHT_CONTROL: bool leftShift = glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS;
io.KeyCtrl = false; bool rightShift = glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;
break; bool leftAlt = glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS;
case GLFW_KEY_LEFT_SHIFT: bool rightAlt = glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS;
case GLFW_KEY_RIGHT_SHIFT:
io.KeyShift = false; io.KeyCtrl = leftCtrl || rightCtrl;
break; io.KeyShift = leftShift || rightShift;
case GLFW_KEY_LEFT_ALT: io.KeyAlt = leftAlt || rightAlt;
case GLFW_KEY_RIGHT_ALT:
io.KeyAlt = false;
break;
default:
io.KeysDown[key] = false;
}
}
} }
void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c) void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)

Loading…
Cancel
Save