1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-12 02:00:58 +01:00

Removed extraneous calls to GetCurrentWindowRead() when we already have a ImGuiContext. Internal RenderXXX functions also don't need to write into the Accessed field at all.

This commit is contained in:
omar 2017-10-06 11:48:07 -07:00
parent 335c8dd159
commit acb6f12d2c

View File

@ -1937,12 +1937,12 @@ static inline bool IsWindowContentHoverable(ImGuiWindow* window)
// Advance cursor given item size for layout.
void ImGui::ItemSize(const ImVec2& size, float text_offset_y)
{
ImGuiWindow* window = GetCurrentWindow();
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
if (window->SkipItems)
return;
// Always align ourselves on pixel boundaries
ImGuiContext& g = *GImGui;
const float line_height = ImMax(window->DC.CurrentLineHeight, size.y);
const float text_base_offset = ImMax(window->DC.CurrentLineTextBaseOffset, text_offset_y);
//if (g.IO.KeyAlt) window->DrawList->AddRect(window->DC.CursorPos, window->DC.CursorPos + ImVec2(size.x, line_height), IM_COL32(255,0,0,200)); // [DEBUG]
@ -2034,7 +2034,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id)
bool ImGui::IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
if (!bb.Overlaps(window->ClipRect))
if (!id || *id != g.ActiveId)
if (clip_even_when_logged || !g.LogEnabled)
@ -2893,7 +2893,7 @@ void ImGui::LogText(const char* fmt, ...)
static void LogRenderedText(const ImVec2* ref_pos, const char* text, const char* text_end = NULL)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
if (!text_end)
text_end = ImGui::FindRenderedTextEnd(text, text_end);
@ -2945,7 +2945,7 @@ static void LogRenderedText(const ImVec2* ref_pos, const char* text, const char*
void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool hide_text_after_hash)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
ImGuiWindow* window = g.CurrentWindow;
// Hide anything after a '##' string
const char* text_display_end;
@ -2972,7 +2972,7 @@ void ImGui::RenderText(ImVec2 pos, const char* text, const char* text_end, bool
void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
ImGuiWindow* window = g.CurrentWindow;
if (!text_end)
text_end = text + strlen(text); // FIXME-OPT
@ -2997,7 +2997,7 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
return;
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
ImGuiWindow* window = g.CurrentWindow;
// Perform CPU side clipping for single clipped element to avoid using scissor state
ImVec2 pos = pos_min;
@ -3030,8 +3030,8 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
// Render a rectangle shaped with optional rounding and borders
void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
{
ImGuiWindow* window = GetCurrentWindow();
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding);
if (border && (window->Flags & ImGuiWindowFlags_ShowBorders))
{
@ -3042,7 +3042,8 @@ void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
{
ImGuiWindow* window = GetCurrentWindow();
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
if (window->Flags & ImGuiWindowFlags_ShowBorders)
{
window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), GetColorU32(ImGuiCol_BorderShadow), rounding);
@ -3054,7 +3055,7 @@ void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
ImGuiWindow* window = g.CurrentWindow;
const float h = g.FontSize * 1.00f;
const float r = h * 0.40f * scale;
@ -3080,14 +3081,15 @@ void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale)
void ImGui::RenderBullet(ImVec2 pos)
{
ImGuiWindow* window = GetCurrentWindow();
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
window->DrawList->AddCircleFilled(pos, GImGui->FontSize*0.20f, GetColorU32(ImGuiCol_Text), 8);
}
void ImGui::RenderCheckMark(ImVec2 pos, ImU32 col)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
ImGuiWindow* window = g.CurrentWindow;
float start_x = (float)(int)(g.FontSize * 0.307f + 0.5f);
float rem_third = (float)(int)((g.FontSize - start_x) / 3.0f);
float bx = pos.x + 0.5f + start_x + rem_third;
@ -3132,7 +3134,7 @@ ImVec2 ImGui::CalcTextSize(const char* text, const char* text_end, bool hide_tex
void ImGui::CalcListClipping(int items_count, float items_height, int* out_items_display_start, int* out_items_display_end)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
if (g.LogEnabled)
{
// If logging is active, do not perform any clipping
@ -3184,7 +3186,7 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs)
bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool clip)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
// Clip
ImRect rect_clipped(r_min, r_max);
@ -3382,7 +3384,7 @@ bool ImGui::IsItemActive()
ImGuiContext& g = *GImGui;
if (g.ActiveId)
{
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
return g.ActiveId == window->DC.LastItemId;
}
return false;
@ -5947,7 +5949,7 @@ void ImGui::LogToTTY(int max_depth)
ImGuiContext& g = *GImGui;
if (g.LogEnabled)
return;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
g.LogEnabled = true;
g.LogFile = stdout;
@ -5962,7 +5964,7 @@ void ImGui::LogToFile(int max_depth, const char* filename)
ImGuiContext& g = *GImGui;
if (g.LogEnabled)
return;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
if (!filename)
{
@ -5989,7 +5991,7 @@ void ImGui::LogToClipboard(int max_depth)
ImGuiContext& g = *GImGui;
if (g.LogEnabled)
return;
ImGuiWindow* window = GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
g.LogEnabled = true;
g.LogFile = NULL;
@ -10175,7 +10177,7 @@ static float GetDraggedColumnOffset(int column_index)
// Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing
// window creates a feedback loop because we store normalized positions. So while dragging we enforce absolute positioning.
ImGuiContext& g = *GImGui;
ImGuiWindow* window = ImGui::GetCurrentWindowRead();
ImGuiWindow* window = g.CurrentWindow;
IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets.
IM_ASSERT(g.ActiveId == window->DC.ColumnsSetId + ImGuiID(column_index));