Skip to content

Commit f032ad6

Browse files
committed
Viewports: Renamed GetRect() to GetMainRect() in prevision for work rect. Comments
1 parent 871727d commit f032ad6

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

imgui.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -3851,7 +3851,7 @@ void ImGui::NewFrame()
38513851
IM_ASSERT(g.Font->IsLoaded());
38523852
ImRect virtual_space(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
38533853
for (int n = 0; n < g.Viewports.Size; n++)
3854-
virtual_space.Add(g.Viewports[n]->GetRect());
3854+
virtual_space.Add(g.Viewports[n]->GetMainRect());
38553855
g.DrawListSharedData.ClipRectFullscreen = ImVec4(virtual_space.Min.x, virtual_space.Min.y, virtual_space.Max.x, virtual_space.Max.y);
38563856
g.DrawListSharedData.CurveTessellationTol = g.Style.CurveTessellationTol;
38573857
g.DrawListSharedData.SetCircleSegmentMaxError(g.Style.CircleSegmentMaxError);
@@ -4376,7 +4376,7 @@ static void ImGui::EndFrameDrawDimmedBackgrounds()
43764376
float rounding = ImMax(window->WindowRounding, g.Style.WindowRounding);
43774377
ImRect bb = window->Rect();
43784378
bb.Expand(g.FontSize);
4379-
if (bb.Contains(window->Viewport->GetRect())) // If a window fits the entire viewport, adjust its highlight inward
4379+
if (bb.Contains(window->Viewport->GetMainRect())) // If a window fits the entire viewport, adjust its highlight inward
43804380
{
43814381
bb.Expand(-g.FontSize - 1.0f);
43824382
rounding = window->WindowRounding;
@@ -4523,7 +4523,7 @@ void ImGui::Render()
45234523
if (mouse_cursor_size.x > 0.0f && mouse_cursor_size.y > 0.0f)
45244524
{
45254525
float scale = g.Style.MouseCursorScale * viewport->DpiScale;
4526-
if (viewport->GetRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale)))
4526+
if (viewport->GetMainRect().Overlaps(ImRect(g.IO.MousePos, g.IO.MousePos + ImVec2(mouse_cursor_size.x + 2, mouse_cursor_size.y + 2) * scale)))
45274527
RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, scale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48));
45284528
}
45294529

@@ -4648,7 +4648,7 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
46484648
const ImRect rect_for_touch(rect_clipped.Min - g.Style.TouchExtraPadding, rect_clipped.Max + g.Style.TouchExtraPadding);
46494649
if (!rect_for_touch.Contains(g.IO.MousePos))
46504650
return false;
4651-
if (!g.MouseViewport->GetRect().Overlaps(rect_clipped))
4651+
if (!g.MouseViewport->GetMainRect().Overlaps(rect_clipped))
46524652
return false;
46534653
return true;
46544654
}
@@ -6100,7 +6100,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
61006100

