Skip to content

Commit

Permalink
ImDrawList: Prefixed internal functions with underscore, renamed Upda…
Browse files Browse the repository at this point in the history
…teClipRect() to _OnChangedClipRect(), UpdateTextureID() -> _OnChangedTextureID()
  • Loading branch information
ocornut committed Jun 8, 2020
1 parent e35a813 commit b1f2eac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2994,7 +2994,7 @@ void ImGui::GcCompactTransientWindowBuffers(ImGuiWindow* window)
window->MemoryDrawListIdxCapacity = window->DrawList->IdxBuffer.Capacity;
window->MemoryDrawListVtxCapacity = window->DrawList->VtxBuffer.Capacity;
window->IDStack.clear();
window->DrawList->ClearFreeMemory();
window->DrawList->_ClearFreeMemory();
window->DC.ChildWindows.clear();
window->DC.ItemFlagsStack.clear();
window->DC.ItemWidthStack.clear();
Expand Down Expand Up @@ -3777,11 +3777,11 @@ void ImGui::NewFrame()
if (g.IO.BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset)
g.DrawListSharedData.InitialFlags |= ImDrawListFlags_AllowVtxOffset;

g.BackgroundDrawList.ResetForNewFrame();
g.BackgroundDrawList._ResetForNewFrame();
g.BackgroundDrawList.PushTextureID(g.IO.Fonts->TexID);
g.BackgroundDrawList.PushClipRectFullScreen();

g.ForegroundDrawList.ResetForNewFrame();
g.ForegroundDrawList._ResetForNewFrame();
g.ForegroundDrawList.PushTextureID(g.IO.Fonts->TexID);
g.ForegroundDrawList.PushClipRectFullScreen();

Expand Down Expand Up @@ -4019,8 +4019,8 @@ void ImGui::Shutdown(ImGuiContext* context)
g.OpenPopupStack.clear();
g.BeginPopupStack.clear();
g.DrawDataBuilder.ClearFreeMemory();
g.BackgroundDrawList.ClearFreeMemory();
g.ForegroundDrawList.ClearFreeMemory();
g.BackgroundDrawList._ClearFreeMemory();
g.ForegroundDrawList._ClearFreeMemory();

g.TabBars.Clear();
g.CurrentTabBarStack.clear();
Expand Down Expand Up @@ -4079,7 +4079,7 @@ static void AddDrawListToDrawData(ImVector<ImDrawList*>* out_list, ImDrawList* d
{
// Remove trailing command if unused.
// Technically we could return directly instead of popping, but this make things looks neat in Metrics window as well.
draw_list->PopUnusedDrawCmd();
draw_list->_PopUnusedDrawCmd();
if (draw_list->CmdBuffer.Size == 0)
return;

Expand Down Expand Up @@ -5859,7 +5859,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
// DRAWING

// Setup draw list and outer clipping rectangle
window->DrawList->ResetForNewFrame();
window->DrawList->_ResetForNewFrame();
window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
PushClipRect(host_rect.Min, host_rect.Max, false);

Expand Down
12 changes: 6 additions & 6 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ struct ImDrawList
// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui)
ImDrawList(const ImDrawListSharedData* shared_data) { _Data = shared_data; Flags = ImDrawListFlags_None; _VtxCurrentIdx = 0; _VtxWritePtr = NULL; _IdxWritePtr = NULL; _OwnerName = NULL; }

~ImDrawList() { ClearFreeMemory(); }
~ImDrawList() { _ClearFreeMemory(); }
IMGUI_API void PushClipRect(ImVec2 clip_rect_min, ImVec2 clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling)
IMGUI_API void PushClipRectFullScreen();
IMGUI_API void PopClipRect();
Expand Down Expand Up @@ -2070,11 +2070,11 @@ struct ImDrawList
inline void PrimVtx(const ImVec2& pos, const ImVec2& uv, ImU32 col) { PrimWriteIdx((ImDrawIdx)_VtxCurrentIdx); PrimWriteVtx(pos, uv, col); } // Write vertex with unique index

// [Internal helpers]
IMGUI_API void ResetForNewFrame();
IMGUI_API void ClearFreeMemory();
IMGUI_API void PopUnusedDrawCmd();
IMGUI_API void UpdateClipRect();
IMGUI_API void UpdateTextureID();
IMGUI_API void _ResetForNewFrame();
IMGUI_API void _ClearFreeMemory();
IMGUI_API void _PopUnusedDrawCmd();
IMGUI_API void _OnChangedClipRect();
IMGUI_API void _OnChangedTextureID();
};

// All draw data to render a Dear ImGui frame
Expand Down
24 changes: 12 additions & 12 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void ImDrawListSharedData::SetCircleSegmentMaxError(float max_error)
}

