From 209ab823d6e2cd3597c4165031aa636a9c74b0ff Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 4 Feb 2015 09:43:11 +0100 Subject: [PATCH] Cleanup of previous merge. Moved rarely used Get/Set InternalState functions to the bottom of the list to avoid being misleadnig. --- imgui.cpp | 41 +++++++++++++++++++++++------------------ imgui.h | 8 +++++--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 76d99ee3..252cf270 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1036,8 +1036,8 @@ struct ImGuiState } }; -static ImGuiState GImDefaultState; -static ImGuiState* GImGui = &GImDefaultState; +static ImGuiState GImDefaultState; // Internal state storage +static ImGuiState* GImGui = &GImDefaultState; // We access everything through this pointer. NB: this pointer is always assumed to be != NULL struct ImGuiWindow { @@ -1104,20 +1104,23 @@ public: static ImGuiWindow* GetCurrentWindow() { - IM_ASSERT(GImGui->CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? - GImGui->CurrentWindow->Accessed = true; - return GImGui->CurrentWindow; + ImGuiState& g = *GImGui; + IM_ASSERT(g.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? + g.CurrentWindow->Accessed = true; + return g.CurrentWindow; } static void SetActiveId(ImGuiID id) { - GImGui->ActiveId = id; + ImGuiState& g = *GImGui; + g.ActiveId = id; } static void RegisterAliveId(const ImGuiID& id) { - if (GImGui->ActiveId == id) - GImGui->ActiveIdIsAlive = true; + ImGuiState& g = *GImGui; + if (g.ActiveId == id) + g.ActiveIdIsAlive = true; } //----------------------------------------------------------------------------- @@ -1611,25 +1614,26 @@ static void MarkSettingsDirty() g.SettingsDirtyTimer = g.IO.IniSavingRate; } +// Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself +// Note that we still point to some static data and members (such as GFontAtlas), so the state instance you end up using will point to the static data within its module void* ImGui::GetInternalState() { return GImGui; } -unsigned ImGui::GetInternalStateSize() +size_t ImGui::GetInternalStateSize() { return sizeof(ImGuiState); } void ImGui::SetInternalState(void* state, bool construct) { - if( construct ) - new (state) ImGuiState; + if (construct) + new (state) ImGuiState(); GImGui = (ImGuiState*)state; } - ImGuiIO& ImGui::GetIO() { return GImGui->IO; @@ -7579,15 +7583,16 @@ static const char* GetClipboardTextFn_DefaultImpl() // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers static void SetClipboardTextFn_DefaultImpl(const char* text) { - if (GImGui->PrivateClipboard) + ImGuiState& g = *GImGui; + if (g.PrivateClipboard) { - ImGui::MemFree(GImGui->PrivateClipboard); - GImGui->PrivateClipboard = NULL; + ImGui::MemFree(g.PrivateClipboard); + g.PrivateClipboard = NULL; } const char* text_end = text + strlen(text); - GImGui->PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1); - memcpy(GImGui->PrivateClipboard, text, (size_t)(text_end - text)); - GImGui->PrivateClipboard[(size_t)(text_end - text)] = 0; + g.PrivateClipboard = (char*)ImGui::MemAlloc((size_t)(text_end - text) + 1); + memcpy(g.PrivateClipboard, text, (size_t)(text_end - text)); + g.PrivateClipboard[(size_t)(text_end - text)] = 0; } #endif diff --git a/imgui.h b/imgui.h index 5c3fd09e..ab6681a2 100644 --- a/imgui.h +++ b/imgui.h @@ -146,9 +146,6 @@ public: namespace ImGui { // Main - IMGUI_API void* GetInternalState(); - IMGUI_API unsigned GetInternalStateSize(); - IMGUI_API void SetInternalState(void* state, bool construct = false); IMGUI_API ImGuiIO& GetIO(); IMGUI_API ImGuiStyle& GetStyle(); IMGUI_API void NewFrame(); @@ -337,6 +334,11 @@ namespace ImGui IMGUI_API void ColorConvertRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v); IMGUI_API void ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b); + // Internal state access - if you want to share ImGui state between modules (e.g. DLL) or allocate it yourself + IMGUI_API void* GetInternalState(); + IMGUI_API size_t GetInternalStateSize(); + IMGUI_API void SetInternalState(void* state, bool construct = false); + // Obsolete (will be removed) IMGUI_API void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size);