61016101
// Late create viewport if we don't fit within our current host viewport.
61026102
if (window->ViewportAllowPlatformMonitorExtend >= 0 && !window->ViewportOwned && !(window->Viewport->Flags & ImGuiViewportFlags_Minimized))
6103-
if (!window->Viewport->GetRect().Contains(window->Rect()))
6103+
if (!window->Viewport->GetMainRect().Contains(window->Rect()))
61046104
{
61056105
// This is based on the assumption that the DPI will be known ahead (same as the DPI of the selection done in UpdateSelectWindowViewport)
61066106
//ImGuiViewport* old_viewport = window->Viewport;
@@ -6182,7 +6182,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
61826182

61836183
// Clamp position/size so window stays visible within its viewport or monitor
61846184
// Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
6185-
ImRect viewport_rect = window->Viewport->GetRect();
6185+
ImRect viewport_rect = window->Viewport->GetMainRect();
61866186
if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
61876187
{
61886188
ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
@@ -6242,7 +6242,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
62426242
window->Viewport->Pos = window->Pos;
62436243
if (!window->Viewport->PlatformRequestResize)
62446244
window->Viewport->Size = window->Size;
6245-
viewport_rect = window->Viewport->GetRect();
6245+
viewport_rect = window->Viewport->GetMainRect();
62466246
}
62476247

62486248
// Save last known viewport position within the window itself (so it can be saved in .ini file and restored)
@@ -8374,7 +8374,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
83748374
if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0)
83758375
{
83768376
ImGuiViewportP* viewport = window->WasActive ? window->Viewport : (ImGuiViewportP*)GetMainViewport(); // FIXME-VIEWPORT: What may be our reference viewport?
8377-
SetNextWindowPos(viewport->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
8377+
SetNextWindowPos(viewport->GetMainRect().GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
83788378
}
83798379

83808380
flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDocking;
@@ -9009,7 +9009,7 @@ static ImVec2 ImGui::NavCalcPreferredRefPos()
90099009
// When navigation is active and mouse is disabled, decide on an arbitrary position around the bottom left of the currently navigated item.
90109010
const ImRect& rect_rel = g.NavWindow->NavRectRel[g.NavLayer];
90119011
ImVec2 pos = g.NavWindow->Pos + ImVec2(rect_rel.Min.x + ImMin(g.Style.FramePadding.x * 4, rect_rel.GetWidth()), rect_rel.Max.y - ImMin(g.Style.FramePadding.y, rect_rel.GetHeight()));
9012-
ImRect visible_rect = g.NavWindow->Viewport->GetRect();
9012+
ImRect visible_rect = g.NavWindow->Viewport->GetMainRect();
90139013
return ImFloor(ImClamp(pos, visible_rect.Min, visible_rect.Max)); // ImFloor() is important because non-integer mouse position application in back-end might be lossy and result in undesirable non-zero delta.
90149014
}
90159015
}
@@ -10557,7 +10557,7 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
1055710557
ImGuiContext& g = *GImGui;
1055810558
if (!(viewport->Flags & (ImGuiViewportFlags_CanHostOtherWindows | ImGuiViewportFlags_Minimized)) || window->Viewport == viewport)
1055910559
return false;
10560-
if (!viewport->GetRect().Contains(window->Rect()))
10560+
if (!viewport->GetMainRect().Contains(window->Rect()))
1056110561
return false;
1056210562
if (GetWindowAlwaysWantOwnViewport(window))
1056310563
return false;
@@ -10568,7 +10568,7 @@ static bool ImGui::UpdateTryMergeWindowIntoHostViewport(ImGuiWindow* window, ImG
1056810568
if (window_behind == window)
1056910569
break;
1057010570
if (window_behind->WasActive && window_behind->ViewportOwned && !(window_behind->Flags & ImGuiWindowFlags_ChildWindow))
10571-
if (window_behind->Viewport->GetRect().Overlaps(window->Rect()))
10571+
if (window_behind->Viewport->GetMainRect().Overlaps(window->Rect()))
1057210572
return false;
1057310573
}
1057410574

@@ -10636,7 +10636,7 @@ static ImGuiViewportP* FindHoveredViewportFromPlatformWindowStack(const ImVec2 m
1063610636
for (int n = 0; n < g.Viewports.Size; n++)
1063710637
{
1063810638
ImGuiViewportP* viewport = g.Viewports[n];
10639-
if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetRect().Contains(mouse_platform_pos))
10639+
if (!(viewport->Flags & (ImGuiViewportFlags_NoInputs | ImGuiViewportFlags_Minimized)) && viewport->GetMainRect().Contains(mouse_platform_pos))
1064010640
if (best_candidate == NULL || best_candidate->LastFrontMostStampCount < viewport->LastFrontMostStampCount)
1064110641
best_candidate = viewport;
1064210642
}
@@ -11231,7 +11231,7 @@ static int ImGui::FindPlatformMonitorForRect(const ImRect& rect)
1123111231
// Update monitor from viewport rectangle (we'll use this info to clamp windows and save windows lost in a removed monitor)
1123211232
static void ImGui::UpdateViewportPlatformMonitor(ImGuiViewportP* viewport)
1123311233
{
11234-
viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetRect());
11234+
viewport->PlatformMonitor = (short)FindPlatformMonitorForRect(viewport->GetMainRect());
1123511235
}
1123611236

1123711237
void ImGui::DestroyPlatformWindow(ImGuiViewportP* viewport)
@@ -14957,7 +14957,7 @@ void ImGui::ShowViewportThumbnails()
1495714957
//for (int n = 0; n < g.PlatformIO.Monitors.Size; n++)
1495814958
// bb_full.Add(GetPlatformMonitorMainRect(g.PlatformIO.Monitors[n]));
1495914959
for (int n = 0; n < g.Viewports.Size; n++)
14960-
bb_full.Add(g.Viewports[n]->GetRect());
14960+
bb_full.Add(g.Viewports[n]->GetMainRect());
1496114961
ImVec2 p = window->DC.CursorPos;
1496214962
ImVec2 off = p - bb_full.Min * SCALE;
1496314963
//for (int n = 0; n < g.PlatformIO.Monitors.Size; n++)

