Internals: Using simpler ImVec2ih construct + fixed misnamed member.

This commit is contained in:
omar 2019-08-23 12:31:14 +02:00
parent e1fca8d982
commit 483534b525
2 changed files with 20 additions and 19 deletions

View File

@ -5182,7 +5182,7 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWindowFl
if (settings->ViewportId) if (settings->ViewportId)
{ {
window->ViewportId = settings->ViewportId; window->ViewportId = settings->ViewportId;
window->ViewportPos = ImVec2(settings->ViewportPosh.x, settings->ViewportPosh.y); window->ViewportPos = ImVec2(settings->ViewportPos.x, settings->ViewportPos.y);
} }
else else
{ {
@ -7304,8 +7304,8 @@ void ImGui::SetWindowCollapsed(ImGuiWindow* window, bool collapsed, ImGuiCond co
static void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size) static void SetWindowHitTestHole(ImGuiWindow* window, const ImVec2& pos, const ImVec2& size)
{ {
IM_ASSERT(window->HitTestHoleSize.x == 0); // We don't support multiple holes/hit test filters IM_ASSERT(window->HitTestHoleSize.x == 0); // We don't support multiple holes/hit test filters
window->HitTestHoleSize = ImVec2ih((short)size.x, (short)size.y); window->HitTestHoleSize = ImVec2ih(size);
window->HitTestHoleOffset = ImVec2ih((short)(pos.x - window->Pos.x), (short)(pos.y - window->Pos.y)); window->HitTestHoleOffset = ImVec2ih(pos - window->Pos);
} }
void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond) void ImGui::SetWindowCollapsed(bool collapsed, ImGuiCond cond)
@ -10217,7 +10217,7 @@ static void SettingsHandlerWindow_ReadLine(ImGuiContext*, ImGuiSettingsHandler*,
if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) { settings->Pos = ImVec2ih((short)x, (short)y); } if (sscanf(line, "Pos=%i,%i", &x, &y) == 2) { settings->Pos = ImVec2ih((short)x, (short)y); }
else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) { settings->Size = ImVec2ih((short)x, (short)y); } else if (sscanf(line, "Size=%i,%i", &x, &y) == 2) { settings->Size = ImVec2ih((short)x, (short)y); }
else if (sscanf(line, "ViewportId=0x%08X", &u1) == 1) { settings->ViewportId = u1; } else if (sscanf(line, "ViewportId=0x%08X", &u1) == 1) { settings->ViewportId = u1; }
else if (sscanf(line, "ViewportPos=%i,%i", &x, &y) == 2) { settings->ViewportPosh = ImVec2ih((short)x, (short)y); } else if (sscanf(line, "ViewportPos=%i,%i", &x, &y) == 2) { settings->ViewportPos = ImVec2ih((short)x, (short)y); }
else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); } else if (sscanf(line, "Collapsed=%d", &i) == 1) { settings->Collapsed = (i != 0); }
else if (sscanf(line, "DockId=0x%X,%d", &u1, &i) == 2) { settings->DockId = u1; settings->DockOrder = (short)i; } else if (sscanf(line, "DockId=0x%X,%d", &u1, &i) == 2) { settings->DockId = u1; settings->DockOrder = (short)i; }
else if (sscanf(line, "DockId=0x%X", &u1) == 1) { settings->DockId = u1; settings->DockOrder = -1; } else if (sscanf(line, "DockId=0x%X", &u1) == 1) { settings->DockId = u1; settings->DockOrder = -1; }
@ -10242,10 +10242,10 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings); window->SettingsIdx = g.SettingsWindows.index_from_ptr(settings);
} }
IM_ASSERT(settings->ID == window->ID); IM_ASSERT(settings->ID == window->ID);
settings->Pos = ImVec2ih((short)(window->Pos.y - window->ViewportPos.y), (short)(window->Pos.y - window->ViewportPos.y)); settings->Pos = ImVec2ih(window->Pos - window->ViewportPos);
settings->Size = ImVec2ih((short)window->SizeFull.x, (short)window->SizeFull.y); settings->Size = ImVec2ih(window->SizeFull);
settings->ViewportId = window->ViewportId; settings->ViewportId = window->ViewportId;
settings->ViewportPosh = ImVec2ih((short)window->ViewportPos.x, (short)window->ViewportPos.y); settings->ViewportPos = ImVec2ih(window->ViewportPos);
IM_ASSERT(window->DockNode == NULL || window->DockNode->ID == window->DockId); IM_ASSERT(window->DockNode == NULL || window->DockNode->ID == window->DockId);
settings->DockId = window->DockId; settings->DockId = window->DockId;
settings->ClassId = window->WindowClass.ClassId; settings->ClassId = window->WindowClass.ClassId;
@ -10261,7 +10261,7 @@ static void SettingsHandlerWindow_WriteAll(ImGuiContext* ctx, ImGuiSettingsHandl
buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name); buf->appendf("[%s][%s]\n", handler->TypeName, settings->Name);
if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID) if (settings->ViewportId != 0 && settings->ViewportId != ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
{ {
buf->appendf("ViewportPos=%d,%d\n", settings->ViewportPosh.x, settings->ViewportPosh.y); buf->appendf("ViewportPos=%d,%d\n", settings->ViewportPos.x, settings->ViewportPos.y);
buf->appendf("ViewportId=0x%08X\n", settings->ViewportId); buf->appendf("ViewportId=0x%08X\n", settings->ViewportId);
} }
if (settings->Pos.x != 0 || settings->Pos.y != 0 || settings->ViewportId == ImGui::IMGUI_VIEWPORT_DEFAULT_ID) if (settings->Pos.x != 0 || settings->Pos.y != 0 || settings->ViewportId == ImGui::IMGUI_VIEWPORT_DEFAULT_ID)
@ -13929,10 +13929,10 @@ void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_
} }
else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name)) else if (ImGuiWindowSettings* dst_settings = FindOrCreateWindowSettings(dst_name))
{ {
ImVec2ih window_pos_2ih = ImVec2ih((short)src_window->Pos.x, (short)src_window->Pos.y); ImVec2ih window_pos_2ih = ImVec2ih(src_window->Pos);
if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID) if (src_window->ViewportId != 0 && src_window->ViewportId != IMGUI_VIEWPORT_DEFAULT_ID)
{ {
dst_settings->ViewportPosh = window_pos_2ih; dst_settings->ViewportPos = window_pos_2ih;
dst_settings->ViewportId = src_window->ViewportId; dst_settings->ViewportId = src_window->ViewportId;
dst_settings->Pos = ImVec2ih(0, 0); dst_settings->Pos = ImVec2ih(0, 0);
} }
@ -13940,7 +13940,7 @@ void ImGui::DockBuilderCopyWindowSettings(const char* src_name, const char* dst_
{ {
dst_settings->Pos = window_pos_2ih; dst_settings->Pos = window_pos_2ih;
} }
dst_settings->Size = ImVec2ih((short)src_window->SizeFull.x, (short)src_window->SizeFull.y); dst_settings->Size = ImVec2ih(src_window->SizeFull);
dst_settings->Collapsed = src_window->Collapsed; dst_settings->Collapsed = src_window->Collapsed;
} }
} }
@ -14412,9 +14412,9 @@ static void DockSettingsHandler_DockNodeToSettings(ImGuiDockContext* dc, ImGuiDo
node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None; node_settings.SplitAxis = node->IsSplitNode() ? (char)node->SplitAxis : ImGuiAxis_None;
node_settings.Depth = (char)depth; node_settings.Depth = (char)depth;
node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_); node_settings.Flags = (node->LocalFlags & ImGuiDockNodeFlags_SavedFlagsMask_);
node_settings.Pos = ImVec2ih((short)node->Pos.x, (short)node->Pos.y); node_settings.Pos = ImVec2ih(node->Pos);
node_settings.Size = ImVec2ih((short)node->Size.x, (short)node->Size.y); node_settings.Size = ImVec2ih(node->Size);
node_settings.SizeRef = ImVec2ih((short)node->SizeRef.x, (short)node->SizeRef.y); node_settings.SizeRef = ImVec2ih(node->SizeRef);
dc->SettingsNodes.push_back(node_settings); dc->SettingsNodes.push_back(node_settings);
if (node->ChildNodes[0]) if (node->ChildNodes[0])
DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[0], depth + 1); DockSettingsHandler_DockNodeToSettings(dc, node->ChildNodes[0], depth + 1);

