Skip to content

Commit

Permalink
Nav/Examples: honoring the io.WantMoveMouse flag in most common examp…
Browse files Browse the repository at this point in the history
…les (#323)

Missing support Vulkan (#549), Apple (#575, #247), SDL (#58, #356),
Allegro, Marmalade (#368, #375)
  • Loading branch information
ocornut committed Jul 30, 2016
1 parent d88dcc2 commit 79e7ece
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ vulkan_example/
Vulkan example.
This is quite long and tedious, because: Vulkan.

TODO: Apple, SDL GL/GL3, Allegro, Marmalade, Vulkan examples do not honor the io.WantMoveMouse flag.
8 changes: 8 additions & 0 deletions examples/directx10_example/imgui_impl_dx10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ void ImGui_ImplDX10_NewFrame()
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events

// Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
if (io.WantMoveMouse)
{
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
ClientToScreen(g_hWnd, &pos);
SetCursorPos(pos.x, pos.y);
}

// Hide OS mouse cursor if ImGui is drawing it
SetCursor(io.MouseDrawCursor ? NULL : LoadCursor(NULL, IDC_ARROW));

Expand Down
8 changes: 8 additions & 0 deletions examples/directx11_example/imgui_impl_dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ void ImGui_ImplDX11_NewFrame()
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events

// Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
if (io.WantMoveMouse)
{
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
ClientToScreen(g_hWnd, &pos);
SetCursorPos(pos.x, pos.y);
}

// Hide OS mouse cursor if ImGui is drawing it
SetCursor(io.MouseDrawCursor ? NULL : LoadCursor(NULL, IDC_ARROW));

Expand Down
8 changes: 8 additions & 0 deletions examples/directx9_example/imgui_impl_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ void ImGui_ImplDX9_NewFrame()
// io.MouseDown : filled by WM_*BUTTON* events
// io.MouseWheel : filled by WM_MOUSEWHEEL events

// Set OS mouse position if requested last frame by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
if (io.WantMoveMouse)
{
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
ClientToScreen(g_hWnd, &pos);
SetCursorPos(pos.x, pos.y);
}

// Hide OS mouse cursor if ImGui is drawing it
SetCursor(io.MouseDrawCursor ? NULL : LoadCursor(NULL, IDC_ARROW));

Expand Down
13 changes: 10 additions & 3 deletions examples/opengl3_example/imgui_impl_glfw_gl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,16 @@ void ImGui_ImplGlfwGL3_NewFrame()
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
{
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
if (io.WantMoveMouse)
{
glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); // Set mouse position if requested by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
}
else
{
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Get mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
}
}
else
{
Expand Down
13 changes: 10 additions & 3 deletions examples/opengl_example/imgui_impl_glfw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,16 @@ void ImGui_ImplGlfw_NewFrame()
// (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
{
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
if (io.WantMoveMouse)
{
glfwSetCursorPos(g_Window, (double)io.MousePos.x, (double)io.MousePos.y); // Set mouse position if requested by io.WantMoveMouse flag (used when io.NavMovesTrue is enabled by user and using directional navigation)
}
else
{
double mouse_x, mouse_y;
glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Get mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
}
}
else
{
Expand Down

0 comments on commit 79e7ece

Please sign in to comment.