Skip to content

Commit

Permalink
IO, Inputs: rename SetMousePos() to TeleportMousePos(). (#6837, #228)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Sep 18, 2023
1 parent ff36fe3 commit 6c022f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8416,13 +8416,15 @@ ImVec2 ImGui::GetMousePos()
return g.IO.MousePos;
}

// This is called TeleportMousePos() and not SetMousePos() to emphasis that setting MousePosPrev will effectively clear mouse delta as well.
// It is expected you only call this if (io.BackendFlags & ImGuiBackendFlags_HasSetMousePos) is set and supported by backend.
void ImGui::SetMousePos(const ImVec2& pos)
void ImGui::TeleportMousePos(const ImVec2& pos)
{
ImGuiContext& g = *GImGui;
g.IO.MousePos = g.IO.MousePosPrev = pos;
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
g.IO.WantSetMousePos = true;
//IMGUI_DEBUG_LOG_IO("SetMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y);
//IMGUI_DEBUG_LOG_IO("TeleportMousePos: (%.1f,%.1f)\n", io.MousePos.x, io.MousePos.y);
}

// NB: prefer to call right after BeginPopup(). At the time Selectable/MenuItem is activated, the popup is already closed!
Expand Down Expand Up @@ -11562,7 +11564,7 @@ static void ImGui::NavUpdate()
// Update mouse position if requested
// (This will take into account the possibility that a Scroll was queued in the window to offset our absolute mouse position before scroll has been applied)
if (set_mouse_pos && (io.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos) && (io.BackendFlags & ImGuiBackendFlags_HasSetMousePos))
SetMousePos(NavCalcPreferredRefPos());
TeleportMousePos(NavCalcPreferredRefPos());

// [DEBUG]
g.NavScoringDebugCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,7 @@ namespace ImGui
IMGUI_API float GetNavTweakPressedAmount(ImGuiAxis axis);
IMGUI_API int CalcTypematicRepeatAmount(float t0, float t1, float repeat_delay, float repeat_rate);
IMGUI_API void GetTypematicRepeatRate(ImGuiInputFlags flags, float* repeat_delay, float* repeat_rate);
IMGUI_API void SetMousePos(const ImVec2& pos);
IMGUI_API void TeleportMousePos(const ImVec2& pos);
IMGUI_API void SetActiveIdUsingAllKeyboardKeys();
inline bool IsActiveIdUsingNavDir(ImGuiDir dir) { ImGuiContext& g = *GImGui; return (g.ActiveIdUsingNavDirMask & (1 << dir)) != 0; }

Expand Down

0 comments on commit 6c022f9

Please sign in to comment.