mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-22 07:36:35 +00:00
Internals: added ImRect::ContainsWithPad()
This commit is contained in:
parent
94da5842ef
commit
204ae8a407
13
imgui.cpp
13
imgui.cpp
@ -5212,12 +5212,8 @@ static void FindHoveredWindow()
|
||||
continue;
|
||||
|
||||
// Using the clipped AABB, a child window will typically be clipped by its parent (not always)
|
||||
ImRect bb(window->OuterRectClipped);
|
||||
if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
bb.Expand(padding_regular);
|
||||
else
|
||||
bb.Expand(padding_for_resize);
|
||||
if (!bb.Contains(g.IO.MousePos))
|
||||
ImVec2 hit_padding = (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)) ? padding_regular : padding_for_resize;
|
||||
if (!window->OuterRectClipped.ContainsWithPad(g.IO.MousePos, hit_padding))
|
||||
continue;
|
||||
|
||||
// Support for one rectangular hole in any given window
|
||||
@ -8387,9 +8383,8 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
|
||||
if (clip)
|
||||
rect_clipped.ClipWith(g.CurrentWindow->ClipRect);
|
||||
|
||||
// Expand for touch input
|
||||
const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
|
||||
if (!rect_for_touch.Contains(g.IO.MousePos))
|
||||
// Hit testing, expanded for touch input
|
||||
if (!rect_clipped.ContainsWithPad(g.IO.MousePos, g.Style.TouchExtraPadding))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -544,6 +544,7 @@ struct IMGUI_API ImRect
|
||||
ImVec2 GetBR() const { return Max; } // Bottom-right
|
||||
bool Contains(const ImVec2& p) const { return p.x >= Min.x && p.y >= Min.y && p.x < Max.x && p.y < Max.y; }
|
||||
bool Contains(const ImRect& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; }
|
||||
bool ContainsWithPad(const ImVec2& p, const ImVec2& pad) const { return p.x >= Min.x - pad.x && p.y >= Min.y - pad.y && p.x < Max.x + pad.x && p.y < Max.y + pad.y; }
|
||||
bool Overlaps(const ImRect& r) const { return r.Min.y < Max.y && r.Max.y > Min.y && r.Min.x < Max.x && r.Max.x > Min.x; }
|
||||
void Add(const ImVec2& p) { if (Min.x > p.x) Min.x = p.x; if (Min.y > p.y) Min.y = p.y; if (Max.x < p.x) Max.x = p.x; if (Max.y < p.y) Max.y = p.y; }
|
||||
void Add(const ImRect& r) { if (Min.x > r.Min.x) Min.x = r.Min.x; if (Min.y > r.Min.y) Min.y = r.Min.y; if (Max.x < r.Max.x) Max.x = r.Max.x; if (Max.y < r.Max.y) Max.y = r.Max.y; }
|
||||
|
Loading…
Reference in New Issue
Block a user