// Initialize before use in a new frame. We always have a command ready in the buffer.
void ImDrawList::ResetForNewFrame()
void ImDrawList::_ResetForNewFrame()
{
// Verify that the ImDrawCmd fields we want to memcmp() are contiguous in memory.
// (those should be IM_STATIC_ASSERT() in theory but with our pre C++11 setup the whole check doesn't compile with GCC)
Expand All @@ -400,7 +400,7 @@ void ImDrawList::ResetForNewFrame()
CmdBuffer.push_back(ImDrawCmd());
}

void ImDrawList::ClearFreeMemory()
void ImDrawList::_ClearFreeMemory()
{
CmdBuffer.clear();
IdxBuffer.clear();
Expand Down Expand Up @@ -439,7 +439,7 @@ void ImDrawList::AddDrawCmd()

// Pop trailing draw command (used before merging or presenting to user)
// Note that this leaves the ImDrawList in a state unfit for further commands, as most code assume that CmdBuffer.Size > 0 && CmdBuffer.back().UserCallback == NULL
void ImDrawList::PopUnusedDrawCmd()
void ImDrawList::_PopUnusedDrawCmd()
{
if (CmdBuffer.Size == 0)
return;
Expand Down Expand Up @@ -469,7 +469,7 @@ void ImDrawList::AddCallback(ImDrawCallback callback, void* callback_data)

// Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack.
// The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only.
void ImDrawList::UpdateClipRect()
void ImDrawList::_OnChangedClipRect()
{
// If current command is used with different settings we need to add a new command
ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
Expand All @@ -490,7 +490,7 @@ void ImDrawList::UpdateClipRect()
curr_cmd->ClipRect = _CmdHeader.ClipRect;
}

void ImDrawList::UpdateTextureID()
void ImDrawList::_OnChangedTextureID()
{
// If current command is used with different settings we need to add a new command
ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1];
Expand Down Expand Up @@ -528,7 +528,7 @@ void ImDrawList::PushClipRect(ImVec2 cr_min, ImVec2 cr_max, bool intersect_with_

_ClipRectStack.push_back(cr);
_CmdHeader.ClipRect = cr;
UpdateClipRect();
_OnChangedClipRect();
}

void ImDrawList::PushClipRectFullScreen()
Expand All @@ -540,21 +540,21 @@ void ImDrawList::PopClipRect()
{
_ClipRectStack.pop_back();
_CmdHeader.ClipRect = (_ClipRectStack.Size == 0) ? _Data->ClipRectFullscreen : _ClipRectStack.Data[_ClipRectStack.Size - 1];
UpdateClipRect();
_OnChangedClipRect();
}

void ImDrawList::PushTextureID(ImTextureID texture_id)
{
_TextureIdStack.push_back(texture_id);
_CmdHeader.TextureId = texture_id;
UpdateTextureID();
_OnChangedTextureID();
}

void ImDrawList::PopTextureID()
{
_TextureIdStack.pop_back();
_CmdHeader.TextureId = (_TextureIdStack.Size == 0) ? (ImTextureID)NULL : _TextureIdStack.Data[_TextureIdStack.Size - 1];
UpdateTextureID();
_OnChangedTextureID();
}

// Reserve space for a number of vertices and indices.
Expand Down Expand Up @@ -1378,7 +1378,7 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list)
return;

SetCurrentChannel(draw_list, 0);
draw_list->PopUnusedDrawCmd();
draw_list->_PopUnusedDrawCmd();

// Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command.
int new_cmd_buffer_count = 0;
Expand Down Expand Up @@ -1427,8 +1427,8 @@ void ImDrawListSplitter::Merge(ImDrawList* draw_list)
if (int sz = ch._IdxBuffer.Size) { memcpy(idx_write, ch._IdxBuffer.Data, sz * sizeof(ImDrawIdx)); idx_write += sz; }
}
draw_list->_IdxWritePtr = idx_write;
draw_list->UpdateClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call.
draw_list->UpdateTextureID();
draw_list->_OnChangedClipRect(); // We call this instead of AddDrawCmd(), so that empty channels won't produce an extra draw call.
draw_list->_OnChangedTextureID();
_Count = 1;
}

Expand Down

0 comments on commit b1f2eac

Please sign in to comment.