Merge pull request #159 from adamdmoss/master

Examples: OpenGL: if content window doesn't have focus, tell ImGui we don't have a mouse position.
This commit is contained in:
omar 2015-03-16 11:46:29 +00:00
commit d4c0ecea0e
2 changed files with 24 additions and 10 deletions

View File

@ -329,11 +329,18 @@ void ImGui_ImplGlfwGL3_NewFrame()
// Setup inputs // Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
double mouse_x, mouse_y; if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); {
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels double mouse_x, mouse_y;
mouse_y *= (float)display_h / h; glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
mouse_y *= (float)display_h / h;
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
}
else
{
io.MousePos = ImVec2(-1,-1);
}
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {

View File

@ -233,11 +233,18 @@ void ImGui_ImplGlfw_NewFrame()
// Setup inputs // Setup inputs
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
double mouse_x, mouse_y; if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y); {
mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels double mouse_x, mouse_y;
mouse_y *= (float)display_h / h; glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) mouse_x *= (float)display_w / w; // Convert mouse coordinates to pixels
mouse_y *= (float)display_h / h;
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
}
else
{
io.MousePos = ImVec2(-1,-1);
}
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {