mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Added IsMousePosValid() helper.
This commit is contained in:
parent
f72ca6d22c
commit
5938f1ba61
16
imgui.cpp
16
imgui.cpp
@ -2153,11 +2153,10 @@ void ImGui::NewFrame()
|
||||
|
||||
// Update mouse input state
|
||||
// If mouse just appeared or disappeared (usually denoted by -FLT_MAX component, but in reality we test for -256000.0f) we cancel out movement in MouseDelta
|
||||
const float MOUSE_INVALID = -256000.0f;
|
||||
if ((g.IO.MousePos.x < MOUSE_INVALID && g.IO.MousePos.y < MOUSE_INVALID) || (g.IO.MousePosPrev.x < MOUSE_INVALID && g.IO.MousePosPrev.y < MOUSE_INVALID))
|
||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||
else
|
||||
if (IsMousePosValid(&g.IO.MousePos) && IsMousePosValid(&g.IO.MousePosPrev))
|
||||
g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev;
|
||||
else
|
||||
g.IO.MouseDelta = ImVec2(0.0f, 0.0f);
|
||||
g.IO.MousePosPrev = g.IO.MousePos;
|
||||
for (int i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++)
|
||||
{
|
||||
@ -3228,6 +3227,15 @@ ImVec2 ImGui::GetMousePosOnOpeningCurrentPopup()
|
||||
return g.IO.MousePos;
|
||||
}
|
||||
|
||||
// We typically use ImVec2(-FLT_MAX,-FLT_MAX) to denote an invalid mouse position
|
||||
bool ImGui::IsMousePosValid(const ImVec2* mouse_pos)
|
||||
{
|
||||
if (mouse_pos == NULL)
|
||||
mouse_pos = &GImGui->IO.MousePos;
|
||||
const float MOUSE_INVALID = -256000.0f;
|
||||
return mouse_pos->x >= MOUSE_INVALID && mouse_pos->y >= MOUSE_INVALID;
|
||||
}
|
||||
|
||||
ImVec2 ImGui::GetMouseDragDelta(int button, float lock_threshold)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
|
1
imgui.h
1
imgui.h
@ -458,6 +458,7 @@ namespace ImGui
|
||||
IMGUI_API bool IsMouseReleased(int button); // did mouse button released (went from Down to !Down)
|
||||
IMGUI_API bool IsMouseDragging(int button = 0, float lock_threshold = -1.0f); // is mouse dragging. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
IMGUI_API bool IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip = true); // is mouse hovering given bounding rect (in screen space). clipped by current clipping settings. disregarding of consideration of focus/window ordering/blocked by a popup.
|
||||
IMGUI_API bool IsMousePosValid(const ImVec2* mouse_pos = NULL); //
|
||||
IMGUI_API ImVec2 GetMousePos(); // shortcut to ImGui::GetIO().MousePos provided by user, to be consistent with other calls
|
||||
IMGUI_API ImVec2 GetMousePosOnOpeningCurrentPopup(); // retrieve backup of mouse positioning at the time of opening popup we have BeginPopup() into
|
||||
IMGUI_API ImVec2 GetMouseDragDelta(int button = 0, float lock_threshold = -1.0f); // dragging amount since clicking. if lock_threshold < -1.0f uses io.MouseDraggingThreshold
|
||||
|
Loading…
Reference in New Issue
Block a user