imgui.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ namespace ImGui
716716
IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b);
717717

718718
// Inputs Utilities: Keyboard
719-
// - For 'int user_key_index' you can use your own indices/enums according to how your backend/engine stored them in io.KeysDown[].
719+
// - For 'int user_key_index' you can use your own indices/enums according to how your back-end/engine stored them in io.KeysDown[].
720720
// - We don't know the meaning of those value. You can use GetKeyIndex() to map a ImGuiKey_ value into the user index.
721721
IMGUI_API int GetKeyIndex(ImGuiKey imgui_key); // map ImGuiKey_* values into user's key index. == io.KeyMap[key]
722722
IMGUI_API bool IsKeyDown(int user_key_index); // is key being held. == io.KeysDown[user_key_index].
@@ -2479,15 +2479,17 @@ struct ImGuiViewport
24792479
ImDrawData* DrawData; // The ImDrawData corresponding to this viewport. Valid after Render() and until the next call to NewFrame().
24802480
ImGuiID ParentViewportId; // (Advanced) 0: no parent. Instruct the platform back-end to setup a parent/child relationship between platform windows.
24812481

2482-
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, frame-buffers etc.). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this.
2483-
void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context). If somehow everything you need can fit in the void* PlatformHandle field you may ignore this.
2482+
// Our design separate the Renderer and Platform back-ends to facilitate combining default back-ends with each others.
2483+
// When our create your own back-end for a custom engine, it is possible that both Renderer and Platform will be handled by the same system and you may not need to use all the UserData/Handle fields.
2484+
void* RendererUserData; // void* to hold custom data structure for the renderer (e.g. swap chain, framebuffers etc.).
2485+
void* PlatformUserData; // void* to hold custom data structure for the OS / platform (e.g. windowing info, render context).
24842486
void* PlatformHandle; // void* for FindViewportByPlatformHandle(). (e.g. suggested to use natural platform handle such as HWND, GLFWWindow*, SDL_Window*)
2485-
void* PlatformHandleRaw; // void* to hold low-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*)
2486-
bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4)
2487+
void* PlatformHandleRaw; // void* to hold lower-level, platform-native window handle (e.g. the HWND) when using an abstraction layer like GLFW or SDL (where PlatformHandle would be a SDL_Window*)
24872488
bool PlatformRequestMove; // Platform window requested move (e.g. window was moved by the OS / host window manager, authoritative position will be OS window position)
24882489
bool PlatformRequestResize; // Platform window requested resize (e.g. window was resized by the OS / host window manager, authoritative size will be OS window size)
2490+
bool PlatformRequestClose; // Platform window requested closure (e.g. window was moved by the OS / host window manager, e.g. pressing ALT-F4)
24892491

2490-
ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
2492+
ImGuiViewport() { ID = 0; Flags = 0; DpiScale = 0.0f; DrawData = NULL; ParentViewportId = 0; RendererUserData = PlatformUserData = PlatformHandle = PlatformHandleRaw = NULL; PlatformRequestMove = PlatformRequestResize = PlatformRequestClose = false; }
24912493
~ImGuiViewport() { IM_ASSERT(PlatformUserData == NULL && RendererUserData == NULL); }
24922494
};
24932495

imgui_internal.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,10 @@ struct ImGuiViewportP : public ImGuiViewport
935935
ImVec2 LastPlatformSize;
936936
ImVec2 LastRendererSize;
937937

938-
ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
939-
~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); }
940-
ImRect GetRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
941-
ImVec2 GetCenter() const { return ImVec2(Pos.x + Size.x * 0.5f, Pos.y + Size.y * 0.5f); }
942-
void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
938+
ImGuiViewportP() { Idx = -1; LastFrameActive = LastFrameDrawLists[0] = LastFrameDrawLists[1] = LastFrontMostStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; PlatformMonitor = -1; PlatformWindowCreated = false; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); }
939+
~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); }
940+
ImRect GetMainRect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
941+
void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }
943942
};
944943

945944
struct ImGuiNavMoveResult

0 commit comments

Comments
 (0)