View File

@ -544,8 +544,9 @@ struct ImVec1
struct ImVec2ih struct ImVec2ih
{ {
short x, y; short x, y;
ImVec2ih() { x = y = 0; } ImVec2ih() { x = y = 0; }
ImVec2ih(short _x, short _y) { x = _x; y = _y; } ImVec2ih(short _x, short _y) { x = _x; y = _y; }
explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; }
}; };
// 2D axis aligned bounding-box // 2D axis aligned bounding-box
@ -677,14 +678,14 @@ struct ImGuiWindowSettings
ImGuiID ID; ImGuiID ID;
ImVec2ih Pos; // NB: Settings position are stored RELATIVE to the viewport! Whereas runtime ones are absolute positions. ImVec2ih Pos; // NB: Settings position are stored RELATIVE to the viewport! Whereas runtime ones are absolute positions.
ImVec2ih Size; ImVec2ih Size;
ImVec2ih ViewportPosh; ImVec2ih ViewportPos;
ImGuiID ViewportId; ImGuiID ViewportId;
ImGuiID DockId; // ID of last known DockNode (even if the DockNode is invisible because it has only 1 active window), or 0 if none. ImGuiID DockId; // ID of last known DockNode (even if the DockNode is invisible because it has only 1 active window), or 0 if none.
ImGuiID ClassId; // ID of window class if specified ImGuiID ClassId; // ID of window class if specified
short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible. short DockOrder; // Order of the last time the window was visible within its DockNode. This is used to reorder windows that are reappearing on the same frame. Same value between windows that were active and windows that were none are possible.
bool Collapsed; bool Collapsed;
ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ViewportPosh = ImVec2ih(0, 0); ViewportId = DockId = ClassId = 0; DockOrder = -1; Collapsed = false; } ImGuiWindowSettings() { Name = NULL; ID = 0; Pos = Size = ViewportPos = ImVec2ih(0, 0); ViewportId = DockId = ClassId = 0; DockOrder = -1; Collapsed = false; }
}; };
struct ImGuiSettingsHandler struct ImGuiSettingsHandler
@ -1210,7 +1211,7 @@ struct ImGuiContext
{ {
Initialized = false; Initialized = false;
FrameScopeActive = FrameScopePushedFallbackWindow = false; FrameScopeActive = FrameScopePushedFallbackWindow = false;
ConfigFlagsCurrFrame = ImGuiConfigFlags_None; ConfigFlagsCurrFrame = ConfigFlagsLastFrame = ImGuiConfigFlags_None;
Font = NULL; Font = NULL;
FontSize = FontBaseSize = 0.0f; FontSize = FontBaseSize = 0.0f;
FontAtlasOwnedByContext = shared_font_atlas ? false : true; FontAtlasOwnedByContext = shared_font_atlas ? false : true;