From 76a39ad224d5396708a95b34735d2d5592f21d91 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 13:03:02 +0100 Subject: [PATCH 01/44] Added global Alpha in ImGuiStyle + commented ImGuiStyle fields in .h --- imgui.cpp | 21 +++++++++++---------- imgui.h | 26 +++++++++++++------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e4a3ec2b..2ad1af7c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -210,18 +210,19 @@ static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_ ImGuiStyle::ImGuiStyle() { + Alpha = 1.0f; // Global alpha applies to everything in ImGui WindowPadding = ImVec2(8,8); // Padding within a window WindowMinSize = ImVec2(48,48); // Minimum window size FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets) - ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets + ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) - WindowFillAlphaDefault = 0.70f; - WindowRounding = 10.0f; - TreeNodeSpacing = 22.0f; - ColumnsMinSpacing = 6.0f; // Minimum space between two columns - ScrollBarWidth = 16.0f; + WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() + WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node + ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns + ScrollBarWidth = 16.0f; // Width of the vertical scroll bar Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); @@ -705,7 +706,8 @@ public: float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; } ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; } - ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= a; return ImConvertColorFloat4ToU32(c); } + ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImConvertColorFloat4ToU32(c); } + ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImConvertColorFloat4ToU32(c); } }; static ImGuiWindow* GetCurrentWindow() @@ -4215,9 +4217,7 @@ bool ColorButton(const ImVec4& col, bool small_height, bool outline_border) const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); const bool pressed = hovered && g.IO.MouseClicked[0]; - - const ImU32 col32 = ImConvertColorFloat4ToU32(col); - RenderFrame(bb.Min, bb.Max, col32, outline_border); + RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border); if (hovered) { @@ -5391,6 +5391,7 @@ void ShowStyleEditor(ImGuiStyle* ref) *ref = g.Style; } + ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero. ImGui::SliderFloat("Rounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; diff --git a/imgui.h b/imgui.h index 697100eb..00bc6ee9 100644 --- a/imgui.h +++ b/imgui.h @@ -353,21 +353,21 @@ enum ImGuiColorEditMode_ ImGuiColorEditMode_HEX = 2, }; -// See constructor for comments of individual fields. struct ImGuiStyle { - ImVec2 WindowPadding; - ImVec2 WindowMinSize; - ImVec2 FramePadding; - ImVec2 ItemSpacing; - ImVec2 ItemInnerSpacing; - ImVec2 TouchExtraPadding; - ImVec2 AutoFitPadding; - float WindowFillAlphaDefault; - float WindowRounding; - float TreeNodeSpacing; - float ColumnsMinSpacing; - float ScrollBarWidth; + float Alpha; // Global alpha applies to everything in ImGui + ImVec2 WindowPadding; // Padding within a window + ImVec2 WindowMinSize; // Minimum window size + ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) + ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines + ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! + ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip) + float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() + float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + float TreeNodeSpacing; // Horizontal spacing when entering a tree node + float ColumnsMinSpacing; // Minimum horizontal spacing between two columns + float ScrollBarWidth; // Width of the vertical scroll bar ImVec4 Colors[ImGuiCol_COUNT]; ImGuiStyle(); From d6f6afabb36282937969de735f3fb849bf694cfa Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 13:09:48 +0100 Subject: [PATCH 02/44] Initialised window->Accessed in constructor. Begin() return false with Alpha==0.0 --- imgui.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2ad1af7c..ebf2e9c0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -669,9 +669,9 @@ struct ImGuiWindow float ScrollY; float NextScrollY; bool ScrollbarY; - bool Visible; + bool Visible; // Set to true on Begin() + bool Accessed; // Set to true when any widget access the current window bool Collapsed; - bool Accessed; int AutoFitFrames; ImGuiDrawContext DC; @@ -924,6 +924,7 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si NextScrollY = 0.0f; ScrollbarY = false; Visible = false; + Accessed = false; Collapsed = false; AutoFitFrames = -1; LastFrameDrawn = -1; @@ -2177,13 +2178,14 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin // We also hide the window from rendering because we've already added its border to the command list. // (we could perform the check earlier in the function but it is simplier at this point) - // FIXME-WIP if (window->Collapsed) window->Visible = false; } // Return collapsed so that user can perform an early out optimisation - return !window->Collapsed; + const bool hidden = g.Style.Alpha <= 0.0f; + const bool collapsed = window->Collapsed; + return hidden || !collapsed; } void End() From c5dacee3a7a4b996d393205c43ecff01257cc52d Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 13:18:32 +0100 Subject: [PATCH 03/44] Undo Begin() return false with Alpha==0.0, misleading at the moment --- imgui.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ebf2e9c0..30a9068b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2183,9 +2183,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin } // Return collapsed so that user can perform an early out optimisation - const bool hidden = g.Style.Alpha <= 0.0f; - const bool collapsed = window->Collapsed; - return hidden || !collapsed; + return !window->Collapsed; } void End() From ca027e1754e9d4c1c836b0c89b876f52cb8f8520 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 13:20:57 +0100 Subject: [PATCH 04/44] Skip rendering if alpha is 0.0 --- imgui.cpp | 55 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 30a9068b..b8434f88 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1401,34 +1401,39 @@ void Render() memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); } - // Render tooltip - if (g.Tooltip[0]) + // Skip render altogether if alpha is 0.0 + // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place. + if (g.Style.Alpha > 0.0f) { - // Use a dummy window to render the tooltip - ImGui::BeginTooltip(); - ImGui::TextUnformatted(g.Tooltip); - ImGui::EndTooltip(); - } + // Render tooltip + if (g.Tooltip[0]) + { + // Use a dummy window to render the tooltip + ImGui::BeginTooltip(); + ImGui::TextUnformatted(g.Tooltip); + ImGui::EndTooltip(); + } - // Gather windows to render - g.RenderDrawLists.resize(0); - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) - window->AddToRenderList(); - } - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) - window->AddToRenderList(); - } + // Gather windows to render + g.RenderDrawLists.resize(0); + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) + window->AddToRenderList(); + } + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) + window->AddToRenderList(); + } - // Render - if (!g.RenderDrawLists.empty()) - g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); - g.RenderDrawLists.resize(0); + // Render + if (!g.RenderDrawLists.empty()) + g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); + g.RenderDrawLists.resize(0); + } } // Find the optional ## from which we stop displaying text. From 7c61822d26add61485a28b0920ab74850e27acf8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 14:30:33 +0100 Subject: [PATCH 05/44] Skip most logic is alpha is 0.0, Begin() also return false to allow user to early out --- imgui.cpp | 66 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index b8434f88..851da486 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -671,7 +671,8 @@ struct ImGuiWindow bool ScrollbarY; bool Visible; // Set to true on Begin() bool Accessed; // Set to true when any widget access the current window - bool Collapsed; + bool Collapsed; // Set when collapsing window to become only title-bar + bool SkipItems; // == Visible && !Collapsed int AutoFitFrames; ImGuiDrawContext DC; @@ -926,6 +927,7 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si Visible = false; Accessed = false; Collapsed = false; + SkipItems = false; AutoFitFrames = -1; LastFrameDrawn = -1; ItemWidthDefault = 0.0f; @@ -1945,7 +1947,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin // Apply and ImClamp scrolling window->ScrollY = window->NextScrollY; window->ScrollY = ImMax(window->ScrollY, 0.0f); - if (!window->Collapsed) + if (!window->Collapsed && !window->SkipItems) window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y)); window->NextScrollY = window->ScrollY; @@ -2186,9 +2188,12 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin if (window->Collapsed) window->Visible = false; } + if (g.Style.Alpha <= 0.0f) + window->Visible = false; - // Return collapsed so that user can perform an early out optimisation - return !window->Collapsed; + // Return false if we don't intend to display anything to allow user to perform an early out optimisation + window->SkipItems = !window->Visible || window->Collapsed; + return !window->SkipItems; } void End() @@ -2456,7 +2461,7 @@ ImGuiStorage* GetTreeStateStorage() void TextV(const char* fmt, va_list args) { ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; static char buf[1024]; @@ -2486,7 +2491,7 @@ void TextUnformatted(const char* text, const char* text_end) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; const char* text_begin = text; @@ -2584,7 +2589,7 @@ void AlignFirstTextHeightToWidgets() { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height. @@ -2596,7 +2601,7 @@ void LabelText(const char* label, const char* fmt, ...) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; const ImGuiStyle& style = g.Style; const float w = window->DC.ItemWidth.back(); @@ -2669,7 +2674,7 @@ bool Button(const char* label, ImVec2 size, bool repeat_when_held) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -2709,7 +2714,7 @@ bool SmallButton(const char* label) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -2827,7 +2832,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_ { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -2907,7 +2912,7 @@ void BulletText(const char* fmt, ...) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; static char buf[1024]; @@ -3059,7 +3064,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -3295,7 +3300,7 @@ static bool SliderFloatN(const char* label, float v[3], int components, float v_ { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -3358,7 +3363,7 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; const ImGuiStyle& style = g.Style; @@ -3466,7 +3471,7 @@ void Checkbox(const char* label, bool* v) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; const ImGuiStyle& style = g.Style; @@ -3520,7 +3525,7 @@ bool RadioButton(const char* label, bool active) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -3709,7 +3714,7 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -3773,7 +3778,7 @@ bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlag { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiIO& io = g.IO; @@ -3997,7 +4002,7 @@ static bool InputFloatN(const char* label, float* v, int components, int decimal { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -4094,7 +4099,7 @@ bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -4209,7 +4214,7 @@ bool ColorButton(const ImVec4& col, bool small_height, bool outline_border) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -4256,7 +4261,7 @@ bool ColorEdit4(const char* label, float col[4], bool alpha) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return false; const ImGuiStyle& style = g.Style; @@ -4392,7 +4397,7 @@ void ColorEditMode(ImGuiColorEditMode mode) void Separator() { ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; if (window->DC.ColumnsCount > 1) @@ -4417,7 +4422,7 @@ void Separator() void Spacing() { ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; ItemSize(ImVec2(0,0)); @@ -4427,7 +4432,7 @@ static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); @@ -4453,7 +4458,7 @@ void NextColumn() { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; if (window->DC.ColumnsCount > 1) @@ -4507,7 +4512,7 @@ void SameLine(int column_x, int spacing_w) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; float x, y; @@ -4580,7 +4585,7 @@ void Columns(int columns_count, const char* id, bool border) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); - if (window->Collapsed) + if (window->SkipItems) return; if (window->DC.ColumnsCount != 1) @@ -4809,6 +4814,9 @@ void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col) void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) { + if ((col >> 24) == 0) + return; + static ImVec2 circle_vtx[12]; static bool circle_vtx_builds = false; if (!circle_vtx_builds) From 7de89e0da305e760cc0d63f465340173b5f6bf08 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 14:31:47 +0100 Subject: [PATCH 06/44] Removing line from Todo list --- imgui.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 851da486..7e5d2a30 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -113,7 +113,6 @@ - window: autofit is losing its purpose when user relies on any dynamic layout (window width multiplier, column). maybe just discard autofit? - window: support horizontal scroll - window: fix resize grip scaling along with Rounding style setting - - window/style: add global alpha modifier (not just "fill_alpha") - widgets: switching from "widget-label" to "label-widget" would make it more convenient to integrate widgets in trees - widgets: clip text? hover clipped text shows it in a tooltip or in-place overlay - main: make IsHovered() more consistent for various type of widgets, widgets with multiple components, etc. also effectively IsHovered() region sometimes differs from hot region, e.g tree nodes From a17885f470381059e8d7a83bf4b55dd88563c6b6 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 18:43:39 +0100 Subject: [PATCH 07/44] Fixed tooltip size (broken earlier today) + added todo items --- imgui.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 7e5d2a30..62dd160d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -129,6 +129,8 @@ - combo: turn child handling code into popup helper - list selection, concept of a selectable "block" (that can be multiple widgets) - menubar, menus + - plot: make it easier for user to draw into the graph (e.g: draw basis, highlight certain pointsm, 2d plots, multiple plots) + - plot: "smooth" automatic scale, user give an input 0.0(full user scale) 1.0(full derived from value) - plot: add a helper e.g. Plot(char* label, float value, float time_span=2.0f) that stores values and Plot them for you - probably another function name. and/or automatically allow to plot ANY displayed value (more reliance on stable ID) - file selection widget -> build the tool in our codebase to improve model-dialog idioms (may or not lead to ImGui changes) - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() @@ -2191,7 +2193,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin window->Visible = false; // Return false if we don't intend to display anything to allow user to perform an early out optimisation - window->SkipItems = !window->Visible || window->Collapsed; + window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0); return !window->SkipItems; } From bbda8998013f8ced0ef325bbdf1147f86a04ada1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 19:10:00 +0100 Subject: [PATCH 08/44] Removed unused parameter in demo window code --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 62dd160d..b38018ca 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5586,7 +5586,7 @@ void ShowTestWindow(bool* open) ImGui::SliderFloat("float", &f1, 0.0f, 2.0f); ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f); ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f); - ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f", 3.0f); + ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f"); static float angle = 0.0f; ImGui::SliderAngle("angle", &angle); From efc473df985db6a1e9322bf5f9988c8ac66bf3f4 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 18 Aug 2014 19:13:18 +0100 Subject: [PATCH 09/44] Todo list --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index b38018ca..9c63d3d8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -121,7 +121,7 @@ - scrollbar: make the grab visible and a minimum size for long scroll regions - input number: optional range min/max - input number: holding [-]/[+] buttons should increase the step non-linearly - - input number: rename Input*() to Input(), Slider*() to Slider() ? + - input number: use mouse wheel to step up/down - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 horrible layout code. item width should include frame padding, then we can have a generic horizontal layout helper. - columns: declare column set (each column: fixed size, %, fill, distribute default size among fills) - columns: columns header to act as button (~sort op) and allow resize/reorder From 42d4b4be6aa8d70b5093d07bf19befd1b60ed43f Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:09:13 +0100 Subject: [PATCH 10/44] Converted all Tabs to Spaces (git diff -w shows an empty diff) --- examples/directx9_example/main.cpp | 460 +- examples/opengl_example/main.cpp | 370 +- imconfig.h | 24 +- imgui.cpp | 8430 ++++++++++++++-------------- imgui.h | 896 +-- 5 files changed, 5090 insertions(+), 5090 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 3036eb75..f302db66 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -5,98 +5,98 @@ #include #include "../../imgui.h" -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strdup +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strdup static HWND hWnd; -static LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice +static LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device -static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices -static LPDIRECT3DTEXTURE9 g_pTexture = NULL; // Our texture +static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold vertices +static LPDIRECT3DTEXTURE9 g_pTexture = NULL; // Our texture struct CUSTOMVERTEX { - D3DXVECTOR3 position; - D3DCOLOR color; - float tu, tv; + D3DXVECTOR3 position; + D3DCOLOR color; + float tu, tv; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer) static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { - size_t total_vtx_count = 0; - for (int n = 0; n < cmd_lists_count; n++) - total_vtx_count += cmd_lists[n]->vtx_buffer.size(); - if (total_vtx_count == 0) - return; + size_t total_vtx_count = 0; + for (int n = 0; n < cmd_lists_count; n++) + total_vtx_count += cmd_lists[n]->vtx_buffer.size(); + if (total_vtx_count == 0) + return; - // Copy and convert all vertices into a single contiguous buffer + // Copy and convert all vertices into a single contiguous buffer CUSTOMVERTEX* vtx_dst; if (g_pVB->Lock(0, total_vtx_count, (void**)&vtx_dst, D3DLOCK_DISCARD) < 0) return; - for (int n = 0; n < cmd_lists_count; n++) - { - const ImDrawList* cmd_list = cmd_lists[n]; - const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0]; - for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++) - { - vtx_dst->position.x = vtx_src->pos.x; - vtx_dst->position.y = vtx_src->pos.y; - vtx_dst->position.z = 0.0f; - vtx_dst->color = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 - vtx_dst->tu = vtx_src->uv.x; - vtx_dst->tv = vtx_src->uv.y; - vtx_dst++; - vtx_src++; - } - } + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + const ImDrawVert* vtx_src = &cmd_list->vtx_buffer[0]; + for (size_t i = 0; i < cmd_list->vtx_buffer.size(); i++) + { + vtx_dst->position.x = vtx_src->pos.x; + vtx_dst->position.y = vtx_src->pos.y; + vtx_dst->position.z = 0.0f; + vtx_dst->color = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16); // RGBA --> ARGB for DirectX9 + vtx_dst->tu = vtx_src->uv.x; + vtx_dst->tv = vtx_src->uv.y; + vtx_dst++; + vtx_src++; + } + } g_pVB->Unlock(); - g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) ); - g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); + g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) ); + g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); - // Setup render state: alpha-blending, no face culling, no depth testing + // Setup render state: alpha-blending, no face culling, no depth testing g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, false ); g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, false ); - g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true ); - g_pd3dDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD ); - g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false ); - g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); - g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); - g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, true ); + g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true ); + g_pd3dDevice->SetRenderState( D3DRS_BLENDOP, D3DBLENDOP_ADD ); + g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, false ); + g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); + g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); + g_pd3dDevice->SetRenderState( D3DRS_SCISSORTESTENABLE, true ); - // Setup texture - g_pd3dDevice->SetTexture( 0, g_pTexture ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); + // Setup texture + g_pd3dDevice->SetTexture( 0, g_pTexture ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); + g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); - // Setup orthographic projection matrix - D3DXMATRIXA16 mat; - D3DXMatrixIdentity(&mat); - g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat); - g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat); - D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0.0f, -1.0f, +1.0f); - g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat); + // Setup orthographic projection matrix + D3DXMATRIXA16 mat; + D3DXMatrixIdentity(&mat); + g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat); + g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat); + D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0.0f, -1.0f, +1.0f); + g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat); - // Render command lists - int vtx_offset = 0; - for (int n = 0; n < cmd_lists_count; n++) - { - // Render command list - const ImDrawList* cmd_list = cmd_lists[n]; - const ImDrawCmd* pcmd_end = cmd_list->commands.end(); - for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) - { - const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; - g_pd3dDevice->SetScissorRect(&r); - g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3); - vtx_offset += pcmd->vtx_count; - } - } + // Render command lists + int vtx_offset = 0; + for (int n = 0; n < cmd_lists_count; n++) + { + // Render command list + const ImDrawList* cmd_list = cmd_lists[n]; + const ImDrawCmd* pcmd_end = cmd_list->commands.end(); + for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) + { + const RECT r = { (LONG)pcmd->clip_rect.x, (LONG)pcmd->clip_rect.y, (LONG)pcmd->clip_rect.z, (LONG)pcmd->clip_rect.w }; + g_pd3dDevice->SetScissorRect(&r); + g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, vtx_offset, pcmd->vtx_count/3); + vtx_offset += pcmd->vtx_count; + } + } } HRESULT InitD3D(HWND hWnd) @@ -111,7 +111,7 @@ HRESULT InitD3D(HWND hWnd) d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Create the D3DDevice if (g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice) < 0) @@ -134,90 +134,90 @@ void Cleanup() LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - ImGuiIO& io = ImGui::GetIO(); - switch (msg) - { - case WM_LBUTTONDOWN: - io.MouseDown[0] = true; - return true; - case WM_LBUTTONUP: - io.MouseDown[0] = false; - return true; - case WM_RBUTTONDOWN: - io.MouseDown[1] = true; - return true; - case WM_RBUTTONUP: - io.MouseDown[1] = false; - return true; - case WM_MOUSEWHEEL: - // Mouse wheel: -1,0,+1 - io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1 : -1; - return true; - case WM_MOUSEMOVE: - // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - io.MousePos.x = (signed short)(lParam); - io.MousePos.y = (signed short)(lParam >> 16); - return true; - case WM_CHAR: - // You can also use ToAscii()+GetKeyboardState() to retrieve characters. - if (wParam > 1 && wParam < 256) - io.AddInputCharacter((char)wParam); - return true; - case WM_DESTROY: - { - Cleanup(); - PostQuitMessage(0); - return 0; - } - } + ImGuiIO& io = ImGui::GetIO(); + switch (msg) + { + case WM_LBUTTONDOWN: + io.MouseDown[0] = true; + return true; + case WM_LBUTTONUP: + io.MouseDown[0] = false; + return true; + case WM_RBUTTONDOWN: + io.MouseDown[1] = true; + return true; + case WM_RBUTTONUP: + io.MouseDown[1] = false; + return true; + case WM_MOUSEWHEEL: + // Mouse wheel: -1,0,+1 + io.MouseWheel = GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1 : -1; + return true; + case WM_MOUSEMOVE: + // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MousePos.x = (signed short)(lParam); + io.MousePos.y = (signed short)(lParam >> 16); + return true; + case WM_CHAR: + // You can also use ToAscii()+GetKeyboardState() to retrieve characters. + if (wParam > 1 && wParam < 256) + io.AddInputCharacter((char)wParam); + return true; + case WM_DESTROY: + { + Cleanup(); + PostQuitMessage(0); + return 0; + } + } return DefWindowProc(hWnd, msg, wParam, lParam); } void InitImGui() { - RECT rect; - GetClientRect(hWnd, &rect); + RECT rect; + GetClientRect(hWnd, &rect); - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.0f; // Align Direct3D Texels - io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. - io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = VK_UP; - io.KeyMap[ImGuiKey_DownArrow] = VK_UP; - io.KeyMap[ImGuiKey_Home] = VK_HOME; - io.KeyMap[ImGuiKey_End] = VK_END; - io.KeyMap[ImGuiKey_Delete] = VK_DELETE; - io.KeyMap[ImGuiKey_Backspace] = VK_BACK; - io.KeyMap[ImGuiKey_Enter] = VK_RETURN; - io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.0f; // Align Direct3D Texels + io.KeyMap[ImGuiKey_Tab] = VK_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array that we will update during the application lifetime. + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_UP; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; - io.RenderDrawListsFn = ImImpl_RenderDrawLists; - - // Create the vertex buffer - if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) - { - IM_ASSERT(0); - return; - } + io.RenderDrawListsFn = ImImpl_RenderDrawLists; + + // Create the vertex buffer + if (g_pd3dDevice->CreateVertexBuffer(10000 * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0) + { + IM_ASSERT(0); + return; + } - // Load font texture - const void* png_data; - unsigned int png_size; - ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); - if (D3DXCreateTextureFromFileInMemory(g_pd3dDevice, png_data, png_size, &g_pTexture) < 0) - { - IM_ASSERT(0); - return; - } + // Load font texture + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + if (D3DXCreateTextureFromFileInMemory(g_pd3dDevice, png_data, png_size, &g_pTexture) < 0) + { + IM_ASSERT(0); + return; + } } INT64 ticks_per_second = 0; @@ -225,28 +225,28 @@ INT64 time = 0; void UpdateImGui() { - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); - // Setup timestep - INT64 current_time; - QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); - io.DeltaTime = (float)(current_time - time) / ticks_per_second; - time = current_time; + // Setup timestep + INT64 current_time; + QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + io.DeltaTime = (float)(current_time - time) / ticks_per_second; + time = current_time; - // Setup inputs - // (we already got mouse position, buttons, wheel from the window message callback) - BYTE keystate[256]; - GetKeyboardState(keystate); - for (int i = 0; i < 256; i++) - io.KeysDown[i] = (keystate[i] & 0x80) != 0; - io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0; - io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0; - // io.MousePos : filled by WM_MOUSEMOVE event - // io.MouseDown : filled by WM_*BUTTON* events - // io.MouseWheel : filled by WM_MOUSEWHEEL events + // Setup inputs + // (we already got mouse position, buttons, wheel from the window message callback) + BYTE keystate[256]; + GetKeyboardState(keystate); + for (int i = 0; i < 256; i++) + io.KeysDown[i] = (keystate[i] & 0x80) != 0; + io.KeyCtrl = (keystate[VK_CONTROL] & 0x80) != 0; + io.KeyShift = (keystate[VK_SHIFT] & 0x80) != 0; + // io.MousePos : filled by WM_MOUSEMOVE event + // io.MouseDown : filled by WM_*BUTTON* events + // io.MouseWheel : filled by WM_MOUSEWHEEL events - // Start the frame - ImGui::NewFrame(); + // Start the frame + ImGui::NewFrame(); } int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) @@ -258,25 +258,25 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) // Create the application's window hWnd = CreateWindow(L"ImGui Example", L"ImGui DirectX9 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL); - if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) - return 1; - if (!QueryPerformanceCounter((LARGE_INTEGER *)&time)) - return 1; + if (!QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second)) + return 1; + if (!QueryPerformanceCounter((LARGE_INTEGER *)&time)) + return 1; - // Initialize Direct3D + // Initialize Direct3D if (InitD3D(hWnd) < 0) - { - if (g_pVB) - g_pVB->Release(); - UnregisterClass(L"ImGui Example", wc.hInstance); - return 1; - } + { + if (g_pVB) + g_pVB->Release(); + UnregisterClass(L"ImGui Example", wc.hInstance); + return 1; + } - // Show the window - ShowWindow(hWnd, SW_SHOWDEFAULT); - UpdateWindow(hWnd); + // Show the window + ShowWindow(hWnd, SW_SHOWDEFAULT); + UpdateWindow(hWnd); - InitImGui(); + InitImGui(); // Enter the message loop MSG msg; @@ -287,65 +287,65 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int) { TranslateMessage(&msg); DispatchMessage(&msg); - continue; + continue; } - - UpdateImGui(); + + UpdateImGui(); - // Create a simple window - // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - static bool show_test_window = true; - static bool show_another_window = false; - static float f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + // Create a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + static bool show_test_window = true; + static bool show_another_window = false; + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); - // Calculate and show framerate - static float ms_per_frame[120] = { 0 }; - static int ms_per_frame_idx = 0; - static float ms_per_frame_accum = 0.0f; - ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; - ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; - ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; - ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; - const float ms_per_frame_avg = ms_per_frame_accum / 120; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + // Calculate and show framerate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); - // Show the ImGui test window - // Most of user example code is in ImGui::ShowTestWindow() - if (show_test_window) - { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! - ImGui::ShowTestWindow(&show_test_window); - } + // Show the ImGui test window + // Most of user example code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } - // Show another simple window - if (show_another_window) - { - ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); - ImGui::Text("Hello"); - ImGui::End(); - } + // Show another simple window + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } - // Rendering - g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); - g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); - g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false); - g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0); - if (g_pd3dDevice->BeginScene() >= 0) - { - ImGui::Render(); - g_pd3dDevice->EndScene(); - } - g_pd3dDevice->Present(NULL, NULL, NULL, NULL); - } + // Rendering + g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); + g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false); + g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(204, 153, 153), 1.0f, 0); + if (g_pd3dDevice->BeginScene() >= 0) + { + ImGui::Render(); + g_pd3dDevice->EndScene(); + } + g_pd3dDevice->Present(NULL, NULL, NULL, NULL); + } - ImGui::Shutdown(); + ImGui::Shutdown(); - if (g_pVB) - g_pVB->Release(); + if (g_pVB) + g_pVB->Release(); UnregisterClass(L"ImGui Example", wc.hInstance); return 0; diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 609021ea..d2c76fa8 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -2,10 +2,10 @@ #include #include #define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" // for .png loading +#include "stb_image.h" // for .png loading #include "../../imgui.h" #ifdef _MSC_VER -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen +#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen #endif static GLFWwindow* window; @@ -16,253 +16,253 @@ static GLuint fontTex; // A faster way would be to collate all vertices from all cmd_lists into a single vertex buffer static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { - if (cmd_lists_count == 0) - return; + if (cmd_lists_count == 0) + return; - // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glEnable(GL_SCISSOR_TEST); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); - // Setup texture - glBindTexture(GL_TEXTURE_2D, fontTex); - glEnable(GL_TEXTURE_2D); + // Setup texture + glBindTexture(GL_TEXTURE_2D, fontTex); + glEnable(GL_TEXTURE_2D); - // Setup orthographic projection matrix - const float width = ImGui::GetIO().DisplaySize.x; - const float height = ImGui::GetIO().DisplaySize.y; - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + // Setup orthographic projection matrix + const float width = ImGui::GetIO().DisplaySize.x; + const float height = ImGui::GetIO().DisplaySize.y; + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.0f, width, height, 0.0f, -1.0f, +1.0f); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); - // Render command lists - for (int n = 0; n < cmd_lists_count; n++) - { - const ImDrawList* cmd_list = cmd_lists[n]; - const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin(); - glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer)); - glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8)); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16)); + // Render command lists + for (int n = 0; n < cmd_lists_count; n++) + { + const ImDrawList* cmd_list = cmd_lists[n]; + const unsigned char* vtx_buffer = (const unsigned char*)cmd_list->vtx_buffer.begin(); + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer)); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (void*)(vtx_buffer+8)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (void*)(vtx_buffer+16)); - int vtx_offset = 0; - const ImDrawCmd* pcmd_end = cmd_list->commands.end(); - for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) - { - glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); - glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); - vtx_offset += pcmd->vtx_count; - } - } - glDisable(GL_SCISSOR_TEST); + int vtx_offset = 0; + const ImDrawCmd* pcmd_end = cmd_list->commands.end(); + for (const ImDrawCmd* pcmd = cmd_list->commands.begin(); pcmd != pcmd_end; pcmd++) + { + glScissor((int)pcmd->clip_rect.x, (int)(height - pcmd->clip_rect.w), (int)(pcmd->clip_rect.z - pcmd->clip_rect.x), (int)(pcmd->clip_rect.w - pcmd->clip_rect.y)); + glDrawArrays(GL_TRIANGLES, vtx_offset, pcmd->vtx_count); + vtx_offset += pcmd->vtx_count; + } + } + glDisable(GL_SCISSOR_TEST); } static const char* ImImpl_GetClipboardTextFn() { - return glfwGetClipboardString(window); + return glfwGetClipboardString(window); } static void ImImpl_SetClipboardTextFn(const char* text, const char* text_end) { - if (!text_end) - text_end = text + strlen(text); + if (!text_end) + text_end = text + strlen(text); - if (*text_end == 0) - { - // Already got a zero-terminator at 'text_end', we don't need to add one - glfwSetClipboardString(window, text); - } - else - { - // Add a zero-terminator because glfw function doesn't take a size - char* buf = (char*)malloc(text_end - text + 1); - memcpy(buf, text, text_end-text); - buf[text_end-text] = '\0'; - glfwSetClipboardString(window, buf); - free(buf); - } + if (*text_end == 0) + { + // Already got a zero-terminator at 'text_end', we don't need to add one + glfwSetClipboardString(window, text); + } + else + { + // Add a zero-terminator because glfw function doesn't take a size + char* buf = (char*)malloc(text_end - text + 1); + memcpy(buf, text, text_end-text); + buf[text_end-text] = '\0'; + glfwSetClipboardString(window, buf); + free(buf); + } } // GLFW callbacks to get events static void glfw_error_callback(int error, const char* description) { - fputs(description, stderr); + fputs(description, stderr); } static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) { - ImGuiIO& io = ImGui::GetIO(); - io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1 + ImGuiIO& io = ImGui::GetIO(); + io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1 : - 1 : 0; // Mouse wheel: -1,0,+1 } static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - ImGuiIO& io = ImGui::GetIO(); - if (action == GLFW_PRESS) - io.KeysDown[key] = true; - if (action == GLFW_RELEASE) - io.KeysDown[key] = false; - io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; - io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; + ImGuiIO& io = ImGui::GetIO(); + if (action == GLFW_PRESS) + io.KeysDown[key] = true; + if (action == GLFW_RELEASE) + io.KeysDown[key] = false; + io.KeyCtrl = (mods & GLFW_MOD_CONTROL) != 0; + io.KeyShift = (mods & GLFW_MOD_SHIFT) != 0; } static void glfw_char_callback(GLFWwindow* window, unsigned int c) { - if (c > 0 && c <= 255) - ImGui::GetIO().AddInputCharacter((char)c); + if (c > 0 && c <= 255) + ImGui::GetIO().AddInputCharacter((char)c); } // OpenGL code based on http://open.gl tutorials void InitGL() { - glfwSetErrorCallback(glfw_error_callback); + glfwSetErrorCallback(glfw_error_callback); - if (!glfwInit()) - exit(1); + if (!glfwInit()) + exit(1); - glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); - window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); - glfwMakeContextCurrent(window); - glfwSetKeyCallback(window, glfw_key_callback); - glfwSetScrollCallback(window, glfw_scroll_callback); - glfwSetCharCallback(window, glfw_char_callback); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + window = glfwCreateWindow(1280, 720, "ImGui OpenGL example", NULL, NULL); + glfwMakeContextCurrent(window); + glfwSetKeyCallback(window, glfw_key_callback); + glfwSetScrollCallback(window, glfw_scroll_callback); + glfwSetCharCallback(window, glfw_char_callback); - glewInit(); + glewInit(); } void InitImGui() { - int w, h; - glfwGetWindowSize(window, &w, &h); + int w, h; + glfwGetWindowSize(window, &w, &h); - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.5f; // Align OpenGL texels - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. - io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; - io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; - io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; - io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; - io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; - io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; - io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; - io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; - io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; - io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; - io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; - io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; - io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; - io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.5f; // Align OpenGL texels + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; + io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN; + io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME; + io.KeyMap[ImGuiKey_End] = GLFW_KEY_END; + io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE; + io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE; + io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER; + io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE; + io.KeyMap[ImGuiKey_A] = GLFW_KEY_A; + io.KeyMap[ImGuiKey_C] = GLFW_KEY_C; + io.KeyMap[ImGuiKey_V] = GLFW_KEY_V; + io.KeyMap[ImGuiKey_X] = GLFW_KEY_X; + io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y; + io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z; - io.RenderDrawListsFn = ImImpl_RenderDrawLists; - io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; - io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; + io.RenderDrawListsFn = ImImpl_RenderDrawLists; + io.SetClipboardTextFn = ImImpl_SetClipboardTextFn; + io.GetClipboardTextFn = ImImpl_GetClipboardTextFn; - // Load font texture - glGenTextures(1, &fontTex); - glBindTexture(GL_TEXTURE_2D, fontTex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - const void* png_data; - unsigned int png_size; - ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); - int tex_x, tex_y, tex_comp; - void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data); - stbi_image_free(tex_data); + // Load font texture + glGenTextures(1, &fontTex); + glBindTexture(GL_TEXTURE_2D, fontTex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + const void* png_data; + unsigned int png_size; + ImGui::GetDefaultFontData(NULL, NULL, &png_data, &png_size); + int tex_x, tex_y, tex_comp; + void* tex_data = stbi_load_from_memory((const unsigned char*)png_data, (int)png_size, &tex_x, &tex_y, &tex_comp, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_x, tex_y, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data); + stbi_image_free(tex_data); } void UpdateImGui() { - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); - // Setup timestep - static double time = 0.0f; - const double current_time = glfwGetTime(); - io.DeltaTime = (float)(current_time - time); - time = current_time; + // Setup timestep + static double time = 0.0f; + const double current_time = glfwGetTime(); + io.DeltaTime = (float)(current_time - time); + time = current_time; - // Setup inputs - // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) - double mouse_x, mouse_y; - glfwGetCursorPos(window, &mouse_x, &mouse_y); - io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; - io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; + // Setup inputs + // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents()) + double mouse_x, mouse_y; + glfwGetCursorPos(window, &mouse_x, &mouse_y); + io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + io.MouseDown[0] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) != 0; + io.MouseDown[1] = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) != 0; - // Start the frame - ImGui::NewFrame(); + // Start the frame + ImGui::NewFrame(); } // Application code int main(int argc, char** argv) { - InitGL(); - InitImGui(); + InitGL(); + InitImGui(); - while (!glfwWindowShouldClose(window)) - { - ImGuiIO& io = ImGui::GetIO(); - io.MouseWheel = 0; - glfwPollEvents(); - UpdateImGui(); + while (!glfwWindowShouldClose(window)) + { + ImGuiIO& io = ImGui::GetIO(); + io.MouseWheel = 0; + glfwPollEvents(); + UpdateImGui(); - // Create a simple window - // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" - static bool show_test_window = true; - static bool show_another_window = false; - static float f; - ImGui::Text("Hello, world!"); - ImGui::SliderFloat("float", &f, 0.0f, 1.0f); - show_test_window ^= ImGui::Button("Test Window"); - show_another_window ^= ImGui::Button("Another Window"); + // Create a simple window + // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug" + static bool show_test_window = true; + static bool show_another_window = false; + static float f; + ImGui::Text("Hello, world!"); + ImGui::SliderFloat("float", &f, 0.0f, 1.0f); + show_test_window ^= ImGui::Button("Test Window"); + show_another_window ^= ImGui::Button("Another Window"); - // Calculate and show framerate - static float ms_per_frame[120] = { 0 }; - static int ms_per_frame_idx = 0; - static float ms_per_frame_accum = 0.0f; - ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; - ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; - ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; - ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; - const float ms_per_frame_avg = ms_per_frame_accum / 120; - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); + // Calculate and show framerate + static float ms_per_frame[120] = { 0 }; + static int ms_per_frame_idx = 0; + static float ms_per_frame_accum = 0.0f; + ms_per_frame_accum -= ms_per_frame[ms_per_frame_idx]; + ms_per_frame[ms_per_frame_idx] = ImGui::GetIO().DeltaTime * 1000.0f; + ms_per_frame_accum += ms_per_frame[ms_per_frame_idx]; + ms_per_frame_idx = (ms_per_frame_idx + 1) % 120; + const float ms_per_frame_avg = ms_per_frame_accum / 120; + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", ms_per_frame_avg, 1000.0f / ms_per_frame_avg); - // Show the ImGui test window - // Most of user example code is in ImGui::ShowTestWindow() - if (show_test_window) - { - ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! - ImGui::ShowTestWindow(&show_test_window); - } + // Show the ImGui test window + // Most of user example code is in ImGui::ShowTestWindow() + if (show_test_window) + { + ImGui::SetNewWindowDefaultPos(ImVec2(650, 20)); // Normally user code doesn't need/want to call it because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly! + ImGui::ShowTestWindow(&show_test_window); + } - // Show another simple window - if (show_another_window) - { - ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); - ImGui::Text("Hello"); - ImGui::End(); - } + // Show another simple window + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window, ImVec2(200,100)); + ImGui::Text("Hello"); + ImGui::End(); + } - // Rendering - glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); - glClearColor(0.8f, 0.6f, 0.6f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - ImGui::Render(); - glfwSwapBuffers(window); - } + // Rendering + glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); + glClearColor(0.8f, 0.6f, 0.6f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + ImGui::Render(); + glfwSwapBuffers(window); + } - ImGui::Shutdown(); - glfwTerminate(); - return 0; + ImGui::Shutdown(); + glfwTerminate(); + return 0; } diff --git a/imconfig.h b/imconfig.h index 98b16f1b..aeb8d542 100644 --- a/imconfig.h +++ b/imconfig.h @@ -6,28 +6,28 @@ //---- Define your own ImVector<> type if you don't want to use the provided implementation defined in imgui.h //#include -//#define ImVector std::vector -//#define ImVector MyVector +//#define ImVector std::vector +//#define ImVector MyVector //---- Define assertion handler. Defaults to calling assert(). -//#define IM_ASSERT(_EXPR) MyAssert(_EXPR) +//#define IM_ASSERT(_EXPR) MyAssert(_EXPR) //---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard(), etc.) //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS //---- If you are loading a custom font, ImGui expect to find a pure white pixel at (0,0) // Change it's UV coordinate here if you can't have a white pixel at (0,0) -//#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f/256.f,0.f/256.f) +//#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f/256.f,0.f/256.f) //---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. /* -#define IM_VEC2_CLASS_EXTRA \ - ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ - operator MyVec2() const { return MyVec2(x,y); } +#define IM_VEC2_CLASS_EXTRA \ + ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ + operator MyVec2() const { return MyVec2(x,y); } -#define IM_VEC4_CLASS_EXTRA \ - ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ - operator MyVec4() const { return MyVec4(x,y,z,w); } +#define IM_VEC4_CLASS_EXTRA \ + ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ + operator MyVec4() const { return MyVec4(x,y,z,w); } */ //---- Freely implement extra functions within the ImGui:: namespace. @@ -35,7 +35,7 @@ /* namespace ImGui { - void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL); - void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL); + void Value(const char* prefix, const MyVec2& v, const char* float_format = NULL); + void Value(const char* prefix, const MyVec4& v, const char* float_format = NULL); }; */ diff --git a/imgui.cpp b/imgui.cpp index 9c63d3d8..e8154e88 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -58,34 +58,34 @@ - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations. - a typical application skeleton may be: - // Application init - // TODO: Fill all 'Settings' fields of the io structure - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize.x = 1920.0f; - io.DisplaySize.y = 1280.0f; - io.DeltaTime = 1.0f/60.0f; - io.IniFilename = "imgui.ini"; + // Application init + // TODO: Fill all 'Settings' fields of the io structure + ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize.x = 1920.0f; + io.DisplaySize.y = 1280.0f; + io.DeltaTime = 1.0f/60.0f; + io.IniFilename = "imgui.ini"; - // Application mainloop - while (true) - { - // 1/ get low-level input - // e.g. on Win32, GetKeyboardState(), or poll your events, etc. - - // 2/ TODO: Fill all 'Input' fields of io structure and call NewFrame - ImGuiIO& io = ImGui::GetIO(); - io.MousePos = ... - io.KeysDown[i] = ... - ImGui::NewFrame(); + // Application mainloop + while (true) + { + // 1/ get low-level input + // e.g. on Win32, GetKeyboardState(), or poll your events, etc. + + // 2/ TODO: Fill all 'Input' fields of io structure and call NewFrame + ImGuiIO& io = ImGui::GetIO(); + io.MousePos = ... + io.KeysDown[i] = ... + ImGui::NewFrame(); - // 3/ most of your application code here - you can use any of ImGui::* functions between NewFrame() and Render() calls - GameUpdate(); - GameRender(); + // 3/ most of your application code here - you can use any of ImGui::* functions between NewFrame() and Render() calls + GameUpdate(); + GameRender(); - // 4/ render & swap video buffers - ImGui::Render(); - // swap video buffer, etc. - } + // 4/ render & swap video buffers + ImGui::Render(); + // swap video buffer, etc. + } - some widgets carry state and requires an unique ID to do so. - unique ID are typically derived from a string label, an indice or a pointer. @@ -159,11 +159,11 @@ */ #include "imgui.h" -#include // toupper -#include // sqrt -#include // intptr_t -#include // vsnprintf -#include // memset +#include // toupper +#include // sqrt +#include // intptr_t +#include // vsnprintf +#include // memset #ifdef _MSC_VER #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen @@ -176,23 +176,23 @@ namespace ImGui { -static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false); -static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); -static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); -static ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); -static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); +static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false); +static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); +static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); +static ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); +static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); -static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); -static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); -static void PushColumnClipRect(int column_index = -1); -static bool IsClipped(const ImGuiAabb& aabb); -static bool ClipAdvance(const ImGuiAabb& aabb); +static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); +static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); +static void PushColumnClipRect(int column_index = -1); +static bool IsClipped(const ImGuiAabb& aabb); +static bool ClipAdvance(const ImGuiAabb& aabb); -static bool IsMouseHoveringBox(const ImGuiAabb& box); -static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); +static bool IsMouseHoveringBox(const ImGuiAabb& box); +static bool IsKeyPressedMap(ImGuiKey key, bool repeat = true); -static bool CloseWindowButton(bool* open = NULL); -static void FocusWindow(ImGuiWindow* window); +static bool CloseWindowButton(bool* open = NULL); +static void FocusWindow(ImGuiWindow* window); static ImGuiWindow* FindWindow(const char* name); static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); @@ -202,8 +202,8 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs); // Platform dependant default implementations //----------------------------------------------------------------------------- -static const char* GetClipboardTextFn_DefaultImpl(); -static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_end); +static const char* GetClipboardTextFn_DefaultImpl(); +static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_end); //----------------------------------------------------------------------------- // User facing structures @@ -211,77 +211,77 @@ static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_ ImGuiStyle::ImGuiStyle() { - Alpha = 1.0f; // Global alpha applies to everything in ImGui - WindowPadding = ImVec2(8,8); // Padding within a window - WindowMinSize = ImVec2(48,48); // Minimum window size - FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets) - ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines - ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) - TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! - AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) - WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() - WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows - TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node - ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns - ScrollBarWidth = 16.0f; // Width of the vertical scroll bar + Alpha = 1.0f; // Global alpha applies to everything in ImGui + WindowPadding = ImVec2(8,8); // Padding within a window + WindowMinSize = ImVec2(48,48); // Minimum window size + FramePadding = ImVec2(5,4); // Padding within a framed rectangle (used by most widgets) + ItemSpacing = ImVec2(10,5); // Horizontal and vertical spacing between widgets/lines + ItemInnerSpacing = ImVec2(5,5); // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + TouchExtraPadding = ImVec2(0,0); // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! + AutoFitPadding = ImVec2(8,8); // Extra space after auto-fit (double-clicking on resize grip) + WindowFillAlphaDefault = 0.70f; // Default alpha of window background, if not specified in ImGui::Begin() + WindowRounding = 10.0f; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + TreeNodeSpacing = 22.0f; // Horizontal spacing when entering a tree node + ColumnsMinSpacing = 6.0f; // Minimum horizontal spacing between two columns + ScrollBarWidth = 16.0f; // Width of the vertical scroll bar - Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); - Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f); - Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input - Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f); - Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f); - Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f); - Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f); - Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); - Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); - Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); - Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); - Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); - Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); - Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); - Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f); - Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f); - Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); - Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f); - Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f); - Colors[ImGuiCol_HeaderActive] = ImVec4(0.60f, 0.60f, 0.80f, 1.00f); - Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f); - Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); - Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); - Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); - Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f); - Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f); - Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f); - Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); - Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); - Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); - Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); - Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); - Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); - Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f); + Colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); + Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + Colors[ImGuiCol_Border] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.60f); + Colors[ImGuiCol_FrameBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.30f); // Background of checkbox, radio button, plot, slider, text input + Colors[ImGuiCol_TitleBg] = ImVec4(0.50f, 0.50f, 1.00f, 0.45f); + Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f); + Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.40f, 0.40f, 0.80f, 0.15f); + Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f); + Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); + Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 0.40f); + Colors[ImGuiCol_ComboBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.99f); + Colors[ImGuiCol_CheckHovered] = ImVec4(0.60f, 0.40f, 0.40f, 0.45f); + Colors[ImGuiCol_CheckActive] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); + Colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); + Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); + Colors[ImGuiCol_Button] = ImVec4(0.67f, 0.40f, 0.40f, 0.60f); + Colors[ImGuiCol_ButtonHovered] = ImVec4(0.67f, 0.40f, 0.40f, 1.00f); + Colors[ImGuiCol_ButtonActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); + Colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f); + Colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f); + Colors[ImGuiCol_HeaderActive] = ImVec4(0.60f, 0.60f, 0.80f, 1.00f); + Colors[ImGuiCol_Column] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + Colors[ImGuiCol_ColumnHovered] = ImVec4(0.60f, 0.40f, 0.40f, 1.00f); + Colors[ImGuiCol_ColumnActive] = ImVec4(0.80f, 0.50f, 0.50f, 1.00f); + Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); + Colors[ImGuiCol_ResizeGripHovered] = ImVec4(1.00f, 1.00f, 1.00f, 0.60f); + Colors[ImGuiCol_ResizeGripActive] = ImVec4(1.00f, 1.00f, 1.00f, 0.90f); + Colors[ImGuiCol_CloseButton] = ImVec4(0.50f, 0.50f, 0.90f, 0.50f); + Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.70f, 0.70f, 0.90f, 0.60f); + Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.70f, 0.70f, 0.70f, 1.00f); + Colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + Colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); + Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); + Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); + Colors[ImGuiCol_TooltipBg] = ImVec4(0.05f, 0.05f, 0.10f, 0.90f); } ImGuiIO::ImGuiIO() { - memset(this, 0, sizeof(*this)); - DeltaTime = 1.0f/60.0f; - IniSavingRate = 5.0f; - IniFilename = "imgui.ini"; - LogFilename = "imgui_log.txt"; - Font = NULL; - FontAllowScaling = false; - PixelCenterOffset = 0.5f; - MousePos = ImVec2(-1,-1); - MousePosPrev = ImVec2(-1,-1); - MouseDoubleClickTime = 0.30f; - MouseDoubleClickMaxDist = 6.0f; + memset(this, 0, sizeof(*this)); + DeltaTime = 1.0f/60.0f; + IniSavingRate = 5.0f; + IniFilename = "imgui.ini"; + LogFilename = "imgui_log.txt"; + Font = NULL; + FontAllowScaling = false; + PixelCenterOffset = 0.5f; + MousePos = ImVec2(-1,-1); + MousePosPrev = ImVec2(-1,-1); + MouseDoubleClickTime = 0.30f; + MouseDoubleClickMaxDist = 6.0f; - // Platform dependant default implementations - GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; - SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; + // Platform dependant default implementations + GetClipboardTextFn = GetClipboardTextFn_DefaultImpl; + SetClipboardTextFn = SetClipboardTextFn_DefaultImpl; } // Pass in translated ASCII characters for text input. @@ -289,19 +289,19 @@ ImGuiIO::ImGuiIO() // - on Windows you can get those using ToAscii+keyboard state, or via the VM_CHAR message void ImGuiIO::AddInputCharacter(char c) { - const size_t n = strlen(InputCharacters); - if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0])) - { - InputCharacters[n] = c; - InputCharacters[n+1] = 0; - } + const size_t n = strlen(InputCharacters); + if (n < sizeof(InputCharacters) / sizeof(InputCharacters[0])) + { + InputCharacters[n] = c; + InputCharacters[n+1] = 0; + } } //----------------------------------------------------------------------------- // Helpers //----------------------------------------------------------------------------- -#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) +#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) #undef PI const float PI = 3.14159265358979323846f; @@ -314,703 +314,703 @@ const float PI = 3.14159265358979323846f; // Math bits // We are keeping those static in the .cpp file so as not to leak them outside, in the case the user has implicit cast operators between ImVec2 and its own types. -static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } -static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); } -static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); } -static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); } -static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } -static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } -static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } -static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } -static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } -static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } +static inline ImVec2 operator*(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x*rhs, lhs.y*rhs); } +static inline ImVec2 operator/(const ImVec2& lhs, const float rhs) { return ImVec2(lhs.x/rhs, lhs.y/rhs); } +static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); } +static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); } +static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x*rhs.x, lhs.y*rhs.y); } +static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2 rhs) { return ImVec2(lhs.x/rhs.x, lhs.y/rhs.y); } +static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } +static inline ImVec2& operator-=(ImVec2& lhs, const ImVec2& rhs) { lhs.x -= rhs.x; lhs.y -= rhs.y; return lhs; } +static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } +static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } -static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; } -static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; } -static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; } -static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; } -static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); } -static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); } -static inline float ImClamp(float f, float mn, float mx) { return (f < mn) ? mn : (f > mx) ? mx : f; } -static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); } -static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } -static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } -static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return a + (b - a) * t; } -static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } -static inline float ImLength(const ImVec2& lhs) { return sqrt(lhs.x*lhs.x + lhs.y*lhs.y); } +static inline int ImMin(int lhs, int rhs) { return lhs < rhs ? lhs : rhs; } +static inline int ImMax(int lhs, int rhs) { return lhs >= rhs ? lhs : rhs; } +static inline float ImMin(float lhs, float rhs) { return lhs < rhs ? lhs : rhs; } +static inline float ImMax(float lhs, float rhs) { return lhs >= rhs ? lhs : rhs; } +static inline ImVec2 ImMin(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMin(lhs.x,rhs.x), ImMin(lhs.y,rhs.y)); } +static inline ImVec2 ImMax(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(ImMax(lhs.x,rhs.x), ImMax(lhs.y,rhs.y)); } +static inline float ImClamp(float f, float mn, float mx) { return (f < mn) ? mn : (f > mx) ? mx : f; } +static inline ImVec2 ImClamp(const ImVec2& f, const ImVec2& mn, ImVec2 mx) { return ImVec2(ImClamp(f.x,mn.x,mx.x), ImClamp(f.y,mn.y,mx.y)); } +static inline float ImSaturate(float f) { return (f < 0.0f) ? 0.0f : (f > 1.0f) ? 1.0f : f; } +static inline float ImLerp(float a, float b, float t) { return a + (b - a) * t; } +static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, float t) { return a + (b - a) * t; } +static inline ImVec2 ImLerp(const ImVec2& a, const ImVec2& b, const ImVec2& t) { return ImVec2(a.x + (b.x - a.x) * t.x, a.y + (b.y - a.y) * t.y); } +static inline float ImLength(const ImVec2& lhs) { return sqrt(lhs.x*lhs.x + lhs.y*lhs.y); } static int ImStricmp(const char* str1, const char* str2) { - int d; - while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } - return d; + int d; + while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } + return d; } static const char* ImStristr(const char* haystack, const char* needle, const char* needle_end) { - if (!needle_end) - needle_end = needle + strlen(needle); + if (!needle_end) + needle_end = needle + strlen(needle); - const char un0 = (char)toupper(*needle); - while (*haystack) - { - if (toupper(*haystack) == un0) - { - const char* b = needle + 1; - for (const char* a = haystack + 1; b < needle_end; a++, b++) - if (toupper(*a) != toupper(*b)) - break; - if (b == needle_end) - return haystack; - } - haystack++; - } - return NULL; + const char un0 = (char)toupper(*needle); + while (*haystack) + { + if (toupper(*haystack) == un0) + { + const char* b = needle + 1; + for (const char* a = haystack + 1; b < needle_end; a++, b++) + if (toupper(*a) != toupper(*b)) + break; + if (b == needle_end) + return haystack; + } + haystack++; + } + return NULL; } static ImU32 crc32(const void* data, size_t data_size, ImU32 seed = 0) { - static ImU32 crc32_lut[256] = { 0 }; - if (!crc32_lut[1]) - { - const ImU32 polynomial = 0xEDB88320; - for (ImU32 i = 0; i < 256; i++) - { - ImU32 crc = i; - for (ImU32 j = 0; j < 8; j++) - crc = (crc >> 1) ^ (-int(crc & 1) & polynomial); - crc32_lut[i] = crc; - } - } - ImU32 crc = ~seed; - const unsigned char* current = (const unsigned char*)data; - while (data_size--) - crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; - return ~crc; + static ImU32 crc32_lut[256] = { 0 }; + if (!crc32_lut[1]) + { + const ImU32 polynomial = 0xEDB88320; + for (ImU32 i = 0; i < 256; i++) + { + ImU32 crc = i; + for (ImU32 j = 0; j < 8; j++) + crc = (crc >> 1) ^ (-int(crc & 1) & polynomial); + crc32_lut[i] = crc; + } + } + ImU32 crc = ~seed; + const unsigned char* current = (const unsigned char*)data; + while (data_size--) + crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *current++]; + return ~crc; } static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) { - va_list args; - va_start(args, fmt); - int w = vsnprintf(buf, buf_size, fmt, args); - va_end(args); - buf[buf_size-1] = 0; - if (w == -1) w = (int)buf_size; - return w; + va_list args; + va_start(args, fmt); + int w = vsnprintf(buf, buf_size, fmt, args); + va_end(args); + buf[buf_size-1] = 0; + if (w == -1) w = (int)buf_size; + return w; } static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) { - int w = vsnprintf(buf, buf_size, fmt, args); - buf[buf_size-1] = 0; - if (w == -1) w = (int)buf_size; - return w; + int w = vsnprintf(buf, buf_size, fmt, args); + buf[buf_size-1] = 0; + if (w == -1) w = (int)buf_size; + return w; } static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in) { - ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f)); - out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8); - out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16); - out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24); - return out; + ImU32 out = ((ImU32)(ImSaturate(in.x)*255.f)); + out |= ((ImU32)(ImSaturate(in.y)*255.f) << 8); + out |= ((ImU32)(ImSaturate(in.z)*255.f) << 16); + out |= ((ImU32)(ImSaturate(in.w)*255.f) << 24); + return out; } // Convert rgb floats ([0-1],[0-1],[0-1]) to hsv floats ([0-1],[0-1],[0-1]), from Foley & van Dam p592 // Optimized http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv static void ImConvertColorRGBtoHSV(float r, float g, float b, float& out_h, float& out_s, float& out_v) { - float K = 0.f; - if (g < b) - { - const float tmp = g; g = b; b = tmp; - K = -1.f; - } - if (r < g) - { - const float tmp = r; r = g; g = tmp; - K = -2.f / 6.f - K; - } + float K = 0.f; + if (g < b) + { + const float tmp = g; g = b; b = tmp; + K = -1.f; + } + if (r < g) + { + const float tmp = r; r = g; g = tmp; + K = -2.f / 6.f - K; + } - const float chroma = r - (g < b ? g : b); - out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f)); - out_s = chroma / (r + 1e-20f); - out_v = r; + const float chroma = r - (g < b ? g : b); + out_h = fabsf(K + (g - b) / (6.f * chroma + 1e-20f)); + out_s = chroma / (r + 1e-20f); + out_v = r; } // Convert hsv floats ([0-1],[0-1],[0-1]) to rgb floats ([0-1],[0-1],[0-1]), from Foley & van Dam p593 // also http://en.wikipedia.org/wiki/HSL_and_HSV static void ImConvertColorHSVtoRGB(float h, float s, float v, float& out_r, float& out_g, float& out_b) { - if (s == 0.0f) - { - // gray - out_r = out_g = out_b = v; - return; - } + if (s == 0.0f) + { + // gray + out_r = out_g = out_b = v; + return; + } - h = fmodf(h, 1.0f) / (60.0f/360.0f); - int i = (int)h; - float f = h - (float)i; - float p = v * (1.0f - s); - float q = v * (1.0f - s * f); - float t = v * (1.0f - s * (1.0f - f)); + h = fmodf(h, 1.0f) / (60.0f/360.0f); + int i = (int)h; + float f = h - (float)i; + float p = v * (1.0f - s); + float q = v * (1.0f - s * f); + float t = v * (1.0f - s * (1.0f - f)); - switch (i) - { - case 0: out_r = v; out_g = t; out_b = p; break; - case 1: out_r = q; out_g = v; out_b = p; break; - case 2: out_r = p; out_g = v; out_b = t; break; - case 3: out_r = p; out_g = q; out_b = v; break; - case 4: out_r = t; out_g = p; out_b = v; break; - case 5: default: out_r = v; out_g = p; out_b = q; break; - } + switch (i) + { + case 0: out_r = v; out_g = t; out_b = p; break; + case 1: out_r = q; out_g = v; out_b = p; break; + case 2: out_r = p; out_g = v; out_b = t; break; + case 3: out_r = p; out_g = q; out_b = v; break; + case 4: out_r = t; out_g = p; out_b = v; break; + case 5: default: out_r = v; out_g = p; out_b = q; break; + } } //----------------------------------------------------------------------------- -struct ImGuiColMod // Color/style modifier, backup of modified data so we can restore it +struct ImGuiColMod // Color/style modifier, backup of modified data so we can restore it { - ImGuiCol Col; - ImVec4 PreviousValue; + ImGuiCol Col; + ImVec4 PreviousValue; }; -struct ImGuiAabb // 2D axis aligned bounding-box +struct ImGuiAabb // 2D axis aligned bounding-box { - ImVec2 Min; - ImVec2 Max; + ImVec2 Min; + ImVec2 Max; - ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); } - ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; } - ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; } - ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; } + ImGuiAabb() { Min = ImVec2(FLT_MAX,FLT_MAX); Max = ImVec2(-FLT_MAX,-FLT_MAX); } + ImGuiAabb(const ImVec2& min, const ImVec2& max) { Min = min; Max = max; } + ImGuiAabb(const ImVec4& v) { Min.x = v.x; Min.y = v.y; Max.x = v.z; Max.y = v.w; } + ImGuiAabb(float x1, float y1, float x2, float y2) { Min.x = x1; Min.y = y1; Max.x = x2; Max.y = y2; } - ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; } - ImVec2 GetSize() const { return Max-Min; } - float GetWidth() const { return (Max-Min).x; } - float GetHeight() const { return (Max-Min).y; } - ImVec2 GetTL() const { return Min; } - ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); } - ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); } - ImVec2 GetBR() const { return Max; } - bool Contains(ImVec2 p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; } - bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; } - bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; } - void Expand(ImVec2 sz) { Min -= sz; Max += sz; } - void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); } + ImVec2 GetCenter() const { return Min + (Max-Min)*0.5f; } + ImVec2 GetSize() const { return Max-Min; } + float GetWidth() const { return (Max-Min).x; } + float GetHeight() const { return (Max-Min).y; } + ImVec2 GetTL() const { return Min; } + ImVec2 GetTR() const { return ImVec2(Max.x,Min.y); } + ImVec2 GetBL() const { return ImVec2(Min.x,Max.y); } + ImVec2 GetBR() const { return Max; } + bool Contains(ImVec2 p) const { return p.x >= Min.x && p.y >= Min.y && p.x <= Max.x && p.y <= Max.y; } + bool Contains(const ImGuiAabb& r) const { return r.Min.x >= Min.x && r.Min.y >= Min.y && r.Max.x <= Max.x && r.Max.y <= Max.y; } + bool Overlaps(const ImGuiAabb& r) const { return r.Min.y <= Max.y && r.Max.y >= Min.y && r.Min.x <= Max.x && r.Max.x >= Min.x; } + void Expand(ImVec2 sz) { Min -= sz; Max += sz; } + void Clip(const ImGuiAabb& clip) { Min.x = ImMax(Min.x, clip.Min.x); Min.y = ImMax(Min.y, clip.Min.y); Max.x = ImMin(Max.x, clip.Max.x); Max.y = ImMin(Max.y, clip.Max.y); } }; // Temporary per-window data, reset at the beginning of the frame struct ImGuiDrawContext { - ImVec2 CursorPos; - ImVec2 CursorPosPrevLine; - ImVec2 CursorStartPos; - float CurrentLineHeight; - float PrevLineHeight; - float LogLineHeight; - int TreeDepth; - ImGuiAabb LastItemAabb; - bool LastItemHovered; - ImVector ChildWindows; - ImVector AllowKeyboardFocus; - ImVector ItemWidth; - ImVector ColorModifiers; - ImGuiColorEditMode ColorEditMode; - ImGuiStorage* StateStorage; - int OpenNextNode; + ImVec2 CursorPos; + ImVec2 CursorPosPrevLine; + ImVec2 CursorStartPos; + float CurrentLineHeight; + float PrevLineHeight; + float LogLineHeight; + int TreeDepth; + ImGuiAabb LastItemAabb; + bool LastItemHovered; + ImVector ChildWindows; + ImVector AllowKeyboardFocus; + ImVector ItemWidth; + ImVector ColorModifiers; + ImGuiColorEditMode ColorEditMode; + ImGuiStorage* StateStorage; + int OpenNextNode; - float ColumnStartX; - int ColumnCurrent; - int ColumnsCount; - bool ColumnsShowBorders; - ImVec2 ColumnsStartCursorPos; - ImGuiID ColumnsSetID; + float ColumnStartX; + int ColumnCurrent; + int ColumnsCount; + bool ColumnsShowBorders; + ImVec2 ColumnsStartCursorPos; + ImGuiID ColumnsSetID; - ImGuiDrawContext() - { - CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f); - CurrentLineHeight = PrevLineHeight = 0.0f; - LogLineHeight = -1.0f; - TreeDepth = 0; - LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f); - LastItemHovered = false; - StateStorage = NULL; - OpenNextNode = -1; + ImGuiDrawContext() + { + CursorPos = CursorPosPrevLine = CursorStartPos = ImVec2(0.0f, 0.0f); + CurrentLineHeight = PrevLineHeight = 0.0f; + LogLineHeight = -1.0f; + TreeDepth = 0; + LastItemAabb = ImGuiAabb(0.0f,0.0f,0.0f,0.0f); + LastItemHovered = false; + StateStorage = NULL; + OpenNextNode = -1; - ColumnStartX = 0.0f; - ColumnCurrent = 0; - ColumnsCount = 1; - ColumnsShowBorders = true; - ColumnsStartCursorPos = ImVec2(0,0); - } + ColumnStartX = 0.0f; + ColumnCurrent = 0; + ColumnsCount = 1; + ColumnsShowBorders = true; + ColumnsStartCursorPos = ImVec2(0,0); + } }; struct ImGuiTextEditState; -#define STB_TEXTEDIT_STRING ImGuiTextEditState +#define STB_TEXTEDIT_STRING ImGuiTextEditState #define STB_TEXTEDIT_CHARTYPE char #include "stb_textedit.h" // State of the currently focused/edited text input box struct ImGuiTextEditState { - char Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so own buffer. - char InitialText[1024]; // backup of end-user buffer at focusing time, to ESC key can do a revert. Also used for arithmetic operations (but could use a pre-parsed float there). - size_t BufSize; // end-user buffer size, <= 1024 (or increase above) - float Width; // widget width - float ScrollX; - STB_TexteditState StbState; - float CursorAnim; - bool SelectedAllMouseLock; - ImFont Font; - float FontSize; + char Text[1024]; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so own buffer. + char InitialText[1024]; // backup of end-user buffer at focusing time, to ESC key can do a revert. Also used for arithmetic operations (but could use a pre-parsed float there). + size_t BufSize; // end-user buffer size, <= 1024 (or increase above) + float Width; // widget width + float ScrollX; + STB_TexteditState StbState; + float CursorAnim; + bool SelectedAllMouseLock; + ImFont Font; + float FontSize; - ImGuiTextEditState() { memset(this, 0, sizeof(*this)); } + ImGuiTextEditState() { memset(this, 0, sizeof(*this)); } - void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking - bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking - bool HasSelection() const { return StbState.select_start != StbState.select_end; } - void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)strlen(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; } + void CursorAnimReset() { CursorAnim = -0.30f; } // After a user-input the cursor stays on for a while without blinking + bool CursorIsVisible() const { return CursorAnim <= 0.0f || fmodf(CursorAnim, 1.20f) <= 0.80f; } // Blinking + bool HasSelection() const { return StbState.select_start != StbState.select_end; } + void SelectAll() { StbState.select_start = 0; StbState.select_end = (int)strlen(Text); StbState.cursor = StbState.select_end; StbState.has_preferred_x = false; } - void OnKeyboardPressed(int key); - void UpdateScrollOffset(); - ImVec2 CalcDisplayOffsetFromCharIdx(int i) const; + void OnKeyboardPressed(int key); + void UpdateScrollOffset(); + ImVec2 CalcDisplayOffsetFromCharIdx(int i) const; - // Static functions because they are used to render non-focused instances of a text input box - static const char* GetTextPointerClipped(ImFont font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL); - static void RenderTextScrolledClipped(ImFont font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x); + // Static functions because they are used to render non-focused instances of a text input box + static const char* GetTextPointerClipped(ImFont font, float font_size, const char* text, float width, ImVec2* out_text_size = NULL); + static void RenderTextScrolledClipped(ImFont font, float font_size, const char* text, ImVec2 pos_base, float width, float scroll_x); }; struct ImGuiIniData { - char* Name; - ImVec2 Pos; - ImVec2 Size; - bool Collapsed; + char* Name; + ImVec2 Pos; + ImVec2 Size; + bool Collapsed; - ImGuiIniData() { memset(this, 0, sizeof(*this)); } - ~ImGuiIniData() { if (Name) { free(Name); Name = NULL; } } + ImGuiIniData() { memset(this, 0, sizeof(*this)); } + ~ImGuiIniData() { if (Name) { free(Name); Name = NULL; } } }; struct ImGuiState { - bool Initialized; - ImGuiIO IO; - ImGuiStyle Style; - float Time; - int FrameCount; - int FrameCountRendered; - ImVector Windows; - ImGuiWindow* CurrentWindow; // Being drawn into - ImVector CurrentWindowStack; - ImGuiWindow* FocusedWindow; // Will catch keyboard inputs - ImGuiWindow* HoveredWindow; // Will catch mouse inputs - ImGuiWindow* HoveredWindowExcludingChilds; // Will catch mouse inputs (for focus/move only) - ImGuiID HoveredId; - ImGuiID ActiveId; - ImGuiID ActiveIdPreviousFrame; - bool ActiveIdIsAlive; - float SettingsDirtyTimer; - ImVector Settings; - ImVec2 NewWindowDefaultPos; + bool Initialized; + ImGuiIO IO; + ImGuiStyle Style; + float Time; + int FrameCount; + int FrameCountRendered; + ImVector Windows; + ImGuiWindow* CurrentWindow; // Being drawn into + ImVector CurrentWindowStack; + ImGuiWindow* FocusedWindow; // Will catch keyboard inputs + ImGuiWindow* HoveredWindow; // Will catch mouse inputs + ImGuiWindow* HoveredWindowExcludingChilds; // Will catch mouse inputs (for focus/move only) + ImGuiID HoveredId; + ImGuiID ActiveId; + ImGuiID ActiveIdPreviousFrame; + bool ActiveIdIsAlive; + float SettingsDirtyTimer; + ImVector Settings; + ImVec2 NewWindowDefaultPos; - // Render - ImVector RenderDrawLists; + // Render + ImVector RenderDrawLists; - // Widget state - ImGuiTextEditState InputTextState; - ImGuiID SliderAsInputTextId; - ImGuiStorage ColorEditModeStorage; // for user selection - ImGuiID ActiveComboID; - char Tooltip[1024]; - char* PrivateClipboard; // if no custom clipboard handler is defined + // Widget state + ImGuiTextEditState InputTextState; + ImGuiID SliderAsInputTextId; + ImGuiStorage ColorEditModeStorage; // for user selection + ImGuiID ActiveComboID; + char Tooltip[1024]; + char* PrivateClipboard; // if no custom clipboard handler is defined - // Logging - bool LogEnabled; - FILE* LogFile; - ImGuiTextBuffer LogClipboard; - int LogAutoExpandMaxDepth; + // Logging + bool LogEnabled; + FILE* LogFile; + ImGuiTextBuffer LogClipboard; + int LogAutoExpandMaxDepth; - ImGuiState() - { - Initialized = false; - Time = 0.0f; - FrameCount = 0; - FrameCountRendered = -1; - CurrentWindow = NULL; - FocusedWindow = NULL; - HoveredWindow = NULL; - HoveredWindowExcludingChilds = NULL; - ActiveIdIsAlive = false; - SettingsDirtyTimer = 0.0f; - NewWindowDefaultPos = ImVec2(60, 60); - SliderAsInputTextId = 0; - ActiveComboID = 0; - memset(Tooltip, 0, sizeof(Tooltip)); - PrivateClipboard = NULL; - LogEnabled = false; - LogFile = NULL; - LogAutoExpandMaxDepth = 2; - } + ImGuiState() + { + Initialized = false; + Time = 0.0f; + FrameCount = 0; + FrameCountRendered = -1; + CurrentWindow = NULL; + FocusedWindow = NULL; + HoveredWindow = NULL; + HoveredWindowExcludingChilds = NULL; + ActiveIdIsAlive = false; + SettingsDirtyTimer = 0.0f; + NewWindowDefaultPos = ImVec2(60, 60); + SliderAsInputTextId = 0; + ActiveComboID = 0; + memset(Tooltip, 0, sizeof(Tooltip)); + PrivateClipboard = NULL; + LogEnabled = false; + LogFile = NULL; + LogAutoExpandMaxDepth = 2; + } }; -static ImGuiState GImGui; +static ImGuiState GImGui; struct ImGuiWindow { - char* Name; - ImGuiID ID; - ImGuiWindowFlags Flags; - ImVec2 PosFloat; - ImVec2 Pos; // Position rounded-up to nearest pixel - ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) - ImVec2 SizeFull; // Size when non collapsed - ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size. - float ScrollY; - float NextScrollY; - bool ScrollbarY; - bool Visible; // Set to true on Begin() - bool Accessed; // Set to true when any widget access the current window - bool Collapsed; // Set when collapsing window to become only title-bar - bool SkipItems; // == Visible && !Collapsed - int AutoFitFrames; + char* Name; + ImGuiID ID; + ImGuiWindowFlags Flags; + ImVec2 PosFloat; + ImVec2 Pos; // Position rounded-up to nearest pixel + ImVec2 Size; // Current size (==SizeFull or collapsed title bar size) + ImVec2 SizeFull; // Size when non collapsed + ImVec2 SizeContentsFit; // Size of contents (extents reach by the drawing cursor) - may not fit within Size. + float ScrollY; + float NextScrollY; + bool ScrollbarY; + bool Visible; // Set to true on Begin() + bool Accessed; // Set to true when any widget access the current window + bool Collapsed; // Set when collapsing window to become only title-bar + bool SkipItems; // == Visible && !Collapsed + int AutoFitFrames; - ImGuiDrawContext DC; - ImVector IDStack; - ImVector ClipRectStack; - int LastFrameDrawn; - float ItemWidthDefault; - ImGuiStorage StateStorage; - float FontScale; + ImGuiDrawContext DC; + ImVector IDStack; + ImVector ClipRectStack; + int LastFrameDrawn; + float ItemWidthDefault; + ImGuiStorage StateStorage; + float FontScale; - int FocusIdxCounter; // Start at -1 and increase as assigned via FocusItemRegister() - int FocusIdxRequestCurrent; // Item being requested for focus, rely on layout to be stable between the frame pressing TAB and the next frame - int FocusIdxRequestNext; // Item being requested for focus, for next update + int FocusIdxCounter; // Start at -1 and increase as assigned via FocusItemRegister() + int FocusIdxRequestCurrent; // Item being requested for focus, rely on layout to be stable between the frame pressing TAB and the next frame + int FocusIdxRequestNext; // Item being requested for focus, for next update - ImDrawList* DrawList; + ImDrawList* DrawList; public: - ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size); - ~ImGuiWindow(); + ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size); + ~ImGuiWindow(); - ImGuiID GetID(const char* str); - ImGuiID GetID(const void* ptr); + ImGuiID GetID(const char* str); + ImGuiID GetID(const void* ptr); - void AddToRenderList(); - bool FocusItemRegister(bool is_active, int* out_idx = NULL); // Return TRUE if focus is requested - void FocusItemUnregister(); + void AddToRenderList(); + bool FocusItemRegister(bool is_active, int* out_idx = NULL); // Return TRUE if focus is requested + void FocusItemUnregister(); - ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); } - ImFont Font() const { return GImGui.IO.Font; } - float FontSize() const { return GImGui.IO.FontHeight * FontScale; } - ImVec2 CursorPos() const { return DC.CursorPos; } - float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; } - ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } - ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; } - ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImConvertColorFloat4ToU32(c); } - ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImConvertColorFloat4ToU32(c); } + ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); } + ImFont Font() const { return GImGui.IO.Font; } + float FontSize() const { return GImGui.IO.FontHeight * FontScale; } + ImVec2 CursorPos() const { return DC.CursorPos; } + float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; } + ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } + ImVec2 WindowPadding() const { return ((Flags & ImGuiWindowFlags_ChildWindow) && !(Flags & ImGuiWindowFlags_ShowBorders)) ? ImVec2(1,1) : GImGui.Style.WindowPadding; } + ImU32 Color(ImGuiCol idx, float a=1.f) const { ImVec4 c = GImGui.Style.Colors[idx]; c.w *= GImGui.Style.Alpha * a; return ImConvertColorFloat4ToU32(c); } + ImU32 Color(const ImVec4& col) const { ImVec4 c = col; c.w *= GImGui.Style.Alpha; return ImConvertColorFloat4ToU32(c); } }; -static ImGuiWindow* GetCurrentWindow() +static ImGuiWindow* GetCurrentWindow() { - IM_ASSERT(GImGui.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? - GImGui.CurrentWindow->Accessed = true; - return GImGui.CurrentWindow; + IM_ASSERT(GImGui.CurrentWindow != NULL); // ImGui::NewFrame() hasn't been called yet? + GImGui.CurrentWindow->Accessed = true; + return GImGui.CurrentWindow; } static void RegisterAliveId(const ImGuiID& id) { - if (GImGui.ActiveId == id) - GImGui.ActiveIdIsAlive = true; + if (GImGui.ActiveId == id) + GImGui.ActiveIdIsAlive = true; } //----------------------------------------------------------------------------- void ImGuiStorage::Clear() { - Data.clear(); + Data.clear(); } // std::lower_bound but without the bullshit static ImVector::iterator LowerBound(ImVector& data, ImU32 key) { - ImVector::iterator first = data.begin(); - ImVector::iterator last = data.end(); - int count = (int)(last - first); - while (count > 0) - { - int count2 = count / 2; - ImVector::iterator mid = first + count2; - if (mid->key < key) - { - first = ++mid; - count -= count2 + 1; - } - else - { - count = count2; - } - } - return first; + ImVector::iterator first = data.begin(); + ImVector::iterator last = data.end(); + int count = (int)(last - first); + while (count > 0) + { + int count2 = count / 2; + ImVector::iterator mid = first + count2; + if (mid->key < key) + { + first = ++mid; + count -= count2 + 1; + } + else + { + count = count2; + } + } + return first; } int* ImGuiStorage::Find(ImU32 key) { - ImVector::iterator it = LowerBound(Data, key); - if (it == Data.end()) - return NULL; - if (it->key != key) - return NULL; - return &it->val; + ImVector::iterator it = LowerBound(Data, key); + if (it == Data.end()) + return NULL; + if (it->key != key) + return NULL; + return &it->val; } int ImGuiStorage::GetInt(ImU32 key, int default_val) { - int* pval = Find(key); - if (!pval) - return default_val; - return *pval; + int* pval = Find(key); + if (!pval) + return default_val; + return *pval; } // FIXME-OPT: We are wasting time because all SetInt() are preceeded by GetInt() calls so we should have the result from lower_bound already in place. // However we only use SetInt() on explicit user action (so that's maximum once a frame) so the optimisation isn't much needed. void ImGuiStorage::SetInt(ImU32 key, int val) { - ImVector::iterator it = LowerBound(Data, key); - if (it != Data.end() && it->key == key) - { - it->val = val; - } - else - { - Pair pair_key; - pair_key.key = key; - pair_key.val = val; - Data.insert(it, pair_key); - } + ImVector::iterator it = LowerBound(Data, key); + if (it != Data.end() && it->key == key) + { + it->val = val; + } + else + { + Pair pair_key; + pair_key.key = key; + pair_key.val = val; + Data.insert(it, pair_key); + } } void ImGuiStorage::SetAllInt(int v) { - for (size_t i = 0; i < Data.size(); i++) - Data[i].val = v; + for (size_t i = 0; i < Data.size(); i++) + Data[i].val = v; } //----------------------------------------------------------------------------- ImGuiTextFilter::ImGuiTextFilter() { - InputBuf[0] = 0; - CountGrep = 0; + InputBuf[0] = 0; + CountGrep = 0; } void ImGuiTextFilter::Draw(const char* label, float width) { - ImGuiWindow* window = GetCurrentWindow(); - if (width < 0.0f) - { - ImVec2 label_size = ImGui::CalcTextSize(label, NULL); - width = ImMax(window->Pos.x + ImGui::GetWindowContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f); - } - ImGui::PushItemWidth(width); - ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf)); - ImGui::PopItemWidth(); - Build(); + ImGuiWindow* window = GetCurrentWindow(); + if (width < 0.0f) + { + ImVec2 label_size = ImGui::CalcTextSize(label, NULL); + width = ImMax(window->Pos.x + ImGui::GetWindowContentRegionMax().x - window->DC.CursorPos.x - (label_size.x + GImGui.Style.ItemSpacing.x*4), 10.0f); + } + ImGui::PushItemWidth(width); + ImGui::InputText(label, InputBuf, IM_ARRAYSIZE(InputBuf)); + ImGui::PopItemWidth(); + Build(); } void ImGuiTextFilter::TextRange::split(char separator, ImVector& out) { - out.resize(0); - const char* wb = b; - const char* we = wb; - while (we < e) - { - if (*we == separator) - { - out.push_back(TextRange(wb, we)); - wb = we + 1; - } - we++; - } - if (wb != we) - out.push_back(TextRange(wb, we)); + out.resize(0); + const char* wb = b; + const char* we = wb; + while (we < e) + { + if (*we == separator) + { + out.push_back(TextRange(wb, we)); + wb = we + 1; + } + we++; + } + if (wb != we) + out.push_back(TextRange(wb, we)); } void ImGuiTextFilter::Build() { - Filters.resize(0); - TextRange input_range(InputBuf, InputBuf+strlen(InputBuf)); - input_range.split(',', Filters); + Filters.resize(0); + TextRange input_range(InputBuf, InputBuf+strlen(InputBuf)); + input_range.split(',', Filters); - CountGrep = 0; - for (size_t i = 0; i != Filters.size(); i++) - { - Filters[i].trim_blanks(); - if (Filters[i].empty()) - continue; - if (Filters[i].front() != '-') - CountGrep += 1; - } + CountGrep = 0; + for (size_t i = 0; i != Filters.size(); i++) + { + Filters[i].trim_blanks(); + if (Filters[i].empty()) + continue; + if (Filters[i].front() != '-') + CountGrep += 1; + } } bool ImGuiTextFilter::PassFilter(const char* val) const { - if (Filters.empty()) - return true; + if (Filters.empty()) + return true; - if (val == NULL) - val = ""; + if (val == NULL) + val = ""; - for (size_t i = 0; i != Filters.size(); i++) - { - const TextRange& f = Filters[i]; - if (f.empty()) - continue; - if (f.front() == '-') - { - // Subtract - if (ImStristr(val, f.begin()+1, f.end()) != NULL) - return false; - } - else - { - // Grep - if (ImStristr(val, f.begin(), f.end()) != NULL) - return true; - } - } + for (size_t i = 0; i != Filters.size(); i++) + { + const TextRange& f = Filters[i]; + if (f.empty()) + continue; + if (f.front() == '-') + { + // Subtract + if (ImStristr(val, f.begin()+1, f.end()) != NULL) + return false; + } + else + { + // Grep + if (ImStristr(val, f.begin(), f.end()) != NULL) + return true; + } + } - // Implicit * grep - if (CountGrep == 0) - return true; + // Implicit * grep + if (CountGrep == 0) + return true; - return false; + return false; } //----------------------------------------------------------------------------- void ImGuiTextBuffer::append(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - int len = vsnprintf(NULL, 0, fmt, args); - va_end(args); - if (len <= 0) - return; + va_list args; + va_start(args, fmt); + int len = vsnprintf(NULL, 0, fmt, args); + va_end(args); + if (len <= 0) + return; - const size_t write_off = Buf.size(); - if (write_off + len >= Buf.capacity()) - Buf.reserve(Buf.capacity() * 2); + const size_t write_off = Buf.size(); + if (write_off + len >= Buf.capacity()) + Buf.reserve(Buf.capacity() * 2); - Buf.resize(write_off + (size_t)len); + Buf.resize(write_off + (size_t)len); - va_start(args, fmt); - ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args); - va_end(args); + va_start(args, fmt); + ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args); + va_end(args); } //----------------------------------------------------------------------------- ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_size) { - Name = strdup(name); - ID = GetID(name); - IDStack.push_back(ID); + Name = strdup(name); + ID = GetID(name); + IDStack.push_back(ID); - PosFloat = default_pos; - Pos = ImVec2((float)(int)PosFloat.x, (float)(int)PosFloat.y); - Size = SizeFull = default_size; - SizeContentsFit = ImVec2(0.0f, 0.0f); - ScrollY = 0.0f; - NextScrollY = 0.0f; - ScrollbarY = false; - Visible = false; - Accessed = false; - Collapsed = false; - SkipItems = false; - AutoFitFrames = -1; - LastFrameDrawn = -1; - ItemWidthDefault = 0.0f; - FontScale = 1.0f; + PosFloat = default_pos; + Pos = ImVec2((float)(int)PosFloat.x, (float)(int)PosFloat.y); + Size = SizeFull = default_size; + SizeContentsFit = ImVec2(0.0f, 0.0f); + ScrollY = 0.0f; + NextScrollY = 0.0f; + ScrollbarY = false; + Visible = false; + Accessed = false; + Collapsed = false; + SkipItems = false; + AutoFitFrames = -1; + LastFrameDrawn = -1; + ItemWidthDefault = 0.0f; + FontScale = 1.0f; - if (ImLength(Size) < 0.001f) - AutoFitFrames = 3; + if (ImLength(Size) < 0.001f) + AutoFitFrames = 3; - FocusIdxCounter = -1; - FocusIdxRequestCurrent = IM_INT_MAX; - FocusIdxRequestNext = IM_INT_MAX; + FocusIdxCounter = -1; + FocusIdxRequestCurrent = IM_INT_MAX; + FocusIdxRequestNext = IM_INT_MAX; - DrawList = new ImDrawList(); + DrawList = new ImDrawList(); } ImGuiWindow::~ImGuiWindow() { - delete DrawList; - DrawList = NULL; - free(Name); - Name = NULL; + delete DrawList; + DrawList = NULL; + free(Name); + Name = NULL; } ImGuiID ImGuiWindow::GetID(const char* str) { - const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); - const ImGuiID id = crc32(str, strlen(str), seed); - RegisterAliveId(id); - return id; + const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); + const ImGuiID id = crc32(str, strlen(str), seed); + RegisterAliveId(id); + return id; } ImGuiID ImGuiWindow::GetID(const void* ptr) { - const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); - const ImGuiID id = crc32(&ptr, sizeof(void*), seed); - RegisterAliveId(id); - return id; + const ImGuiID seed = IDStack.empty() ? 0 : IDStack.back(); + const ImGuiID id = crc32(&ptr, sizeof(void*), seed); + RegisterAliveId(id); + return id; } bool ImGuiWindow::FocusItemRegister(bool is_active, int* out_idx) { - FocusIdxCounter++; - if (out_idx) - *out_idx = FocusIdxCounter; + FocusIdxCounter++; + if (out_idx) + *out_idx = FocusIdxCounter; - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (!window->DC.AllowKeyboardFocus.back()) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (!window->DC.AllowKeyboardFocus.back()) + return false; - // Process input at this point: TAB, Shift-TAB switch focus - if (FocusIdxRequestNext == IM_INT_MAX && is_active && ImGui::IsKeyPressedMap(ImGuiKey_Tab)) - { - // Modulo on index will be applied at the end of frame once we've got the total counter of items. - FocusIdxRequestNext = FocusIdxCounter + (g.IO.KeyShift ? -1 : +1); - } + // Process input at this point: TAB, Shift-TAB switch focus + if (FocusIdxRequestNext == IM_INT_MAX && is_active && ImGui::IsKeyPressedMap(ImGuiKey_Tab)) + { + // Modulo on index will be applied at the end of frame once we've got the total counter of items. + FocusIdxRequestNext = FocusIdxCounter + (g.IO.KeyShift ? -1 : +1); + } - const bool focus_requested = (FocusIdxCounter == FocusIdxRequestCurrent); - return focus_requested; + const bool focus_requested = (FocusIdxCounter == FocusIdxRequestCurrent); + return focus_requested; } void ImGuiWindow::FocusItemUnregister() { - FocusIdxCounter--; + FocusIdxCounter--; } void ImGuiWindow::AddToRenderList() { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty()) - { - if (DrawList->commands.back().vtx_count == 0) - DrawList->commands.pop_back(); - g.RenderDrawLists.push_back(DrawList); - } - for (size_t i = 0; i < DC.ChildWindows.size(); i++) - { - ImGuiWindow* child = DC.ChildWindows[i]; - if (child->Visible) // clipped childs may have been marked not Visible - child->AddToRenderList(); - } + if (!DrawList->commands.empty() && !DrawList->vtx_buffer.empty()) + { + if (DrawList->commands.back().vtx_count == 0) + DrawList->commands.pop_back(); + g.RenderDrawLists.push_back(DrawList); + } + for (size_t i = 0; i < DC.ChildWindows.size(); i++) + { + ImGuiWindow* child = DC.ChildWindows[i]; + if (child->Visible) // clipped childs may have been marked not Visible + child->AddToRenderList(); + } } //----------------------------------------------------------------------------- @@ -1020,2624 +1020,2624 @@ namespace ImGui static ImGuiIniData* FindWindowSettings(const char* name) { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - for (size_t i = 0; i != g.Settings.size(); i++) - { - ImGuiIniData* ini = g.Settings[i]; - if (ImStricmp(ini->Name, name) == 0) - return ini; - } - ImGuiIniData* ini = new ImGuiIniData(); - ini->Name = strdup(name); - ini->Collapsed = false; - ini->Pos = ImVec2(FLT_MAX,FLT_MAX); - ini->Size = ImVec2(0,0); - g.Settings.push_back(ini); - return ini; + for (size_t i = 0; i != g.Settings.size(); i++) + { + ImGuiIniData* ini = g.Settings[i]; + if (ImStricmp(ini->Name, name) == 0) + return ini; + } + ImGuiIniData* ini = new ImGuiIniData(); + ini->Name = strdup(name); + ini->Collapsed = false; + ini->Pos = ImVec2(FLT_MAX,FLT_MAX); + ini->Size = ImVec2(0,0); + g.Settings.push_back(ini); + return ini; } // Zero-tolerance, poor-man .ini parsing // FIXME: Write something less rubbish static void LoadSettings() { - ImGuiState& g = GImGui; - const char* filename = g.IO.IniFilename; - if (!filename) - return; + ImGuiState& g = GImGui; + const char* filename = g.IO.IniFilename; + if (!filename) + return; - // Load file - FILE* f; - if ((f = fopen(filename, "rt")) == NULL) - return; - if (fseek(f, 0, SEEK_END)) - return; - long f_size = ftell(f); - if (f_size == -1) - return; - if (fseek(f, 0, SEEK_SET)) - return; - char* f_data = new char[f_size+1]; - f_size = (long)fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value - fclose(f); - if (f_size == 0) - { - delete[] f_data; - return; - } - f_data[f_size] = 0; + // Load file + FILE* f; + if ((f = fopen(filename, "rt")) == NULL) + return; + if (fseek(f, 0, SEEK_END)) + return; + long f_size = ftell(f); + if (f_size == -1) + return; + if (fseek(f, 0, SEEK_SET)) + return; + char* f_data = new char[f_size+1]; + f_size = (long)fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value + fclose(f); + if (f_size == 0) + { + delete[] f_data; + return; + } + f_data[f_size] = 0; - ImGuiIniData* settings = NULL; - const char* buf_end = f_data + f_size; - for (const char* line_start = f_data; line_start < buf_end; ) - { - const char* line_end = line_start; - while (line_end < buf_end && *line_end != '\n' && *line_end != '\r') - line_end++; - - if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']') - { - char name[64]; - ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1); - settings = FindWindowSettings(name); - } - else if (settings) - { - float x, y; - int i; - if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2) - settings->Pos = ImVec2(x, y); - else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2) - settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize); - else if (sscanf(line_start, "Collapsed=%d", &i) == 1) - settings->Collapsed = (i != 0); - } + ImGuiIniData* settings = NULL; + const char* buf_end = f_data + f_size; + for (const char* line_start = f_data; line_start < buf_end; ) + { + const char* line_end = line_start; + while (line_end < buf_end && *line_end != '\n' && *line_end != '\r') + line_end++; + + if (line_start[0] == '[' && line_end > line_start && line_end[-1] == ']') + { + char name[64]; + ImFormatString(name, IM_ARRAYSIZE(name), "%.*s", line_end-line_start-2, line_start+1); + settings = FindWindowSettings(name); + } + else if (settings) + { + float x, y; + int i; + if (sscanf(line_start, "Pos=%f,%f", &x, &y) == 2) + settings->Pos = ImVec2(x, y); + else if (sscanf(line_start, "Size=%f,%f", &x, &y) == 2) + settings->Size = ImMax(ImVec2(x, y), g.Style.WindowMinSize); + else if (sscanf(line_start, "Collapsed=%d", &i) == 1) + settings->Collapsed = (i != 0); + } - line_start = line_end+1; - } + line_start = line_end+1; + } - delete[] f_data; + delete[] f_data; } static void SaveSettings() { - ImGuiState& g = GImGui; - const char* filename = g.IO.IniFilename; - if (!filename) - return; + ImGuiState& g = GImGui; + const char* filename = g.IO.IniFilename; + if (!filename) + return; - // Gather data from windows that were active during this session - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) - continue; - ImGuiIniData* settings = FindWindowSettings(window->Name); - settings->Pos = window->Pos; - settings->Size = window->SizeFull; - settings->Collapsed = window->Collapsed; - } + // Gather data from windows that were active during this session + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) + continue; + ImGuiIniData* settings = FindWindowSettings(window->Name); + settings->Pos = window->Pos; + settings->Size = window->SizeFull; + settings->Collapsed = window->Collapsed; + } - // Write .ini file - // If a window wasn't opened in this session we preserve its settings - FILE* f = fopen(filename, "wt"); - if (!f) - return; - for (size_t i = 0; i != g.Settings.size(); i++) - { - const ImGuiIniData* settings = g.Settings[i]; - if (settings->Pos.x == FLT_MAX) - continue; - fprintf(f, "[%s]\n", settings->Name); - fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y); - fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y); - fprintf(f, "Collapsed=%d\n", settings->Collapsed); - fprintf(f, "\n"); - } + // Write .ini file + // If a window wasn't opened in this session we preserve its settings + FILE* f = fopen(filename, "wt"); + if (!f) + return; + for (size_t i = 0; i != g.Settings.size(); i++) + { + const ImGuiIniData* settings = g.Settings[i]; + if (settings->Pos.x == FLT_MAX) + continue; + fprintf(f, "[%s]\n", settings->Name); + fprintf(f, "Pos=%d,%d\n", (int)settings->Pos.x, (int)settings->Pos.y); + fprintf(f, "Size=%d,%d\n", (int)settings->Size.x, (int)settings->Size.y); + fprintf(f, "Collapsed=%d\n", settings->Collapsed); + fprintf(f, "\n"); + } - fclose(f); + fclose(f); } static void MarkSettingsDirty() { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - if (g.SettingsDirtyTimer <= 0.0f) - g.SettingsDirtyTimer = g.IO.IniSavingRate; + if (g.SettingsDirtyTimer <= 0.0f) + g.SettingsDirtyTimer = g.IO.IniSavingRate; } ImGuiIO& GetIO() { - return GImGui.IO; + return GImGui.IO; } ImGuiStyle& GetStyle() { - return GImGui.Style; + return GImGui.Style; } void NewFrame() { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - // Check user inputs - IM_ASSERT(g.IO.DeltaTime > 0.0f); - IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f); - IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented + // Check user inputs + IM_ASSERT(g.IO.DeltaTime > 0.0f); + IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f); + IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented - if (!g.Initialized) - { - // Initialize on first frame - IM_ASSERT(g.Settings.empty()); - LoadSettings(); - if (!g.IO.Font) - { - // Default font - const void* fnt_data; - unsigned int fnt_size; - ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL); - g.IO.Font = new ImBitmapFont(); - g.IO.Font->LoadFromMemory(fnt_data, fnt_size); - g.IO.FontHeight = g.IO.Font->GetFontSize(); - } - g.Initialized = true; - } + if (!g.Initialized) + { + // Initialize on first frame + IM_ASSERT(g.Settings.empty()); + LoadSettings(); + if (!g.IO.Font) + { + // Default font + const void* fnt_data; + unsigned int fnt_size; + ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL); + g.IO.Font = new ImBitmapFont(); + g.IO.Font->LoadFromMemory(fnt_data, fnt_size); + g.IO.FontHeight = g.IO.Font->GetFontSize(); + } + g.Initialized = true; + } - g.Time += g.IO.DeltaTime; - g.FrameCount += 1; - g.Tooltip[0] = '\0'; + g.Time += g.IO.DeltaTime; + g.FrameCount += 1; + g.Tooltip[0] = '\0'; - // Update inputs state - if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) - g.IO.MousePos = ImVec2(-9999.0f, -9999.0f); - if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePosPrev.x < 0 && g.IO.MousePosPrev.y < 0)) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta - g.IO.MouseDelta = ImVec2(0.0f, 0.0f); - else - g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; - g.IO.MousePosPrev = g.IO.MousePos; - for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++) - { - g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f; - g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f); - g.IO.MouseDoubleClicked[i] = false; - if (g.IO.MouseClicked[i]) - { - if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime) - { - if (ImLength(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist) - g.IO.MouseDoubleClicked[i] = true; - g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click - } - else - { - g.IO.MouseClickedTime[i] = g.Time; - g.IO.MouseClickedPos[i] = g.IO.MousePos; - } - } - } - for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) - g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f; + // Update inputs state + if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) + g.IO.MousePos = ImVec2(-9999.0f, -9999.0f); + if ((g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) || (g.IO.MousePosPrev.x < 0 && g.IO.MousePosPrev.y < 0)) // if mouse just appeared or disappeared (negative coordinate) we cancel out movement in MouseDelta + g.IO.MouseDelta = ImVec2(0.0f, 0.0f); + else + g.IO.MouseDelta = g.IO.MousePos - g.IO.MousePosPrev; + g.IO.MousePosPrev = g.IO.MousePos; + for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.MouseDown); i++) + { + g.IO.MouseDownTime[i] = g.IO.MouseDown[i] ? (g.IO.MouseDownTime[i] < 0.0f ? 0.0f : g.IO.MouseDownTime[i] + g.IO.DeltaTime) : -1.0f; + g.IO.MouseClicked[i] = (g.IO.MouseDownTime[i] == 0.0f); + g.IO.MouseDoubleClicked[i] = false; + if (g.IO.MouseClicked[i]) + { + if (g.Time - g.IO.MouseClickedTime[i] < g.IO.MouseDoubleClickTime) + { + if (ImLength(g.IO.MousePos - g.IO.MouseClickedPos[i]) < g.IO.MouseDoubleClickMaxDist) + g.IO.MouseDoubleClicked[i] = true; + g.IO.MouseClickedTime[i] = -FLT_MAX; // so the third click isn't turned into a double-click + } + else + { + g.IO.MouseClickedTime[i] = g.Time; + g.IO.MouseClickedPos[i] = g.IO.MousePos; + } + } + } + for (size_t i = 0; i < IM_ARRAYSIZE(g.IO.KeysDown); i++) + g.IO.KeysDownTime[i] = g.IO.KeysDown[i] ? (g.IO.KeysDownTime[i] < 0.0f ? 0.0f : g.IO.KeysDownTime[i] + g.IO.DeltaTime) : -1.0f; - // Clear reference to active widget if the widget isn't alive anymore - g.HoveredId = 0; - if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) - g.ActiveId = 0; - g.ActiveIdPreviousFrame = g.ActiveId; - g.ActiveIdIsAlive = false; + // Clear reference to active widget if the widget isn't alive anymore + g.HoveredId = 0; + if (!g.ActiveIdIsAlive && g.ActiveIdPreviousFrame == g.ActiveId && g.ActiveId != 0) + g.ActiveId = 0; + g.ActiveIdPreviousFrame = g.ActiveId; + g.ActiveIdIsAlive = false; - // Delay saving settings so we don't spam disk too much - if (g.SettingsDirtyTimer > 0.0f) - { - g.SettingsDirtyTimer -= g.IO.DeltaTime; - if (g.SettingsDirtyTimer <= 0.0f) - SaveSettings(); - } + // Delay saving settings so we don't spam disk too much + if (g.SettingsDirtyTimer > 0.0f) + { + g.SettingsDirtyTimer -= g.IO.DeltaTime; + if (g.SettingsDirtyTimer <= 0.0f) + SaveSettings(); + } - g.HoveredWindow = ImGui::FindHoveredWindow(g.IO.MousePos, false); - g.HoveredWindowExcludingChilds = ImGui::FindHoveredWindow(g.IO.MousePos, true); + g.HoveredWindow = ImGui::FindHoveredWindow(g.IO.MousePos, false); + g.HoveredWindowExcludingChilds = ImGui::FindHoveredWindow(g.IO.MousePos, true); - // Are we snooping input? - g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0); - g.IO.WantCaptureKeyboard = (g.ActiveId != 0); + // Are we snooping input? + g.IO.WantCaptureMouse = (g.HoveredWindow != NULL) || (g.ActiveId != 0); + g.IO.WantCaptureKeyboard = (g.ActiveId != 0); - // Scale & Scrolling - if (g.HoveredWindow && g.IO.MouseWheel != 0) - { - ImGuiWindow* window = g.HoveredWindow; - if (g.IO.KeyCtrl) - { - if (g.IO.FontAllowScaling) - { - // Zoom / Scale window - float new_font_scale = ImClamp(window->FontScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); - float scale = new_font_scale / window->FontScale; - window->FontScale = new_font_scale; + // Scale & Scrolling + if (g.HoveredWindow && g.IO.MouseWheel != 0) + { + ImGuiWindow* window = g.HoveredWindow; + if (g.IO.KeyCtrl) + { + if (g.IO.FontAllowScaling) + { + // Zoom / Scale window + float new_font_scale = ImClamp(window->FontScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f); + float scale = new_font_scale / window->FontScale; + window->FontScale = new_font_scale; - const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; - window->Pos += offset; - window->PosFloat += offset; - window->Size *= scale; - window->SizeFull *= scale; - } - } - else - { - // Scroll - const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; - window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; - } - } + const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size; + window->Pos += offset; + window->PosFloat += offset; + window->Size *= scale; + window->SizeFull *= scale; + } + } + else + { + // Scroll + const int scroll_lines = (window->Flags & ImGuiWindowFlags_ComboBox) ? 3 : 5; + window->NextScrollY -= g.IO.MouseWheel * window->FontSize() * scroll_lines; + } + } - // Pressing TAB activate widget focus - // NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus. - if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false)) - { - g.FocusedWindow->FocusIdxRequestNext = 0; - } + // Pressing TAB activate widget focus + // NB: Don't discard FocusedWindow if it isn't active, so that a window that go on/off programatically won't lose its keyboard focus. + if (g.ActiveId == 0 && g.FocusedWindow != NULL && g.FocusedWindow->Visible && IsKeyPressedMap(ImGuiKey_Tab, false)) + { + g.FocusedWindow->FocusIdxRequestNext = 0; + } - // Mark all windows as not visible - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - window->Visible = false; - window->Accessed = false; - } + // Mark all windows as not visible + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + window->Visible = false; + window->Accessed = false; + } - // No window should be open at the beginning of the frame. - // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear. - g.CurrentWindowStack.clear(); + // No window should be open at the beginning of the frame. + // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear. + g.CurrentWindowStack.clear(); - // Create implicit window - we will only render it if the user has added something to it. - ImGui::Begin("Debug", NULL, ImVec2(400,400)); + // Create implicit window - we will only render it if the user has added something to it. + ImGui::Begin("Debug", NULL, ImVec2(400,400)); } // NB: behaviour of ImGui after Shutdown() is not tested/guaranteed at the moment. This function is merely here to free heap allocations. void Shutdown() { - ImGuiState& g = GImGui; - if (!g.Initialized) - return; + ImGuiState& g = GImGui; + if (!g.Initialized) + return; - SaveSettings(); + SaveSettings(); - for (size_t i = 0; i < g.Windows.size(); i++) - delete g.Windows[i]; - g.Windows.clear(); - g.CurrentWindowStack.clear(); - g.FocusedWindow = NULL; - g.HoveredWindow = NULL; - g.HoveredWindowExcludingChilds = NULL; - for (size_t i = 0; i < g.Settings.size(); i++) - delete g.Settings[i]; - g.Settings.clear(); - g.ColorEditModeStorage.Clear(); - if (g.LogFile && g.LogFile != stdout) - { - fclose(g.LogFile); - g.LogFile = NULL; - } - if (g.IO.Font) - { - delete g.IO.Font; - g.IO.Font = NULL; - } + for (size_t i = 0; i < g.Windows.size(); i++) + delete g.Windows[i]; + g.Windows.clear(); + g.CurrentWindowStack.clear(); + g.FocusedWindow = NULL; + g.HoveredWindow = NULL; + g.HoveredWindowExcludingChilds = NULL; + for (size_t i = 0; i < g.Settings.size(); i++) + delete g.Settings[i]; + g.Settings.clear(); + g.ColorEditModeStorage.Clear(); + if (g.LogFile && g.LogFile != stdout) + { + fclose(g.LogFile); + g.LogFile = NULL; + } + if (g.IO.Font) + { + delete g.IO.Font; + g.IO.Font = NULL; + } - if (g.PrivateClipboard) - { - free(g.PrivateClipboard); - g.PrivateClipboard = NULL; - } + if (g.PrivateClipboard) + { + free(g.PrivateClipboard); + g.PrivateClipboard = NULL; + } - g.Initialized = false; + g.Initialized = false; } static void AddWindowToSortedBuffer(ImGuiWindow* window, ImVector& sorted_windows) { - sorted_windows.push_back(window); - if (window->Visible) - { - for (size_t i = 0; i < window->DC.ChildWindows.size(); i++) - { - ImGuiWindow* child = window->DC.ChildWindows[i]; - if (child->Visible) - AddWindowToSortedBuffer(child, sorted_windows); - } - } + sorted_windows.push_back(window); + if (window->Visible) + { + for (size_t i = 0; i < window->DC.ChildWindows.size(); i++) + { + ImGuiWindow* child = window->DC.ChildWindows[i]; + if (child->Visible) + AddWindowToSortedBuffer(child, sorted_windows); + } + } } static void PushClipRect(const ImVec4& clip_rect, bool clipped = true) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - ImVec4 cr = clip_rect; - if (clipped && !window->ClipRectStack.empty()) - { - // Clip to new clip rect - const ImVec4 cur_cr = window->ClipRectStack.back(); - cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w)); - } + ImVec4 cr = clip_rect; + if (clipped && !window->ClipRectStack.empty()) + { + // Clip to new clip rect + const ImVec4 cur_cr = window->ClipRectStack.back(); + cr = ImVec4(ImMax(cr.x, cur_cr.x), ImMax(cr.y, cur_cr.y), ImMin(cr.z, cur_cr.z), ImMin(cr.w, cur_cr.w)); + } - window->ClipRectStack.push_back(cr); - window->DrawList->PushClipRect(cr); + window->ClipRectStack.push_back(cr); + window->DrawList->PushClipRect(cr); } static void PopClipRect() { - ImGuiWindow* window = GetCurrentWindow(); - window->ClipRectStack.pop_back(); - window->DrawList->PopClipRect(); + ImGuiWindow* window = GetCurrentWindow(); + window->ClipRectStack.pop_back(); + window->DrawList->PopClipRect(); } void Render() { - ImGuiState& g = GImGui; - IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() + ImGuiState& g = GImGui; + IM_ASSERT(g.Initialized); // Forgot to call ImGui::NewFrame() - const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount); - g.FrameCountRendered = g.FrameCount; - - if (first_render_of_the_frame) - { - // Hide implicit window if it hasn't been used - IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End - if (g.CurrentWindow && !g.CurrentWindow->Accessed) - g.CurrentWindow->Visible = false; - ImGui::End(); + const bool first_render_of_the_frame = (g.FrameCountRendered != g.FrameCount); + g.FrameCountRendered = g.FrameCount; + + if (first_render_of_the_frame) + { + // Hide implicit window if it hasn't been used + IM_ASSERT(g.CurrentWindowStack.size() == 1); // Mismatched Begin/End + if (g.CurrentWindow && !g.CurrentWindow->Accessed) + g.CurrentWindow->Visible = false; + ImGui::End(); - // Sort the window list so that all child windows are after their parent - // We cannot do that on FocusWindow() because childs may not exist yet - ImVector sorted_windows; - sorted_windows.reserve(g.Windows.size()); - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it - if (window->Visible) - continue; - AddWindowToSortedBuffer(window, sorted_windows); - } - IM_ASSERT(g.Windows.size() == sorted_windows.size()); // We done something wrong - g.Windows.swap(sorted_windows); + // Sort the window list so that all child windows are after their parent + // We cannot do that on FocusWindow() because childs may not exist yet + ImVector sorted_windows; + sorted_windows.reserve(g.Windows.size()); + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Flags & ImGuiWindowFlags_ChildWindow) // if a child is visible its parent will add it + if (window->Visible) + continue; + AddWindowToSortedBuffer(window, sorted_windows); + } + IM_ASSERT(g.Windows.size() == sorted_windows.size()); // We done something wrong + g.Windows.swap(sorted_windows); - // Clear data for next frame - g.IO.MouseWheel = 0; - memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); - } + // Clear data for next frame + g.IO.MouseWheel = 0; + memset(g.IO.InputCharacters, 0, sizeof(g.IO.InputCharacters)); + } - // Skip render altogether if alpha is 0.0 - // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place. - if (g.Style.Alpha > 0.0f) - { - // Render tooltip - if (g.Tooltip[0]) - { - // Use a dummy window to render the tooltip - ImGui::BeginTooltip(); - ImGui::TextUnformatted(g.Tooltip); - ImGui::EndTooltip(); - } + // Skip render altogether if alpha is 0.0 + // Note that vertex buffers have been created, so it is best practice that you don't call Begin/End in the first place. + if (g.Style.Alpha > 0.0f) + { + // Render tooltip + if (g.Tooltip[0]) + { + // Use a dummy window to render the tooltip + ImGui::BeginTooltip(); + ImGui::TextUnformatted(g.Tooltip); + ImGui::EndTooltip(); + } - // Gather windows to render - g.RenderDrawLists.resize(0); - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) - window->AddToRenderList(); - } - for (size_t i = 0; i != g.Windows.size(); i++) - { - ImGuiWindow* window = g.Windows[i]; - if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) - window->AddToRenderList(); - } + // Gather windows to render + g.RenderDrawLists.resize(0); + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) == 0) + window->AddToRenderList(); + } + for (size_t i = 0; i != g.Windows.size(); i++) + { + ImGuiWindow* window = g.Windows[i]; + if (window->Visible && (window->Flags & ImGuiWindowFlags_Tooltip)) + window->AddToRenderList(); + } - // Render - if (!g.RenderDrawLists.empty()) - g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); - g.RenderDrawLists.resize(0); - } + // Render + if (!g.RenderDrawLists.empty()) + g.IO.RenderDrawListsFn(&g.RenderDrawLists[0], (int)g.RenderDrawLists.size()); + g.RenderDrawLists.resize(0); + } } // Find the optional ## from which we stop displaying text. -static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL) +static const char* FindTextDisplayEnd(const char* text, const char* text_end = NULL) { - const char* text_display_end = text; - while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) - text_display_end++; - return text_display_end; + const char* text_display_end = text; + while ((!text_end || text_display_end < text_end) && *text_display_end != '\0' && (text_display_end[0] != '#' || text_display_end[1] != '#')) + text_display_end++; + return text_display_end; } static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - if (!text_end) - text_end = FindTextDisplayEnd(text, text_end); + if (!text_end) + text_end = FindTextDisplayEnd(text, text_end); - const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1; - window->DC.LogLineHeight = ref_pos.y; + const bool log_new_line = ref_pos.y > window->DC.LogLineHeight+1; + window->DC.LogLineHeight = ref_pos.y; - const char* text_remaining = text; - const int tree_depth = window->DC.TreeDepth; - while (true) - { - const char* line_end = text_remaining; - while (line_end < text_end) - if (*line_end == '\n') - break; - else - line_end++; - if (line_end >= text_end) - line_end = NULL; + const char* text_remaining = text; + const int tree_depth = window->DC.TreeDepth; + while (true) + { + const char* line_end = text_remaining; + while (line_end < text_end) + if (*line_end == '\n') + break; + else + line_end++; + if (line_end >= text_end) + line_end = NULL; - bool is_first_line = (text == text_remaining); - bool is_last_line = false; - if (line_end == NULL) - { - is_last_line = true; - line_end = text_end; - } - if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0)) - { - const int char_count = (int)(line_end - text_remaining); - if (g.LogFile) - { - if (log_new_line || !is_first_line) - fprintf(g.LogFile, "\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); - else - fprintf(g.LogFile, " %.*s", char_count, text_remaining); - } - else - { - if (log_new_line || !is_first_line) - g.LogClipboard.append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); - else - g.LogClipboard.append(" %.*s", char_count, text_remaining); - } - } + bool is_first_line = (text == text_remaining); + bool is_last_line = false; + if (line_end == NULL) + { + is_last_line = true; + line_end = text_end; + } + if (line_end != NULL && !(is_last_line && (line_end - text_remaining)==0)) + { + const int char_count = (int)(line_end - text_remaining); + if (g.LogFile) + { + if (log_new_line || !is_first_line) + fprintf(g.LogFile, "\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); + else + fprintf(g.LogFile, " %.*s", char_count, text_remaining); + } + else + { + if (log_new_line || !is_first_line) + g.LogClipboard.append("\n%*s%.*s", tree_depth*4, "", char_count, text_remaining); + else + g.LogClipboard.append(" %.*s", char_count, text_remaining); + } + } - if (is_last_line) - break; - text_remaining = line_end + 1; - } + if (is_last_line) + break; + text_remaining = line_end + 1; + } } static void RenderText(ImVec2 pos, const char* text, const char* text_end, const bool hide_text_after_hash) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - // Hide anything after a '##' string - const char* text_display_end; - if (hide_text_after_hash) - { - text_display_end = FindTextDisplayEnd(text, text_end); - } - else - { - if (!text_end) - text_end = text + strlen(text); - text_display_end = text_end; - } + // Hide anything after a '##' string + const char* text_display_end; + if (hide_text_after_hash) + { + text_display_end = FindTextDisplayEnd(text, text_end); + } + else + { + if (!text_end) + text_end = text + strlen(text); + text_display_end = text_end; + } - const int text_len = (int)(text_display_end - text); - //IM_ASSERT(text_len >= 0 && text_len < 10000); // Suspicious text length - if (text_len > 0) - { - // Render - window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text + text_len); + const int text_len = (int)(text_display_end - text); + //IM_ASSERT(text_len >= 0 && text_len < 10000); // Suspicious text length + if (text_len > 0) + { + // Render + window->DrawList->AddText(window->Font(), window->FontSize(), pos, window->Color(ImGuiCol_Text), text, text + text_len); - // Log as text. We split text into individual lines to add the tree level padding - if (g.LogEnabled) - LogText(pos, text, text_display_end); - } + // Log as text. We split text into individual lines to add the tree level padding + if (g.LogEnabled) + LogText(pos, text, text_display_end); + } } static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding); - if (border && (window->Flags & ImGuiWindowFlags_ShowBorders)) - { - window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); - window->DrawList->AddRect(p_min, p_max, window->Color(ImGuiCol_Border), rounding); - } + window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding); + if (border && (window->Flags & ImGuiWindowFlags_ShowBorders)) + { + window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); + window->DrawList->AddRect(p_min, p_max, window->Color(ImGuiCol_Border), rounding); + } } static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - const float h = window->FontSize() * 1.00f; - const float r = h * 0.40f * scale; - ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale); + const float h = window->FontSize() * 1.00f; + const float r = h * 0.40f * scale; + ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale); - ImVec2 a, b, c; - if (open) - { - center.y -= r*0.25f; - a = center + ImVec2(0,1)*r; - b = center + ImVec2(-0.866f,-0.5f)*r; - c = center + ImVec2(0.866f,-0.5f)*r; - } - else - { - a = center + ImVec2(1,0)*r; - b = center + ImVec2(-0.500f,0.866f)*r; - c = center + ImVec2(-0.500f,-0.866f)*r; - } - - if (shadow) - window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow)); - window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border)); + ImVec2 a, b, c; + if (open) + { + center.y -= r*0.25f; + a = center + ImVec2(0,1)*r; + b = center + ImVec2(-0.866f,-0.5f)*r; + c = center + ImVec2(0.866f,-0.5f)*r; + } + else + { + a = center + ImVec2(1,0)*r; + b = center + ImVec2(-0.500f,0.866f)*r; + c = center + ImVec2(-0.500f,-0.866f)*r; + } + + if (shadow) + window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow)); + window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border)); } static ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - const char* text_display_end; - if (hide_text_after_hash) - text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string - else - text_display_end = text_end; + const char* text_display_end; + if (hide_text_after_hash) + text_display_end = FindTextDisplayEnd(text, text_end); // Hide anything after a '##' string + else + text_display_end = text_end; - const ImVec2 size = window->Font()->CalcTextSize(window->FontSize(), 0, text, text_display_end, NULL); - return size; + const ImVec2 size = window->Font()->CalcTextSize(window->FontSize(), 0, text, text_display_end, NULL); + return size; } static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs) { - ImGuiState& g = GImGui; - for (int i = (int)g.Windows.size()-1; i >= 0; i--) - { - ImGuiWindow* window = g.Windows[(size_t)i]; - if (!window->Visible) - continue; - if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0) - continue; - ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos+window->Size + g.Style.TouchExtraPadding); - if (bb.Contains(pos)) - return window; - } - return NULL; + ImGuiState& g = GImGui; + for (int i = (int)g.Windows.size()-1; i >= 0; i--) + { + ImGuiWindow* window = g.Windows[(size_t)i]; + if (!window->Visible) + continue; + if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0) + continue; + ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos+window->Size + g.Style.TouchExtraPadding); + if (bb.Contains(pos)) + return window; + } + return NULL; } // - Box is clipped by our current clip setting // - Expand to be generous on unprecise inputs systems (touch) static bool IsMouseHoveringBox(const ImGuiAabb& box) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - // Clip - ImGuiAabb box_clipped = box; - if (!window->ClipRectStack.empty()) - { - const ImVec4 clip_rect = window->ClipRectStack.back(); - box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w))); - } + // Clip + ImGuiAabb box_clipped = box; + if (!window->ClipRectStack.empty()) + { + const ImVec4 clip_rect = window->ClipRectStack.back(); + box_clipped.Clip(ImGuiAabb(ImVec2(clip_rect.x, clip_rect.y), ImVec2(clip_rect.z, clip_rect.w))); + } - // Expand for touch input - ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding); - return box_for_touch.Contains(g.IO.MousePos); + // Expand for touch input + ImGuiAabb box_for_touch(box_clipped.Min - g.Style.TouchExtraPadding, box_clipped.Max + g.Style.TouchExtraPadding); + return box_for_touch.Contains(g.IO.MousePos); } bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max) { - return IsMouseHoveringBox(ImGuiAabb(box_min, box_max)); + return IsMouseHoveringBox(ImGuiAabb(box_min, box_max)); } static bool IsKeyPressedMap(ImGuiKey key, bool repeat) { - ImGuiState& g = GImGui; - const int key_index = g.IO.KeyMap[key]; - return IsKeyPressed(key_index, repeat); + ImGuiState& g = GImGui; + const int key_index = g.IO.KeyMap[key]; + return IsKeyPressed(key_index, repeat); } bool IsKeyPressed(int key_index, bool repeat) { - ImGuiState& g = GImGui; - IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); - const float t = g.IO.KeysDownTime[key_index]; - if (t == 0.0f) - return true; + ImGuiState& g = GImGui; + IM_ASSERT(key_index >= 0 && key_index < IM_ARRAYSIZE(g.IO.KeysDown)); + const float t = g.IO.KeysDownTime[key_index]; + if (t == 0.0f) + return true; - // FIXME: Repeat rate should be provided elsewhere? - const float KEY_REPEAT_DELAY = 0.250f; - const float KEY_REPEAT_RATE = 0.020f; - if (repeat && t > KEY_REPEAT_DELAY) - if ((fmodf(t - KEY_REPEAT_DELAY, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f) != (fmodf(t - KEY_REPEAT_DELAY - g.IO.DeltaTime, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f)) - return true; + // FIXME: Repeat rate should be provided elsewhere? + const float KEY_REPEAT_DELAY = 0.250f; + const float KEY_REPEAT_RATE = 0.020f; + if (repeat && t > KEY_REPEAT_DELAY) + if ((fmodf(t - KEY_REPEAT_DELAY, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f) != (fmodf(t - KEY_REPEAT_DELAY - g.IO.DeltaTime, KEY_REPEAT_RATE) > KEY_REPEAT_RATE*0.5f)) + return true; - return false; + return false; } bool IsMouseClicked(int button, bool repeat) { - ImGuiState& g = GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - const float t = g.IO.MouseDownTime[button]; - if (t == 0.0f) - return true; + ImGuiState& g = GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + const float t = g.IO.MouseDownTime[button]; + if (t == 0.0f) + return true; - // FIXME: Repeat rate should be provided elsewhere? - const float MOUSE_REPEAT_DELAY = 0.250f; - const float MOUSE_REPEAT_RATE = 0.020f; - if (repeat && t > MOUSE_REPEAT_DELAY) - if ((fmodf(t - MOUSE_REPEAT_DELAY, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f) != (fmodf(t - MOUSE_REPEAT_DELAY - g.IO.DeltaTime, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f)) - return true; + // FIXME: Repeat rate should be provided elsewhere? + const float MOUSE_REPEAT_DELAY = 0.250f; + const float MOUSE_REPEAT_RATE = 0.020f; + if (repeat && t > MOUSE_REPEAT_DELAY) + if ((fmodf(t - MOUSE_REPEAT_DELAY, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f) != (fmodf(t - MOUSE_REPEAT_DELAY - g.IO.DeltaTime, MOUSE_REPEAT_RATE) > MOUSE_REPEAT_RATE*0.5f)) + return true; - return false; + return false; } bool IsMouseDoubleClicked(int button) { - ImGuiState& g = GImGui; - IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); - return g.IO.MouseDoubleClicked[button]; + ImGuiState& g = GImGui; + IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown)); + return g.IO.MouseDoubleClicked[button]; } ImVec2 GetMousePos() { - return GImGui.IO.MousePos; + return GImGui.IO.MousePos; } bool IsHovered() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemHovered; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemHovered; } ImVec2 GetItemBoxMin() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemAabb.Min; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemAabb.Min; } ImVec2 GetItemBoxMax() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.LastItemAabb.Max; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.LastItemAabb.Max; } void SetTooltip(const char* fmt, ...) { - ImGuiState& g = GImGui; - va_list args; - va_start(args, fmt); - ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args); - va_end(args); + ImGuiState& g = GImGui; + va_list args; + va_start(args, fmt); + ImFormatStringV(g.Tooltip, IM_ARRAYSIZE(g.Tooltip), fmt, args); + va_end(args); } void SetNewWindowDefaultPos(const ImVec2& pos) { - ImGuiState& g = GImGui; - g.NewWindowDefaultPos = pos; + ImGuiState& g = GImGui; + g.NewWindowDefaultPos = pos; } float GetTime() { - return GImGui.Time; + return GImGui.Time; } int GetFrameCount() { - return GImGui.FrameCount; + return GImGui.FrameCount; } static ImGuiWindow* FindWindow(const char* name) { - ImGuiState& g = GImGui; - for (size_t i = 0; i != g.Windows.size(); i++) - if (strcmp(g.Windows[i]->Name, name) == 0) - return g.Windows[i]; - return NULL; + ImGuiState& g = GImGui; + for (size_t i = 0; i != g.Windows.size(); i++) + if (strcmp(g.Windows[i]->Name, name) == 0) + return g.Windows[i]; + return NULL; } void BeginTooltip() { - ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_Tooltip); + ImGui::Begin("##Tooltip", NULL, ImVec2(0,0), 0.9f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_Tooltip); } void EndTooltip() { - IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip); - ImGui::End(); + IM_ASSERT(GetCurrentWindow()->Flags & ImGuiWindowFlags_Tooltip); + ImGui::End(); } void BeginChild(const char* str_id, ImVec2 size, bool border, ImGuiWindowFlags extra_flags) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow; + ImGuiWindowFlags flags = ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_ChildWindow; - const ImVec2 content_max = window->Pos + ImGui::GetWindowContentRegionMax(); - const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos(); - if (size.x <= 0.0f) - { - size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x); - flags |= ImGuiWindowFlags_ChildWindowAutoFitX; - } - if (size.y <= 0.0f) - { - size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y); - flags |= ImGuiWindowFlags_ChildWindowAutoFitY; - } - if (border) - flags |= ImGuiWindowFlags_ShowBorders; - flags |= extra_flags; + const ImVec2 content_max = window->Pos + ImGui::GetWindowContentRegionMax(); + const ImVec2 cursor_pos = window->Pos + ImGui::GetCursorPos(); + if (size.x <= 0.0f) + { + size.x = ImMax(content_max.x - cursor_pos.x, g.Style.WindowMinSize.x); + flags |= ImGuiWindowFlags_ChildWindowAutoFitX; + } + if (size.y <= 0.0f) + { + size.y = ImMax(content_max.y - cursor_pos.y, g.Style.WindowMinSize.y); + flags |= ImGuiWindowFlags_ChildWindowAutoFitY; + } + if (border) + flags |= ImGuiWindowFlags_ShowBorders; + flags |= extra_flags; - char title[256]; - ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id); + char title[256]; + ImFormatString(title, IM_ARRAYSIZE(title), "%s.%s", window->Name, str_id); - const float alpha = (flags & ImGuiWindowFlags_ComboBox) ? 1.0f : 0.0f; - ImGui::Begin(title, NULL, size, alpha, flags); + const float alpha = (flags & ImGuiWindowFlags_ComboBox) ? 1.0f : 0.0f; + ImGui::Begin(title, NULL, size, alpha, flags); - if (!(window->Flags & ImGuiWindowFlags_ShowBorders)) - g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders; + if (!(window->Flags & ImGuiWindowFlags_ShowBorders)) + g.CurrentWindow->Flags &= ~ImGuiWindowFlags_ShowBorders; } void EndChild() { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - if (window->Flags & ImGuiWindowFlags_ComboBox) - { - ImGui::End(); - } - else - { - // When using filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic fitting - ImVec2 sz = ImGui::GetWindowSize(); - if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX) - sz.x = 0; - if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY) - sz.y = 0; - - ImGui::End(); - ImGui::ItemSize(sz); - } + if (window->Flags & ImGuiWindowFlags_ComboBox) + { + ImGui::End(); + } + else + { + // When using filling child window, we don't provide the width/height to ItemSize so that it doesn't feed back into automatic fitting + ImVec2 sz = ImGui::GetWindowSize(); + if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitX) + sz.x = 0; + if (window->Flags & ImGuiWindowFlags_ChildWindowAutoFitY) + sz.y = 0; + + ImGui::End(); + ImGui::ItemSize(sz); + } } bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWindowFlags flags) { - ImGuiState& g = GImGui; - const ImGuiStyle& style = g.Style; + ImGuiState& g = GImGui; + const ImGuiStyle& style = g.Style; - ImGuiWindow* window = FindWindow(name); - if (!window) - { - // Create window the first time, and load settings - if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) - { - window = new ImGuiWindow(name, ImVec2(0,0), size); - } - else - { - ImGuiIniData* settings = FindWindowSettings(name); - if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f) - size = settings->Size; + ImGuiWindow* window = FindWindow(name); + if (!window) + { + // Create window the first time, and load settings + if (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Tooltip)) + { + window = new ImGuiWindow(name, ImVec2(0,0), size); + } + else + { + ImGuiIniData* settings = FindWindowSettings(name); + if (settings && ImLength(settings->Size) > 0.0f && !(flags & ImGuiWindowFlags_NoResize))// && ImLengthsize) == 0.0f) + size = settings->Size; - window = new ImGuiWindow(name, g.NewWindowDefaultPos, size); + window = new ImGuiWindow(name, g.NewWindowDefaultPos, size); - if (settings->Pos.x != FLT_MAX) - { - window->PosFloat = settings->Pos; - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - window->Collapsed = settings->Collapsed; - } - } - g.Windows.push_back(window); - } - window->Flags = (ImGuiWindowFlags)flags; + if (settings->Pos.x != FLT_MAX) + { + window->PosFloat = settings->Pos; + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + window->Collapsed = settings->Collapsed; + } + } + g.Windows.push_back(window); + } + window->Flags = (ImGuiWindowFlags)flags; - g.CurrentWindowStack.push_back(window); - g.CurrentWindow = window; + g.CurrentWindowStack.push_back(window); + g.CurrentWindow = window; - // Default alpha - if (fill_alpha < 0.0f) - fill_alpha = style.WindowFillAlphaDefault; + // Default alpha + if (fill_alpha < 0.0f) + fill_alpha = style.WindowFillAlphaDefault; - // When reusing window again multiple times a frame, just append content (don't need to setup again) - const int current_frame = ImGui::GetFrameCount(); - const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame); - if (first_begin_of_the_frame) - { - window->DrawList->Clear(); - window->Visible = true; + // When reusing window again multiple times a frame, just append content (don't need to setup again) + const int current_frame = ImGui::GetFrameCount(); + const bool first_begin_of_the_frame = (window->LastFrameDrawn != current_frame); + if (first_begin_of_the_frame) + { + window->DrawList->Clear(); + window->Visible = true; - // New windows appears in front - if (window->LastFrameDrawn < current_frame - 1) - { - ImGui::FocusWindow(window); - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - // Hide for 1 frame while resizing - window->AutoFitFrames = 2; - window->Visible = false; - } - } + // New windows appears in front + if (window->LastFrameDrawn < current_frame - 1) + { + ImGui::FocusWindow(window); + if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + { + // Hide for 1 frame while resizing + window->AutoFitFrames = 2; + window->Visible = false; + } + } - window->LastFrameDrawn = current_frame; - window->ClipRectStack.resize(0); + window->LastFrameDrawn = current_frame; + window->ClipRectStack.resize(0); - if (flags & ImGuiWindowFlags_ChildWindow) - { - ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2]; - parent_window->DC.ChildWindows.push_back(window); - window->Pos = window->PosFloat = parent_window->DC.CursorPos; - window->SizeFull = size; - } + if (flags & ImGuiWindowFlags_ChildWindow) + { + ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2]; + parent_window->DC.ChildWindows.push_back(window); + window->Pos = window->PosFloat = parent_window->DC.CursorPos; + window->SizeFull = size; + } - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - ImGui::PushClipRect(g.CurrentWindowStack[g.CurrentWindowStack.size()-2]->ClipRectStack.back()); - else - ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + // Outer clipping rectangle + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) + ImGui::PushClipRect(g.CurrentWindowStack[g.CurrentWindowStack.size()-2]->ClipRectStack.back()); + else + ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); - // ID stack - window->IDStack.resize(0); - ImGui::PushID(window); + // ID stack + window->IDStack.resize(0); + ImGui::PushID(window); - // Move window (at the beginning of the frame) - const ImGuiID move_id = window->GetID("#MOVE"); - RegisterAliveId(move_id); - if (g.ActiveId == move_id) - { - if (g.IO.MouseDown[0]) - { - if (!(window->Flags & ImGuiWindowFlags_NoMove)) - { - window->PosFloat += g.IO.MouseDelta; - MarkSettingsDirty(); - } - ImGui::FocusWindow(window); - } - else - { - g.ActiveId = 0; - } - } + // Move window (at the beginning of the frame) + const ImGuiID move_id = window->GetID("#MOVE"); + RegisterAliveId(move_id); + if (g.ActiveId == move_id) + { + if (g.IO.MouseDown[0]) + { + if (!(window->Flags & ImGuiWindowFlags_NoMove)) + { + window->PosFloat += g.IO.MouseDelta; + MarkSettingsDirty(); + } + ImGui::FocusWindow(window); + } + else + { + g.ActiveId = 0; + } + } - // Tooltips always follow mouse - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - window->PosFloat = g.IO.MousePos + ImVec2(32,16) - g.Style.FramePadding*2; - } + // Tooltips always follow mouse + if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + { + window->PosFloat = g.IO.MousePos + ImVec2(32,16) - g.Style.FramePadding*2; + } - // Clamp into view - if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) - { - const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); - window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; - window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - window->SizeFull = ImMax(window->SizeFull, pad); - } - else - { - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - } + // Clamp into view + if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) + { + const ImVec2 pad = ImVec2(window->FontSize()*2.0f, window->FontSize()*2.0f); + window->PosFloat = ImMax(window->PosFloat + window->Size, pad) - window->Size; + window->PosFloat = ImMin(window->PosFloat, ImVec2(g.IO.DisplaySize.x, g.IO.DisplaySize.y) - pad); + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + window->SizeFull = ImMax(window->SizeFull, pad); + } + else + { + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + } - // Default item width - if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip)) - window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); - else - window->ItemWidthDefault = 200.0f; + // Default item width + if (window->Size.x > 0.0f && !(window->Flags & ImGuiWindowFlags_Tooltip)) + window->ItemWidthDefault = (float)(int)(window->Size.x * 0.65f); + else + window->ItemWidthDefault = 200.0f; - // Prepare for focus requests - if (window->FocusIdxRequestNext == IM_INT_MAX || window->FocusIdxCounter == -1) - { - window->FocusIdxRequestCurrent = IM_INT_MAX; - } - else - { - const int mod = window->FocusIdxCounter+1; - window->FocusIdxRequestCurrent = (window->FocusIdxRequestNext + mod) % mod; - } - window->FocusIdxCounter = -1; - window->FocusIdxRequestNext = IM_INT_MAX; + // Prepare for focus requests + if (window->FocusIdxRequestNext == IM_INT_MAX || window->FocusIdxCounter == -1) + { + window->FocusIdxRequestCurrent = IM_INT_MAX; + } + else + { + const int mod = window->FocusIdxCounter+1; + window->FocusIdxRequestCurrent = (window->FocusIdxRequestNext + mod) % mod; + } + window->FocusIdxCounter = -1; + window->FocusIdxRequestNext = IM_INT_MAX; - ImGuiAabb title_bar_aabb = window->TitleBarAabb(); + ImGuiAabb title_bar_aabb = window->TitleBarAabb(); - // Apply and ImClamp scrolling - window->ScrollY = window->NextScrollY; - window->ScrollY = ImMax(window->ScrollY, 0.0f); - if (!window->Collapsed && !window->SkipItems) - window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y)); - window->NextScrollY = window->ScrollY; + // Apply and ImClamp scrolling + window->ScrollY = window->NextScrollY; + window->ScrollY = ImMax(window->ScrollY, 0.0f); + if (!window->Collapsed && !window->SkipItems) + window->ScrollY = ImMin(window->ScrollY, ImMax(0.0f, (float)window->SizeContentsFit.y - window->SizeFull.y)); + window->NextScrollY = window->ScrollY; - // NB- at this point we don't have a clipping rectangle setup yet! - // Collapse window by double-clicking on title bar - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - { - if (g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0]) - { - window->Collapsed = !window->Collapsed; - MarkSettingsDirty(); - ImGui::FocusWindow(window); - } - } - else - { - window->Collapsed = false; - } + // NB- at this point we don't have a clipping rectangle setup yet! + // Collapse window by double-clicking on title bar + if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) + { + if (g.HoveredWindow == window && IsMouseHoveringBox(title_bar_aabb) && g.IO.MouseDoubleClicked[0]) + { + window->Collapsed = !window->Collapsed; + MarkSettingsDirty(); + ImGui::FocusWindow(window); + } + } + else + { + window->Collapsed = false; + } - if (window->Collapsed) - { - // Title bar only - window->Size = title_bar_aabb.GetSize(); - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), g.Style.WindowRounding); - if (window->Flags & ImGuiWindowFlags_ShowBorders) - { - window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), g.Style.WindowRounding); - window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), g.Style.WindowRounding); - } - } - else - { - window->Size = window->SizeFull; + if (window->Collapsed) + { + // Title bar only + window->Size = title_bar_aabb.GetSize(); + window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBgCollapsed), g.Style.WindowRounding); + if (window->Flags & ImGuiWindowFlags_ShowBorders) + { + window->DrawList->AddRect(title_bar_aabb.GetTL()+ImVec2(1,1), title_bar_aabb.GetBR()+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), g.Style.WindowRounding); + window->DrawList->AddRect(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border), g.Style.WindowRounding); + } + } + else + { + window->Size = window->SizeFull; - // Draw resize grip and resize - ImU32 resize_col = 0; - if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) - { - if (window->AutoFitFrames > 0) - { - // Tooltip always resize - window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y); - } - } - else if (!(window->Flags & ImGuiWindowFlags_NoResize)) - { - const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); - const ImGuiID resize_id = window->GetID("#RESIZE"); - bool hovered, held; - ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); - resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); + // Draw resize grip and resize + ImU32 resize_col = 0; + if ((window->Flags & ImGuiWindowFlags_Tooltip) != 0) + { + if (window->AutoFitFrames > 0) + { + // Tooltip always resize + window->SizeFull = window->SizeContentsFit + g.Style.WindowPadding - ImVec2(0.0f, g.Style.ItemSpacing.y); + } + } + else if (!(window->Flags & ImGuiWindowFlags_NoResize)) + { + const ImGuiAabb resize_aabb(window->Aabb().GetBR()-ImVec2(18,18), window->Aabb().GetBR()); + const ImGuiID resize_id = window->GetID("#RESIZE"); + bool hovered, held; + ButtonBehaviour(resize_aabb, resize_id, &hovered, &held, true); + resize_col = window->Color(held ? ImGuiCol_ResizeGripActive : hovered ? ImGuiCol_ResizeGripHovered : ImGuiCol_ResizeGrip); - ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding); - if (window->AutoFitFrames > 0) - { - // Auto-fit only grows during the first few frames - window->SizeFull = ImMax(window->SizeFull, size_auto_fit); - MarkSettingsDirty(); - } - else if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) - { - // Manual auto-fit - window->SizeFull = size_auto_fit; - window->Size = window->SizeFull; - MarkSettingsDirty(); - } - else if (held) - { - // Resize - window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); - window->Size = window->SizeFull; - MarkSettingsDirty(); - } + ImVec2 size_auto_fit = ImClamp(window->SizeContentsFit + style.AutoFitPadding, style.WindowMinSize, g.IO.DisplaySize - style.AutoFitPadding); + if (window->AutoFitFrames > 0) + { + // Auto-fit only grows during the first few frames + window->SizeFull = ImMax(window->SizeFull, size_auto_fit); + MarkSettingsDirty(); + } + else if (g.HoveredWindow == window && held && g.IO.MouseDoubleClicked[0]) + { + // Manual auto-fit + window->SizeFull = size_auto_fit; + window->Size = window->SizeFull; + MarkSettingsDirty(); + } + else if (held) + { + // Resize + window->SizeFull = ImMax(window->SizeFull + g.IO.MouseDelta, style.WindowMinSize); + window->Size = window->SizeFull; + MarkSettingsDirty(); + } - // Update aabb immediately so that the rendering below isn't one frame late - title_bar_aabb = window->TitleBarAabb(); - } + // Update aabb immediately so that the rendering below isn't one frame late + title_bar_aabb = window->TitleBarAabb(); + } - // Title bar + Window box - if (fill_alpha > 0.0f) - { - if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) - window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0); - else - window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), g.Style.WindowRounding); - } + // Title bar + Window box + if (fill_alpha > 0.0f) + { + if ((window->Flags & ImGuiWindowFlags_ComboBox) != 0) + window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_ComboBg, fill_alpha), 0); + else + window->DrawList->AddRectFilled(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_WindowBg, fill_alpha), g.Style.WindowRounding); + } - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), g.Style.WindowRounding, 1|2); + if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddRectFilled(title_bar_aabb.GetTL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_TitleBg), g.Style.WindowRounding, 1|2); - if (window->Flags & ImGuiWindowFlags_ShowBorders) - { - const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : g.Style.WindowRounding; - window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); - window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding); - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border)); - } + if (window->Flags & ImGuiWindowFlags_ShowBorders) + { + const float rounding = (window->Flags & ImGuiWindowFlags_ComboBox) ? 0.0f : g.Style.WindowRounding; + window->DrawList->AddRect(window->Pos+ImVec2(1,1), window->Pos+window->Size+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); + window->DrawList->AddRect(window->Pos, window->Pos+window->Size, window->Color(ImGuiCol_Border), rounding); + if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) + window->DrawList->AddLine(title_bar_aabb.GetBL(), title_bar_aabb.GetBR(), window->Color(ImGuiCol_Border)); + } - // Scrollbar - window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar); - if (window->ScrollbarY) - { - ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1); - //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]); - window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg)); - scrollbar_bb.Max.x -= 3; - scrollbar_bb.Expand(ImVec2(0,-3)); + // Scrollbar + window->ScrollbarY = (window->SizeContentsFit.y > window->Size.y) && !(window->Flags & ImGuiWindowFlags_NoScrollbar); + if (window->ScrollbarY) + { + ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1); + //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]); + window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg)); + scrollbar_bb.Max.x -= 3; + scrollbar_bb.Expand(ImVec2(0,-3)); - const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y)); - const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm; + const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y)); + const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm; - // Handle input right away (none of the code above is relying on scrolling) - bool held = false; - bool hovered = false; - if (grab_size_y_norm < 1.0f) - { - const ImGuiID scrollbar_id = window->GetID("#SCROLLY"); - ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true); - if (held) - { - g.HoveredId = scrollbar_id; - const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y*0.5f)) / (scrollbar_bb.GetHeight() - grab_size_y)) * (1.0f - grab_size_y_norm); - window->ScrollY = pos_y_norm * window->SizeContentsFit.y; - window->NextScrollY = window->ScrollY; - } - } + // Handle input right away (none of the code above is relying on scrolling) + bool held = false; + bool hovered = false; + if (grab_size_y_norm < 1.0f) + { + const ImGuiID scrollbar_id = window->GetID("#SCROLLY"); + ButtonBehaviour(scrollbar_bb, scrollbar_id, &hovered, &held, true); + if (held) + { + g.HoveredId = scrollbar_id; + const float pos_y_norm = ImSaturate((g.IO.MousePos.y - (scrollbar_bb.Min.y + grab_size_y*0.5f)) / (scrollbar_bb.GetHeight() - grab_size_y)) * (1.0f - grab_size_y_norm); + window->ScrollY = pos_y_norm * window->SizeContentsFit.y; + window->NextScrollY = window->ScrollY; + } + } - // Normalized height of the grab - const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y)); - const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); - window->DrawList->AddRectFilled( - ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)), - ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col); - } + // Normalized height of the grab + const float pos_y_norm = ImSaturate(window->ScrollY / ImMax(0.0f, window->SizeContentsFit.y)); + const ImU32 grab_col = window->Color(held ? ImGuiCol_ScrollbarGrabActive : hovered ? ImGuiCol_ScrollbarGrabHovered : ImGuiCol_ScrollbarGrab); + window->DrawList->AddRectFilled( + ImVec2(scrollbar_bb.Min.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm)), + ImVec2(scrollbar_bb.Max.x, ImLerp(scrollbar_bb.Min.y, scrollbar_bb.Max.y, pos_y_norm + grab_size_y_norm)), grab_col); + } - // Render resize grip - // (after the input handling so we don't have a frame of latency) - if (!(window->Flags & ImGuiWindowFlags_NoResize)) - { - const float r = style.WindowRounding; - const ImVec2 br = window->Aabb().GetBR(); - if (r == 0.0f) - { - window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col); - } - else - { - // FIXME: We should draw 4 triangles and decide on a size that's not dependant on the rounding size (previously used 18) - window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true); - window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col); - window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col); - } - } - } + // Render resize grip + // (after the input handling so we don't have a frame of latency) + if (!(window->Flags & ImGuiWindowFlags_NoResize)) + { + const float r = style.WindowRounding; + const ImVec2 br = window->Aabb().GetBR(); + if (r == 0.0f) + { + window->DrawList->AddTriangleFilled(br, br-ImVec2(0,14), br-ImVec2(14,0), resize_col); + } + else + { + // FIXME: We should draw 4 triangles and decide on a size that's not dependant on the rounding size (previously used 18) + window->DrawList->AddArc(br - ImVec2(r,r), r, resize_col, 6, 9, true); + window->DrawList->AddTriangleFilled(br+ImVec2(0,-2*r),br+ImVec2(0,-r),br+ImVec2(-r,-r), resize_col); + window->DrawList->AddTriangleFilled(br+ImVec2(-r,-r), br+ImVec2(-r,0),br+ImVec2(-2*r,0), resize_col); + } + } + } - // Setup drawing context - window->DC.ColumnStartX = window->WindowPadding().x; - window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnStartX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY); - window->DC.CursorPos = window->DC.CursorStartPos; - window->DC.CursorPosPrevLine = window->DC.CursorPos; - window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f; - window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f; - window->DC.ChildWindows.resize(0); - window->DC.ItemWidth.resize(0); - window->DC.ItemWidth.push_back(window->ItemWidthDefault); - window->DC.AllowKeyboardFocus.resize(0); - window->DC.AllowKeyboardFocus.push_back(true); - window->DC.ColorModifiers.resize(0); - window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect; - window->DC.ColumnCurrent = 0; - window->DC.ColumnsCount = 1; - window->DC.TreeDepth = 0; - window->DC.StateStorage = &window->StateStorage; - window->DC.OpenNextNode = -1; + // Setup drawing context + window->DC.ColumnStartX = window->WindowPadding().x; + window->DC.CursorStartPos = window->Pos + ImVec2(window->DC.ColumnStartX, window->TitleBarHeight() + window->WindowPadding().y) - ImVec2(0.0f, window->ScrollY); + window->DC.CursorPos = window->DC.CursorStartPos; + window->DC.CursorPosPrevLine = window->DC.CursorPos; + window->DC.CurrentLineHeight = window->DC.PrevLineHeight = 0.0f; + window->DC.LogLineHeight = window->DC.CursorPos.y - 9999.0f; + window->DC.ChildWindows.resize(0); + window->DC.ItemWidth.resize(0); + window->DC.ItemWidth.push_back(window->ItemWidthDefault); + window->DC.AllowKeyboardFocus.resize(0); + window->DC.AllowKeyboardFocus.push_back(true); + window->DC.ColorModifiers.resize(0); + window->DC.ColorEditMode = ImGuiColorEditMode_UserSelect; + window->DC.ColumnCurrent = 0; + window->DC.ColumnsCount = 1; + window->DC.TreeDepth = 0; + window->DC.StateStorage = &window->StateStorage; + window->DC.OpenNextNode = -1; - // Reset contents size for auto-fitting - window->SizeContentsFit = ImVec2(0.0f, 0.0f); - if (window->AutoFitFrames > 0) - window->AutoFitFrames--; + // Reset contents size for auto-fitting + window->SizeContentsFit = ImVec2(0.0f, 0.0f); + if (window->AutoFitFrames > 0) + window->AutoFitFrames--; - // Title bar - if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) - { - RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); - if (open) - ImGui::CloseWindowButton(open); + // Title bar + if (!(window->Flags & ImGuiWindowFlags_NoTitleBar)) + { + RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true); + if (open) + ImGui::CloseWindowButton(open); - const ImVec2 text_size = CalcTextSize(name); - const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f); - const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (open ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y); - const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call - if (clip_title) - ImGui::PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y)); - RenderText(text_min, name); - if (clip_title) - ImGui::PopClipRect(); - } - } - else - { - // Outer clipping rectangle - if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) - { - ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2]; - ImGui::PushClipRect(parent_window->ClipRectStack.back()); - } - else - { - ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); - } - } + const ImVec2 text_size = CalcTextSize(name); + const ImVec2 text_min = window->Pos + style.FramePadding + ImVec2(window->FontSize() + style.ItemInnerSpacing.x, 0.0f); + const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (open ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y + text_size.y); + const bool clip_title = text_size.x > (text_max.x - text_min.x); // only push a clip rectangle if we need to, because it may turn into a separate draw call + if (clip_title) + ImGui::PushClipRect(ImVec4(text_min.x, text_min.y, text_max.x, text_max.y)); + RenderText(text_min, name); + if (clip_title) + ImGui::PopClipRect(); + } + } + else + { + // Outer clipping rectangle + if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_ComboBox)) + { + ImGuiWindow* parent_window = g.CurrentWindowStack[g.CurrentWindowStack.size()-2]; + ImGui::PushClipRect(parent_window->ClipRectStack.back()); + } + else + { + ImGui::PushClipRect(ImVec4(0.0f, 0.0f, g.IO.DisplaySize.x, g.IO.DisplaySize.y)); + } + } - // Inner clipping rectangle - // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame - const ImGuiAabb title_bar_aabb = window->TitleBarAabb(); - ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f); - if (window->ScrollbarY) - clip_rect.z -= g.Style.ScrollBarWidth; - ImGui::PushClipRect(clip_rect); + // Inner clipping rectangle + // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame + const ImGuiAabb title_bar_aabb = window->TitleBarAabb(); + ImVec4 clip_rect(title_bar_aabb.Min.x+0.5f+window->WindowPadding().x*0.5f, title_bar_aabb.Max.y+0.5f, window->Aabb().Max.x+0.5f-window->WindowPadding().x*0.5f, window->Aabb().Max.y-1.5f); + if (window->ScrollbarY) + clip_rect.z -= g.Style.ScrollBarWidth; + ImGui::PushClipRect(clip_rect); - if (first_begin_of_the_frame) - { - // Clear 'accessed' flag last thing - window->Accessed = false; - } + if (first_begin_of_the_frame) + { + // Clear 'accessed' flag last thing + window->Accessed = false; + } - // Child window can be out of sight and have "negative" clip windows. - // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). - if (flags & ImGuiWindowFlags_ChildWindow) - { - IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0); - const ImVec4 clip_rect = window->ClipRectStack.back(); - window->Collapsed = (clip_rect.x >= clip_rect.z || clip_rect.y >= clip_rect.w); + // Child window can be out of sight and have "negative" clip windows. + // Mark them as collapsed so commands are skipped earlier (we can't manually collapse because they have no title bar). + if (flags & ImGuiWindowFlags_ChildWindow) + { + IM_ASSERT((flags & ImGuiWindowFlags_NoTitleBar) != 0); + const ImVec4 clip_rect = window->ClipRectStack.back(); + window->Collapsed = (clip_rect.x >= clip_rect.z || clip_rect.y >= clip_rect.w); - // We also hide the window from rendering because we've already added its border to the command list. - // (we could perform the check earlier in the function but it is simplier at this point) - if (window->Collapsed) - window->Visible = false; - } - if (g.Style.Alpha <= 0.0f) - window->Visible = false; + // We also hide the window from rendering because we've already added its border to the command list. + // (we could perform the check earlier in the function but it is simplier at this point) + if (window->Collapsed) + window->Visible = false; + } + if (g.Style.Alpha <= 0.0f) + window->Visible = false; - // Return false if we don't intend to display anything to allow user to perform an early out optimisation - window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0); - return !window->SkipItems; + // Return false if we don't intend to display anything to allow user to perform an early out optimisation + window->SkipItems = window->Collapsed || (!window->Visible && window->AutoFitFrames == 0); + return !window->SkipItems; } void End() { - ImGuiState& g = GImGui; - ImGuiWindow* window = g.CurrentWindow; + ImGuiState& g = GImGui; + ImGuiWindow* window = g.CurrentWindow; - ImGui::Columns(1, "#CloseColumns"); - ImGui::PopClipRect(); // inner window clip rectangle - ImGui::PopClipRect(); // outer window clip rectangle + ImGui::Columns(1, "#CloseColumns"); + ImGui::PopClipRect(); // inner window clip rectangle + ImGui::PopClipRect(); // outer window clip rectangle - // Select window for move/focus when we're done with all our widgets - ImGuiAabb bb(window->Pos, window->Pos+window->Size); - if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredWindowExcludingChilds == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0]) - g.ActiveId = window->GetID("#MOVE"); + // Select window for move/focus when we're done with all our widgets + ImGuiAabb bb(window->Pos, window->Pos+window->Size); + if (g.ActiveId == 0 && g.HoveredId == 0 && g.HoveredWindowExcludingChilds == window && IsMouseHoveringBox(bb) && g.IO.MouseClicked[0]) + g.ActiveId = window->GetID("#MOVE"); - // Stop logging - if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: more options for scope of logging - { - g.LogEnabled = false; - if (g.LogFile != NULL) - { - fprintf(g.LogFile, "\n"); - if (g.LogFile == stdout) - fflush(g.LogFile); - else - fclose(g.LogFile); - g.LogFile = NULL; - } - if (g.LogClipboard.size() > 1) - { - g.LogClipboard.append("\n"); - if (g.IO.SetClipboardTextFn) - g.IO.SetClipboardTextFn(g.LogClipboard.begin(), g.LogClipboard.end()); - g.LogClipboard.clear(); - } - } + // Stop logging + if (!(window->Flags & ImGuiWindowFlags_ChildWindow)) // FIXME: more options for scope of logging + { + g.LogEnabled = false; + if (g.LogFile != NULL) + { + fprintf(g.LogFile, "\n"); + if (g.LogFile == stdout) + fflush(g.LogFile); + else + fclose(g.LogFile); + g.LogFile = NULL; + } + if (g.LogClipboard.size() > 1) + { + g.LogClipboard.append("\n"); + if (g.IO.SetClipboardTextFn) + g.IO.SetClipboardTextFn(g.LogClipboard.begin(), g.LogClipboard.end()); + g.LogClipboard.clear(); + } + } - // Pop - g.CurrentWindowStack.pop_back(); - g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); + // Pop + g.CurrentWindowStack.pop_back(); + g.CurrentWindow = g.CurrentWindowStack.empty() ? NULL : g.CurrentWindowStack.back(); } static void FocusWindow(ImGuiWindow* window) { - ImGuiState& g = GImGui; - g.FocusedWindow = window; + ImGuiState& g = GImGui; + g.FocusedWindow = window; - // Move to front - for (size_t i = 0; i < g.Windows.size(); i++) - if (g.Windows[i] == window) - { - g.Windows.erase(g.Windows.begin() + i); - break; - } - g.Windows.push_back(window); + // Move to front + for (size_t i = 0; i < g.Windows.size(); i++) + if (g.Windows[i] == window) + { + g.Windows.erase(g.Windows.begin() + i); + break; + } + g.Windows.push_back(window); } void PushItemWidth(float item_width) { - ImGuiWindow* window = GetCurrentWindow(); - item_width = (float)(int)item_width; - window->DC.ItemWidth.push_back(item_width > 0.0f ? item_width : window->ItemWidthDefault); + ImGuiWindow* window = GetCurrentWindow(); + item_width = (float)(int)item_width; + window->DC.ItemWidth.push_back(item_width > 0.0f ? item_width : window->ItemWidthDefault); } void PopItemWidth() { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ItemWidth.pop_back(); + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ItemWidth.pop_back(); } float GetItemWidth() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.ItemWidth.back(); + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.ItemWidth.back(); } void PushAllowKeyboardFocus(bool allow_keyboard_focus) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus); + ImGuiWindow* window = GetCurrentWindow(); + window->DC.AllowKeyboardFocus.push_back(allow_keyboard_focus); } void PopAllowKeyboardFocus() { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.AllowKeyboardFocus.pop_back(); + ImGuiWindow* window = GetCurrentWindow(); + window->DC.AllowKeyboardFocus.pop_back(); } void PushStyleColor(ImGuiCol idx, const ImVec4& col) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - ImGuiColMod backup; - backup.Col = idx; - backup.PreviousValue = g.Style.Colors[idx]; - window->DC.ColorModifiers.push_back(backup); - g.Style.Colors[idx] = col; + ImGuiColMod backup; + backup.Col = idx; + backup.PreviousValue = g.Style.Colors[idx]; + window->DC.ColorModifiers.push_back(backup); + g.Style.Colors[idx] = col; } void PopStyleColor() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - ImGuiColMod& backup = window->DC.ColorModifiers.back(); - g.Style.Colors[backup.Col] = backup.PreviousValue; - window->DC.ColorModifiers.pop_back(); + ImGuiColMod& backup = window->DC.ColorModifiers.back(); + g.Style.Colors[backup.Col] = backup.PreviousValue; + window->DC.ColorModifiers.pop_back(); } const char* GetStyleColorName(ImGuiCol idx) { - // Create with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; - switch (idx) - { - case ImGuiCol_Text: return "Text"; - case ImGuiCol_WindowBg: return "WindowBg"; - case ImGuiCol_Border: return "Border"; - case ImGuiCol_BorderShadow: return "BorderShadow"; - case ImGuiCol_FrameBg: return "FrameBg"; - case ImGuiCol_TitleBg: return "TitleBg"; - case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; - case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; - case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab"; - case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; - case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; - case ImGuiCol_ComboBg: return "ComboBg"; - case ImGuiCol_CheckHovered: return "CheckHovered"; - case ImGuiCol_CheckActive: return "CheckActive"; - case ImGuiCol_SliderGrab: return "SliderGrab"; - case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; - case ImGuiCol_Button: return "Button"; - case ImGuiCol_ButtonHovered: return "ButtonHovered"; - case ImGuiCol_ButtonActive: return "ButtonActive"; - case ImGuiCol_Header: return "Header"; - case ImGuiCol_HeaderHovered: return "HeaderHovered"; - case ImGuiCol_HeaderActive: return "HeaderActive"; - case ImGuiCol_Column: return "Column"; - case ImGuiCol_ColumnHovered: return "ColumnHovered"; - case ImGuiCol_ColumnActive: return "ColumnActive"; - case ImGuiCol_ResizeGrip: return "ResizeGrip"; - case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; - case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; - case ImGuiCol_CloseButton: return "CloseButton"; - case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered"; - case ImGuiCol_CloseButtonActive: return "CloseButtonActive"; - case ImGuiCol_PlotLines: return "PlotLines"; - case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; - case ImGuiCol_PlotHistogram: return "PlotHistogram"; - case ImGuiCol_PlotHistogramHovered: return "ImGuiCol_PlotHistogramHovered"; - case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; - case ImGuiCol_TooltipBg: return "TooltipBg"; - } - IM_ASSERT(0); - return "Unknown"; + // Create with regexp: ImGuiCol_{.*}, --> case ImGuiCol_\1: return "\1"; + switch (idx) + { + case ImGuiCol_Text: return "Text"; + case ImGuiCol_WindowBg: return "WindowBg"; + case ImGuiCol_Border: return "Border"; + case ImGuiCol_BorderShadow: return "BorderShadow"; + case ImGuiCol_FrameBg: return "FrameBg"; + case ImGuiCol_TitleBg: return "TitleBg"; + case ImGuiCol_TitleBgCollapsed: return "TitleBgCollapsed"; + case ImGuiCol_ScrollbarBg: return "ScrollbarBg"; + case ImGuiCol_ScrollbarGrab: return "ScrollbarGrab"; + case ImGuiCol_ScrollbarGrabHovered: return "ScrollbarGrabHovered"; + case ImGuiCol_ScrollbarGrabActive: return "ScrollbarGrabActive"; + case ImGuiCol_ComboBg: return "ComboBg"; + case ImGuiCol_CheckHovered: return "CheckHovered"; + case ImGuiCol_CheckActive: return "CheckActive"; + case ImGuiCol_SliderGrab: return "SliderGrab"; + case ImGuiCol_SliderGrabActive: return "SliderGrabActive"; + case ImGuiCol_Button: return "Button"; + case ImGuiCol_ButtonHovered: return "ButtonHovered"; + case ImGuiCol_ButtonActive: return "ButtonActive"; + case ImGuiCol_Header: return "Header"; + case ImGuiCol_HeaderHovered: return "HeaderHovered"; + case ImGuiCol_HeaderActive: return "HeaderActive"; + case ImGuiCol_Column: return "Column"; + case ImGuiCol_ColumnHovered: return "ColumnHovered"; + case ImGuiCol_ColumnActive: return "ColumnActive"; + case ImGuiCol_ResizeGrip: return "ResizeGrip"; + case ImGuiCol_ResizeGripHovered: return "ResizeGripHovered"; + case ImGuiCol_ResizeGripActive: return "ResizeGripActive"; + case ImGuiCol_CloseButton: return "CloseButton"; + case ImGuiCol_CloseButtonHovered: return "CloseButtonHovered"; + case ImGuiCol_CloseButtonActive: return "CloseButtonActive"; + case ImGuiCol_PlotLines: return "PlotLines"; + case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; + case ImGuiCol_PlotHistogram: return "PlotHistogram"; + case ImGuiCol_PlotHistogramHovered: return "ImGuiCol_PlotHistogramHovered"; + case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; + case ImGuiCol_TooltipBg: return "TooltipBg"; + } + IM_ASSERT(0); + return "Unknown"; } bool GetWindowIsFocused() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - return g.FocusedWindow == window; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + return g.FocusedWindow == window; } float GetWindowWidth() { - ImGuiWindow* window = GetCurrentWindow(); - return window->Size.x; + ImGuiWindow* window = GetCurrentWindow(); + return window->Size.x; } ImVec2 GetWindowPos() { - ImGuiWindow* window = GetCurrentWindow(); - return window->Pos; + ImGuiWindow* window = GetCurrentWindow(); + return window->Pos; } void SetWindowPos(const ImVec2& pos) { - ImGuiWindow* window = GetCurrentWindow(); - const ImVec2 old_pos = window->Pos; - window->PosFloat = pos; - window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); + ImGuiWindow* window = GetCurrentWindow(); + const ImVec2 old_pos = window->Pos; + window->PosFloat = pos; + window->Pos = ImVec2((float)(int)window->PosFloat.x, (float)(int)window->PosFloat.y); - // If we happen to move the window while it is showing (which is a bad idea) let's at least offset the cursor - window->DC.CursorPos += (window->Pos - old_pos); + // If we happen to move the window while it is showing (which is a bad idea) let's at least offset the cursor + window->DC.CursorPos += (window->Pos - old_pos); } ImVec2 GetWindowSize() { - ImGuiWindow* window = GetCurrentWindow(); - return window->Size; + ImGuiWindow* window = GetCurrentWindow(); + return window->Size; } ImVec2 GetWindowContentRegionMin() { - ImGuiWindow* window = GetCurrentWindow(); - return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding(); + ImGuiWindow* window = GetCurrentWindow(); + return ImVec2(0, window->TitleBarHeight()) + window->WindowPadding(); } ImVec2 GetWindowContentRegionMax() { - ImGuiWindow* window = GetCurrentWindow(); - ImVec2 m = window->Size - window->WindowPadding(); - if (window->ScrollbarY) - m.x -= GImGui.Style.ScrollBarWidth; - return m; + ImGuiWindow* window = GetCurrentWindow(); + ImVec2 m = window->Size - window->WindowPadding(); + if (window->ScrollbarY) + m.x -= GImGui.Style.ScrollBarWidth; + return m; } float GetTextLineHeight() { - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize(); + ImGuiWindow* window = GetCurrentWindow(); + return window->FontSize(); } float GetTextLineSpacing() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - return window->FontSize() + g.Style.ItemSpacing.y; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + return window->FontSize() + g.Style.ItemSpacing.y; } -ImDrawList* GetWindowDrawList() +ImDrawList* GetWindowDrawList() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DrawList; + ImGuiWindow* window = GetCurrentWindow(); + return window->DrawList; } void SetFontScale(float scale) { - ImGuiWindow* window = GetCurrentWindow(); - window->FontScale = scale; + ImGuiWindow* window = GetCurrentWindow(); + window->FontScale = scale; } ImVec2 GetCursorPos() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.CursorPos - window->Pos; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.CursorPos - window->Pos; } void SetCursorPos(const ImVec2& pos) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.CursorPos = window->Pos + pos; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos = window->Pos + pos; } void SetScrollPosHere() { - ImGuiWindow* window = GetCurrentWindow(); - window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y); + ImGuiWindow* window = GetCurrentWindow(); + window->NextScrollY = (window->DC.CursorPos.y + window->ScrollY) - (window->Pos.y + window->SizeFull.y * 0.5f) - (window->TitleBarHeight() + window->WindowPadding().y); } void SetTreeStateStorage(ImGuiStorage* tree) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.StateStorage = tree ? tree : &window->StateStorage; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.StateStorage = tree ? tree : &window->StateStorage; } ImGuiStorage* GetTreeStateStorage() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.StateStorage; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.StateStorage; } void TextV(const char* fmt, va_list args) { - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - static char buf[1024]; - const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - TextUnformatted(buf, text_end); + static char buf[1024]; + const char* text_end = buf + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + TextUnformatted(buf, text_end); } void Text(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - TextV(fmt, args); - va_end(args); + va_list args; + va_start(args, fmt); + TextV(fmt, args); + va_end(args); } void TextColored(const ImVec4& col, const char* fmt, ...) { - ImGui::PushStyleColor(ImGuiCol_Text, col); - va_list args; - va_start(args, fmt); - TextV(fmt, args); - va_end(args); - ImGui::PopStyleColor(); + ImGui::PushStyleColor(ImGuiCol_Text, col); + va_list args; + va_start(args, fmt); + TextV(fmt, args); + va_end(args); + ImGui::PopStyleColor(); } void TextUnformatted(const char* text, const char* text_end) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - const char* text_begin = text; - if (text_end == NULL) - text_end = text + strlen(text); + const char* text_begin = text; + if (text_end == NULL) + text_end = text + strlen(text); - if (text_end - text > 2000) - { - // Long text! - // Perform manual coarse clipping to optimize for long multi-line text - // From this point we will only compute the width of lines that are visible. - const char* line = text; - const float line_height = ImGui::GetTextLineHeight(); - const ImVec2 start_pos = window->DC.CursorPos; - const ImVec4 clip_rect = window->ClipRectStack.back(); - ImVec2 text_size(0,0); + if (text_end - text > 2000) + { + // Long text! + // Perform manual coarse clipping to optimize for long multi-line text + // From this point we will only compute the width of lines that are visible. + const char* line = text; + const float line_height = ImGui::GetTextLineHeight(); + const ImVec2 start_pos = window->DC.CursorPos; + const ImVec4 clip_rect = window->ClipRectStack.back(); + ImVec2 text_size(0,0); - if (start_pos.y <= clip_rect.w) - { - ImVec2 pos = start_pos; + if (start_pos.y <= clip_rect.w) + { + ImVec2 pos = start_pos; - // lines to skip (can't skip when logging text) - if (!g.LogEnabled) - { - int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1; - if (lines_skippable > 0) - { - int lines_skipped = 0; - while (line < text_end && lines_skipped <= lines_skippable) - { - const char* line_end = strchr(line, '\n'); - line = line_end + 1; - lines_skipped++; - } - pos.y += lines_skipped * line_height; - } - } + // lines to skip (can't skip when logging text) + if (!g.LogEnabled) + { + int lines_skippable = (int)((clip_rect.y - start_pos.y) / line_height) - 1; + if (lines_skippable > 0) + { + int lines_skipped = 0; + while (line < text_end && lines_skipped <= lines_skippable) + { + const char* line_end = strchr(line, '\n'); + line = line_end + 1; + lines_skipped++; + } + pos.y += lines_skipped * line_height; + } + } - // lines to render? - if (line < text_end) - { - ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height)); - while (line < text_end) - { - const char* line_end = strchr(line, '\n'); - if (ImGui::IsClipped(line_box)) - break; + // lines to render? + if (line < text_end) + { + ImGuiAabb line_box(pos, pos + ImVec2(ImGui::GetWindowWidth(), line_height)); + while (line < text_end) + { + const char* line_end = strchr(line, '\n'); + if (ImGui::IsClipped(line_box)) + break; - const ImVec2 line_size = CalcTextSize(line, line_end, false); - text_size.x = ImMax(text_size.x, line_size.x); - RenderText(pos, line, line_end, false); - if (!line_end) - line_end = text_end; - line = line_end + 1; - line_box.Min.y += line_height; - line_box.Max.y += line_height; - pos.y += line_height; - } + const ImVec2 line_size = CalcTextSize(line, line_end, false); + text_size.x = ImMax(text_size.x, line_size.x); + RenderText(pos, line, line_end, false); + if (!line_end) + line_end = text_end; + line = line_end + 1; + line_box.Min.y += line_height; + line_box.Max.y += line_height; + pos.y += line_height; + } - // count remaining lines - int lines_skipped = 0; - while (line < text_end) - { - const char* line_end = strchr(line, '\n'); - if (!line_end) - line_end = text_end; - line = line_end + 1; - lines_skipped++; - } - pos.y += lines_skipped * line_height; - } + // count remaining lines + int lines_skipped = 0; + while (line < text_end) + { + const char* line_end = strchr(line, '\n'); + if (!line_end) + line_end = text_end; + line = line_end + 1; + lines_skipped++; + } + pos.y += lines_skipped * line_height; + } - text_size.y += (pos - start_pos).y; - } - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); - ItemSize(bb); - ClipAdvance(bb); - } - else - { - const ImVec2 text_size = CalcTextSize(text_begin, text_end, false); - ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); - ItemSize(bb.GetSize(), &bb.Min); + text_size.y += (pos - start_pos).y; + } + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); + ItemSize(bb); + ClipAdvance(bb); + } + else + { + const ImVec2 text_size = CalcTextSize(text_begin, text_end, false); + ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + text_size); + ItemSize(bb.GetSize(), &bb.Min); - if (ClipAdvance(bb)) - return; + if (ClipAdvance(bb)) + return; - // Render - // We don't hide text after # in this end-user function. - RenderText(bb.Min, text_begin, text_end, false); - } + // Render + // We don't hide text after # in this end-user function. + RenderText(bb.Min, text_begin, text_end, false); + } } void AlignFirstTextHeightToWidgets() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height. - ImGui::ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2)); - ImGui::SameLine(0, 0); + // Declare a dummy item size to that upcoming items that are smaller will center-align on the newly expanded line height. + ImGui::ItemSize(ImVec2(0, window->FontSize() + g.Style.FramePadding.y*2)); + ImGui::SameLine(0, 0); } void LabelText(const char* label, const char* fmt, ...) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; - const ImGuiStyle& style = g.Style; - const float w = window->DC.ItemWidth.back(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + const ImGuiStyle& style = g.Style; + const float w = window->DC.ItemWidth.back(); - static char buf[1024]; - va_list args; - va_start(args, fmt); - const char* text_begin = &buf[0]; - const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - va_end(args); + static char buf[1024]; + va_list args; + va_start(args, fmt); + const char* text_begin = &buf[0]; + const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + va_end(args); - const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y)); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + style.ItemInnerSpacing.x, 0.0f) + text_size); - ItemSize(bb); + const ImVec2 text_size = CalcTextSize(label); + const ImGuiAabb value_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2, text_size.y)); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w + style.FramePadding.x*2 + style.ItemInnerSpacing.x, 0.0f) + text_size); + ItemSize(bb); - if (ClipAdvance(value_bb)) - return; + if (ClipAdvance(value_bb)) + return; - // Render - RenderText(value_bb.Min, text_begin, text_end); - RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label); + // Render + RenderText(value_bb.Min, text_begin, text_end); + RenderText(ImVec2(value_bb.Max.x + style.ItemInnerSpacing.x, value_bb.Min.y), label); } static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); - bool pressed = false; - if (hovered) - { - g.HoveredId = id; - if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift)) - { - if (g.IO.MouseClicked[0]) - { - g.ActiveId = id; - } - else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true)) - { - pressed = true; - } - } - } + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + bool pressed = false; + if (hovered) + { + g.HoveredId = id; + if (allow_key_modifiers || (!g.IO.KeyCtrl && !g.IO.KeyShift)) + { + if (g.IO.MouseClicked[0]) + { + g.ActiveId = id; + } + else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true)) + { + pressed = true; + } + } + } - bool held = false; - if (g.ActiveId == id) - { - if (g.IO.MouseDown[0]) - { - held = true; - } - else - { - if (hovered) - pressed = true; - g.ActiveId = 0; - } - } + bool held = false; + if (g.ActiveId == id) + { + if (g.IO.MouseDown[0]) + { + held = true; + } + else + { + if (hovered) + pressed = true; + g.ActiveId = 0; + } + } - if (out_hovered) *out_hovered = hovered; - if (out_held) *out_held = held; + if (out_hovered) *out_hovered = hovered; + if (out_held) *out_held = held; - return pressed; + return pressed; } bool Button(const char* label, ImVec2 size, bool repeat_when_held) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); - if (size.x == 0.0f) - size.x = text_size.x; - if (size.y == 0.0f) - size.y = text_size.y; + const ImVec2 text_size = CalcTextSize(label); + if (size.x == 0.0f) + size.x = text_size.x; + if (size.y == 0.0f) + size.y = text_size.y; - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+size + style.FramePadding*2.0f); - ItemSize(bb); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+size + style.FramePadding*2.0f); + ItemSize(bb); - if (ClipAdvance(bb)) - return false; + if (ClipAdvance(bb)) + return false; - bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held); + bool hovered, held; + bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true, repeat_when_held); - // Render - const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); - RenderFrame(bb.Min, bb.Max, col); + // Render + const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + RenderFrame(bb.Min, bb.Max, col); - if (size.x < text_size.x || size.y < text_size.y) - PushClipRect(ImVec4(bb.Min.x+style.FramePadding.x, bb.Min.y+style.FramePadding.y, bb.Max.x, bb.Max.y-style.FramePadding.y)); // Allow extra to draw over the horizontal padding to make it visible that text doesn't fit - const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f); - RenderText(bb.Min + style.FramePadding + off, label); - if (size.x < text_size.x || size.y < text_size.y) - PopClipRect(); + if (size.x < text_size.x || size.y < text_size.y) + PushClipRect(ImVec4(bb.Min.x+style.FramePadding.x, bb.Min.y+style.FramePadding.y, bb.Max.x, bb.Max.y-style.FramePadding.y)); // Allow extra to draw over the horizontal padding to make it visible that text doesn't fit + const ImVec2 off = ImVec2(ImMax(0.0f, size.x - text_size.x) * 0.5f, ImMax(0.0f, size.y - text_size.y) * 0.5f); + RenderText(bb.Min + style.FramePadding + off, label); + if (size.x < text_size.x || size.y < text_size.y) + PopClipRect(); - return pressed; + return pressed; } // Fits within text without additional spacing. bool SmallButton(const char* label) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+CalcTextSize(label) + ImVec2(style.FramePadding.x*2,0)); - ItemSize(bb); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos+CalcTextSize(label) + ImVec2(style.FramePadding.x*2,0)); + ItemSize(bb); - if (ClipAdvance(bb)) - return false; + if (ClipAdvance(bb)) + return false; - bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool hovered, held; + bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); - // Render - const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); - RenderFrame(bb.Min, bb.Max, col); - RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label); + // Render + const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); + RenderFrame(bb.Min, bb.Max, col); + RenderText(bb.Min + ImVec2(style.FramePadding.x,0), label); - return pressed; + return pressed; } static bool CloseWindowButton(bool* open) { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiWindow* window = GetCurrentWindow(); - const ImGuiID id = window->GetID("##CLOSE"); - const float title_bar_height = window->TitleBarHeight(); - const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+3.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f)); + const ImGuiID id = window->GetID("##CLOSE"); + const float title_bar_height = window->TitleBarHeight(); + const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+3.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f)); - bool hovered, held; - bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); + bool hovered, held; + bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); - // Render - const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); - window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,title_bar_height*0.5f-4), col, 16); + // Render + const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); + window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,title_bar_height*0.5f-4), col, 16); - const float cross_padding = 4; - if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2) - { - window->DrawList->AddLine(bb.GetTL()+ImVec2(+cross_padding,+cross_padding), bb.GetBR()+ImVec2(-cross_padding,-cross_padding), window->Color(ImGuiCol_Text)); - window->DrawList->AddLine(bb.GetBL()+ImVec2(+cross_padding,-cross_padding), bb.GetTR()+ImVec2(-cross_padding,+cross_padding), window->Color(ImGuiCol_Text)); - } + const float cross_padding = 4; + if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2) + { + window->DrawList->AddLine(bb.GetTL()+ImVec2(+cross_padding,+cross_padding), bb.GetBR()+ImVec2(-cross_padding,-cross_padding), window->Color(ImGuiCol_Text)); + window->DrawList->AddLine(bb.GetBL()+ImVec2(+cross_padding,-cross_padding), bb.GetTR()+ImVec2(-cross_padding,+cross_padding), window->Color(ImGuiCol_Text)); + } - if (open != NULL && pressed) - *open = !*open; + if (open != NULL && pressed) + *open = !*open; - return pressed; + return pressed; } void LogToTTY(int max_depth) { - ImGuiState& g = GImGui; - if (g.LogEnabled) - return; - g.LogEnabled = true; - g.LogFile = stdout; - if (max_depth >= 0) - g.LogAutoExpandMaxDepth = max_depth; + ImGuiState& g = GImGui; + if (g.LogEnabled) + return; + g.LogEnabled = true; + g.LogFile = stdout; + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; } void LogToFile(int max_depth, const char* filename) { - ImGuiState& g = GImGui; - if (g.LogEnabled) - return; - if (!filename) - filename = g.IO.LogFilename; - g.LogEnabled = true; - g.LogFile = fopen(filename, "at"); - if (max_depth >= 0) - g.LogAutoExpandMaxDepth = max_depth; + ImGuiState& g = GImGui; + if (g.LogEnabled) + return; + if (!filename) + filename = g.IO.LogFilename; + g.LogEnabled = true; + g.LogFile = fopen(filename, "at"); + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; } void LogToClipboard(int max_depth) { - ImGuiState& g = GImGui; - if (g.LogEnabled) - return; - g.LogEnabled = true; - g.LogFile = NULL; - if (max_depth >= 0) - g.LogAutoExpandMaxDepth = max_depth; + ImGuiState& g = GImGui; + if (g.LogEnabled) + return; + g.LogEnabled = true; + g.LogFile = NULL; + if (max_depth >= 0) + g.LogAutoExpandMaxDepth = max_depth; } void LogButtons() { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - ImGui::PushID("LogButtons"); - const bool log_to_tty = ImGui::Button("Log To TTY"); - ImGui::SameLine(); - const bool log_to_file = ImGui::Button("Log To File"); - ImGui::SameLine(); - const bool log_to_clipboard = ImGui::Button("Log To Clipboard"); - ImGui::SameLine(); + ImGui::PushID("LogButtons"); + const bool log_to_tty = ImGui::Button("Log To TTY"); + ImGui::SameLine(); + const bool log_to_file = ImGui::Button("Log To File"); + ImGui::SameLine(); + const bool log_to_clipboard = ImGui::Button("Log To Clipboard"); + ImGui::SameLine(); - ImGui::PushItemWidth(80.0f); - ImGui::PushAllowKeyboardFocus(false); - ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL); - ImGui::PopAllowKeyboardFocus(); - ImGui::PopItemWidth(); - ImGui::PopID(); + ImGui::PushItemWidth(80.0f); + ImGui::PushAllowKeyboardFocus(false); + ImGui::SliderInt("Depth", &g.LogAutoExpandMaxDepth, 0, 9, NULL); + ImGui::PopAllowKeyboardFocus(); + ImGui::PopItemWidth(); + ImGui::PopID(); - // Start logging at the end of the function so that the buttons don't appear in the log - if (log_to_tty) - LogToTTY(g.LogAutoExpandMaxDepth); - if (log_to_file) - LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename); - if (log_to_clipboard) - LogToClipboard(g.LogAutoExpandMaxDepth); + // Start logging at the end of the function so that the buttons don't appear in the log + if (log_to_tty) + LogToTTY(g.LogAutoExpandMaxDepth); + if (log_to_file) + LogToFile(g.LogAutoExpandMaxDepth, g.IO.LogFilename); + if (log_to_clipboard) + LogToClipboard(g.LogAutoExpandMaxDepth); } bool CollapsingHeader(const char* label, const char* str_id, const bool display_frame, const bool default_open) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; + const ImGuiStyle& style = g.Style; - IM_ASSERT(str_id != NULL || label != NULL); - if (str_id == NULL) - str_id = label; - if (label == NULL) - label = str_id; - const ImGuiID id = window->GetID(str_id); + IM_ASSERT(str_id != NULL || label != NULL); + if (str_id == NULL) + str_id = label; + if (label == NULL) + label = str_id; + const ImGuiID id = window->GetID(str_id); - ImGuiStorage* tree = window->DC.StateStorage; - bool opened; - if (window->DC.OpenNextNode != -1) - { - opened = window->DC.OpenNextNode > 0; - tree->SetInt(id, opened); - window->DC.OpenNextNode = -1; - } - else - { - opened = tree->GetInt(id, default_open) != 0; - } + ImGuiStorage* tree = window->DC.StateStorage; + bool opened; + if (window->DC.OpenNextNode != -1) + { + opened = window->DC.OpenNextNode > 0; + tree->SetInt(id, opened); + window->DC.OpenNextNode = -1; + } + else + { + opened = tree->GetInt(id, default_open) != 0; + } - const ImVec2 window_padding = window->WindowPadding(); - const ImVec2 text_size = CalcTextSize(label); - const ImVec2 pos_min = window->DC.CursorPos; - const ImVec2 pos_max = window->Pos + GetWindowContentRegionMax(); - ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y)); - if (display_frame) - { - bb.Min.x -= window_padding.x*0.5f; - bb.Max.x += window_padding.x*0.5f; - bb.Max.y += style.FramePadding.y * 2; - } + const ImVec2 window_padding = window->WindowPadding(); + const ImVec2 text_size = CalcTextSize(label); + const ImVec2 pos_min = window->DC.CursorPos; + const ImVec2 pos_max = window->Pos + GetWindowContentRegionMax(); + ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y)); + if (display_frame) + { + bb.Min.x -= window_padding.x*0.5f; + bb.Max.x += window_padding.x*0.5f; + bb.Max.y += style.FramePadding.y * 2; + } - const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size); - ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit + const ImGuiAabb text_bb(bb.Min, bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2*2,0) + text_size); + ItemSize(ImVec2(text_bb.GetSize().x, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit - // Logging auto expand tree nodes (but not collapsing headers.. seems like sensible behaviour) - // NB- If we are above max depth we still allow manually opened nodes to be logged - if (!display_frame) - if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) - opened = true; + // Logging auto expand tree nodes (but not collapsing headers.. seems like sensible behaviour) + // NB- If we are above max depth we still allow manually opened nodes to be logged + if (!display_frame) + if (g.LogEnabled && window->DC.TreeDepth < g.LogAutoExpandMaxDepth) + opened = true; - if (ClipAdvance(bb)) - return opened; + if (ClipAdvance(bb)) + return opened; - bool hovered, held; - bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false); - if (pressed) - { - opened = !opened; - tree->SetInt(id, opened); - } + bool hovered, held; + bool pressed = ButtonBehaviour(display_frame ? bb : text_bb, id, &hovered, &held, false); + if (pressed) + { + opened = !opened; + tree->SetInt(id, opened); + } - // Render - const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); - if (display_frame) - { - RenderFrame(bb.Min, bb.Max, col, true); - RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true); - RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); - } - else - { - if ((held && hovered) || hovered) - RenderFrame(bb.Min, bb.Max, col, false); - RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f); - RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); - } + // Render + const ImU32 col = window->Color((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); + if (display_frame) + { + RenderFrame(bb.Min, bb.Max, col, true); + RenderCollapseTriangle(bb.Min + style.FramePadding, opened, 1.0f, true); + RenderText(bb.Min + style.FramePadding + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + } + else + { + if ((held && hovered) || hovered) + RenderFrame(bb.Min, bb.Max, col, false); + RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f); + RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); + } - return opened; + return opened; } void BulletText(const char* fmt, ...) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - static char buf[1024]; - va_list args; - va_start(args, fmt); - const char* text_begin = buf; - const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - va_end(args); + static char buf[1024]; + va_list args; + va_start(args, fmt); + const char* text_begin = buf; + const char* text_end = text_begin + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + va_end(args); - const float line_height = window->FontSize(); - const ImVec2 text_size = CalcTextSize(text_begin, text_end); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding - ItemSize(bb); + const float line_height = window->FontSize(); + const ImVec2 text_size = CalcTextSize(text_begin, text_end); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(line_height + (text_size.x > 0.0f ? (g.Style.FramePadding.x*2) : 0.0f),0) + text_size); // Empty text doesn't add padding + ItemSize(bb); - if (ClipAdvance(bb)) - return; + if (ClipAdvance(bb)) + return; - // Render - const float bullet_size = line_height*0.15f; - window->DrawList->AddCircleFilled(bb.Min + ImVec2(g.Style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); - RenderText(bb.Min+ImVec2(window->FontSize()+g.Style.FramePadding.x*2,0), text_begin, text_end); + // Render + const float bullet_size = line_height*0.15f; + window->DrawList->AddCircleFilled(bb.Min + ImVec2(g.Style.FramePadding.x + line_height*0.5f, line_height*0.5f), bullet_size, window->Color(ImGuiCol_Text)); + RenderText(bb.Min+ImVec2(window->FontSize()+g.Style.FramePadding.x*2,0), text_begin, text_end); } bool TreeNode(const char* str_id, const char* fmt, ...) { - static char buf[1024]; - va_list args; - va_start(args, fmt); - ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - va_end(args); + static char buf[1024]; + va_list args; + va_start(args, fmt); + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + va_end(args); - if (!str_id || !str_id[0]) - str_id = fmt; + if (!str_id || !str_id[0]) + str_id = fmt; - ImGui::PushID(str_id); - const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access - ImGui::PopID(); + ImGui::PushID(str_id); + const bool opened = ImGui::CollapsingHeader(buf, "", false); // do not add to the ID so that TreeNodeSetOpen can access + ImGui::PopID(); - if (opened) - ImGui::TreePush(str_id); + if (opened) + ImGui::TreePush(str_id); - return opened; + return opened; } bool TreeNode(const void* ptr_id, const char* fmt, ...) { - static char buf[1024]; - va_list args; - va_start(args, fmt); - ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); - va_end(args); + static char buf[1024]; + va_list args; + va_start(args, fmt); + ImFormatStringV(buf, IM_ARRAYSIZE(buf), fmt, args); + va_end(args); - if (!ptr_id) - ptr_id = fmt; + if (!ptr_id) + ptr_id = fmt; - ImGui::PushID(ptr_id); - const bool opened = ImGui::CollapsingHeader(buf, "", false); - ImGui::PopID(); + ImGui::PushID(ptr_id); + const bool opened = ImGui::CollapsingHeader(buf, "", false); + ImGui::PopID(); - if (opened) - ImGui::TreePush(ptr_id); + if (opened) + ImGui::TreePush(ptr_id); - return opened; + return opened; } bool TreeNode(const char* str_label_id) { - return TreeNode(str_label_id, "%s", str_label_id); + return TreeNode(str_label_id, "%s", str_label_id); } void OpenNextNode(bool open) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.OpenNextNode = open ? 1 : 0; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.OpenNextNode = open ? 1 : 0; } void PushID(const char* str_id) { - ImGuiWindow* window = GetCurrentWindow(); - window->IDStack.push_back(window->GetID(str_id)); + ImGuiWindow* window = GetCurrentWindow(); + window->IDStack.push_back(window->GetID(str_id)); } void PushID(const void* ptr_id) { - ImGuiWindow* window = GetCurrentWindow(); - window->IDStack.push_back(window->GetID(ptr_id)); + ImGuiWindow* window = GetCurrentWindow(); + window->IDStack.push_back(window->GetID(ptr_id)); } void PushID(int int_id) { - const void* ptr_id = (void*)(intptr_t)int_id; - ImGuiWindow* window = GetCurrentWindow(); - window->IDStack.push_back(window->GetID(ptr_id)); + const void* ptr_id = (void*)(intptr_t)int_id; + ImGuiWindow* window = GetCurrentWindow(); + window->IDStack.push_back(window->GetID(ptr_id)); } void PopID() { - ImGuiWindow* window = GetCurrentWindow(); - window->IDStack.pop_back(); + ImGuiWindow* window = GetCurrentWindow(); + window->IDStack.pop_back(); } // NB: only call right after InputText because we are using its InitialValue storage static void ApplyNumericalTextInput(const char* buf, float *v) { - while (*buf == ' ' || *buf == '\t') - buf++; + while (*buf == ' ' || *buf == '\t') + buf++; - // We don't support '-' op because it would conflict with inputing negative value. - // Instead you can use +-100 to subtract from an existing value - char op = buf[0]; - if (op == '+' || op == '*' || op == '/') - { - buf++; - while (*buf == ' ' || *buf == '\t') - buf++; - } - else - { - op = 0; - } - if (!buf[0]) - return; + // We don't support '-' op because it would conflict with inputing negative value. + // Instead you can use +-100 to subtract from an existing value + char op = buf[0]; + if (op == '+' || op == '*' || op == '/') + { + buf++; + while (*buf == ' ' || *buf == '\t') + buf++; + } + else + { + op = 0; + } + if (!buf[0]) + return; - float ref_v = *v; - if (op) - if (sscanf(GImGui.InputTextState.InitialText, "%f", &ref_v) < 1) - return; + float ref_v = *v; + if (op) + if (sscanf(GImGui.InputTextState.InitialText, "%f", &ref_v) < 1) + return; - float op_v = 0.0f; - if (sscanf(buf, "%f", &op_v) < 1) - return; + float op_v = 0.0f; + if (sscanf(buf, "%f", &op_v) < 1) + return; - if (op == '+') - *v = ref_v + op_v; - else if (op == '*') - *v = ref_v * op_v; - else if (op == '/') - { - if (op_v == 0.0f) - return; - *v = ref_v / op_v; - } - else - *v = op_v; + if (op == '+') + *v = ref_v + op_v; + else if (op == '*') + *v = ref_v * op_v; + else if (op == '/') + { + if (op_v == 0.0f) + return; + *v = ref_v / op_v; + } + else + *v = op_v; } // use power!=1.0 for logarithmic sliders bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); - const float w = window->DC.ItemWidth.back(); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w = window->DC.ItemWidth.back(); - if (!display_format) - display_format = "%.3f"; + if (!display_format) + display_format = "%.3f"; - // Dodgily parse display precision back from the display format - int decimal_precision = 3; - if (const char* p = strchr(display_format, '%')) - { - p++; - while (*p >= '0' && *p <= '9') - p++; - if (*p == '.') - { - decimal_precision = atoi(p+1); - if (decimal_precision < 0 || decimal_precision > 10) - decimal_precision = 3; - } - } + // Dodgily parse display precision back from the display format + int decimal_precision = 3; + if (const char* p = strchr(display_format, '%')) + { + p++; + while (*p >= '0' && *p <= '9') + p++; + if (*p == '.') + { + decimal_precision = atoi(p+1); + if (decimal_precision < 0 || decimal_precision > 10) + decimal_precision = 3; + } + } - const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); + const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); - const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); + const ImVec2 text_size = CalcTextSize(label); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); + const ImGuiAabb slider_bb(frame_bb.Min+g.Style.FramePadding, frame_bb.Max-g.Style.FramePadding); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); - if (IsClipped(slider_bb)) - { - // NB- we don't use ClipAdvance() because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself - ItemSize(bb); - return false; - } + if (IsClipped(slider_bb)) + { + // NB- we don't use ClipAdvance() because we don't want to submit ItemSize() because we may change into a text edit later which may submit an ItemSize itself + ItemSize(bb); + return false; + } - const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX; + const bool is_unbound = v_min == -FLT_MAX || v_min == FLT_MAX || v_max == -FLT_MAX || v_max == FLT_MAX; - const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision? - float grab_size_in_pixels; - if (decimal_precision > 0 || is_unbound) - grab_size_in_pixels = 10.0f; - else - grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders - const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels; - const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f; - const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f; + const float grab_size_in_units = 1.0f; // In 'v' units. Probably needs to be parametrized, based on a 'v_step' value? decimal precision? + float grab_size_in_pixels; + if (decimal_precision > 0 || is_unbound) + grab_size_in_pixels = 10.0f; + else + grab_size_in_pixels = ImMax(grab_size_in_units * (w / (v_max-v_min+1.0f)), 8.0f); // Integer sliders + const float slider_effective_w = slider_bb.GetWidth() - grab_size_in_pixels; + const float slider_effective_x1 = slider_bb.Min.x + grab_size_in_pixels*0.5f; + const float slider_effective_x2 = slider_bb.Max.x - grab_size_in_pixels*0.5f; - // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symetric around 0.0 - float linear_zero_pos = 0.0f; // 0.0->1.0f - if (!is_unbound) - { - if (v_min * v_max < 0.0f) - { - // Different sign - const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power); - const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power); - linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); - } - else - { - // Same sign - linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f; - } - } + // For logarithmic sliders that cross over sign boundary we want the exponential increase to be symetric around 0.0 + float linear_zero_pos = 0.0f; // 0.0->1.0f + if (!is_unbound) + { + if (v_min * v_max < 0.0f) + { + // Different sign + const float linear_dist_min_to_0 = powf(fabsf(0.0f - v_min), 1.0f/power); + const float linear_dist_max_to_0 = powf(fabsf(v_max - 0.0f), 1.0f/power); + linear_zero_pos = linear_dist_min_to_0 / (linear_dist_min_to_0+linear_dist_max_to_0); + } + else + { + // Same sign + linear_zero_pos = v_min < 0.0f ? 1.0f : 0.0f; + } + } - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(slider_bb); - if (hovered) - g.HoveredId = id; + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(slider_bb); + if (hovered) + g.HoveredId = id; - bool start_text_input = false; - if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) - { - g.ActiveId = id; + bool start_text_input = false; + if (tab_focus_requested || (hovered && g.IO.MouseClicked[0])) + { + g.ActiveId = id; - const bool is_ctrl_down = g.IO.KeyCtrl; - if (tab_focus_requested || is_ctrl_down || is_unbound) - { - start_text_input = true; - g.SliderAsInputTextId = 0; - } - } + const bool is_ctrl_down = g.IO.KeyCtrl; + if (tab_focus_requested || is_ctrl_down || is_unbound) + { + start_text_input = true; + g.SliderAsInputTextId = 0; + } + } - // Tabbing thru or CTRL-clicking through slider turns into an input box - bool value_changed = false; - if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId)) - { - char text_buf[64]; - ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v); + // Tabbing thru or CTRL-clicking through slider turns into an input box + bool value_changed = false; + if (start_text_input || (g.ActiveId == id && id == g.SliderAsInputTextId)) + { + char text_buf[64]; + ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), "%.*f", decimal_precision, *v); - g.ActiveId = g.SliderAsInputTextId; - g.HoveredId = 0; - window->FocusItemUnregister(); // Our replacement slider will override the focus ID (that we needed to declare previously to allow for a TAB focus to happen before we got selected) - value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_AlignCenter); - if (g.SliderAsInputTextId == 0) - { - // First frame - IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both) - g.SliderAsInputTextId = g.ActiveId; - g.ActiveId = id; - g.HoveredId = id; - } - else - { - if (g.ActiveId == g.SliderAsInputTextId) - g.ActiveId = id; - else - g.ActiveId = g.SliderAsInputTextId = 0; - } - if (value_changed) - { - ApplyNumericalTextInput(text_buf, v); - } - return value_changed; - } + g.ActiveId = g.SliderAsInputTextId; + g.HoveredId = 0; + window->FocusItemUnregister(); // Our replacement slider will override the focus ID (that we needed to declare previously to allow for a TAB focus to happen before we got selected) + value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_AlignCenter); + if (g.SliderAsInputTextId == 0) + { + // First frame + IM_ASSERT(g.ActiveId == id); // InputText ID should match the Slider ID (else we'd need to store them both) + g.SliderAsInputTextId = g.ActiveId; + g.ActiveId = id; + g.HoveredId = id; + } + else + { + if (g.ActiveId == g.SliderAsInputTextId) + g.ActiveId = id; + else + g.ActiveId = g.SliderAsInputTextId = 0; + } + if (value_changed) + { + ApplyNumericalTextInput(text_buf, v); + } + return value_changed; + } - ItemSize(bb); - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); + ItemSize(bb); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); - if (g.ActiveId == id) - { - if (g.IO.MouseDown[0]) - { - if (!is_unbound) - { - const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f); - - // Linear slider - //float new_value = ImLerp(v_min, v_max, normalized_pos); + if (g.ActiveId == id) + { + if (g.IO.MouseDown[0]) + { + if (!is_unbound) + { + const float normalized_pos = ImClamp((g.IO.MousePos.x - slider_effective_x1) / slider_effective_w, 0.0f, 1.0f); + + // Linear slider + //float new_value = ImLerp(v_min, v_max, normalized_pos); - // Account for logarithmic scale on both sides of the zero - float new_value; - if (normalized_pos < linear_zero_pos) - { - // Negative: rescale to the negative range before powering - float a = 1.0f - (normalized_pos / linear_zero_pos); - a = powf(a, power); - new_value = ImLerp(ImMin(v_max,0.f), v_min, a); - } - else - { - // Positive: rescale to the positive range before powering - float a; - if (fabsf(linear_zero_pos - 1.0f) > 1.e-6) - a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos); - else - a = normalized_pos; - a = powf(a, power); - new_value = ImLerp(ImMax(v_min,0.0f), v_max, a); - } + // Account for logarithmic scale on both sides of the zero + float new_value; + if (normalized_pos < linear_zero_pos) + { + // Negative: rescale to the negative range before powering + float a = 1.0f - (normalized_pos / linear_zero_pos); + a = powf(a, power); + new_value = ImLerp(ImMin(v_max,0.f), v_min, a); + } + else + { + // Positive: rescale to the positive range before powering + float a; + if (fabsf(linear_zero_pos - 1.0f) > 1.e-6) + a = (normalized_pos - linear_zero_pos) / (1.0f - linear_zero_pos); + else + a = normalized_pos; + a = powf(a, power); + new_value = ImLerp(ImMax(v_min,0.0f), v_max, a); + } - // Round past decimal precision - // 0: 1 - // 1: 0.1 - // 2: 0.01 - // etc.. - // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 - const float min_step = 1.0f / powf(10.0f, (float)decimal_precision); - const float remainder = fmodf(new_value, min_step); - if (remainder <= min_step*0.5f) - new_value -= remainder; - else - new_value += (min_step - remainder); + // Round past decimal precision + // 0: 1 + // 1: 0.1 + // 2: 0.01 + // etc.. + // So when our value is 1.99999 with a precision of 0.001 we'll end up rounding to 2.0 + const float min_step = 1.0f / powf(10.0f, (float)decimal_precision); + const float remainder = fmodf(new_value, min_step); + if (remainder <= min_step*0.5f) + new_value -= remainder; + else + new_value += (min_step - remainder); - if (*v != new_value) - { - *v = new_value; - value_changed = true; - } - } - } - else - { - g.ActiveId = 0; - } - } + if (*v != new_value) + { + *v = new_value; + value_changed = true; + } + } + } + else + { + g.ActiveId = 0; + } + } - if (!is_unbound) - { - // Linear slider - // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min); + if (!is_unbound) + { + // Linear slider + // const float grab_t = (ImClamp(*v, v_min, v_max) - v_min) / (v_max - v_min); - // Calculate slider grab positioning - float grab_t; - float v_clamped = ImClamp(*v, v_min, v_max); - if (v_clamped < 0.0f) - { - float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min); - grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos; - } - else - { - float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); - grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); - } + // Calculate slider grab positioning + float grab_t; + float v_clamped = ImClamp(*v, v_min, v_max); + if (v_clamped < 0.0f) + { + float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min); + grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos; + } + else + { + float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); + grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); + } - // Draw - const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t); - const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-1.0f)); - window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab)); - } + // Draw + const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t); + const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-1.0f)); + window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab)); + } - char value_buf[64]; - ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); - RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); + char value_buf[64]; + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v); + RenderText(ImVec2(slider_bb.GetCenter().x-CalcTextSize(value_buf).x*0.5f, frame_bb.Min.y + style.FramePadding.y), value_buf); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, slider_bb.Min.y), label); - return value_changed; + return value_changed; } bool SliderAngle(const char* label, float* v, float v_degrees_min, float v_degrees_max) { - float v_deg = *v * 360.0f / (2*PI); - bool changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f); - *v = v_deg * (2*PI) / 360.0f; - return changed; + float v_deg = *v * 360.0f / (2*PI); + bool changed = ImGui::SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f); + *v = v_deg * (2*PI) / 360.0f; + return changed; } bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format) { - if (!display_format) - display_format = "%.0f"; - float v_f = (float)*v; - bool changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); - *v = (int)v_f; - return changed; + if (!display_format) + display_format = "%.0f"; + float v_f = (float)*v; + bool changed = ImGui::SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f); + *v = (int)v_f; + return changed; } static bool SliderFloatN(const char* label, float v[3], int components, float v_min, float v_max, const char* display_format, float power) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const float w_full = window->DC.ItemWidth.back(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1))); + const ImGuiStyle& style = g.Style; + const float w_full = window->DC.ItemWidth.back(); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x)*(components-1))); - bool value_changed = false; - ImGui::PushID(label); - ImGui::PushItemWidth(w_item_one); - for (int i = 0; i < components; i++) - { - ImGui::PushID(i); - if (i + 1 == components) - { - ImGui::PopItemWidth(); - ImGui::PushItemWidth(w_item_last); - } - value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power); - ImGui::SameLine(0, 0); - ImGui::PopID(); - } - ImGui::PopItemWidth(); - ImGui::PopID(); + bool value_changed = false; + ImGui::PushID(label); + ImGui::PushItemWidth(w_item_one); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + if (i + 1 == components) + { + ImGui::PopItemWidth(); + ImGui::PushItemWidth(w_item_last); + } + value_changed |= ImGui::SliderFloat("##v", &v[i], v_min, v_max, display_format, power); + ImGui::SameLine(0, 0); + ImGui::PopID(); + } + ImGui::PopItemWidth(); + ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - return value_changed; + return value_changed; } bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power) { - return SliderFloatN(label, v, 2, v_min, v_max, display_format, power); + return SliderFloatN(label, v, 2, v_min, v_max, display_format, power); } bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power) { - return SliderFloatN(label, v, 3, v_min, v_max, display_format, power); + return SliderFloatN(label, v, 3, v_min, v_max, display_format, power); } bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power) { - return SliderFloatN(label, v, 4, v_min, v_max, display_format, power); + return SliderFloatN(label, v, 4, v_min, v_max, display_format, power); } // Enum for ImGui::Plot() enum ImGuiPlotType { - ImGuiPlotType_Lines, - ImGuiPlotType_Histogram, + ImGuiPlotType_Lines, + ImGuiPlotType_Histogram, }; static float PlotGetValue(const float* values, size_t stride, int idx) { - float v = *(float*)((unsigned char*)values + idx * stride); - return v; + float v = *(float*)((unsigned char*)values + idx * stride); + return v; } static void Plot(ImGuiPlotType plot_type, const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - const ImGuiStyle& style = g.Style; + const ImGuiStyle& style = g.Style; - const ImVec2 text_size = CalcTextSize(label); - if (graph_size.x == 0) - graph_size.x = window->DC.ItemWidth.back(); - if (graph_size.y == 0) - graph_size.y = text_size.y; + const ImVec2 text_size = CalcTextSize(label); + if (graph_size.x == 0) + graph_size.x = window->DC.ItemWidth.back(); + if (graph_size.y == 0) + graph_size.y = text_size.y; - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f); - const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); - ItemSize(bb); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(graph_size.x, graph_size.y) + style.FramePadding*2.0f); + const ImGuiAabb graph_bb(frame_bb.Min + style.FramePadding, frame_bb.Max - style.FramePadding); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); + ItemSize(bb); - if (ClipAdvance(bb)) - return; + if (ClipAdvance(bb)) + return; - // Determine scale if not specified - if (scale_min == FLT_MAX || scale_max == FLT_MAX) - { - float v_min = FLT_MAX; - float v_max = -FLT_MAX; - for (int i = 0; i < values_count; i++) - { - const float v = PlotGetValue(values, stride, i); - v_min = ImMin(v_min, v); - v_max = ImMax(v_max, v); - } - if (scale_min == FLT_MAX) - scale_min = v_min; - if (scale_max == FLT_MAX) - scale_max = v_max; - } + // Determine scale if not specified + if (scale_min == FLT_MAX || scale_max == FLT_MAX) + { + float v_min = FLT_MAX; + float v_max = -FLT_MAX; + for (int i = 0; i < values_count; i++) + { + const float v = PlotGetValue(values, stride, i); + v_min = ImMin(v_min, v); + v_max = ImMax(v_max, v); + } + if (scale_min == FLT_MAX) + scale_min = v_min; + if (scale_max == FLT_MAX) + scale_max = v_max; + } - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); - int res_w = ImMin((int)graph_size.x, values_count); - if (plot_type == ImGuiPlotType_Lines) - res_w -= 1; + int res_w = ImMin((int)graph_size.x, values_count); + if (plot_type == ImGuiPlotType_Lines) + res_w -= 1; - // Tooltip on hover - int v_hovered = -1; - if (IsMouseHoveringBox(graph_bb)) - { - const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f); - const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); - IM_ASSERT(v_idx >= 0 && v_idx < values_count); - - const float v0 = PlotGetValue(values, stride, (v_idx + values_offset) % values_count); - const float v1 = PlotGetValue(values, stride, (v_idx + 1 + values_offset) % values_count); - if (plot_type == ImGuiPlotType_Lines) - ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1); - else if (plot_type == ImGuiPlotType_Histogram) - ImGui::SetTooltip("%d: %8.4g", v_idx, v0); - v_hovered = v_idx; - } + // Tooltip on hover + int v_hovered = -1; + if (IsMouseHoveringBox(graph_bb)) + { + const float t = ImClamp((g.IO.MousePos.x - graph_bb.Min.x) / (graph_bb.Max.x - graph_bb.Min.x), 0.0f, 0.9999f); + const int v_idx = (int)(t * (values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0))); + IM_ASSERT(v_idx >= 0 && v_idx < values_count); + + const float v0 = PlotGetValue(values, stride, (v_idx + values_offset) % values_count); + const float v1 = PlotGetValue(values, stride, (v_idx + 1 + values_offset) % values_count); + if (plot_type == ImGuiPlotType_Lines) + ImGui::SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1); + else if (plot_type == ImGuiPlotType_Histogram) + ImGui::SetTooltip("%d: %8.4g", v_idx, v0); + v_hovered = v_idx; + } - const float t_step = 1.0f / (float)res_w; + const float t_step = 1.0f / (float)res_w; - float v0 = PlotGetValue(values, stride, (0 + values_offset) % values_count); - float t0 = 0.0f; - ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) ); + float v0 = PlotGetValue(values, stride, (0 + values_offset) % values_count); + float t0 = 0.0f; + ImVec2 p0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) ); - const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram); - const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered); + const ImU32 col_base = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram); + const ImU32 col_hovered = window->Color((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered); - for (int n = 0; n < res_w; n++) - { - const float t1 = t0 + t_step; - const int v_idx = (int)(t0 * values_count); - IM_ASSERT(v_idx >= 0 && v_idx < values_count); - const float v1 = PlotGetValue(values, stride, (v_idx + values_offset + 1) % values_count); - const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) ); + for (int n = 0; n < res_w; n++) + { + const float t1 = t0 + t_step; + const int v_idx = (int)(t0 * values_count); + IM_ASSERT(v_idx >= 0 && v_idx < values_count); + const float v1 = PlotGetValue(values, stride, (v_idx + values_offset + 1) % values_count); + const ImVec2 p1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) ); - // NB: draw calls are merged into ones - if (plot_type == ImGuiPlotType_Lines) - window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base); - else if (plot_type == ImGuiPlotType_Histogram) - window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base); + // NB: draw calls are merged into ones + if (plot_type == ImGuiPlotType_Lines) + window->DrawList->AddLine(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, p1), v_hovered == v_idx ? col_hovered : col_base); + else if (plot_type == ImGuiPlotType_Histogram) + window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base); - v0 = v1; - t0 = t1; - p0 = p1; - } + v0 = v1; + t0 = t1; + p0 = p1; + } - // Overlay last value - if (overlay_text) - RenderText(ImVec2(graph_bb.GetCenter().x-CalcTextSize(overlay_text).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text); + // Overlay last value + if (overlay_text) + RenderText(ImVec2(graph_bb.GetCenter().x-CalcTextSize(overlay_text).x*0.5f, frame_bb.Min.y + style.FramePadding.y), overlay_text); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, graph_bb.Min.y), label); } void PlotLines(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride) { - ImGui::Plot(ImGuiPlotType_Lines, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); + ImGui::Plot(ImGuiPlotType_Lines, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); } void PlotHistogram(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, size_t stride) { - ImGui::Plot(ImGuiPlotType_Histogram, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); + ImGui::Plot(ImGuiPlotType_Histogram, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); } void Checkbox(const char* label, bool* v) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); - ItemSize(check_bb); - SameLine(0, (int)g.Style.ItemInnerSpacing.x); + const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2, text_size.y + style.FramePadding.y*2)); + ItemSize(check_bb); + SameLine(0, (int)g.Style.ItemInnerSpacing.x); - const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0,style.FramePadding.y), window->DC.CursorPos + ImVec2(0,style.FramePadding.y) + text_size); + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); + const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); - if (ClipAdvance(total_bb)) - return; + if (ClipAdvance(total_bb)) + return; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); - const bool pressed = hovered && g.IO.MouseClicked[0]; - if (hovered) - g.HoveredId = id; - if (pressed) - { - *v = !(*v); - g.ActiveId = 0; // Clear focus - } + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); + const bool pressed = hovered && g.IO.MouseClicked[0]; + if (hovered) + g.HoveredId = id; + if (pressed) + { + *v = !(*v); + g.ActiveId = 0; // Clear focus + } - RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); - if (*v) - { - window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive)); - } + RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); + if (*v) + { + window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive)); + } - if (g.LogEnabled) - LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]"); - RenderText(text_bb.GetTL(), label); + if (g.LogEnabled) + LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]"); + RenderText(text_bb.GetTL(), label); } void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) { - bool v = (*flags & flags_value) ? true : false; - ImGui::Checkbox(label, &v); - if (v) - *flags |= flags_value; - else - *flags &= ~flags_value; + bool v = (*flags & flags_value) ? true : false; + ImGui::Checkbox(label, &v); + if (v) + *flags |= flags_value; + else + *flags &= ~flags_value; } bool RadioButton(const char* label, bool active) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); + const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1)); - ItemSize(check_bb); - SameLine(0, (int)style.ItemInnerSpacing.x); + const ImGuiAabb check_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(text_size.y + style.FramePadding.y*2-1, text_size.y + style.FramePadding.y*2-1)); + ItemSize(check_bb); + SameLine(0, (int)style.ItemInnerSpacing.x); - const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size); - ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); - const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); + const ImGuiAabb text_bb(window->DC.CursorPos + ImVec2(0, style.FramePadding.y), window->DC.CursorPos + ImVec2(0, style.FramePadding.y) + text_size); + ItemSize(ImVec2(text_bb.GetWidth(), check_bb.GetHeight())); + const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); - if (ClipAdvance(total_bb)) - return false; + if (ClipAdvance(total_bb)) + return false; - ImVec2 center = check_bb.GetCenter(); - center.x = (float)(int)center.x + 0.5f; - center.y = (float)(int)center.y + 0.5f; - const float radius = check_bb.GetHeight() * 0.5f; + ImVec2 center = check_bb.GetCenter(); + center.x = (float)(int)center.x + 0.5f; + center.y = (float)(int)center.y + 0.5f; + const float radius = check_bb.GetHeight() * 0.5f; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); - const bool pressed = hovered && g.IO.MouseClicked[0]; - if (hovered) - g.HoveredId = id; + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); + const bool pressed = hovered && g.IO.MouseClicked[0]; + if (hovered) + g.HoveredId = id; - window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); - if (active) - window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16); + window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); + if (active) + window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16); - if (window->Flags & ImGuiWindowFlags_ShowBorders) - { - window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16); - window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16); - } + if (window->Flags & ImGuiWindowFlags_ShowBorders) + { + window->DrawList->AddCircle(center+ImVec2(1,1), radius, window->Color(ImGuiCol_BorderShadow), 16); + window->DrawList->AddCircle(center, radius, window->Color(ImGuiCol_Border), 16); + } - RenderText(text_bb.GetTL(), label); + RenderText(text_bb.GetTL(), label); - return pressed; + return pressed; } bool RadioButton(const char* label, int* v, int v_button) { - const bool pressed = ImGui::RadioButton(label, *v == v_button); - if (pressed) - { - *v = v_button; - } - return pressed; + const bool pressed = ImGui::RadioButton(label, *v == v_button); + if (pressed) + { + *v = v_button; + } + return pressed; } }; // namespace ImGui // Wrapper for stb_textedit.h to edit text (our wrapper is for: statically sized buffer, single-line, ASCII, fixed-width font) -int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)strlen(obj->Text); } -char STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return (char)obj->Text[idx]; } -float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSize(obj->FontSize, 0, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; } -char STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : (char)key; } -char STB_TEXTEDIT_NEWLINE = '\n'; -void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx) +int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return (int)strlen(obj->Text); } +char STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return (char)obj->Text[idx]; } +float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { (void)line_start_idx; return obj->Font->CalcTextSize(obj->FontSize, 0, &obj->Text[char_idx], &obj->Text[char_idx]+1, NULL).x; } +char STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : (char)key; } +char STB_TEXTEDIT_NEWLINE = '\n'; +void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx) { - const char* text_remaining = NULL; - const ImVec2 size = obj->Font->CalcTextSize(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining); - r->x0 = 0.0f; - r->x1 = size.x; - r->baseline_y_delta = size.y; - r->ymin = 0.0f; - r->ymax = size.y; - r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx)); + const char* text_remaining = NULL; + const ImVec2 size = obj->Font->CalcTextSize(obj->FontSize, FLT_MAX, obj->Text + line_start_idx, NULL, &text_remaining); + r->x0 = 0.0f; + r->x1 = size.x; + r->baseline_y_delta = size.y; + r->ymin = 0.0f; + r->ymax = size.y; + r->num_chars = (int)(text_remaining - (obj->Text + line_start_idx)); } -static bool is_white(char c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; } -static bool is_separator(char c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; } +static bool is_white(char c) { return c==0 || c==' ' || c=='\t' || c=='\r' || c=='\n'; } +static bool is_separator(char c) { return c==',' || c==';' || c=='(' || c==')' || c=='{' || c=='}' || c=='[' || c==']' || c=='|'; } -#define STB_TEXTEDIT_IS_SPACE(c) (is_white(c) || is_separator(c)) -void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) { char* dst = obj->Text+idx; const char* src = obj->Text+idx+n; while (char c = *src++) *dst++ = c; *dst = '\0'; } +#define STB_TEXTEDIT_IS_SPACE(c) (is_white(c) || is_separator(c)) +void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) { char* dst = obj->Text+idx; const char* src = obj->Text+idx+n; while (char c = *src++) *dst++ = c; *dst = '\0'; } -bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_len) +bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_len) { - char* buf_end = obj->Text + obj->BufSize; - const int text_len = (int)strlen(obj->Text); + char* buf_end = obj->Text + obj->BufSize; + const int text_len = (int)strlen(obj->Text); - if (new_text_len > buf_end - (obj->Text + text_len + 1)) - return false; + if (new_text_len > buf_end - (obj->Text + text_len + 1)) + return false; - memmove(obj->Text + idx + new_text_len, obj->Text + idx, text_len - idx); - memcpy(obj->Text + idx, new_text, new_text_len); - obj->Text[text_len + new_text_len] = 0; + memmove(obj->Text + idx + new_text_len, obj->Text + idx, text_len - idx); + memcpy(obj->Text + idx, new_text, new_text_len); + obj->Text[text_len + new_text_len] = 0; - return true; + return true; } enum { - STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left - STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right - STB_TEXTEDIT_K_UP, // keyboard input to move cursor up - STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down - STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line - STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line - STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text - STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text - STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor - STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor - STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo - STB_TEXTEDIT_K_REDO, // keyboard input to perform redo - STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word - STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word - STB_TEXTEDIT_K_SHIFT = 1 << 17, + STB_TEXTEDIT_K_LEFT = 1 << 16, // keyboard input to move cursor left + STB_TEXTEDIT_K_RIGHT, // keyboard input to move cursor right + STB_TEXTEDIT_K_UP, // keyboard input to move cursor up + STB_TEXTEDIT_K_DOWN, // keyboard input to move cursor down + STB_TEXTEDIT_K_LINESTART, // keyboard input to move cursor to start of line + STB_TEXTEDIT_K_LINEEND, // keyboard input to move cursor to end of line + STB_TEXTEDIT_K_TEXTSTART, // keyboard input to move cursor to start of text + STB_TEXTEDIT_K_TEXTEND, // keyboard input to move cursor to end of text + STB_TEXTEDIT_K_DELETE, // keyboard input to delete selection or character under cursor + STB_TEXTEDIT_K_BACKSPACE, // keyboard input to delete selection or character left of cursor + STB_TEXTEDIT_K_UNDO, // keyboard input to perform undo + STB_TEXTEDIT_K_REDO, // keyboard input to perform redo + STB_TEXTEDIT_K_WORDLEFT, // keyboard input to move cursor left one word + STB_TEXTEDIT_K_WORDRIGHT, // keyboard input to move cursor right one word + STB_TEXTEDIT_K_SHIFT = 1 << 17, }; #define STB_TEXTEDIT_IMPLEMENTATION @@ -3645,67 +3645,67 @@ enum void ImGuiTextEditState::OnKeyboardPressed(int key) { - stb_textedit_key(this, &StbState, key); - CursorAnimReset(); + stb_textedit_key(this, &StbState, key); + CursorAnimReset(); } void ImGuiTextEditState::UpdateScrollOffset() { - // Scroll in chunks of quarter width - const float scroll_x_increment = Width * 0.25f; - const float cursor_offset_x = Font->CalcTextSize(FontSize, 0, Text, Text+StbState.cursor, NULL).x; - if (ScrollX > cursor_offset_x) - ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment); - else if (ScrollX < cursor_offset_x - Width) - ScrollX = cursor_offset_x - Width + scroll_x_increment; + // Scroll in chunks of quarter width + const float scroll_x_increment = Width * 0.25f; + const float cursor_offset_x = Font->CalcTextSize(FontSize, 0, Text, Text+StbState.cursor, NULL).x; + if (ScrollX > cursor_offset_x) + ScrollX = ImMax(0.0f, cursor_offset_x - scroll_x_increment); + else if (ScrollX < cursor_offset_x - Width) + ScrollX = cursor_offset_x - Width + scroll_x_increment; } ImVec2 ImGuiTextEditState::CalcDisplayOffsetFromCharIdx(int i) const { - const char* text_start = GetTextPointerClipped(Font, FontSize, Text, ScrollX, NULL); - const char* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display - IM_ASSERT(text_end >= text_start); + const char* text_start = GetTextPointerClipped(Font, FontSize, Text, ScrollX, NULL); + const char* text_end = (Text+i >= text_start) ? Text+i : text_start; // Clip if requested character is outside of display + IM_ASSERT(text_end >= text_start); - const ImVec2 offset = Font->CalcTextSize(FontSize, Width, text_start, text_end, NULL); - return offset; + const ImVec2 offset = Font->CalcTextSize(FontSize, Width, text_start, text_end, NULL); + return offset; } // [Static] -const char* ImGuiTextEditState::GetTextPointerClipped(ImFont font, float font_size, const char* text, float width, ImVec2* out_text_size) +const char* ImGuiTextEditState::GetTextPointerClipped(ImFont font, float font_size, const char* text, float width, ImVec2* out_text_size) { - if (width <= 0.0f) - return text; + if (width <= 0.0f) + return text; - const char* text_clipped_end = NULL; - const ImVec2 text_size = font->CalcTextSize(font_size, width, text, NULL, &text_clipped_end); - if (out_text_size) - *out_text_size = text_size; - return text_clipped_end; + const char* text_clipped_end = NULL; + const ImVec2 text_size = font->CalcTextSize(font_size, width, text, NULL, &text_clipped_end); + if (out_text_size) + *out_text_size = text_size; + return text_clipped_end; } // [Static] void ImGuiTextEditState::RenderTextScrolledClipped(ImFont font, float font_size, const char* buf, ImVec2 pos, float width, float scroll_x) { - // NB- We start drawing at character boundary - ImVec2 text_size; - const char* text_start = GetTextPointerClipped(font, font_size, buf, scroll_x, NULL); - const char* text_end = GetTextPointerClipped(font, font_size, text_start, width, &text_size); + // NB- We start drawing at character boundary + ImVec2 text_size; + const char* text_start = GetTextPointerClipped(font, font_size, buf, scroll_x, NULL); + const char* text_end = GetTextPointerClipped(font, font_size, text_start, width, &text_size); - // Draw a little clip symbol if we've got text on either left or right of the box - const char symbol_c = '~'; - const float symbol_w = font_size*0.40f; // FIXME: compute correct width - const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f; - const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f; + // Draw a little clip symbol if we've got text on either left or right of the box + const char symbol_c = '~'; + const float symbol_w = font_size*0.40f; // FIXME: compute correct width + const float clip_begin = (text_start > buf && text_start < text_end) ? symbol_w : 0.0f; + const float clip_end = (text_end[0] != '\0' && text_end > text_start) ? symbol_w : 0.0f; - // Draw text - ImGui::RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);//, &text_params_with_clipping); + // Draw text + ImGui::RenderText(pos+ImVec2(clip_begin,0), text_start+(clip_begin>0.0f?1:0), text_end-(clip_end>0.0f?1:0), false);//, &text_params_with_clipping); - // Draw the clip symbol - const char s[2] = {symbol_c,'\0'}; - if (clip_begin > 0.0f) - ImGui::RenderText(pos, s); - if (clip_end > 0.0f) - ImGui::RenderText(pos+ImVec2(width-clip_end,0.0f), s); + // Draw the clip symbol + const char s[2] = {symbol_c,'\0'}; + if (clip_begin > 0.0f) + ImGui::RenderText(pos, s); + if (clip_end > 0.0f) + ImGui::RenderText(pos+ImVec2(width-clip_end,0.0f), s); } namespace ImGui @@ -3713,1013 +3713,1013 @@ namespace ImGui bool InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const float w = window->DC.ItemWidth.back(); - const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); + const ImGuiStyle& style = g.Style; + const float w = window->DC.ItemWidth.back(); + const ImVec2 text_size = CalcTextSize(label); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); - ImGui::PushID(label); - const float button_sz = window->FontSize(); - if (step > 0.0f) - ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2)); + ImGui::PushID(label); + const float button_sz = window->FontSize(); + if (step > 0.0f) + ImGui::PushItemWidth(ImMax(1.0f, window->DC.ItemWidth.back() - (button_sz+g.Style.FramePadding.x*2.0f+g.Style.ItemInnerSpacing.x)*2)); - char buf[64]; - if (decimal_precision < 0) - ImFormatString(buf, IM_ARRAYSIZE(buf), "%f", *v); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits? - else - ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v); - bool value_changed = false; - if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AlignCenter|ImGuiInputTextFlags_AutoSelectAll)) - { - ApplyNumericalTextInput(buf, v); - value_changed = true; - } + char buf[64]; + if (decimal_precision < 0) + ImFormatString(buf, IM_ARRAYSIZE(buf), "%f", *v); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits? + else + ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v); + bool value_changed = false; + if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AlignCenter|ImGuiInputTextFlags_AutoSelectAll)) + { + ApplyNumericalTextInput(buf, v); + value_changed = true; + } - if (step > 0.0f) - { - ImGui::PopItemWidth(); - ImGui::SameLine(0, 0); - if (ImGui::Button("-", ImVec2(button_sz,button_sz), true)) - { - *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; - value_changed = true; - } - ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); - if (ImGui::Button("+", ImVec2(button_sz,button_sz), true)) - { - *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; - value_changed = true; - } - } + if (step > 0.0f) + { + ImGui::PopItemWidth(); + ImGui::SameLine(0, 0); + if (ImGui::Button("-", ImVec2(button_sz,button_sz), true)) + { + *v -= g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; + value_changed = true; + } + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + if (ImGui::Button("+", ImVec2(button_sz,button_sz), true)) + { + *v += g.IO.KeyCtrl && step_fast > 0.0f ? step_fast : step; + value_changed = true; + } + } - ImGui::PopID(); + ImGui::PopID(); - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + g.Style.FramePadding.y), label); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + g.Style.FramePadding.y), label); - //ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); - //ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + //ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + //ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - return value_changed; + return value_changed; } bool InputInt(const char* label, int *v, int step, int step_fast) { - float f = (float)*v; - const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0); - *v = (int)f; - return value_changed; + float f = (float)*v; + const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0); + *v = (int)f; + return value_changed; } bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiIO& io = g.IO; - const ImGuiStyle& style = g.Style; + const ImGuiIO& io = g.IO; + const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); - const float w = window->DC.ItemWidth.back(); + const ImGuiID id = window->GetID(label); + const float w = window->DC.ItemWidth.back(); - const ImVec2 text_size = CalcTextSize(label); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); - ItemSize(bb); + const ImVec2 text_size = CalcTextSize(label); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(w, text_size.y) + style.FramePadding*2.0f); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x, 0.0f)); + ItemSize(bb); - if (ClipAdvance(frame_bb)) - return false; + if (ClipAdvance(frame_bb)) + return false; - // NB: we can only read/write if we are the active widget! - ImGuiTextEditState& edit_state = g.InputTextState; + // NB: we can only read/write if we are the active widget! + ImGuiTextEditState& edit_state = g.InputTextState; - const bool is_ctrl_down = io.KeyCtrl; - const bool is_shift_down = io.KeyShift; - const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); - //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported + const bool is_ctrl_down = io.KeyCtrl; + const bool is_shift_down = io.KeyShift; + const bool tab_focus_requested = window->FocusItemRegister(g.ActiveId == id); + //const bool align_center = (bool)(flags & ImGuiInputTextFlags_AlignCenter); // FIXME: Unsupported - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(frame_bb); - if (hovered) - g.HoveredId = id; + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(frame_bb); + if (hovered) + g.HoveredId = id; - bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0; - if (tab_focus_requested || (hovered && io.MouseClicked[0])) - { - if (g.ActiveId != id) - { - // Start edition - strcpy(edit_state.Text, buf); - strcpy(edit_state.InitialText, buf); - edit_state.ScrollX = 0.0f; - edit_state.Width = w; - stb_textedit_initialize_state(&edit_state.StbState, true); - edit_state.CursorAnimReset(); + bool select_all = (g.ActiveId != id) && (flags & ImGuiInputTextFlags_AutoSelectAll) != 0; + if (tab_focus_requested || (hovered && io.MouseClicked[0])) + { + if (g.ActiveId != id) + { + // Start edition + strcpy(edit_state.Text, buf); + strcpy(edit_state.InitialText, buf); + edit_state.ScrollX = 0.0f; + edit_state.Width = w; + stb_textedit_initialize_state(&edit_state.StbState, true); + edit_state.CursorAnimReset(); - if (tab_focus_requested || is_ctrl_down) - select_all = true; - } - g.ActiveId = id; - } - else if (io.MouseClicked[0]) - { - // Release focus when we click outside - if (g.ActiveId == id) - { - g.ActiveId = 0; - } - } + if (tab_focus_requested || is_ctrl_down) + select_all = true; + } + g.ActiveId = id; + } + else if (io.MouseClicked[0]) + { + // Release focus when we click outside + if (g.ActiveId == id) + { + g.ActiveId = 0; + } + } - bool value_changed = false; - bool cancel_edit = false; - if (g.ActiveId == id) - { - edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text); - edit_state.Font = window->Font(); - edit_state.FontSize = window->FontSize(); - - const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x; - const float my = window->FontSize()*0.5f; // Better for single line + bool value_changed = false; + bool cancel_edit = false; + if (g.ActiveId == id) + { + edit_state.BufSize = buf_size < IM_ARRAYSIZE(edit_state.Text) ? buf_size : IM_ARRAYSIZE(edit_state.Text); + edit_state.Font = window->Font(); + edit_state.FontSize = window->FontSize(); + + const float mx = g.IO.MousePos.x - frame_bb.Min.x - style.FramePadding.x; + const float my = window->FontSize()*0.5f; // Better for single line - edit_state.UpdateScrollOffset(); - if (select_all || (hovered && io.MouseDoubleClicked[0])) - { - edit_state.SelectAll(); - edit_state.SelectedAllMouseLock = true; - } - else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock) - { - stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my); - edit_state.CursorAnimReset(); + edit_state.UpdateScrollOffset(); + if (select_all || (hovered && io.MouseDoubleClicked[0])) + { + edit_state.SelectAll(); + edit_state.SelectedAllMouseLock = true; + } + else if (io.MouseClicked[0] && !edit_state.SelectedAllMouseLock) + { + stb_textedit_click(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my); + edit_state.CursorAnimReset(); - } - else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock) - { - stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my); - edit_state.CursorAnimReset(); - } - if (edit_state.SelectedAllMouseLock && !io.MouseDown[0]) - edit_state.SelectedAllMouseLock = false; + } + else if (io.MouseDown[0] && !edit_state.SelectedAllMouseLock) + { + stb_textedit_drag(&edit_state, &edit_state.StbState, mx + edit_state.ScrollX, my); + edit_state.CursorAnimReset(); + } + if (edit_state.SelectedAllMouseLock && !io.MouseDown[0]) + edit_state.SelectedAllMouseLock = false; - const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0); - if (IsKeyPressedMap(ImGuiKey_LeftArrow)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); - else if (IsKeyPressedMap(ImGuiKey_RightArrow)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); - else if (IsKeyPressedMap(ImGuiKey_UpArrow)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UP | k_mask); - else if (IsKeyPressedMap(ImGuiKey_DownArrow)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_DOWN | k_mask); - else if (IsKeyPressedMap(ImGuiKey_Home)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); - else if (IsKeyPressedMap(ImGuiKey_End)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); - else if (IsKeyPressedMap(ImGuiKey_Delete)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_DELETE | k_mask); - else if (IsKeyPressedMap(ImGuiKey_Backspace)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); - else if (IsKeyPressedMap(ImGuiKey_Enter)) { g.ActiveId = 0; } - else if (IsKeyPressedMap(ImGuiKey_Escape)) { g.ActiveId = 0; cancel_edit = true; } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UNDO); // I don't want to use shortcuts but we should probably have an Input-catch stack - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_REDO); - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) edit_state.SelectAll(); - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_X)) - { - if (!edit_state.HasSelection()) - edit_state.SelectAll(); + const int k_mask = (is_shift_down ? STB_TEXTEDIT_K_SHIFT : 0); + if (IsKeyPressedMap(ImGuiKey_LeftArrow)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDLEFT | k_mask : STB_TEXTEDIT_K_LEFT | k_mask); + else if (IsKeyPressedMap(ImGuiKey_RightArrow)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_WORDRIGHT | k_mask : STB_TEXTEDIT_K_RIGHT | k_mask); + else if (IsKeyPressedMap(ImGuiKey_UpArrow)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UP | k_mask); + else if (IsKeyPressedMap(ImGuiKey_DownArrow)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_DOWN | k_mask); + else if (IsKeyPressedMap(ImGuiKey_Home)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTSTART | k_mask : STB_TEXTEDIT_K_LINESTART | k_mask); + else if (IsKeyPressedMap(ImGuiKey_End)) edit_state.OnKeyboardPressed(is_ctrl_down ? STB_TEXTEDIT_K_TEXTEND | k_mask : STB_TEXTEDIT_K_LINEEND | k_mask); + else if (IsKeyPressedMap(ImGuiKey_Delete)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_DELETE | k_mask); + else if (IsKeyPressedMap(ImGuiKey_Backspace)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask); + else if (IsKeyPressedMap(ImGuiKey_Enter)) { g.ActiveId = 0; } + else if (IsKeyPressedMap(ImGuiKey_Escape)) { g.ActiveId = 0; cancel_edit = true; } + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Z)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_UNDO); // I don't want to use shortcuts but we should probably have an Input-catch stack + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_Y)) edit_state.OnKeyboardPressed(STB_TEXTEDIT_K_REDO); + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_A)) edit_state.SelectAll(); + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_X)) + { + if (!edit_state.HasSelection()) + edit_state.SelectAll(); - const int ib = ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end); - const int ie = ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end); - if (g.IO.SetClipboardTextFn) - g.IO.SetClipboardTextFn(edit_state.Text+ib, edit_state.Text+ie); - stb_textedit_cut(&edit_state, &edit_state.StbState); - } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_C)) - { - const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; - const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)strlen(edit_state.Text); - if (g.IO.SetClipboardTextFn) - g.IO.SetClipboardTextFn(edit_state.Text+ib, edit_state.Text+ie); - } - else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V)) - { - if (g.IO.GetClipboardTextFn) - if (const char* clipboard = g.IO.GetClipboardTextFn()) - { - // Remove new-line from pasted buffer - size_t clipboard_len = strlen(clipboard); - char* clipboard_filtered = (char*)malloc(clipboard_len+1); - int clipboard_filtered_len = 0; - for (int i = 0; clipboard[i]; i++) - { - const char c = clipboard[i]; - if (c == '\n' || c == '\r') - continue; - clipboard_filtered[clipboard_filtered_len++] = clipboard[i]; - } - clipboard_filtered[clipboard_filtered_len] = 0; - stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); - free(clipboard_filtered); - } - } - else if (g.IO.InputCharacters[0]) - { - // Text input - for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++) - { - const char c = g.IO.InputCharacters[n]; - if (c) - { - // Filter - if (!isprint(c) && c != ' ') - continue; - if (flags & ImGuiInputTextFlags_CharsDecimal) - if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) - continue; - if (flags & ImGuiInputTextFlags_CharsHexadecimal) - if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) - continue; + const int ib = ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end); + const int ie = ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end); + if (g.IO.SetClipboardTextFn) + g.IO.SetClipboardTextFn(edit_state.Text+ib, edit_state.Text+ie); + stb_textedit_cut(&edit_state, &edit_state.StbState); + } + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_C)) + { + const int ib = edit_state.HasSelection() ? ImMin(edit_state.StbState.select_start, edit_state.StbState.select_end) : 0; + const int ie = edit_state.HasSelection() ? ImMax(edit_state.StbState.select_start, edit_state.StbState.select_end) : (int)strlen(edit_state.Text); + if (g.IO.SetClipboardTextFn) + g.IO.SetClipboardTextFn(edit_state.Text+ib, edit_state.Text+ie); + } + else if (is_ctrl_down && IsKeyPressedMap(ImGuiKey_V)) + { + if (g.IO.GetClipboardTextFn) + if (const char* clipboard = g.IO.GetClipboardTextFn()) + { + // Remove new-line from pasted buffer + size_t clipboard_len = strlen(clipboard); + char* clipboard_filtered = (char*)malloc(clipboard_len+1); + int clipboard_filtered_len = 0; + for (int i = 0; clipboard[i]; i++) + { + const char c = clipboard[i]; + if (c == '\n' || c == '\r') + continue; + clipboard_filtered[clipboard_filtered_len++] = clipboard[i]; + } + clipboard_filtered[clipboard_filtered_len] = 0; + stb_textedit_paste(&edit_state, &edit_state.StbState, clipboard_filtered, clipboard_filtered_len); + free(clipboard_filtered); + } + } + else if (g.IO.InputCharacters[0]) + { + // Text input + for (int n = 0; n < IM_ARRAYSIZE(g.IO.InputCharacters) && g.IO.InputCharacters[n]; n++) + { + const char c = g.IO.InputCharacters[n]; + if (c) + { + // Filter + if (!isprint(c) && c != ' ') + continue; + if (flags & ImGuiInputTextFlags_CharsDecimal) + if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/')) + continue; + if (flags & ImGuiInputTextFlags_CharsHexadecimal) + if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F')) + continue; - // Insert character! - edit_state.OnKeyboardPressed(c); - } - } - } + // Insert character! + edit_state.OnKeyboardPressed(c); + } + } + } - edit_state.CursorAnim += g.IO.DeltaTime; - edit_state.UpdateScrollOffset(); + edit_state.CursorAnim += g.IO.DeltaTime; + edit_state.UpdateScrollOffset(); - if (cancel_edit) - { - // Restore initial value - ImFormatString(buf, buf_size, "%s", edit_state.InitialText); - value_changed = true; - } - else - { - // Apply new value immediately - copy modified buffer back - if (strcmp(edit_state.Text, buf) != 0) - { - ImFormatString(buf, buf_size, "%s", edit_state.Text); - value_changed = true; - } - } - } - - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true);//, style.Rounding); + if (cancel_edit) + { + // Restore initial value + ImFormatString(buf, buf_size, "%s", edit_state.InitialText); + value_changed = true; + } + else + { + // Apply new value immediately - copy modified buffer back + if (strcmp(edit_state.Text, buf) != 0) + { + ImFormatString(buf, buf_size, "%s", edit_state.Text); + value_changed = true; + } + } + } + + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg), true);//, style.Rounding); - const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: this should be part of the font API - const ImVec2 font_off_dn = ImVec2(0.0f,2.0f); + const ImVec2 font_off_up = ImVec2(0.0f,window->FontSize()+1.0f); // FIXME: this should be part of the font API + const ImVec2 font_off_dn = ImVec2(0.0f,2.0f); - if (g.ActiveId == id) - { - // Draw selection - const int select_begin_idx = edit_state.StbState.select_start; - const int select_end_idx = edit_state.StbState.select_end; - if (select_begin_idx != select_end_idx) - { - const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx)); - const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx)); - window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg)); - } - } + if (g.ActiveId == id) + { + // Draw selection + const int select_begin_idx = edit_state.StbState.select_start; + const int select_end_idx = edit_state.StbState.select_end; + if (select_begin_idx != select_end_idx) + { + const ImVec2 select_begin_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMin(select_begin_idx,select_end_idx)); + const ImVec2 select_end_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(ImMax(select_begin_idx,select_end_idx)); + window->DrawList->AddRectFilled(select_begin_pos - font_off_up, select_end_pos + font_off_dn, window->Color(ImGuiCol_TextSelectedBg)); + } + } - // FIXME: 'align_center' unsupported - ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f); + // FIXME: 'align_center' unsupported + ImGuiTextEditState::RenderTextScrolledClipped(window->Font(), window->FontSize(), buf, frame_bb.Min + style.FramePadding, w, (g.ActiveId == id) ? edit_state.ScrollX : 0.0f); - if (g.ActiveId == id) - { - // Draw blinking cursor - if (g.InputTextState.CursorIsVisible()) - { - const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor); - window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text)); - } - } + if (g.ActiveId == id) + { + // Draw blinking cursor + if (g.InputTextState.CursorIsVisible()) + { + const ImVec2 cursor_pos = frame_bb.Min + style.FramePadding + edit_state.CalcDisplayOffsetFromCharIdx(edit_state.StbState.cursor); + window->DrawList->AddRect(cursor_pos - font_off_up + ImVec2(0,2), cursor_pos + font_off_dn - ImVec2(0,3), window->Color(ImGuiCol_Text)); + } + } - RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); + RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label); - return value_changed; + return value_changed; } static bool InputFloatN(const char* label, float* v, int components, int decimal_precision) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const float w_full = window->DC.ItemWidth.back(); - const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); + const ImGuiStyle& style = g.Style; + const float w_full = window->DC.ItemWidth.back(); + const float w_item_one = ImMax(1.0f, (float)(int)((w_full - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_full - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); - bool value_changed = false; - ImGui::PushID(label); - ImGui::PushItemWidth(w_item_one); - for (int i = 0; i < components; i++) - { - ImGui::PushID(i); - if (i + 1 == components) - { - ImGui::PopItemWidth(); - ImGui::PushItemWidth(w_item_last); - } - value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision); - ImGui::SameLine(0, 0); - ImGui::PopID(); - } - ImGui::PopItemWidth(); - ImGui::PopID(); + bool value_changed = false; + ImGui::PushID(label); + ImGui::PushItemWidth(w_item_one); + for (int i = 0; i < components; i++) + { + ImGui::PushID(i); + if (i + 1 == components) + { + ImGui::PopItemWidth(); + ImGui::PushItemWidth(w_item_last); + } + value_changed |= ImGui::InputFloat("##v", &v[i], 0, 0, decimal_precision); + ImGui::SameLine(0, 0); + ImGui::PopID(); + } + ImGui::PopItemWidth(); + ImGui::PopID(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - return value_changed; + return value_changed; } bool InputFloat2(const char* label, float v[2], int decimal_precision) { - return InputFloatN(label, v, 2, decimal_precision); + return InputFloatN(label, v, 2, decimal_precision); } bool InputFloat3(const char* label, float v[3], int decimal_precision) { - return InputFloatN(label, v, 3, decimal_precision); + return InputFloatN(label, v, 3, decimal_precision); } bool InputFloat4(const char* label, float v[4], int decimal_precision) { - return InputFloatN(label, v, 4, decimal_precision); + return InputFloatN(label, v, 4, decimal_precision); } static bool Combo_ArrayGetter(void* data, int idx, const char** out_text) { - const char** items = (const char**)data; - if (out_text) - *out_text = items[idx]; - return true; + const char** items = (const char**)data; + if (out_text) + *out_text = items[idx]; + return true; } bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items) { - bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items); - return value_changed; + bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items); + return value_changed; } static bool Combo_StringListGetter(void* data, int idx, const char** out_text) { - // FIXME-OPT: we could precompute the indices but let's not bother now. - const char* items_separated_by_zeros = (const char*)data; - int items_count = 0; - const char* p = items_separated_by_zeros; - while (*p) - { - if (idx == items_count) - break; - p += strlen(p) + 1; - items_count++; - } - if (!*p) - return false; - if (out_text) - *out_text = p; - return true; + // FIXME-OPT: we could precompute the indices but let's not bother now. + const char* items_separated_by_zeros = (const char*)data; + int items_count = 0; + const char* p = items_separated_by_zeros; + while (*p) + { + if (idx == items_count) + break; + p += strlen(p) + 1; + items_count++; + } + if (!*p) + return false; + if (out_text) + *out_text = p; + return true; } bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items) { - int items_count = 0; - const char* p = items_separated_by_zeros; - while (*p) - { - p += strlen(p) + 1; - items_count++; - } - bool value_changed = Combo(label, current_item, Combo_StringListGetter, (void*)items_separated_by_zeros, items_count, popup_height_items); - return value_changed; + int items_count = 0; + const char* p = items_separated_by_zeros; + while (*p) + { + p += strlen(p) + 1; + items_count++; + } + bool value_changed = Combo(label, current_item, Combo_StringListGetter, (void*)items_separated_by_zeros, items_count, popup_height_items); + return value_changed; } bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int, const char**), void* data, int items_count, int popup_height_items) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); - const ImVec2 text_size = CalcTextSize(label); - const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); - const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f); - const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); + const ImVec2 text_size = CalcTextSize(label); + const float arrow_size = (window->FontSize() + style.FramePadding.x * 2.0f); + const ImGuiAabb frame_bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(window->DC.ItemWidth.back(), text_size.y) + style.FramePadding*2.0f); + const ImGuiAabb bb(frame_bb.Min, frame_bb.Max + ImVec2(style.ItemInnerSpacing.x + text_size.x,0)); - if (ClipAdvance(frame_bb)) - return false; + if (ClipAdvance(frame_bb)) + return false; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); - bool value_changed = false; - ItemSize(frame_bb); - RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); - RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button)); - RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true); + bool value_changed = false; + ItemSize(frame_bb); + RenderFrame(frame_bb.Min, frame_bb.Max, window->Color(ImGuiCol_FrameBg)); + RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, window->Color(hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button)); + RenderCollapseTriangle(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y) + style.FramePadding, true); - if (*current_item >= 0 && *current_item < items_count) - { - const char* item_text; - if (items_getter(data, *current_item, &item_text)) - RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false); - } + if (*current_item >= 0 && *current_item < items_count) + { + const char* item_text; + if (items_getter(data, *current_item, &item_text)) + RenderText(frame_bb.Min + style.FramePadding, item_text, NULL, false); + } - ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - ImGui::PushID(id); - bool menu_toggled = false; - if (hovered) - { - g.HoveredId = id; - if (g.IO.MouseClicked[0]) - { - menu_toggled = true; - g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id; - } - } - - if (g.ActiveComboID == id) - { - const ImVec2 backup_pos = ImGui::GetCursorPos(); - const float popup_off_x = 0.0f;//g.Style.ItemInnerSpacing.x; - const float popup_height = (text_size.y + g.Style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + g.Style.WindowPadding.y; - const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); - ImGui::SetCursorPos(popup_aabb.Min - window->Pos); + ImGui::PushID(id); + bool menu_toggled = false; + if (hovered) + { + g.HoveredId = id; + if (g.IO.MouseClicked[0]) + { + menu_toggled = true; + g.ActiveComboID = (g.ActiveComboID == id) ? 0 : id; + } + } + + if (g.ActiveComboID == id) + { + const ImVec2 backup_pos = ImGui::GetCursorPos(); + const float popup_off_x = 0.0f;//g.Style.ItemInnerSpacing.x; + const float popup_height = (text_size.y + g.Style.ItemSpacing.y) * ImMin(items_count, popup_height_items) + g.Style.WindowPadding.y; + const ImGuiAabb popup_aabb(ImVec2(frame_bb.Min.x+popup_off_x, frame_bb.Max.y), ImVec2(frame_bb.Max.x+popup_off_x, frame_bb.Max.y + popup_height)); + ImGui::SetCursorPos(popup_aabb.Min - window->Pos); - ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0); - ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags); - ImGuiWindow* child_window = GetCurrentWindow(); - ImGui::Spacing(); + ImGuiWindowFlags flags = ImGuiWindowFlags_ComboBox | ((window->Flags & ImGuiWindowFlags_ShowBorders) ? ImGuiWindowFlags_ShowBorders : 0); + ImGui::BeginChild("#ComboBox", popup_aabb.GetSize(), false, flags); + ImGuiWindow* child_window = GetCurrentWindow(); + ImGui::Spacing(); - bool combo_item_active = false; - combo_item_active |= (g.ActiveId == child_window->GetID("#SCROLLY")); + bool combo_item_active = false; + combo_item_active |= (g.ActiveId == child_window->GetID("#SCROLLY")); - for (int item_idx = 0; item_idx < items_count; item_idx++) - { - const float item_h = child_window->FontSize(); - const float spacing_up = (float)(int)(g.Style.ItemSpacing.y/2); - const float spacing_dn = g.Style.ItemSpacing.y - spacing_up; - const ImGuiAabb item_aabb(ImVec2(popup_aabb.Min.x, child_window->DC.CursorPos.y - spacing_up), ImVec2(popup_aabb.Max.x, child_window->DC.CursorPos.y + item_h + spacing_dn)); - const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx); + for (int item_idx = 0; item_idx < items_count; item_idx++) + { + const float item_h = child_window->FontSize(); + const float spacing_up = (float)(int)(g.Style.ItemSpacing.y/2); + const float spacing_dn = g.Style.ItemSpacing.y - spacing_up; + const ImGuiAabb item_aabb(ImVec2(popup_aabb.Min.x, child_window->DC.CursorPos.y - spacing_up), ImVec2(popup_aabb.Max.x, child_window->DC.CursorPos.y + item_h + spacing_dn)); + const ImGuiID item_id = child_window->GetID((void*)(intptr_t)item_idx); - bool item_hovered, item_held; - bool item_pressed = ButtonBehaviour(item_aabb, item_id, &item_hovered, &item_held, true); - bool item_selected = item_idx == *current_item; + bool item_hovered, item_held; + bool item_pressed = ButtonBehaviour(item_aabb, item_id, &item_hovered, &item_held, true); + bool item_selected = item_idx == *current_item; - if (item_hovered || item_selected) - { - const ImU32 col = window->Color((item_held && item_hovered) ? ImGuiCol_HeaderActive : item_hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); - RenderFrame(item_aabb.Min, item_aabb.Max, col, false); - } + if (item_hovered || item_selected) + { + const ImU32 col = window->Color((item_held && item_hovered) ? ImGuiCol_HeaderActive : item_hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header); + RenderFrame(item_aabb.Min, item_aabb.Max, col, false); + } - const char* item_text; - if (!items_getter(data, item_idx, &item_text)) - item_text = "*Unknown item*"; - ImGui::Text("%s", item_text); - - if (item_selected) - { - if (menu_toggled) - ImGui::SetScrollPosHere(); - } - if (item_pressed) - { - g.ActiveId = 0; - g.ActiveComboID = 0; - value_changed = true; - *current_item = item_idx; - } + const char* item_text; + if (!items_getter(data, item_idx, &item_text)) + item_text = "*Unknown item*"; + ImGui::Text("%s", item_text); + + if (item_selected) + { + if (menu_toggled) + ImGui::SetScrollPosHere(); + } + if (item_pressed) + { + g.ActiveId = 0; + g.ActiveComboID = 0; + value_changed = true; + *current_item = item_idx; + } - combo_item_active |= (g.ActiveId == item_id); - } - ImGui::EndChild(); - ImGui::SetCursorPos(backup_pos); - - if (!combo_item_active && g.ActiveId != 0) - g.ActiveComboID = 0; - } + combo_item_active |= (g.ActiveId == item_id); + } + ImGui::EndChild(); + ImGui::SetCursorPos(backup_pos); + + if (!combo_item_active && g.ActiveId != 0) + g.ActiveComboID = 0; + } - ImGui::PopID(); + ImGui::PopID(); - return value_changed; + return value_changed; } // A little colored square. Return true when clicked. bool ColorButton(const ImVec4& col, bool small_height, bool outline_border) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const float square_size = window->FontSize(); - const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); - ItemSize(bb); + const ImGuiStyle& style = g.Style; + const float square_size = window->FontSize(); + const ImGuiAabb bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(square_size + style.FramePadding.x*2, square_size + (small_height ? 0 : style.FramePadding.y*2))); + ItemSize(bb); - if (ClipAdvance(bb)) - return false; + if (ClipAdvance(bb)) + return false; - const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); - const bool pressed = hovered && g.IO.MouseClicked[0]; - RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border); + const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(bb); + const bool pressed = hovered && g.IO.MouseClicked[0]; + RenderFrame(bb.Min, bb.Max, window->Color(col), outline_border); - if (hovered) - { - int ix = (int)(col.x * 255.0f + 0.5f); - int iy = (int)(col.y * 255.0f + 0.5f); - int iz = (int)(col.z * 255.0f + 0.5f); - int iw = (int)(col.w * 255.0f + 0.5f); - ImGui::SetTooltip("Color:\n(%.2f,%.2f,%.2f,%.2f)\n#%02X%02X%02X%02X", col.x, col.y, col.z, col.w, ix, iy, iz, iw); - } + if (hovered) + { + int ix = (int)(col.x * 255.0f + 0.5f); + int iy = (int)(col.y * 255.0f + 0.5f); + int iz = (int)(col.z * 255.0f + 0.5f); + int iw = (int)(col.w * 255.0f + 0.5f); + ImGui::SetTooltip("Color:\n(%.2f,%.2f,%.2f,%.2f)\n#%02X%02X%02X%02X", col.x, col.y, col.z, col.w, ix, iy, iz, iw); + } - return pressed; + return pressed; } bool ColorEdit3(const char* label, float col[3]) { - float col4[4]; - col4[0] = col[0]; - col4[1] = col[1]; - col4[2] = col[2]; - col4[3] = 1.0f; - bool value_changed = ImGui::ColorEdit4(label, col4, false); - col[0] = col4[0]; - col[1] = col4[1]; - col[2] = col4[2]; - return value_changed; + float col4[4]; + col4[0] = col[0]; + col4[1] = col[1]; + col4[2] = col[2]; + col4[3] = 1.0f; + bool value_changed = ImGui::ColorEdit4(label, col4, false); + col[0] = col4[0]; + col[1] = col4[1]; + col[2] = col4[2]; + return value_changed; } // Edit colours components color in 0..1 range // Use CTRL-Click to input value and TAB to go to next item. bool ColorEdit4(const char* label, float col[4], bool alpha) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return false; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return false; - const ImGuiStyle& style = g.Style; - const ImGuiID id = window->GetID(label); - const float w_full = window->DC.ItemWidth.back(); - const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f); + const ImGuiStyle& style = g.Style; + const ImGuiID id = window->GetID(label); + const float w_full = window->DC.ItemWidth.back(); + const float square_sz = (window->FontSize() + style.FramePadding.x * 2.0f); - ImGuiColorEditMode edit_mode = window->DC.ColorEditMode; - if (edit_mode == ImGuiColorEditMode_UserSelect) - edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3; + ImGuiColorEditMode edit_mode = window->DC.ColorEditMode; + if (edit_mode == ImGuiColorEditMode_UserSelect) + edit_mode = g.ColorEditModeStorage.GetInt(id, 0) % 3; - float fx = col[0]; - float fy = col[1]; - float fz = col[2]; - float fw = col[3]; - const ImVec4 col_display(fx, fy, fz, 1.0f); + float fx = col[0]; + float fy = col[1]; + float fz = col[2]; + float fw = col[3]; + const ImVec4 col_display(fx, fy, fz, 1.0f); - if (edit_mode == ImGuiColorEditMode_HSV) - ImConvertColorRGBtoHSV(fx, fy, fz, fx, fy, fz); + if (edit_mode == ImGuiColorEditMode_HSV) + ImConvertColorRGBtoHSV(fx, fy, fz, fx, fy, fz); - int ix = (int)(fx * 255.0f + 0.5f); - int iy = (int)(fy * 255.0f + 0.5f); - int iz = (int)(fz * 255.0f + 0.5f); - int iw = (int)(fw * 255.0f + 0.5f); + int ix = (int)(fx * 255.0f + 0.5f); + int iy = (int)(fy * 255.0f + 0.5f); + int iz = (int)(fz * 255.0f + 0.5f); + int iw = (int)(fw * 255.0f + 0.5f); - int components = alpha ? 4 : 3; - bool value_changed = false; + int components = alpha ? 4 : 3; + bool value_changed = false; - ImGui::PushID(label); + ImGui::PushID(label); - bool hsv = (edit_mode == 1); - switch (edit_mode) - { - case ImGuiColorEditMode_RGB: - case ImGuiColorEditMode_HSV: - { - // 0: RGB 0..255 - // 1: HSV 0.255 Sliders - const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x); - const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); - const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); + bool hsv = (edit_mode == 1); + switch (edit_mode) + { + case ImGuiColorEditMode_RGB: + case ImGuiColorEditMode_HSV: + { + // 0: RGB 0..255 + // 1: HSV 0.255 Sliders + const float w_items_all = w_full - (square_sz + style.ItemInnerSpacing.x); + const float w_item_one = ImMax(1.0f, (float)(int)((w_items_all - (style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1)) / (float)components)); + const float w_item_last = ImMax(1.0f, (float)(int)(w_items_all - (w_item_one+style.FramePadding.x*2.0f+style.ItemInnerSpacing.x) * (components-1))); - ImGui::PushItemWidth(w_item_one); - value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f"); - ImGui::SameLine(0, 0); - value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f"); - ImGui::SameLine(0, 0); - if (alpha) - { - value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); - ImGui::SameLine(0, 0); - ImGui::PushItemWidth(w_item_last); - value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f"); - } - else - { - ImGui::PushItemWidth(w_item_last); - value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); - } - ImGui::PopItemWidth(); - ImGui::PopItemWidth(); - } - break; - case ImGuiColorEditMode_HEX: - { - // 2: RGB Hexadecimal - const float w_slider_all = w_full - square_sz; - char buf[64]; - if (alpha) - sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw); - else - sprintf(buf, "#%02X%02X%02X", ix, iy, iz); - ImGui::PushItemWidth(w_slider_all - g.Style.ItemInnerSpacing.x); - value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal); - ImGui::PopItemWidth(); - char* p = buf; - while (*p == '#' || *p == ' ' || *p == '\t') - p++; - ix = iy = iz = iw = 0; - if (alpha) - sscanf(p, "%02X%02X%02X%02X", &ix, &iy, &iz, &iw); - else - sscanf(p, "%02X%02X%02X", &ix, &iy, &iz); - } - break; - } + ImGui::PushItemWidth(w_item_one); + value_changed |= ImGui::SliderInt("##X", &ix, 0, 255, hsv ? "H:%3.0f" : "R:%3.0f"); + ImGui::SameLine(0, 0); + value_changed |= ImGui::SliderInt("##Y", &iy, 0, 255, hsv ? "S:%3.0f" : "G:%3.0f"); + ImGui::SameLine(0, 0); + if (alpha) + { + value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); + ImGui::SameLine(0, 0); + ImGui::PushItemWidth(w_item_last); + value_changed |= ImGui::SliderInt("##W", &iw, 0, 255, "A:%3.0f"); + } + else + { + ImGui::PushItemWidth(w_item_last); + value_changed |= ImGui::SliderInt("##Z", &iz, 0, 255, hsv ? "V:%3.0f" : "B:%3.0f"); + } + ImGui::PopItemWidth(); + ImGui::PopItemWidth(); + } + break; + case ImGuiColorEditMode_HEX: + { + // 2: RGB Hexadecimal + const float w_slider_all = w_full - square_sz; + char buf[64]; + if (alpha) + sprintf(buf, "#%02X%02X%02X%02X", ix, iy, iz, iw); + else + sprintf(buf, "#%02X%02X%02X", ix, iy, iz); + ImGui::PushItemWidth(w_slider_all - g.Style.ItemInnerSpacing.x); + value_changed |= ImGui::InputText("##Text", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsHexadecimal); + ImGui::PopItemWidth(); + char* p = buf; + while (*p == '#' || *p == ' ' || *p == '\t') + p++; + ix = iy = iz = iw = 0; + if (alpha) + sscanf(p, "%02X%02X%02X%02X", &ix, &iy, &iz, &iw); + else + sscanf(p, "%02X%02X%02X", &ix, &iy, &iz); + } + break; + } - ImGui::SameLine(0, 0); - ImGui::ColorButton(col_display); + ImGui::SameLine(0, 0); + ImGui::ColorButton(col_display); - if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect) - { - ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); - const char* button_titles[3] = { "RGB", "HSV", "HEX" }; - if (ImGui::Button(button_titles[edit_mode])) - { - // Don't set 'edit_mode' right away! - g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); - } - } + if (window->DC.ColorEditMode == ImGuiColorEditMode_UserSelect) + { + ImGui::SameLine(0, (int)style.ItemInnerSpacing.x); + const char* button_titles[3] = { "RGB", "HSV", "HEX" }; + if (ImGui::Button(button_titles[edit_mode])) + { + // Don't set 'edit_mode' right away! + g.ColorEditModeStorage.SetInt(id, (edit_mode + 1) % 3); + } + } - ImGui::SameLine(); - ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); + ImGui::SameLine(); + ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - // Convert back - fx = ix / 255.0f; - fy = iy / 255.0f; - fz = iz / 255.0f; - fw = iw / 255.0f; - if (edit_mode == 1) - ImConvertColorHSVtoRGB(fx, fy, fz, fx, fy, fz); + // Convert back + fx = ix / 255.0f; + fy = iy / 255.0f; + fz = iz / 255.0f; + fw = iw / 255.0f; + if (edit_mode == 1) + ImConvertColorHSVtoRGB(fx, fy, fz, fx, fy, fz); - if (value_changed) - { - col[0] = fx; - col[1] = fy; - col[2] = fz; - if (alpha) - col[3] = fw; - } + if (value_changed) + { + col[0] = fx; + col[1] = fy; + col[2] = fz; + if (alpha) + col[3] = fw; + } - ImGui::PopID(); + ImGui::PopID(); - return value_changed; + return value_changed; } void ColorEditMode(ImGuiColorEditMode mode) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColorEditMode = mode; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ColorEditMode = mode; } void Separator() { - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - if (window->DC.ColumnsCount > 1) - ImGui::PopClipRect(); + if (window->DC.ColumnsCount > 1) + ImGui::PopClipRect(); - const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y)); - ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit + const ImGuiAabb bb(ImVec2(window->Pos.x, window->DC.CursorPos.y), ImVec2(window->Pos.x + window->Size.x, window->DC.CursorPos.y)); + ItemSize(ImVec2(0.0f, bb.GetSize().y)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit - if (ClipAdvance(bb)) - { - if (window->DC.ColumnsCount > 1) - ImGui::PushColumnClipRect(); - return; - } + if (ClipAdvance(bb)) + { + if (window->DC.ColumnsCount > 1) + ImGui::PushColumnClipRect(); + return; + } - window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border)); + window->DrawList->AddLine(bb.Min, bb.Max, window->Color(ImGuiCol_Border)); - if (window->DC.ColumnsCount > 1) - ImGui::PushColumnClipRect(); + if (window->DC.ColumnsCount > 1) + ImGui::PushColumnClipRect(); } void Spacing() { - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - ItemSize(ImVec2(0,0)); + ItemSize(ImVec2(0,0)); } static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); - if (adjust_start_offset) - adjust_start_offset->y = adjust_start_offset->y + (line_height - size.y) * 0.5f; + const float line_height = ImMax(window->DC.CurrentLineHeight, size.y); + if (adjust_start_offset) + adjust_start_offset->y = adjust_start_offset->y + (line_height - size.y) * 0.5f; - // Always align ourselves on pixel boundaries - window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); - window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnStartX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); + // Always align ourselves on pixel boundaries + window->DC.CursorPosPrevLine = ImVec2(window->DC.CursorPos.x + size.x, window->DC.CursorPos.y); + window->DC.CursorPos = ImVec2((float)(int)(window->Pos.x + window->DC.ColumnStartX), (float)(int)(window->DC.CursorPos.y + line_height + g.Style.ItemSpacing.y)); - window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY)); + window->SizeContentsFit = ImMax(window->SizeContentsFit, ImVec2(window->DC.CursorPosPrevLine.x, window->DC.CursorPos.y) - window->Pos + ImVec2(0.0f, window->ScrollY)); - window->DC.PrevLineHeight = line_height; - window->DC.CurrentLineHeight = 0.0f; + window->DC.PrevLineHeight = line_height; + window->DC.CurrentLineHeight = 0.0f; } static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset) { - ItemSize(aabb.GetSize(), adjust_start_offset); + ItemSize(aabb.GetSize(), adjust_start_offset); } void NextColumn() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - if (window->DC.ColumnsCount > 1) - { - ImGui::PopItemWidth(); - ImGui::PopClipRect(); - if (++window->DC.ColumnCurrent < window->DC.ColumnsCount) - SameLine((int)(ImGui::GetColumnOffset(window->DC.ColumnCurrent) + g.Style.ItemSpacing.x)); - else - window->DC.ColumnCurrent = 0; - ImGui::PushColumnClipRect(); - ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); - } + if (window->DC.ColumnsCount > 1) + { + ImGui::PopItemWidth(); + ImGui::PopClipRect(); + if (++window->DC.ColumnCurrent < window->DC.ColumnsCount) + SameLine((int)(ImGui::GetColumnOffset(window->DC.ColumnCurrent) + g.Style.ItemSpacing.x)); + else + window->DC.ColumnCurrent = 0; + ImGui::PushColumnClipRect(); + ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); + } } bool IsClipped(const ImGuiAabb& bb) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); - if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled) - return true; - return false; + if (!bb.Overlaps(ImGuiAabb(window->ClipRectStack.back())) && !g.LogEnabled) + return true; + return false; } bool IsClipped(const ImVec2& item_size) { - ImGuiWindow* window = GetCurrentWindow(); - return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size)); + ImGuiWindow* window = GetCurrentWindow(); + return IsClipped(ImGuiAabb(window->DC.CursorPos, window->DC.CursorPos + item_size)); } static bool ClipAdvance(const ImGuiAabb& bb) { - ImGuiWindow* window = GetCurrentWindow(); - window->DC.LastItemAabb = bb; - if (ImGui::IsClipped(bb)) - { - window->DC.LastItemHovered = false; - return true; - } - window->DC.LastItemHovered = ImGui::IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ClipAdvance - return false; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.LastItemAabb = bb; + if (ImGui::IsClipped(bb)) + { + window->DC.LastItemHovered = false; + return true; + } + window->DC.LastItemHovered = ImGui::IsMouseHoveringBox(bb); // this is a sensible default but widgets are free to override it after calling ClipAdvance + return false; } // Gets back to previous line and continue with horizontal layout -// column_x == 0 : follow on previous item -// columm_x != 0 : align to specified column -// spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0 -// spacing_w >= 0 : enforce spacing +// column_x == 0 : follow on previous item +// columm_x != 0 : align to specified column +// spacing_w < 0 : use default spacing if column_x==0, no spacing if column_x!=0 +// spacing_w >= 0 : enforce spacing void SameLine(int column_x, int spacing_w) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; - - float x, y; - if (column_x != 0) - { - if (spacing_w < 0) spacing_w = 0; - x = window->Pos.x + (float)column_x + (float)spacing_w; - y = window->DC.CursorPosPrevLine.y; - } - else - { - if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x; - x = window->DC.CursorPosPrevLine.x + (float)spacing_w; - y = window->DC.CursorPosPrevLine.y; - } - window->DC.CurrentLineHeight = window->DC.PrevLineHeight; - window->DC.CursorPos = ImVec2(x, y); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + + float x, y; + if (column_x != 0) + { + if (spacing_w < 0) spacing_w = 0; + x = window->Pos.x + (float)column_x + (float)spacing_w; + y = window->DC.CursorPosPrevLine.y; + } + else + { + if (spacing_w < 0) spacing_w = (int)g.Style.ItemSpacing.x; + x = window->DC.CursorPosPrevLine.x + (float)spacing_w; + y = window->DC.CursorPosPrevLine.y; + } + window->DC.CurrentLineHeight = window->DC.PrevLineHeight; + window->DC.CursorPos = ImVec2(x, y); } float GetColumnOffset(int column_index) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (column_index < 0) - column_index = window->DC.ColumnCurrent; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (column_index < 0) + column_index = window->DC.ColumnCurrent; - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); - RegisterAliveId(column_id); - const float default_t = column_index / (float)window->DC.ColumnsCount; - const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8096)) / 8096; // Cheaply store our floating point value inside the integer (could store an union into the map?) + const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); + RegisterAliveId(column_id); + const float default_t = column_index / (float)window->DC.ColumnsCount; + const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8096)) / 8096; // Cheaply store our floating point value inside the integer (could store an union into the map?) - const float offset = window->DC.ColumnStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX); - return offset; + const float offset = window->DC.ColumnStartX + t * (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX); + return offset; } void SetColumnOffset(int column_index, float offset) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (column_index < 0) - column_index = window->DC.ColumnCurrent; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (column_index < 0) + column_index = window->DC.ColumnCurrent; - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); - const float t = (offset - window->DC.ColumnStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX); - window->StateStorage.SetInt(column_id, (int)(t*8096)); + const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); + const float t = (offset - window->DC.ColumnStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX); + window->StateStorage.SetInt(column_id, (int)(t*8096)); } float GetColumnWidth(int column_index) { - ImGuiWindow* window = GetCurrentWindow(); - if (column_index < 0) - column_index = window->DC.ColumnCurrent; + ImGuiWindow* window = GetCurrentWindow(); + if (column_index < 0) + column_index = window->DC.ColumnCurrent; - const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index); - return w; + const float w = GetColumnOffset(column_index+1) - GetColumnOffset(column_index); + return w; } static void PushColumnClipRect(int column_index) { - ImGuiWindow* window = GetCurrentWindow(); - if (column_index < 0) - column_index = window->DC.ColumnCurrent; + ImGuiWindow* window = GetCurrentWindow(); + if (column_index < 0) + column_index = window->DC.ColumnCurrent; - const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1; - const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1; - ImGui::PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX)); + const float x1 = window->Pos.x + ImGui::GetColumnOffset(column_index) - 1; + const float x2 = window->Pos.x + ImGui::GetColumnOffset(column_index+1) - 1; + ImGui::PushClipRect(ImVec4(x1,-FLT_MAX,x2,+FLT_MAX)); } void Columns(int columns_count, const char* id, bool border) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - if (window->SkipItems) - return; + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; - if (window->DC.ColumnsCount != 1) - { - if (window->DC.ColumnCurrent != 0) - ImGui::ItemSize(ImVec2(0,0)); // Advance to column 0 - ImGui::PopItemWidth(); - ImGui::PopClipRect(); - } + if (window->DC.ColumnsCount != 1) + { + if (window->DC.ColumnCurrent != 0) + ImGui::ItemSize(ImVec2(0,0)); // Advance to column 0 + ImGui::PopItemWidth(); + ImGui::PopClipRect(); + } - if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders) - { - // Draw columns and handle resize - const float y1 = window->DC.ColumnsStartCursorPos.y; - const float y2 = window->DC.CursorPos.y; - for (int i = 1; i < window->DC.ColumnsCount; i++) - { - float x = window->Pos.x + GetColumnOffset(i); - - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + i); - const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2)); + if (window->DC.ColumnsCount != columns_count && window->DC.ColumnsCount != 1 && window->DC.ColumnsShowBorders) + { + // Draw columns and handle resize + const float y1 = window->DC.ColumnsStartCursorPos.y; + const float y2 = window->DC.CursorPos.y; + for (int i = 1; i < window->DC.ColumnsCount; i++) + { + float x = window->Pos.x + GetColumnOffset(i); + + const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + i); + const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2)); - if (IsClipped(column_aabb)) - continue; + if (IsClipped(column_aabb)) + continue; - bool hovered, held; - ButtonBehaviour(column_aabb, column_id, &hovered, &held, true); + bool hovered, held; + ButtonBehaviour(column_aabb, column_id, &hovered, &held, true); - // Draw before resize so our items positioning are in sync with the line - const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column); - const float xi = (float)(int)x; - window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col); + // Draw before resize so our items positioning are in sync with the line + const ImU32 col = window->Color(held ? ImGuiCol_ColumnActive : hovered ? ImGuiCol_ColumnHovered : ImGuiCol_Column); + const float xi = (float)(int)x; + window->DrawList->AddLine(ImVec2(xi, y1), ImVec2(xi, y2), col); - if (held) - { - x -= window->Pos.x; - x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing); - SetColumnOffset(i, x); - x += window->Pos.x; - } - } - } + if (held) + { + x -= window->Pos.x; + x = ImClamp(x + g.IO.MouseDelta.x, ImGui::GetColumnOffset(i-1)+g.Style.ColumnsMinSpacing, ImGui::GetColumnOffset(i+1)-g.Style.ColumnsMinSpacing); + SetColumnOffset(i, x); + x += window->Pos.x; + } + } + } - window->DC.ColumnsSetID = window->GetID(id ? id : ""); - window->DC.ColumnCurrent = 0; - window->DC.ColumnsCount = columns_count; - window->DC.ColumnsShowBorders = border; - window->DC.ColumnsStartCursorPos = window->DC.CursorPos; + window->DC.ColumnsSetID = window->GetID(id ? id : ""); + window->DC.ColumnCurrent = 0; + window->DC.ColumnsCount = columns_count; + window->DC.ColumnsShowBorders = border; + window->DC.ColumnsStartCursorPos = window->DC.CursorPos; - if (window->DC.ColumnsCount != 1) - { - ImGui::PushColumnClipRect(); - ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); - } + if (window->DC.ColumnsCount != 1) + { + ImGui::PushColumnClipRect(); + ImGui::PushItemWidth(ImGui::GetColumnWidth() * 0.65f); + } } void TreePush(const char* str_id) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnStartX += g.Style.TreeNodeSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; - window->DC.TreeDepth++; - PushID(str_id ? str_id : "#TreePush"); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ColumnStartX += g.Style.TreeNodeSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; + window->DC.TreeDepth++; + PushID(str_id ? str_id : "#TreePush"); } void TreePush(const void* ptr_id) { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnStartX += g.Style.TreeNodeSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; - window->DC.TreeDepth++; - PushID(ptr_id ? ptr_id : (const void*)"#TreePush"); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ColumnStartX += g.Style.TreeNodeSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; + window->DC.TreeDepth++; + PushID(ptr_id ? ptr_id : (const void*)"#TreePush"); } void TreePop() { - ImGuiState& g = GImGui; - ImGuiWindow* window = GetCurrentWindow(); - window->DC.ColumnStartX -= g.Style.TreeNodeSpacing; - window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; - window->DC.TreeDepth--; - PopID(); + ImGuiState& g = GImGui; + ImGuiWindow* window = GetCurrentWindow(); + window->DC.ColumnStartX -= g.Style.TreeNodeSpacing; + window->DC.CursorPos.x = window->Pos.x + window->DC.ColumnStartX; + window->DC.TreeDepth--; + PopID(); } void Value(const char* prefix, bool b) { - ImGui::Text("%s: %s", prefix, (b ? "true" : "false")); + ImGui::Text("%s: %s", prefix, (b ? "true" : "false")); } void Value(const char* prefix, int v) { - ImGui::Text("%s: %d", prefix, v); + ImGui::Text("%s: %d", prefix, v); } void Value(const char* prefix, unsigned int v) { - ImGui::Text("%s: %d", prefix, v); + ImGui::Text("%s: %d", prefix, v); } void Value(const char* prefix, float v, const char* float_format) { - if (float_format) - { - char fmt[64]; - sprintf(fmt, "%%s: %s", float_format); - ImGui::Text(fmt, prefix, v); - } - else - { - ImGui::Text("%s: %.3f", prefix, v); - } + if (float_format) + { + char fmt[64]; + sprintf(fmt, "%%s: %s", float_format); + ImGui::Text(fmt, prefix, v); + } + else + { + ImGui::Text("%s: %.3f", prefix, v); + } } void Color(const char* prefix, const ImVec4& v) { - ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w); - ImGui::SameLine(); - ImGui::ColorButton(v, true); + ImGui::Text("%s: (%.2f,%.2f,%.2f,%.2f)", prefix, v.x, v.y, v.z, v.w); + ImGui::SameLine(); + ImGui::ColorButton(v, true); } void Color(const char* prefix, unsigned int v) { - ImGui::Text("%s: %08X", prefix, v); - ImGui::SameLine(); + ImGui::Text("%s: %08X", prefix, v); + ImGui::SameLine(); - ImVec4 col; - col.x = (float)((v >> 0) & 0xFF) / 255.0f; - col.y = (float)((v >> 8) & 0xFF) / 255.0f; - col.z = (float)((v >> 16) & 0xFF) / 255.0f; - col.w = (float)((v >> 24) & 0xFF) / 255.0f; - ImGui::ColorButton(col, true); + ImVec4 col; + col.x = (float)((v >> 0) & 0xFF) / 255.0f; + col.y = (float)((v >> 8) & 0xFF) / 255.0f; + col.z = (float)((v >> 16) & 0xFF) / 255.0f; + col.w = (float)((v >> 24) & 0xFF) / 255.0f; + ImGui::ColorButton(col, true); } }; // namespace ImGui @@ -4730,280 +4730,280 @@ void Color(const char* prefix, unsigned int v) void ImDrawList::Clear() { - commands.resize(0); - vtx_buffer.resize(0); - vtx_write = NULL; - clip_rect_stack.resize(0); + commands.resize(0); + vtx_buffer.resize(0); + vtx_write = NULL; + clip_rect_stack.resize(0); } void ImDrawList::PushClipRect(const ImVec4& clip_rect) { - if (!commands.empty() && commands.back().vtx_count == 0) - { - // Reuse empty command because high-level clipping may have discarded the other vertices already - commands.back().clip_rect = clip_rect; - } - else - { - ImDrawCmd draw_cmd; - draw_cmd.vtx_count = 0; - draw_cmd.clip_rect = clip_rect; - commands.push_back(draw_cmd); - } - clip_rect_stack.push_back(clip_rect); + if (!commands.empty() && commands.back().vtx_count == 0) + { + // Reuse empty command because high-level clipping may have discarded the other vertices already + commands.back().clip_rect = clip_rect; + } + else + { + ImDrawCmd draw_cmd; + draw_cmd.vtx_count = 0; + draw_cmd.clip_rect = clip_rect; + commands.push_back(draw_cmd); + } + clip_rect_stack.push_back(clip_rect); } void ImDrawList::PopClipRect() { - clip_rect_stack.pop_back(); - const ImVec4 clip_rect = clip_rect_stack.empty() ? ImVec4(-9999.0f,-9999.0f, +9999.0f, +9999.0f) : clip_rect_stack.back(); - if (!commands.empty() && commands.back().vtx_count == 0) - { - // Reuse empty command because high-level clipping may have discarded the other vertices already - commands.back().clip_rect = clip_rect; - } - else - { - ImDrawCmd draw_cmd; - draw_cmd.vtx_count = 0; - draw_cmd.clip_rect = clip_rect; - commands.push_back(draw_cmd); - } + clip_rect_stack.pop_back(); + const ImVec4 clip_rect = clip_rect_stack.empty() ? ImVec4(-9999.0f,-9999.0f, +9999.0f, +9999.0f) : clip_rect_stack.back(); + if (!commands.empty() && commands.back().vtx_count == 0) + { + // Reuse empty command because high-level clipping may have discarded the other vertices already + commands.back().clip_rect = clip_rect; + } + else + { + ImDrawCmd draw_cmd; + draw_cmd.vtx_count = 0; + draw_cmd.clip_rect = clip_rect; + commands.push_back(draw_cmd); + } } void ImDrawList::ReserveVertices(unsigned int vtx_count) { - if (vtx_count > 0) - { - ImDrawCmd& draw_cmd = commands.back(); - draw_cmd.vtx_count += vtx_count; - vtx_buffer.resize(vtx_buffer.size() + vtx_count); - vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count]; - } + if (vtx_count > 0) + { + ImDrawCmd& draw_cmd = commands.back(); + draw_cmd.vtx_count += vtx_count; + vtx_buffer.resize(vtx_buffer.size() + vtx_count); + vtx_write = &vtx_buffer[vtx_buffer.size() - vtx_count]; + } } void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) { - vtx_write->pos = pos; - vtx_write->col = col; - vtx_write->uv = IMGUI_FONT_TEX_UV_FOR_WHITE; - vtx_write++; + vtx_write->pos = pos; + vtx_write->col = col; + vtx_write->uv = IMGUI_FONT_TEX_UV_FOR_WHITE; + vtx_write++; } void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) { - const ImVec2 n = (b - a) / ImLength(b - a); - const ImVec2 hn = ImVec2(n.y, -n.x) * 0.5f; + const ImVec2 n = (b - a) / ImLength(b - a); + const ImVec2 hn = ImVec2(n.y, -n.x) * 0.5f; - AddVtx(a - hn, col); - AddVtx(b - hn, col); - AddVtx(a + hn, col); + AddVtx(a - hn, col); + AddVtx(b - hn, col); + AddVtx(a + hn, col); - AddVtx(b - hn, col); - AddVtx(b + hn, col); - AddVtx(a + hn, col); + AddVtx(b - hn, col); + AddVtx(b + hn, col); + AddVtx(a + hn, col); } void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - ReserveVertices(6); - AddVtxLine(a, b, col); + ReserveVertices(6); + AddVtxLine(a, b, col); } void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris, const ImVec2& third_point_offset) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - static ImVec2 circle_vtx[12]; - static bool circle_vtx_builds = false; - if (!circle_vtx_builds) - { - for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++) - { - const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI; - circle_vtx[i].x = cos(a + PI); - circle_vtx[i].y = sin(a + PI); - } - circle_vtx_builds = true; - } - - if (tris) - { - ReserveVertices((a_max-a_min) * 3); - for (int a = a_min; a < a_max; a++) - { - AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col); - AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); - AddVtx(center + third_point_offset, col); - } - } - else - { - ReserveVertices((a_max-a_min) * 6); - for (int a = a_min; a < a_max; a++) - AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); - } + static ImVec2 circle_vtx[12]; + static bool circle_vtx_builds = false; + if (!circle_vtx_builds) + { + for (int i = 0; i < IM_ARRAYSIZE(circle_vtx); i++) + { + const float a = ((float)i / (float)IM_ARRAYSIZE(circle_vtx)) * 2*PI; + circle_vtx[i].x = cos(a + PI); + circle_vtx[i].y = sin(a + PI); + } + circle_vtx_builds = true; + } + + if (tris) + { + ReserveVertices((a_max-a_min) * 3); + for (int a = a_min; a < a_max; a++) + { + AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col); + AddVtx(center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); + AddVtx(center + third_point_offset, col); + } + } + else + { + ReserveVertices((a_max-a_min) * 6); + for (int a = a_min; a < a_max; a++) + AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); + } } void ImDrawList::AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f); - float r = rounding; - r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); - r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); + //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f); + float r = rounding; + r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); + r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); - if (r == 0.0f || rounding_corners == 0) - { - ReserveVertices(4*6); - AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col); - AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col); - AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col); - AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col); - } - else - { - ReserveVertices(4*6); - AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col); - AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col); - AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col); - AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col); + if (r == 0.0f || rounding_corners == 0) + { + ReserveVertices(4*6); + AddVtxLine(ImVec2(a.x,a.y), ImVec2(b.x,a.y), col); + AddVtxLine(ImVec2(b.x,a.y), ImVec2(b.x,b.y), col); + AddVtxLine(ImVec2(b.x,b.y), ImVec2(a.x,b.y), col); + AddVtxLine(ImVec2(a.x,b.y), ImVec2(a.x,a.y), col); + } + else + { + ReserveVertices(4*6); + AddVtxLine(ImVec2(a.x + ((rounding_corners & 1)?r:0), a.y), ImVec2(b.x - ((rounding_corners & 2)?r:0), a.y), col); + AddVtxLine(ImVec2(b.x, a.y + ((rounding_corners & 2)?r:0)), ImVec2(b.x, b.y - ((rounding_corners & 4)?r:0)), col); + AddVtxLine(ImVec2(b.x - ((rounding_corners & 4)?r:0), b.y), ImVec2(a.x + ((rounding_corners & 8)?r:0), b.y), col); + AddVtxLine(ImVec2(a.x, b.y - ((rounding_corners & 8)?r:0)), ImVec2(a.x, a.y + ((rounding_corners & 1)?r:0)), col); - if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3); - if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6); - if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9); - if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12); - } + if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3); + if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6); + if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9); + if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12); + } } void ImDrawList::AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f); - float r = rounding; - r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); - r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); + //const float r = ImMin(rounding, ImMin(fabsf(b.x-a.x), fabsf(b.y-a.y))*0.5f); + float r = rounding; + r = ImMin(r, fabsf(b.x-a.x) * ( ((rounding_corners&(1|2))==(1|2)) || ((rounding_corners&(4|8))==(4|8)) ? 0.5f : 1.0f )); + r = ImMin(r, fabsf(b.y-a.y) * ( ((rounding_corners&(1|8))==(1|8)) || ((rounding_corners&(2|4))==(2|4)) ? 0.5f : 1.0f )); - if (r == 0.0f || rounding_corners == 0) - { - // Use triangle so we can merge more draw calls together (at the cost of extra vertices) - ReserveVertices(6); - AddVtx(ImVec2(a.x,a.y), col); - AddVtx(ImVec2(b.x,a.y), col); - AddVtx(ImVec2(b.x,b.y), col); - AddVtx(ImVec2(a.x,a.y), col); - AddVtx(ImVec2(b.x,b.y), col); - AddVtx(ImVec2(a.x,b.y), col); - } - else - { - ReserveVertices(6+6*2); - AddVtx(ImVec2(a.x+r,a.y), col); - AddVtx(ImVec2(b.x-r,a.y), col); - AddVtx(ImVec2(b.x-r,b.y), col); - AddVtx(ImVec2(a.x+r,a.y), col); - AddVtx(ImVec2(b.x-r,b.y), col); - AddVtx(ImVec2(a.x+r,b.y), col); - - float top_y = (rounding_corners & 1) ? a.y+r : a.y; - float bot_y = (rounding_corners & 8) ? b.y-r : b.y; - AddVtx(ImVec2(a.x,top_y), col); - AddVtx(ImVec2(a.x+r,top_y), col); - AddVtx(ImVec2(a.x+r,bot_y), col); - AddVtx(ImVec2(a.x,top_y), col); - AddVtx(ImVec2(a.x+r,bot_y), col); - AddVtx(ImVec2(a.x,bot_y), col); + if (r == 0.0f || rounding_corners == 0) + { + // Use triangle so we can merge more draw calls together (at the cost of extra vertices) + ReserveVertices(6); + AddVtx(ImVec2(a.x,a.y), col); + AddVtx(ImVec2(b.x,a.y), col); + AddVtx(ImVec2(b.x,b.y), col); + AddVtx(ImVec2(a.x,a.y), col); + AddVtx(ImVec2(b.x,b.y), col); + AddVtx(ImVec2(a.x,b.y), col); + } + else + { + ReserveVertices(6+6*2); + AddVtx(ImVec2(a.x+r,a.y), col); + AddVtx(ImVec2(b.x-r,a.y), col); + AddVtx(ImVec2(b.x-r,b.y), col); + AddVtx(ImVec2(a.x+r,a.y), col); + AddVtx(ImVec2(b.x-r,b.y), col); + AddVtx(ImVec2(a.x+r,b.y), col); + + float top_y = (rounding_corners & 1) ? a.y+r : a.y; + float bot_y = (rounding_corners & 8) ? b.y-r : b.y; + AddVtx(ImVec2(a.x,top_y), col); + AddVtx(ImVec2(a.x+r,top_y), col); + AddVtx(ImVec2(a.x+r,bot_y), col); + AddVtx(ImVec2(a.x,top_y), col); + AddVtx(ImVec2(a.x+r,bot_y), col); + AddVtx(ImVec2(a.x,bot_y), col); - top_y = (rounding_corners & 2) ? a.y+r : a.y; - bot_y = (rounding_corners & 4) ? b.y-r : b.y; - AddVtx(ImVec2(b.x-r,top_y), col); - AddVtx(ImVec2(b.x,top_y), col); - AddVtx(ImVec2(b.x,bot_y), col); - AddVtx(ImVec2(b.x-r,top_y), col); - AddVtx(ImVec2(b.x,bot_y), col); - AddVtx(ImVec2(b.x-r,bot_y), col); + top_y = (rounding_corners & 2) ? a.y+r : a.y; + bot_y = (rounding_corners & 4) ? b.y-r : b.y; + AddVtx(ImVec2(b.x-r,top_y), col); + AddVtx(ImVec2(b.x,top_y), col); + AddVtx(ImVec2(b.x,bot_y), col); + AddVtx(ImVec2(b.x-r,top_y), col); + AddVtx(ImVec2(b.x,bot_y), col); + AddVtx(ImVec2(b.x-r,bot_y), col); - if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true); - if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true); - if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true); - if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true); - } + if (rounding_corners & 1) AddArc(ImVec2(a.x+r,a.y+r), r, col, 0, 3, true); + if (rounding_corners & 2) AddArc(ImVec2(b.x-r,a.y+r), r, col, 3, 6, true); + if (rounding_corners & 4) AddArc(ImVec2(b.x-r,b.y-r), r, col, 6, 9, true); + if (rounding_corners & 8) AddArc(ImVec2(a.x+r,b.y-r), r, col, 9, 12,true); + } } void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - ReserveVertices(3); - AddVtx(a, col); - AddVtx(b, col); - AddVtx(c, col); + ReserveVertices(3); + AddVtx(a, col); + AddVtx(b, col); + AddVtx(c, col); } void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - ReserveVertices(num_segments*6); - const float a_step = 2*PI/(float)num_segments; - float a0 = 0.0f; - for (int i = 0; i < num_segments; i++) - { - const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtxLine(centre + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col); - a0 = a1; - } + ReserveVertices(num_segments*6); + const float a_step = 2*PI/(float)num_segments; + float a0 = 0.0f; + for (int i = 0; i < num_segments; i++) + { + const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; + AddVtxLine(centre + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col); + a0 = a1; + } } void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - ReserveVertices(num_segments*3); - const float a_step = 2*PI/(float)num_segments; - float a0 = 0.0f; - for (int i = 0; i < num_segments; i++) - { - const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtx(centre + ImVec2(cos(a0),sin(a0))*radius, col); - AddVtx(centre + ImVec2(cos(a1),sin(a1))*radius, col); - AddVtx(centre, col); - a0 = a1; - } + ReserveVertices(num_segments*3); + const float a_step = 2*PI/(float)num_segments; + float a0 = 0.0f; + for (int i = 0; i < num_segments; i++) + { + const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; + AddVtx(centre + ImVec2(cos(a0),sin(a0))*radius, col); + AddVtx(centre + ImVec2(cos(a1),sin(a1))*radius, col); + AddVtx(centre, col); + a0 = a1; + } } void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) { - if ((col >> 24) == 0) - return; + if ((col >> 24) == 0) + return; - if (text_end == NULL) - text_end = text_begin + strlen(text_begin); + if (text_end == NULL) + text_end = text_begin + strlen(text_begin); - // reserve vertices for worse case - const int char_count = (int)(text_end - text_begin); - const int vtx_count_max = char_count * 6; - const size_t vtx_begin = vtx_buffer.size(); - ReserveVertices(vtx_count_max); + // reserve vertices for worse case + const int char_count = (int)(text_end - text_begin); + const int vtx_count_max = char_count * 6; + const size_t vtx_begin = vtx_buffer.size(); + ReserveVertices(vtx_count_max); - font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write); + font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write); - // give unused vertices - vtx_buffer.resize(vtx_write - &vtx_buffer.front()); - const int vtx_count = (int)(vtx_buffer.size() - vtx_begin); - commands.back().vtx_count -= (vtx_count_max - vtx_count); - vtx_write -= (vtx_count_max - vtx_count); + // give unused vertices + vtx_buffer.resize(vtx_write - &vtx_buffer.front()); + const int vtx_count = (int)(vtx_buffer.size() - vtx_begin); + commands.back().vtx_count -= (vtx_count_max - vtx_count); + vtx_write -= (vtx_count_max - vtx_count); } //----------------------------------------------------------------------------- @@ -5012,275 +5012,275 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 ImBitmapFont::ImBitmapFont() { - Data = NULL; - DataOwned = false; - Info = NULL; - Common = NULL; - Glyphs = NULL; - GlyphsCount = 0; - TabCount = 4; + Data = NULL; + DataOwned = false; + Info = NULL; + Common = NULL; + Glyphs = NULL; + GlyphsCount = 0; + TabCount = 4; } -void ImBitmapFont::Clear() +void ImBitmapFont::Clear() { - if (Data && DataOwned) - free(Data); - Data = NULL; - DataOwned = false; - Info = NULL; - Common = NULL; - Glyphs = NULL; - GlyphsCount = 0; - Filenames.clear(); - IndexLookup.clear(); + if (Data && DataOwned) + free(Data); + Data = NULL; + DataOwned = false; + Info = NULL; + Common = NULL; + Glyphs = NULL; + GlyphsCount = 0; + Filenames.clear(); + IndexLookup.clear(); } -bool ImBitmapFont::LoadFromFile(const char* filename) +bool ImBitmapFont::LoadFromFile(const char* filename) { - // Load file - FILE* f; - if ((f = fopen(filename, "rb")) == NULL) - return false; - if (fseek(f, 0, SEEK_END)) - return false; - if ((DataSize = (int)ftell(f)) == -1) - return false; - if (fseek(f, 0, SEEK_SET)) - return false; - if ((Data = (unsigned char*)malloc(DataSize)) == NULL) - { - fclose(f); - return false; - } - if ((int)fread(Data, 1, DataSize, f) != DataSize) - { - fclose(f); - free(Data); - return false; - } - fclose(f); - DataOwned = true; - return LoadFromMemory(Data, DataSize); + // Load file + FILE* f; + if ((f = fopen(filename, "rb")) == NULL) + return false; + if (fseek(f, 0, SEEK_END)) + return false; + if ((DataSize = (int)ftell(f)) == -1) + return false; + if (fseek(f, 0, SEEK_SET)) + return false; + if ((Data = (unsigned char*)malloc(DataSize)) == NULL) + { + fclose(f); + return false; + } + if ((int)fread(Data, 1, DataSize, f) != DataSize) + { + fclose(f); + free(Data); + return false; + } + fclose(f); + DataOwned = true; + return LoadFromMemory(Data, DataSize); } -bool ImBitmapFont::LoadFromMemory(const void* data, int data_size) +bool ImBitmapFont::LoadFromMemory(const void* data, int data_size) { - Data = (unsigned char*)data; - DataSize = data_size; + Data = (unsigned char*)data; + DataSize = data_size; - // Parse data - if (DataSize < 4 || Data[0] != 'B' || Data[1] != 'M' || Data[2] != 'F' || Data[3] != 0x03) - return false; - for (const unsigned char* p = Data+4; p < Data + DataSize; ) - { - const unsigned char block_type = *(unsigned char*)p; - p += sizeof(unsigned char); - const ImU32 block_size = *(ImU32*)p; - p += sizeof(ImU32); + // Parse data + if (DataSize < 4 || Data[0] != 'B' || Data[1] != 'M' || Data[2] != 'F' || Data[3] != 0x03) + return false; + for (const unsigned char* p = Data+4; p < Data + DataSize; ) + { + const unsigned char block_type = *(unsigned char*)p; + p += sizeof(unsigned char); + const ImU32 block_size = *(ImU32*)p; + p += sizeof(ImU32); - switch (block_type) - { - case 1: - IM_ASSERT(Info == NULL); - Info = (FntInfo*)p; - break; - case 2: - IM_ASSERT(Common == NULL); - Common = (FntCommon*)p; - break; - case 3: - for (const unsigned char* s = p; s < p+block_size && s < Data+DataSize; s = s + strlen((const char*)s) + 1) - Filenames.push_back((const char*)s); - break; - case 4: - IM_ASSERT(Glyphs == NULL && GlyphsCount == 0); - Glyphs = (FntGlyph*)p; - GlyphsCount = block_size / sizeof(FntGlyph); - break; - default: - IM_ASSERT(Kerning == NULL && KerningCount == 0); - Kerning = (FntKerning*)p; - KerningCount = block_size / sizeof(FntKerning); - break; - } - p += block_size; - } + switch (block_type) + { + case 1: + IM_ASSERT(Info == NULL); + Info = (FntInfo*)p; + break; + case 2: + IM_ASSERT(Common == NULL); + Common = (FntCommon*)p; + break; + case 3: + for (const unsigned char* s = p; s < p+block_size && s < Data+DataSize; s = s + strlen((const char*)s) + 1) + Filenames.push_back((const char*)s); + break; + case 4: + IM_ASSERT(Glyphs == NULL && GlyphsCount == 0); + Glyphs = (FntGlyph*)p; + GlyphsCount = block_size / sizeof(FntGlyph); + break; + default: + IM_ASSERT(Kerning == NULL && KerningCount == 0); + Kerning = (FntKerning*)p; + KerningCount = block_size / sizeof(FntKerning); + break; + } + p += block_size; + } - BuildLookupTable(); - return true; + BuildLookupTable(); + return true; } void ImBitmapFont::BuildLookupTable() { - ImU32 max_c = 0; - for (size_t i = 0; i != GlyphsCount; i++) - if (max_c < Glyphs[i].Id) - max_c = Glyphs[i].Id; + ImU32 max_c = 0; + for (size_t i = 0; i != GlyphsCount; i++) + if (max_c < Glyphs[i].Id) + max_c = Glyphs[i].Id; - IndexLookup.clear(); - IndexLookup.resize(max_c + 1); - for (size_t i = 0; i < IndexLookup.size(); i++) - IndexLookup[i] = -1; - for (size_t i = 0; i < GlyphsCount; i++) - IndexLookup[Glyphs[i].Id] = (int)i; + IndexLookup.clear(); + IndexLookup.resize(max_c + 1); + for (size_t i = 0; i < IndexLookup.size(); i++) + IndexLookup[i] = -1; + for (size_t i = 0; i < GlyphsCount; i++) + IndexLookup[Glyphs[i].Id] = (int)i; } const ImBitmapFont::FntGlyph* ImBitmapFont::FindGlyph(unsigned short c) const { - if (c < (int)IndexLookup.size()) - { - const int i = IndexLookup[c]; - if (i >= 0 && i < (int)GlyphsCount) - return &Glyphs[i]; - } - return NULL; + if (c < (int)IndexLookup.size()) + { + const int i = IndexLookup[c]; + if (i >= 0 && i < (int)GlyphsCount) + return &Glyphs[i]; + } + return NULL; } ImVec2 ImBitmapFont::CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining) const { - if (max_width == 0.0f) - max_width = FLT_MAX; - if (!text_end) - text_end = text_begin + strlen(text_begin); + if (max_width == 0.0f) + max_width = FLT_MAX; + if (!text_end) + text_end = text_begin + strlen(text_begin); - const float scale = size / (float)Info->FontSize; - const float line_height = (float)Info->FontSize * scale; + const float scale = size / (float)Info->FontSize; + const float line_height = (float)Info->FontSize * scale; - ImVec2 text_size = ImVec2(0,0); - float line_width = 0.0f; + ImVec2 text_size = ImVec2(0,0); + float line_width = 0.0f; - const char* s = text_begin; - while (s < text_end) - { - const char c = *s; - if (c == '\n') - { - if (text_size.x < line_width) - text_size.x = line_width; - text_size.y += line_height; - line_width = 0; - } - else if (const FntGlyph* glyph = FindGlyph((unsigned short)c)) - { - const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale; - //const float char_extend = (glyph->XOffset + glyph->Width * scale); + const char* s = text_begin; + while (s < text_end) + { + const char c = *s; + if (c == '\n') + { + if (text_size.x < line_width) + text_size.x = line_width; + text_size.y += line_height; + line_width = 0; + } + else if (const FntGlyph* glyph = FindGlyph((unsigned short)c)) + { + const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale; + //const float char_extend = (glyph->XOffset + glyph->Width * scale); - if (line_width + char_width >= max_width) - break; - line_width += char_width; - } - else if (c == '\t') - { - if (const FntGlyph* glyph = FindGlyph((unsigned short)' ')) - line_width += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale; - } + if (line_width + char_width >= max_width) + break; + line_width += char_width; + } + else if (c == '\t') + { + if (const FntGlyph* glyph = FindGlyph((unsigned short)' ')) + line_width += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale; + } - s += 1; - } + s += 1; + } - if (line_width > 0 || text_size.y == 0.0f) - { - if (text_size.x < line_width) - text_size.x = line_width; - text_size.y += line_height; - } + if (line_width > 0 || text_size.y == 0.0f) + { + if (text_size.x < line_width) + text_size.x = line_width; + text_size.y += line_height; + } - if (remaining) - *remaining = s; + if (remaining) + *remaining = s; - return text_size; + return text_size; } void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect_ref, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const { - if (!text_end) - text_end = text_begin + strlen(text_begin); + if (!text_end) + text_end = text_begin + strlen(text_begin); - const float line_height = (float)Info->FontSize; - const float scale = size / (float)Info->FontSize; - const float tex_scale_x = 1.0f / (float)Common->ScaleW; - const float tex_scale_y = 1.0f / (float)(Common->ScaleH); - const float outline = (float)Info->Outline; + const float line_height = (float)Info->FontSize; + const float scale = size / (float)Info->FontSize; + const float tex_scale_x = 1.0f / (float)Common->ScaleW; + const float tex_scale_y = 1.0f / (float)(Common->ScaleH); + const float outline = (float)Info->Outline; - // Align to be pixel perfect - pos.x = (float)(int)pos.x + 0.5f; - pos.y = (float)(int)pos.y + 0.5f; + // Align to be pixel perfect + pos.x = (float)(int)pos.x + 0.5f; + pos.y = (float)(int)pos.y + 0.5f; - const ImVec4 clip_rect = clip_rect_ref; + const ImVec4 clip_rect = clip_rect_ref; - const float uv_offset = GImGui.IO.PixelCenterOffset; + const float uv_offset = GImGui.IO.PixelCenterOffset; - float x = pos.x; - float y = pos.y; - for (const char* s = text_begin; s < text_end; s++) - { - const char c = *s; - if (c == '\n') - { - x = pos.x; - y += line_height * scale; - continue; - } + float x = pos.x; + float y = pos.y; + for (const char* s = text_begin; s < text_end; s++) + { + const char c = *s; + if (c == '\n') + { + x = pos.x; + y += line_height * scale; + continue; + } - if (const FntGlyph* glyph = FindGlyph((unsigned short)c)) - { - const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale; - //const float char_extend = (glyph->XOffset + glyph->Width * scale); + if (const FntGlyph* glyph = FindGlyph((unsigned short)c)) + { + const float char_width = (glyph->XAdvance + Info->SpacingHoriz) * scale; + //const float char_extend = (glyph->XOffset + glyph->Width * scale); - if (c != ' ' && c != '\n') - { - // Clipping due to Y limits is more likely - const float y1 = (float)(y + (glyph->YOffset + outline*2) * scale); - const float y2 = (float)(y1 + glyph->Height * scale); - if (y1 > clip_rect.w || y2 < clip_rect.y) - { - x += char_width; - continue; - } + if (c != ' ' && c != '\n') + { + // Clipping due to Y limits is more likely + const float y1 = (float)(y + (glyph->YOffset + outline*2) * scale); + const float y2 = (float)(y1 + glyph->Height * scale); + if (y1 > clip_rect.w || y2 < clip_rect.y) + { + x += char_width; + continue; + } - const float x1 = (float)(x + (glyph->XOffset + outline) * scale); - const float x2 = (float)(x1 + glyph->Width * scale); - if (x1 > clip_rect.z || x2 < clip_rect.x) - { - x += char_width; - continue; - } + const float x1 = (float)(x + (glyph->XOffset + outline) * scale); + const float x2 = (float)(x1 + glyph->Width * scale); + if (x1 > clip_rect.z || x2 < clip_rect.x) + { + x += char_width; + continue; + } - const float s1 = (uv_offset + glyph->X) * tex_scale_x; - const float t1 = (uv_offset + glyph->Y) * tex_scale_y; - const float s2 = (uv_offset + glyph->X + glyph->Width) * tex_scale_x; - const float t2 = (uv_offset + glyph->Y + glyph->Height) * tex_scale_y; + const float s1 = (uv_offset + glyph->X) * tex_scale_x; + const float t1 = (uv_offset + glyph->Y) * tex_scale_y; + const float s2 = (uv_offset + glyph->X + glyph->Width) * tex_scale_x; + const float t2 = (uv_offset + glyph->Y + glyph->Height) * tex_scale_y; - out_vertices[0].pos = ImVec2(x1, y1); - out_vertices[0].uv = ImVec2(s1, t1); - out_vertices[0].col = col; + out_vertices[0].pos = ImVec2(x1, y1); + out_vertices[0].uv = ImVec2(s1, t1); + out_vertices[0].col = col; - out_vertices[1].pos = ImVec2(x2, y1); - out_vertices[1].uv = ImVec2(s2, t1); - out_vertices[1].col = col; + out_vertices[1].pos = ImVec2(x2, y1); + out_vertices[1].uv = ImVec2(s2, t1); + out_vertices[1].col = col; - out_vertices[2].pos = ImVec2(x2, y2); - out_vertices[2].uv = ImVec2(s2, t2); - out_vertices[2].col = col; + out_vertices[2].pos = ImVec2(x2, y2); + out_vertices[2].uv = ImVec2(s2, t2); + out_vertices[2].col = col; - out_vertices[3] = out_vertices[0]; - out_vertices[4] = out_vertices[2]; + out_vertices[3] = out_vertices[0]; + out_vertices[4] = out_vertices[2]; - out_vertices[5].pos = ImVec2(x1, y2); - out_vertices[5].uv = ImVec2(s1, t2); - out_vertices[5].col = col; + out_vertices[5].pos = ImVec2(x1, y2); + out_vertices[5].uv = ImVec2(s1, t2); + out_vertices[5].col = col; - out_vertices += 6; - } + out_vertices += 6; + } - x += char_width; - } - else if (c == '\t') - { - if (const FntGlyph* glyph = FindGlyph((unsigned short)' ')) - x += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale; - } - } + x += char_width; + } + else if (c == '\t') + { + if (const FntGlyph* glyph = FindGlyph((unsigned short)' ')) + x += (glyph->XAdvance + Info->SpacingHoriz) * 4 * scale; + } + } } //----------------------------------------------------------------------------- @@ -5293,67 +5293,67 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c #include // Win32 API clipboard implementation -static const char* GetClipboardTextFn_DefaultImpl() +static const char* GetClipboardTextFn_DefaultImpl() { - static char* buf_local = NULL; - if (buf_local) - { - free(buf_local); - buf_local = NULL; - } - if (!OpenClipboard(NULL)) - return NULL; - HANDLE buf_handle = GetClipboardData(CF_TEXT); - if (buf_handle == NULL) - return NULL; - if (char* buf_global = (char*)GlobalLock(buf_handle)) - buf_local = strdup(buf_global); - GlobalUnlock(buf_handle); - CloseClipboard(); - return buf_local; + static char* buf_local = NULL; + if (buf_local) + { + free(buf_local); + buf_local = NULL; + } + if (!OpenClipboard(NULL)) + return NULL; + HANDLE buf_handle = GetClipboardData(CF_TEXT); + if (buf_handle == NULL) + return NULL; + if (char* buf_global = (char*)GlobalLock(buf_handle)) + buf_local = strdup(buf_global); + GlobalUnlock(buf_handle); + CloseClipboard(); + return buf_local; } // Win32 API clipboard implementation static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_end) { - if (!OpenClipboard(NULL)) - return; - if (!text_end) - text_end = text + strlen(text); - const int buf_length = (int)(text_end - text) + 1; - HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, buf_length * sizeof(char)); - if (buf_handle == NULL) - return; - char* buf_global = (char *)GlobalLock(buf_handle); - memcpy(buf_global, text, text_end - text); - buf_global[text_end - text] = 0; - GlobalUnlock(buf_handle); - EmptyClipboard(); - SetClipboardData(CF_TEXT, buf_handle); - CloseClipboard(); + if (!OpenClipboard(NULL)) + return; + if (!text_end) + text_end = text + strlen(text); + const int buf_length = (int)(text_end - text) + 1; + HGLOBAL buf_handle = GlobalAlloc(GMEM_MOVEABLE, buf_length * sizeof(char)); + if (buf_handle == NULL) + return; + char* buf_global = (char *)GlobalLock(buf_handle); + memcpy(buf_global, text, text_end - text); + buf_global[text_end - text] = 0; + GlobalUnlock(buf_handle); + EmptyClipboard(); + SetClipboardData(CF_TEXT, buf_handle); + CloseClipboard(); } #else // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers -static const char* GetClipboardTextFn_DefaultImpl() +static const char* GetClipboardTextFn_DefaultImpl() { - return GImGui.PrivateClipboard; + return GImGui.PrivateClipboard; } // Local ImGui-only clipboard implementation, if user hasn't defined better clipboard handlers static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_end) { - if (GImGui.PrivateClipboard) - { - free(GImGui.PrivateClipboard); - GImGui.PrivateClipboard = NULL; - } - if (!text_end) - text_end = text + strlen(text); - GImGui.PrivateClipboard = (char*)malloc(text_end - text + 1); - memcpy(GImGui.PrivateClipboard, text, text_end - text); - GImGui.PrivateClipboard[text_end - text] = 0; + if (GImGui.PrivateClipboard) + { + free(GImGui.PrivateClipboard); + GImGui.PrivateClipboard = NULL; + } + if (!text_end) + text_end = text + strlen(text); + GImGui.PrivateClipboard = (char*)malloc(text_end - text + 1); + memcpy(GImGui.PrivateClipboard, text, text_end - text); + GImGui.PrivateClipboard[text_end - text] = 0; } #endif @@ -5367,72 +5367,72 @@ namespace ImGui void ShowUserGuide() { - ImGuiState& g = GImGui; + ImGuiState& g = GImGui; - ImGui::BulletText("Double-click on title bar to collapse window."); - ImGui::BulletText("Click and drag on lower right corner to resize window."); - ImGui::BulletText("Click and drag on any empty space to move window."); - ImGui::BulletText("Mouse Wheel to scroll."); - if (g.IO.FontAllowScaling) - ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); - ImGui::BulletText("TAB/SHIFT+TAB to cycle thru keyboard editable fields."); - ImGui::BulletText("CTRL+Click on a slider to input text."); - ImGui::BulletText( - "While editing text:\n" - "- Hold SHIFT or use mouse to select text\n" - "- CTRL+Left/Right to word jump\n" - "- CTRL+A select all\n" - "- CTRL+X,CTRL+C,CTRL+V clipboard\n" - "- CTRL+Z,CTRL+Y undo/redo\n" - "- ESCAPE to revert\n" - "- You can apply arithmetic operators +,*,/ on numerical values.\n" - " Use +- to subtract.\n"); + ImGui::BulletText("Double-click on title bar to collapse window."); + ImGui::BulletText("Click and drag on lower right corner to resize window."); + ImGui::BulletText("Click and drag on any empty space to move window."); + ImGui::BulletText("Mouse Wheel to scroll."); + if (g.IO.FontAllowScaling) + ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents."); + ImGui::BulletText("TAB/SHIFT+TAB to cycle thru keyboard editable fields."); + ImGui::BulletText("CTRL+Click on a slider to input text."); + ImGui::BulletText( + "While editing text:\n" + "- Hold SHIFT or use mouse to select text\n" + "- CTRL+Left/Right to word jump\n" + "- CTRL+A select all\n" + "- CTRL+X,CTRL+C,CTRL+V clipboard\n" + "- CTRL+Z,CTRL+Y undo/redo\n" + "- ESCAPE to revert\n" + "- You can apply arithmetic operators +,*,/ on numerical values.\n" + " Use +- to subtract.\n"); } void ShowStyleEditor(ImGuiStyle* ref) { - ImGuiState& g = GImGui; - ImGuiStyle& style = g.Style; + ImGuiState& g = GImGui; + ImGuiStyle& style = g.Style; - const ImGuiStyle def; + const ImGuiStyle def; - if (ImGui::Button("Revert Style")) - g.Style = ref ? *ref : def; - if (ref) - { - ImGui::SameLine(); - if (ImGui::Button("Save Style")) - *ref = g.Style; - } + if (ImGui::Button("Revert Style")) + g.Style = ref ? *ref : def; + if (ref) + { + ImGui::SameLine(); + if (ImGui::Button("Save Style")) + *ref = g.Style; + } - ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero. - ImGui::SliderFloat("Rounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); + ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero. + ImGui::SliderFloat("Rounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); - static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; - ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB); - ImGui::SameLine(); - ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV); - ImGui::SameLine(); - ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX); + static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; + ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB); + ImGui::SameLine(); + ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV); + ImGui::SameLine(); + ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX); - static ImGuiTextFilter filter; - filter.Draw("Filter colors", 200); + static ImGuiTextFilter filter; + filter.Draw("Filter colors", 200); - ImGui::ColorEditMode(edit_mode); - for (int i = 0; i < ImGuiCol_COUNT; i++) - { - const char* name = GetStyleColorName(i); - if (!filter.PassFilter(name)) - continue; - ImGui::PushID(i); - ImGui::ColorEdit4(name, (float*)&style.Colors[i], true); - if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0) - { - ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i]; - if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; } - } - ImGui::PopID(); - } + ImGui::ColorEditMode(edit_mode); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const char* name = GetStyleColorName(i); + if (!filter.PassFilter(name)) + continue; + ImGui::PushID(i); + ImGui::ColorEdit4(name, (float*)&style.Colors[i], true); + if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0) + { + ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i]; + if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; } + } + ImGui::PopID(); + } } //----------------------------------------------------------------------------- @@ -5442,409 +5442,409 @@ void ShowStyleEditor(ImGuiStyle* ref) // Demonstrate ImGui features (unfortunately this makes this function a little bloated!) void ShowTestWindow(bool* open) { - static bool no_titlebar = false; - static bool no_border = true; - static bool no_resize = false; - static bool no_move = false; - static bool no_scrollbar = false; - static float fill_alpha = 0.65f; + static bool no_titlebar = false; + static bool no_border = true; + static bool no_resize = false; + static bool no_move = false; + static bool no_scrollbar = false; + static float fill_alpha = 0.65f; - const ImU32 layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0); - ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags); - ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); + const ImU32 layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0); + ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags); + ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); - ImGui::Text("ImGui says hello."); - //ImGui::Text("MousePos (%g, %g)", g.IO.MousePos.x, g.IO.MousePos.y); - //ImGui::Text("MouseWheel %d", g.IO.MouseWheel); + ImGui::Text("ImGui says hello."); + //ImGui::Text("MousePos (%g, %g)", g.IO.MousePos.x, g.IO.MousePos.y); + //ImGui::Text("MouseWheel %d", g.IO.MouseWheel); - ImGui::Spacing(); - if (ImGui::CollapsingHeader("Help")) - { - ImGui::ShowUserGuide(); - } + ImGui::Spacing(); + if (ImGui::CollapsingHeader("Help")) + { + ImGui::ShowUserGuide(); + } - if (ImGui::CollapsingHeader("Window options")) - { - ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(200); - ImGui::Checkbox("no border", &no_border); ImGui::SameLine(400); - ImGui::Checkbox("no resize", &no_resize); - ImGui::Checkbox("no move", &no_move); ImGui::SameLine(200); - ImGui::Checkbox("no scrollbar", &no_scrollbar); - ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f); - if (ImGui::TreeNode("Style Editor")) - { - ImGui::ShowStyleEditor(); - ImGui::TreePop(); - } + if (ImGui::CollapsingHeader("Window options")) + { + ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(200); + ImGui::Checkbox("no border", &no_border); ImGui::SameLine(400); + ImGui::Checkbox("no resize", &no_resize); + ImGui::Checkbox("no move", &no_move); ImGui::SameLine(200); + ImGui::Checkbox("no scrollbar", &no_scrollbar); + ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f); + if (ImGui::TreeNode("Style Editor")) + { + ImGui::ShowStyleEditor(); + ImGui::TreePop(); + } - if (ImGui::TreeNode("Logging")) - { - ImGui::LogButtons(); - ImGui::TreePop(); - } - } + if (ImGui::TreeNode("Logging")) + { + ImGui::LogButtons(); + ImGui::TreePop(); + } + } - if (ImGui::CollapsingHeader("Widgets")) - { - //ImGui::PushItemWidth(ImGui::GetWindowWidth() - 220); + if (ImGui::CollapsingHeader("Widgets")) + { + //ImGui::PushItemWidth(ImGui::GetWindowWidth() - 220); - static bool a=false; - if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; } - if (a) - { - ImGui::SameLine(); - ImGui::Text("Thanks for clicking me!"); - } + static bool a=false; + if (ImGui::Button("Button")) { printf("Clicked\n"); a ^= 1; } + if (a) + { + ImGui::SameLine(); + ImGui::Text("Thanks for clicking me!"); + } - static bool check = true; - ImGui::Checkbox("checkbox", &check); + static bool check = true; + ImGui::Checkbox("checkbox", &check); - if (ImGui::TreeNode("Tree")) - { - for (size_t i = 0; i < 5; i++) - { - if (ImGui::TreeNode((void*)i, "Child %d", i)) - { - ImGui::Text("blah blah"); - ImGui::SameLine(); - if (ImGui::SmallButton("print")) - printf("Child %d pressed", (int)i); - ImGui::TreePop(); - } - } - ImGui::TreePop(); - } + if (ImGui::TreeNode("Tree")) + { + for (size_t i = 0; i < 5; i++) + { + if (ImGui::TreeNode((void*)i, "Child %d", i)) + { + ImGui::Text("blah blah"); + ImGui::SameLine(); + if (ImGui::SmallButton("print")) + printf("Child %d pressed", (int)i); + ImGui::TreePop(); + } + } + ImGui::TreePop(); + } - if (ImGui::TreeNode("Bullets")) - { - ImGui::BulletText("Bullet point 1"); - ImGui::BulletText("Bullet point 2\nOn multiple lines"); - ImGui::BulletText("Bullet point 3"); - ImGui::TreePop(); - } + if (ImGui::TreeNode("Bullets")) + { + ImGui::BulletText("Bullet point 1"); + ImGui::BulletText("Bullet point 2\nOn multiple lines"); + ImGui::BulletText("Bullet point 3"); + ImGui::TreePop(); + } - if (ImGui::TreeNode("Colored Text")) - { - // This is a merely a shortcut, you can use PushStyleColor()/PopStyleColor() for more flexibility. - ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink"); - ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow"); - ImGui::TreePop(); - } + if (ImGui::TreeNode("Colored Text")) + { + // This is a merely a shortcut, you can use PushStyleColor()/PopStyleColor() for more flexibility. + ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink"); + ImGui::TextColored(ImVec4(1.0f,1.0f,0.0f,1.0f), "Yellow"); + ImGui::TreePop(); + } - static int e = 0; - ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine(); - ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine(); - ImGui::RadioButton("radio c", &e, 2); + static int e = 0; + ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine(); + ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine(); + ImGui::RadioButton("radio c", &e, 2); - ImGui::Text("Hover me"); - if (ImGui::IsHovered()) - ImGui::SetTooltip("I am a tooltip"); + ImGui::Text("Hover me"); + if (ImGui::IsHovered()) + ImGui::SetTooltip("I am a tooltip"); - ImGui::SameLine(); - ImGui::Text("- or me"); - if (ImGui::IsHovered()) - { - ImGui::BeginTooltip(); - ImGui::Text("I am a fancy tooltip"); - static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; - ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); - ImGui::EndTooltip(); - } + ImGui::SameLine(); + ImGui::Text("- or me"); + if (ImGui::IsHovered()) + { + ImGui::BeginTooltip(); + ImGui::Text("I am a fancy tooltip"); + static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; + ImGui::PlotLines("Curve", arr, IM_ARRAYSIZE(arr)); + ImGui::EndTooltip(); + } - static int item = 1; - ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); + static int item = 1; + ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); - const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" }; - static int item2 = -1; - ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items)); + const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD", "EEEE", "FFFF", "GGGG", "HHHH", "IIII", "JJJJ", "KKKK" }; + static int item2 = -1; + ImGui::Combo("combo scroll", &item2, items, IM_ARRAYSIZE(items)); - static char str0[128] = "Hello, world!"; - static int i0=123; - static float f0=0.001f; - ImGui::InputText("string", str0, IM_ARRAYSIZE(str0)); - ImGui::InputInt("input int", &i0); - ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); + static char str0[128] = "Hello, world!"; + static int i0=123; + static float f0=0.001f; + ImGui::InputText("string", str0, IM_ARRAYSIZE(str0)); + ImGui::InputInt("input int", &i0); + ImGui::InputFloat("input float", &f0, 0.01f, 1.0f); - //static float vec2a[3] = { 0.10f, 0.20f }; - //ImGui::InputFloat2("input float2", vec2a); + //static float vec2a[3] = { 0.10f, 0.20f }; + //ImGui::InputFloat2("input float2", vec2a); - static float vec3a[3] = { 0.10f, 0.20f, 0.30f }; - ImGui::InputFloat3("input float3", vec3a); + static float vec3a[3] = { 0.10f, 0.20f, 0.30f }; + ImGui::InputFloat3("input float3", vec3a); - //static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; - //ImGui::InputFloat4("input float4", vec4a); + //static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; + //ImGui::InputFloat4("input float4", vec4a); - static int i1=0; - static int i2=42; - ImGui::SliderInt("int 0..3", &i1, 0, 3); - ImGui::SliderInt("int -100..100", &i2, -100, 100); + static int i1=0; + static int i2=42; + ImGui::SliderInt("int 0..3", &i1, 0, 3); + ImGui::SliderInt("int -100..100", &i2, -100, 100); - static float f1=1.123f; - static float f2=0; - static float f3=0; - static float f4=123456789.0f; - ImGui::SliderFloat("float", &f1, 0.0f, 2.0f); - ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f); - ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f); - ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f"); - static float angle = 0.0f; - ImGui::SliderAngle("angle", &angle); + static float f1=1.123f; + static float f2=0; + static float f3=0; + static float f4=123456789.0f; + ImGui::SliderFloat("float", &f1, 0.0f, 2.0f); + ImGui::SliderFloat("log float", &f2, 0.0f, 10.0f, "%.4f", 2.0f); + ImGui::SliderFloat("signed log float", &f3, -10.0f, 10.0f, "%.4f", 3.0f); + ImGui::SliderFloat("unbound float", &f4, -FLT_MAX, FLT_MAX, "%.4f"); + static float angle = 0.0f; + ImGui::SliderAngle("angle", &angle); - //static float vec2b[3] = { 0.10f, 0.20f }; - //ImGui::SliderFloat2("slider float2", vec2b, 0.0f, 1.0f); + //static float vec2b[3] = { 0.10f, 0.20f }; + //ImGui::SliderFloat2("slider float2", vec2b, 0.0f, 1.0f); - static float vec3b[3] = { 0.10f, 0.20f, 0.30f }; - ImGui::SliderFloat3("slider float3", vec3b, 0.0f, 1.0f); + static float vec3b[3] = { 0.10f, 0.20f, 0.30f }; + ImGui::SliderFloat3("slider float3", vec3b, 0.0f, 1.0f); - //static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f }; - //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f); + //static float vec4b[4] = { 0.10f, 0.20f, 0.30f, 0.40f }; + //ImGui::SliderFloat4("slider float4", vec4b, 0.0f, 1.0f); - static float col1[3] = { 1.0f,0.0f,0.2f }; - static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; - ImGui::ColorEdit3("color 1", col1); - ImGui::ColorEdit4("color 2", col2); + static float col1[3] = { 1.0f,0.0f,0.2f }; + static float col2[4] = { 0.4f,0.7f,0.0f,0.5f }; + ImGui::ColorEdit3("color 1", col1); + ImGui::ColorEdit4("color 2", col2); - //ImGui::PopItemWidth(); - } + //ImGui::PopItemWidth(); + } - if (ImGui::CollapsingHeader("Graphs widgets")) - { - static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; - ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); + if (ImGui::CollapsingHeader("Graphs widgets")) + { + static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f }; + ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr)); - static bool pause; - static ImVector values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); } - static int values_offset = 0; - if (!pause) - { - // create dummy data at 60 hz - static float refresh_time = -1.0f; - if (ImGui::GetTime() > refresh_time + 1.0f/60.0f) - { - refresh_time = ImGui::GetTime(); - static float phase = 0.0f; - values[values_offset] = cos(phase); - values_offset = (values_offset+1)%values.size(); - phase += 0.10f*values_offset; - } - } - ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70)); + static bool pause; + static ImVector values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); } + static int values_offset = 0; + if (!pause) + { + // create dummy data at 60 hz + static float refresh_time = -1.0f; + if (ImGui::GetTime() > refresh_time + 1.0f/60.0f) + { + refresh_time = ImGui::GetTime(); + static float phase = 0.0f; + values[values_offset] = cos(phase); + values_offset = (values_offset+1)%values.size(); + phase += 0.10f*values_offset; + } + } + ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70)); - ImGui::SameLine(); ImGui::Checkbox("pause", &pause); - ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70)); - } + ImGui::SameLine(); ImGui::Checkbox("pause", &pause); + ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70)); + } - if (ImGui::CollapsingHeader("Widgets on same line")) - { - // Text - ImGui::Text("Hello"); - ImGui::SameLine(); - ImGui::Text("World"); + if (ImGui::CollapsingHeader("Widgets on same line")) + { + // Text + ImGui::Text("Hello"); + ImGui::SameLine(); + ImGui::Text("World"); - // Button - if (ImGui::Button("Banana")) printf("Pressed!\n"); - ImGui::SameLine(); - ImGui::Button("Apple"); - ImGui::SameLine(); - ImGui::Button("Corniflower"); + // Button + if (ImGui::Button("Banana")) printf("Pressed!\n"); + ImGui::SameLine(); + ImGui::Button("Apple"); + ImGui::SameLine(); + ImGui::Button("Corniflower"); - // Button - ImGui::SmallButton("Banana"); - ImGui::SameLine(); - ImGui::SmallButton("Apple"); - ImGui::SameLine(); - ImGui::SmallButton("Corniflower"); - ImGui::SameLine(); - ImGui::Text("Small buttons fit in a text block"); + // Button + ImGui::SmallButton("Banana"); + ImGui::SameLine(); + ImGui::SmallButton("Apple"); + ImGui::SameLine(); + ImGui::SmallButton("Corniflower"); + ImGui::SameLine(); + ImGui::Text("Small buttons fit in a text block"); - // Checkbox - static bool c1=false,c2=false,c3=false,c4=false; - ImGui::Checkbox("My", &c1); - ImGui::SameLine(); - ImGui::Checkbox("Tailor", &c2); - ImGui::SameLine(); - ImGui::Checkbox("Is", &c3); - ImGui::SameLine(); - ImGui::Checkbox("Rich", &c4); + // Checkbox + static bool c1=false,c2=false,c3=false,c4=false; + ImGui::Checkbox("My", &c1); + ImGui::SameLine(); + ImGui::Checkbox("Tailor", &c2); + ImGui::SameLine(); + ImGui::Checkbox("Is", &c3); + ImGui::SameLine(); + ImGui::Checkbox("Rich", &c4); - // SliderFloat - static float f0=1.0f, f1=2.0f, f2=3.0f; - ImGui::PushItemWidth(80); - ImGui::SliderFloat("f0", &f0, 0.0f,5.0f); - ImGui::SameLine(); - ImGui::SliderFloat("f1", &f1, 0.0f,5.0f); - ImGui::SameLine(); - ImGui::SliderFloat("f2", &f2, 0.0f,5.0f); + // SliderFloat + static float f0=1.0f, f1=2.0f, f2=3.0f; + ImGui::PushItemWidth(80); + ImGui::SliderFloat("f0", &f0, 0.0f,5.0f); + ImGui::SameLine(); + ImGui::SliderFloat("f1", &f1, 0.0f,5.0f); + ImGui::SameLine(); + ImGui::SliderFloat("f2", &f2, 0.0f,5.0f); - // InputText - static char s0[128] = "one", s1[128] = "two", s2[128] = "three"; - ImGui::InputText("s0", s0, 128); - ImGui::SameLine(); - ImGui::InputText("s1", s1, 128); - ImGui::SameLine(); - ImGui::InputText("s2", s2, 128); + // InputText + static char s0[128] = "one", s1[128] = "two", s2[128] = "three"; + ImGui::InputText("s0", s0, 128); + ImGui::SameLine(); + ImGui::InputText("s1", s1, 128); + ImGui::SameLine(); + ImGui::InputText("s2", s2, 128); - // LabelText - ImGui::LabelText("l0", "one"); - ImGui::SameLine(); - ImGui::LabelText("l0", "two"); - ImGui::SameLine(); - ImGui::LabelText("l0", "three"); - ImGui::PopItemWidth(); - } + // LabelText + ImGui::LabelText("l0", "one"); + ImGui::SameLine(); + ImGui::LabelText("l0", "two"); + ImGui::SameLine(); + ImGui::LabelText("l0", "three"); + ImGui::PopItemWidth(); + } - if (ImGui::CollapsingHeader("Child regions")) - { - ImGui::Text("Without border"); - static int line = 50; - bool goto_line = ImGui::Button("Goto"); - ImGui::SameLine(); - ImGui::PushItemWidth(100); - ImGui::InputInt("##Line", &line, 0); - ImGui::PopItemWidth(); - ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth()*0.5f,300)); - for (int i = 0; i < 100; i++) - { - ImGui::Text("%04d: scrollable region", i); - if (goto_line && line == i) - ImGui::SetScrollPosHere(); - } - if (goto_line && line >= 100) - ImGui::SetScrollPosHere(); - ImGui::EndChild(); + if (ImGui::CollapsingHeader("Child regions")) + { + ImGui::Text("Without border"); + static int line = 50; + bool goto_line = ImGui::Button("Goto"); + ImGui::SameLine(); + ImGui::PushItemWidth(100); + ImGui::InputInt("##Line", &line, 0); + ImGui::PopItemWidth(); + ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth()*0.5f,300)); + for (int i = 0; i < 100; i++) + { + ImGui::Text("%04d: scrollable region", i); + if (goto_line && line == i) + ImGui::SetScrollPosHere(); + } + if (goto_line && line >= 100) + ImGui::SetScrollPosHere(); + ImGui::EndChild(); - ImGui::SameLine(); + ImGui::SameLine(); - ImGui::BeginChild("Sub2", ImVec2(0,300), true); - ImGui::Text("With border"); - ImGui::Columns(2); - for (int i = 0; i < 100; i++) - { - char buf[32]; - ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731); - ImGui::Button(buf); - ImGui::NextColumn(); - } - ImGui::EndChild(); - } + ImGui::BeginChild("Sub2", ImVec2(0,300), true); + ImGui::Text("With border"); + ImGui::Columns(2); + for (int i = 0; i < 100; i++) + { + char buf[32]; + ImFormatString(buf, IM_ARRAYSIZE(buf), "%08x", i*5731); + ImGui::Button(buf); + ImGui::NextColumn(); + } + ImGui::EndChild(); + } - if (ImGui::CollapsingHeader("Columns")) - { - ImGui::Columns(4, "data", true); - ImGui::Text("ID"); ImGui::NextColumn(); - ImGui::Text("Name"); ImGui::NextColumn(); - ImGui::Text("Path"); ImGui::NextColumn(); - ImGui::Text("Flags"); ImGui::NextColumn(); - ImGui::Separator(); + if (ImGui::CollapsingHeader("Columns")) + { + ImGui::Columns(4, "data", true); + ImGui::Text("ID"); ImGui::NextColumn(); + ImGui::Text("Name"); ImGui::NextColumn(); + ImGui::Text("Path"); ImGui::NextColumn(); + ImGui::Text("Flags"); ImGui::NextColumn(); + ImGui::Separator(); - ImGui::Text("0000"); ImGui::NextColumn(); - ImGui::Text("Robert"); ImGui::NextColumn(); - ImGui::Text("/path/robert"); ImGui::NextColumn(); - ImGui::Text("...."); ImGui::NextColumn(); + ImGui::Text("0000"); ImGui::NextColumn(); + ImGui::Text("Robert"); ImGui::NextColumn(); + ImGui::Text("/path/robert"); ImGui::NextColumn(); + ImGui::Text("...."); ImGui::NextColumn(); - ImGui::Text("0001"); ImGui::NextColumn(); - ImGui::Text("Stephanie"); ImGui::NextColumn(); - ImGui::Text("/path/stephanie"); ImGui::NextColumn(); - ImGui::Text("...."); ImGui::NextColumn(); + ImGui::Text("0001"); ImGui::NextColumn(); + ImGui::Text("Stephanie"); ImGui::NextColumn(); + ImGui::Text("/path/stephanie"); ImGui::NextColumn(); + ImGui::Text("...."); ImGui::NextColumn(); - ImGui::Text("0002"); ImGui::NextColumn(); - ImGui::Text("C64"); ImGui::NextColumn(); - ImGui::Text("/path/computer"); ImGui::NextColumn(); - ImGui::Text("...."); ImGui::NextColumn(); - ImGui::Columns(1); + ImGui::Text("0002"); ImGui::NextColumn(); + ImGui::Text("C64"); ImGui::NextColumn(); + ImGui::Text("/path/computer"); ImGui::NextColumn(); + ImGui::Text("...."); ImGui::NextColumn(); + ImGui::Columns(1); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Columns(3, "mixed"); - ImGui::Text("Hello"); ImGui::NextColumn(); - ImGui::Text("World"); ImGui::NextColumn(); - ImGui::Text("Hmm..."); ImGui::NextColumn(); + ImGui::Columns(3, "mixed"); + ImGui::Text("Hello"); ImGui::NextColumn(); + ImGui::Text("World"); ImGui::NextColumn(); + ImGui::Text("Hmm..."); ImGui::NextColumn(); - ImGui::Button("Banana"); ImGui::NextColumn(); - ImGui::Button("Apple"); ImGui::NextColumn(); - ImGui::Button("Corniflower"); ImGui::NextColumn(); + ImGui::Button("Banana"); ImGui::NextColumn(); + ImGui::Button("Apple"); ImGui::NextColumn(); + ImGui::Button("Corniflower"); ImGui::NextColumn(); - static int e = 0; - ImGui::RadioButton("radio a", &e, 0); ImGui::NextColumn(); - ImGui::RadioButton("radio b", &e, 1); ImGui::NextColumn(); - ImGui::RadioButton("radio c", &e, 2); ImGui::NextColumn(); - ImGui::Columns(1); + static int e = 0; + ImGui::RadioButton("radio a", &e, 0); ImGui::NextColumn(); + ImGui::RadioButton("radio b", &e, 1); ImGui::NextColumn(); + ImGui::RadioButton("radio c", &e, 2); ImGui::NextColumn(); + ImGui::Columns(1); - ImGui::Separator(); + ImGui::Separator(); - ImGui::Columns(2, "multiple components"); - static float foo = 1.0f; - ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn(); - static float bar = 1.0f; - ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn(); - ImGui::Columns(1); + ImGui::Columns(2, "multiple components"); + static float foo = 1.0f; + ImGui::InputFloat("red", &foo, 0.05f, 0, 3); ImGui::NextColumn(); + static float bar = 1.0f; + ImGui::InputFloat("blue", &bar, 0.05f, 0, 3); ImGui::NextColumn(); + ImGui::Columns(1); - ImGui::Separator(); + ImGui::Separator(); - if (ImGui::TreeNode("Inside a tree..")) - { - if (ImGui::TreeNode("node 1 (with borders)")) - { - ImGui::Columns(4); - ImGui::Text("aaa"); ImGui::NextColumn(); - ImGui::Text("bbb"); ImGui::NextColumn(); - ImGui::Text("ccc"); ImGui::NextColumn(); - ImGui::Text("ddd"); ImGui::NextColumn(); - ImGui::Text("eee"); ImGui::NextColumn(); - ImGui::Text("fff"); ImGui::NextColumn(); - ImGui::Text("ggg"); ImGui::NextColumn(); - ImGui::Text("hhh"); ImGui::NextColumn(); - ImGui::Columns(1); - ImGui::TreePop(); - } - if (ImGui::TreeNode("node 2 (without borders)")) - { - ImGui::Columns(4, NULL, false); - ImGui::Text("aaa"); ImGui::NextColumn(); - ImGui::Text("bbb"); ImGui::NextColumn(); - ImGui::Text("ccc"); ImGui::NextColumn(); - ImGui::Text("ddd"); ImGui::NextColumn(); - ImGui::Text("eee"); ImGui::NextColumn(); - ImGui::Text("fff"); ImGui::NextColumn(); - ImGui::Text("ggg"); ImGui::NextColumn(); - ImGui::Text("hhh"); ImGui::NextColumn(); - ImGui::Columns(1); - ImGui::TreePop(); - } - ImGui::TreePop(); - } - } + if (ImGui::TreeNode("Inside a tree..")) + { + if (ImGui::TreeNode("node 1 (with borders)")) + { + ImGui::Columns(4); + ImGui::Text("aaa"); ImGui::NextColumn(); + ImGui::Text("bbb"); ImGui::NextColumn(); + ImGui::Text("ccc"); ImGui::NextColumn(); + ImGui::Text("ddd"); ImGui::NextColumn(); + ImGui::Text("eee"); ImGui::NextColumn(); + ImGui::Text("fff"); ImGui::NextColumn(); + ImGui::Text("ggg"); ImGui::NextColumn(); + ImGui::Text("hhh"); ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::TreePop(); + } + if (ImGui::TreeNode("node 2 (without borders)")) + { + ImGui::Columns(4, NULL, false); + ImGui::Text("aaa"); ImGui::NextColumn(); + ImGui::Text("bbb"); ImGui::NextColumn(); + ImGui::Text("ccc"); ImGui::NextColumn(); + ImGui::Text("ddd"); ImGui::NextColumn(); + ImGui::Text("eee"); ImGui::NextColumn(); + ImGui::Text("fff"); ImGui::NextColumn(); + ImGui::Text("ggg"); ImGui::NextColumn(); + ImGui::Text("hhh"); ImGui::NextColumn(); + ImGui::Columns(1); + ImGui::TreePop(); + } + ImGui::TreePop(); + } + } - if (ImGui::CollapsingHeader("Filtering")) - { - static ImGuiTextFilter filter; - filter.Draw(); - const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; - for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++) - if (filter.PassFilter(lines[i])) - ImGui::BulletText("%s", lines[i]); - } + if (ImGui::CollapsingHeader("Filtering")) + { + static ImGuiTextFilter filter; + filter.Draw(); + const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; + for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++) + if (filter.PassFilter(lines[i])) + ImGui::BulletText("%s", lines[i]); + } - if (ImGui::CollapsingHeader("Long text")) - { - static ImGuiTextBuffer log; - static int lines = 0; - ImGui::Text("Printing unusually long amount of text."); - ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); - if (ImGui::Button("Clear")) { log.clear(); lines = 0; } - ImGui::SameLine(); - if (ImGui::Button("Add 1000 lines")) - { - for (size_t i = 0; i < 1000; i++) - log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i); - lines += 1000; - } - ImGui::BeginChild("Log"); - ImGui::TextUnformatted(log.begin(), log.end()); - ImGui::EndChild(); - } + if (ImGui::CollapsingHeader("Long text")) + { + static ImGuiTextBuffer log; + static int lines = 0; + ImGui::Text("Printing unusually long amount of text."); + ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); + if (ImGui::Button("Clear")) { log.clear(); lines = 0; } + ImGui::SameLine(); + if (ImGui::Button("Add 1000 lines")) + { + for (size_t i = 0; i < 1000; i++) + log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i); + lines += 1000; + } + ImGui::BeginChild("Log"); + ImGui::TextUnformatted(log.begin(), log.end()); + ImGui::EndChild(); + } - ImGui::End(); + ImGui::End(); } // End of Sample code @@ -5883,24 +5883,24 @@ void ShowTestWindow(bool* open) /* static void binary_to_c(const char* name_in, const char* symbol) { - FILE* fi = fopen(name_in, "rb"); fseek(fi, 0, SEEK_END); long sz = ftell(fi); fseek(fi, 0, SEEK_SET); - fprintf(stdout, "static const unsigned int %s_size = %d;\n", symbol, sz); - fprintf(stdout, "static const unsigned int %s_data[%d/4] =\n{", symbol, ((sz+3)/4)*4); - int column = 0; - for (unsigned int data = 0; fread(&data, 1, 4, fi); data = 0) - if ((column++ % 12) == 0) - fprintf(stdout, "\n 0x%08x, ", data); - else - fprintf(stdout, "0x%08x, ", data); - fprintf(stdout, "\n};\n\n"); - fclose(fi); + FILE* fi = fopen(name_in, "rb"); fseek(fi, 0, SEEK_END); long sz = ftell(fi); fseek(fi, 0, SEEK_SET); + fprintf(stdout, "static const unsigned int %s_size = %d;\n", symbol, sz); + fprintf(stdout, "static const unsigned int %s_data[%d/4] =\n{", symbol, ((sz+3)/4)*4); + int column = 0; + for (unsigned int data = 0; fread(&data, 1, 4, fi); data = 0) + if ((column++ % 12) == 0) + fprintf(stdout, "\n 0x%08x, ", data); + else + fprintf(stdout, "0x%08x, ", data); + fprintf(stdout, "\n};\n\n"); + fclose(fi); } int main(int argc, char** argv) { - binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt"); - binary_to_c("proggy_clean_13.png", "proggy_clean_13_png"); - return 1; + binary_to_c("proggy_clean_13.fnt", "proggy_clean_13_fnt"); + binary_to_c("proggy_clean_13.png", "proggy_clean_13_png"); + return 1; } */ //----------------------------------------------------------------------------- @@ -6050,10 +6050,10 @@ namespace ImGui void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size) { - if (fnt_data) *fnt_data = (const void*)proggy_clean_13_fnt_data; - if (fnt_size) *fnt_size = proggy_clean_13_fnt_size; - if (png_data) *png_data = (const void*)proggy_clean_13_png_data; - if (png_size) *png_size = proggy_clean_13_png_size; + if (fnt_data) *fnt_data = (const void*)proggy_clean_13_fnt_data; + if (fnt_size) *fnt_size = proggy_clean_13_fnt_size; + if (png_data) *png_data = (const void*)proggy_clean_13_png_data; + if (png_size) *png_size = proggy_clean_13_png_size; } }; diff --git a/imgui.h b/imgui.h index 00bc6ee9..be1604b9 100644 --- a/imgui.h +++ b/imgui.h @@ -15,43 +15,43 @@ struct ImGuiStyle; struct ImGuiWindow; #include "imconfig.h" -#include // FLT_MAX -#include // va_list -#include // NULL +#include // FLT_MAX +#include // va_list +#include // NULL #ifndef IM_ASSERT #include -#define IM_ASSERT(_EXPR) assert(_EXPR) +#define IM_ASSERT(_EXPR) assert(_EXPR) #endif typedef unsigned int ImU32; typedef ImU32 ImGuiID; -typedef int ImGuiCol; // enum ImGuiCol_ -typedef int ImGuiKey; // enum ImGuiKey_ -typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_ -typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_ -typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_ +typedef int ImGuiCol; // enum ImGuiCol_ +typedef int ImGuiKey; // enum ImGuiKey_ +typedef int ImGuiColorEditMode; // enum ImGuiColorEditMode_ +typedef int ImGuiWindowFlags; // enum ImGuiWindowFlags_ +typedef int ImGuiInputTextFlags; // enum ImGuiInputTextFlags_ typedef ImBitmapFont* ImFont; struct ImVec2 { - float x, y; - ImVec2() {} - ImVec2(float _x, float _y) { x = _x; y = _y; } + float x, y; + ImVec2() {} + ImVec2(float _x, float _y) { x = _x; y = _y; } #ifdef IM_VEC2_CLASS_EXTRA - IM_VEC2_CLASS_EXTRA + IM_VEC2_CLASS_EXTRA #endif }; struct ImVec4 { - float x, y, z, w; - ImVec4() {} - ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } + float x, y, z, w; + ImVec4() {} + ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } #ifdef IM_VEC4_CLASS_EXTRA - IM_VEC4_CLASS_EXTRA + IM_VEC4_CLASS_EXTRA #endif }; @@ -62,373 +62,373 @@ template class ImVector { private: - size_t Size; - size_t Capacity; - T* Data; + size_t Size; + size_t Capacity; + T* Data; public: - typedef T value_type; - typedef value_type* iterator; - typedef const value_type* const_iterator; + typedef T value_type; + typedef value_type* iterator; + typedef const value_type* const_iterator; - ImVector() { Size = Capacity = 0; Data = NULL; } - ~ImVector() { if (Data) free(Data); } + ImVector() { Size = Capacity = 0; Data = NULL; } + ~ImVector() { if (Data) free(Data); } - inline bool empty() const { return Size == 0; } - inline size_t size() const { return Size; } - inline size_t capacity() const { return Capacity; } + inline bool empty() const { return Size == 0; } + inline size_t size() const { return Size; } + inline size_t capacity() const { return Capacity; } - inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; } - inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; } - inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; } - inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; } + inline value_type& at(size_t i) { IM_ASSERT(i < Size); return Data[i]; } + inline const value_type& at(size_t i) const { IM_ASSERT(i < Size); return Data[i]; } + inline value_type& operator[](size_t i) { IM_ASSERT(i < Size); return Data[i]; } + inline const value_type& operator[](size_t i) const { IM_ASSERT(i < Size); return Data[i]; } - inline void clear() { if (Data) { Size = Capacity = 0; free(Data); Data = NULL; } } - inline iterator begin() { return Data; } - inline const_iterator begin() const { return Data; } - inline iterator end() { return Data + Size; } - inline const_iterator end() const { return Data + Size; } - inline value_type& front() { return at(0); } - inline const value_type& front() const { return at(0); } - inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); } - inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); } - inline void swap(ImVector& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } + inline void clear() { if (Data) { Size = Capacity = 0; free(Data); Data = NULL; } } + inline iterator begin() { return Data; } + inline const_iterator begin() const { return Data; } + inline iterator end() { return Data + Size; } + inline const_iterator end() const { return Data + Size; } + inline value_type& front() { return at(0); } + inline const value_type& front() const { return at(0); } + inline value_type& back() { IM_ASSERT(Size > 0); return at(Size-1); } + inline const value_type& back() const { IM_ASSERT(Size > 0); return at(Size-1); } + inline void swap(ImVector& rhs) { const size_t rhs_size = rhs.Size; rhs.Size = Size; Size = rhs_size; const size_t rhs_cap = rhs.Capacity; rhs.Capacity = Capacity; Capacity = rhs_cap; value_type* rhs_data = rhs.Data; rhs.Data = Data; Data = rhs_data; } - inline void reserve(size_t new_capacity) { Data = (value_type*)realloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; } - inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } + inline void reserve(size_t new_capacity) { Data = (value_type*)realloc(Data, new_capacity * sizeof(value_type)); Capacity = new_capacity; } + inline void resize(size_t new_size) { if (new_size > Capacity) reserve(new_size); Size = new_size; } - inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } - inline void pop_back() { IM_ASSERT(Size > 0); Size--; } + inline void push_back(const value_type& v) { if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); Data[Size++] = v; } + inline void pop_back() { IM_ASSERT(Size > 0); Size--; } - inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const int off = it - begin(); memmove(Data + off, Data + off + 1, (Size - off - 1) * sizeof(value_type)); Size--; return Data + off; } - inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const int off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - off) * sizeof(value_type)); Data[off] = v; Size++; } + inline iterator erase(const_iterator it) { IM_ASSERT(it >= begin() && it < end()); const int off = it - begin(); memmove(Data + off, Data + off + 1, (Size - off - 1) * sizeof(value_type)); Size--; return Data + off; } + inline void insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= begin() && it <= end()); const int off = it - begin(); if (Size == Capacity) reserve(Capacity ? Capacity * 2 : 4); if (off < (int)Size) memmove(Data + off + 1, Data + off, (Size - off) * sizeof(value_type)); Data[off] = v; Size++; } }; #endif // #ifndef ImVector // Helpers at bottom of the file: -// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only -// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]" -// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text -// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) -// - struct ImDrawList // Draw command list -// - struct ImBitmapFont // Bitmap font loader +// - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only +// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]" +// - struct ImGuiTextBuffer // Text buffer for logging/accumulating text +// - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) +// - struct ImDrawList // Draw command list +// - struct ImBitmapFont // Bitmap font loader // ImGui End-user API // In a namespace so that user can add extra functions (e.g. Value() helpers for your vector or common types) namespace ImGui { - // Main - ImGuiIO& GetIO(); - ImGuiStyle& GetStyle(); - void NewFrame(); - void Render(); - void Shutdown(); - void ShowUserGuide(); - void ShowStyleEditor(ImGuiStyle* ref = NULL); - void ShowTestWindow(bool* open = NULL); + // Main + ImGuiIO& GetIO(); + ImGuiStyle& GetStyle(); + void NewFrame(); + void Render(); + void Shutdown(); + void ShowUserGuide(); + void ShowStyleEditor(ImGuiStyle* ref = NULL); + void ShowTestWindow(bool* open = NULL); - // Window - bool Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0); - void End(); - void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); - void EndChild(); - bool GetWindowIsFocused(); - float GetWindowWidth(); - ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing - void SetWindowPos(const ImVec2& pos); // set current window pos - ImVec2 GetWindowSize(); - ImVec2 GetWindowContentRegionMin(); - ImVec2 GetWindowContentRegionMax(); - ImDrawList* GetWindowDrawList(); - void SetFontScale(float scale); - void SetScrollPosHere(); - void SetTreeStateStorage(ImGuiStorage* tree); - ImGuiStorage* GetTreeStateStorage(); - void PushItemWidth(float item_width); - void PopItemWidth(); - float GetItemWidth(); - void PushAllowKeyboardFocus(bool v); - void PopAllowKeyboardFocus(); - void PushStyleColor(ImGuiCol idx, const ImVec4& col); - void PopStyleColor(); + // Window + bool Begin(const char* name = "Debug", bool* open = NULL, ImVec2 size = ImVec2(0,0), float fill_alpha = -1.0f, ImGuiWindowFlags flags = 0); + void End(); + void BeginChild(const char* str_id, ImVec2 size = ImVec2(0,0), bool border = false, ImGuiWindowFlags extra_flags = 0); + void EndChild(); + bool GetWindowIsFocused(); + float GetWindowWidth(); + ImVec2 GetWindowPos(); // you should rarely need/care about the window position, but it can be useful if you want to use your own drawing + void SetWindowPos(const ImVec2& pos); // set current window pos + ImVec2 GetWindowSize(); + ImVec2 GetWindowContentRegionMin(); + ImVec2 GetWindowContentRegionMax(); + ImDrawList* GetWindowDrawList(); + void SetFontScale(float scale); + void SetScrollPosHere(); + void SetTreeStateStorage(ImGuiStorage* tree); + ImGuiStorage* GetTreeStateStorage(); + void PushItemWidth(float item_width); + void PopItemWidth(); + float GetItemWidth(); + void PushAllowKeyboardFocus(bool v); + void PopAllowKeyboardFocus(); + void PushStyleColor(ImGuiCol idx, const ImVec4& col); + void PopStyleColor(); - // Tooltip - void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins. - void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text. - void EndTooltip(); + // Tooltip + void SetTooltip(const char* fmt, ...); // set tooltip under mouse-cursor, typically use with ImGui::IsHovered(). last call wins. + void BeginTooltip(); // use to create full-featured tooltip windows that aren't just text. + void EndTooltip(); - // Layout - void Separator(); // horizontal line - void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally - void Spacing(); - void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns - void NextColumn(); // next column - float GetColumnOffset(int column_index = -1); - void SetColumnOffset(int column_index, float offset); - float GetColumnWidth(int column_index = -1); - ImVec2 GetCursorPos(); // cursor position is relative to window position - void SetCursorPos(const ImVec2& pos); // " - void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. - float GetTextLineSpacing(); - float GetTextLineHeight(); + // Layout + void Separator(); // horizontal line + void SameLine(int column_x = 0, int spacing_w = -1); // call between widgets to layout them horizontally + void Spacing(); + void Columns(int count = 1, const char* id = NULL, bool border=true); // setup number of columns + void NextColumn(); // next column + float GetColumnOffset(int column_index = -1); + void SetColumnOffset(int column_index, float offset); + float GetColumnWidth(int column_index = -1); + ImVec2 GetCursorPos(); // cursor position is relative to window position + void SetCursorPos(const ImVec2& pos); // " + void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. + float GetTextLineSpacing(); + float GetTextLineHeight(); - // ID scopes - void PushID(const char* str_id); - void PushID(const void* ptr_id); - void PushID(const int int_id); - void PopID(); + // ID scopes + void PushID(const char* str_id); + void PushID(const void* ptr_id); + void PushID(const int int_id); + void PopID(); - // Widgets - void Text(const char* fmt, ...); - void TextV(const char* fmt, va_list args); - void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut to doing PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor(); - void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, better for long chunks of text. - void LabelText(const char* label, const char* fmt, ...); - void BulletText(const char* fmt, ...); - bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false); - bool SmallButton(const char* label); - bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false); - bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - bool SliderFloat4(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); - bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians - bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); - void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - void Checkbox(const char* label, bool* v); - void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); - bool RadioButton(const char* label, bool active); - bool RadioButton(const char* label, int* v, int v_button); - bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1); - bool InputFloat2(const char* label, float v[2], int decimal_precision = -1); - bool InputFloat3(const char* label, float v[3], int decimal_precision = -1); - bool InputFloat4(const char* label, float v[4], int decimal_precision = -1); - bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100); - bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0); - bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7); - bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0 - bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7); - bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true); - bool ColorEdit3(const char* label, float col[3]); - bool ColorEdit4(const char* label, float col[4], bool show_alpha = true); - void ColorEditMode(ImGuiColorEditMode mode); - bool TreeNode(const char* str_label_id); // if returning 'true' the user is responsible for calling TreePop - bool TreeNode(const char* str_id, const char* fmt, ...); // " - bool TreeNode(const void* ptr_id, const char* fmt, ...); // " - void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layout purpose - void TreePush(const void* ptr_id = NULL); // " - void TreePop(); - void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader + // Widgets + void Text(const char* fmt, ...); + void TextV(const char* fmt, va_list args); + void TextColored(const ImVec4& col, const char* fmt, ...); // shortcut to doing PushStyleColor(ImGuiCol_Text, col); Text(fmt, ...); PopStyleColor(); + void TextUnformatted(const char* text, const char* text_end = NULL); // doesn't require null terminated string if 'text_end' is specified. no copy done to any bounded stack buffer, better for long chunks of text. + void LabelText(const char* label, const char* fmt, ...); + void BulletText(const char* fmt, ...); + bool Button(const char* label, ImVec2 size = ImVec2(0,0), bool repeat_when_held = false); + bool SmallButton(const char* label); + bool CollapsingHeader(const char* label, const char* str_id = NULL, const bool display_frame = true, const bool default_open = false); + bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + bool SliderFloat4(const char* label, float v[3], float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); + bool SliderAngle(const char* label, float* v, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); // *v in radians + bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); + void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); + void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); + void Checkbox(const char* label, bool* v); + void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); + bool RadioButton(const char* label, bool active); + bool RadioButton(const char* label, int* v, int v_button); + bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1); + bool InputFloat2(const char* label, float v[2], int decimal_precision = -1); + bool InputFloat3(const char* label, float v[3], int decimal_precision = -1); + bool InputFloat4(const char* label, float v[4], int decimal_precision = -1); + bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100); + bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0); + bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7); + bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0 + bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7); + bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true); + bool ColorEdit3(const char* label, float col[3]); + bool ColorEdit4(const char* label, float col[4], bool show_alpha = true); + void ColorEditMode(ImGuiColorEditMode mode); + bool TreeNode(const char* str_label_id); // if returning 'true' the user is responsible for calling TreePop + bool TreeNode(const char* str_id, const char* fmt, ...); // " + bool TreeNode(const void* ptr_id, const char* fmt, ...); // " + void TreePush(const char* str_id = NULL); // already called by TreeNode(), but you can call Push/Pop yourself for layout purpose + void TreePush(const void* ptr_id = NULL); // " + void TreePop(); + void OpenNextNode(bool open); // force open/close the next TreeNode or CollapsingHeader - // Value helper output "name: value" - // Freely declare your own in the ImGui namespace. - void Value(const char* prefix, bool b); - void Value(const char* prefix, int v); - void Value(const char* prefix, unsigned int v); - void Value(const char* prefix, float v, const char* float_format = NULL); - void Color(const char* prefix, const ImVec4& v); - void Color(const char* prefix, unsigned int v); + // Value helper output "name: value" + // Freely declare your own in the ImGui namespace. + void Value(const char* prefix, bool b); + void Value(const char* prefix, int v); + void Value(const char* prefix, unsigned int v); + void Value(const char* prefix, float v, const char* float_format = NULL); + void Color(const char* prefix, const ImVec4& v); + void Color(const char* prefix, unsigned int v); - // Logging - void LogButtons(); - void LogToTTY(int max_depth = -1); - void LogToFile(int max_depth = -1, const char* filename = NULL); - void LogToClipboard(int max_depth = -1); + // Logging + void LogButtons(); + void LogToTTY(int max_depth = -1); + void LogToFile(int max_depth = -1, const char* filename = NULL); + void LogToClipboard(int max_depth = -1); - // Utilities - void SetNewWindowDefaultPos(const ImVec2& pos); // set position of window that do - bool IsHovered(); // was the last item active area hovered by mouse? - ImVec2 GetItemBoxMin(); // get bounding box of last item - ImVec2 GetItemBoxMax(); // get bounding box of last item - bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimisation) - bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry - bool IsMouseClicked(int button, bool repeat = false); - bool IsMouseDoubleClicked(int button); - bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); - ImVec2 GetMousePos(); - float GetTime(); - int GetFrameCount(); - const char* GetStyleColorName(ImGuiCol idx); - void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); + // Utilities + void SetNewWindowDefaultPos(const ImVec2& pos); // set position of window that do + bool IsHovered(); // was the last item active area hovered by mouse? + ImVec2 GetItemBoxMin(); // get bounding box of last item + ImVec2 GetItemBoxMax(); // get bounding box of last item + bool IsClipped(const ImVec2& item_size); // to perform coarse clipping on user's side (as an optimisation) + bool IsKeyPressed(int key_index, bool repeat = true); // key_index into the keys_down[512] array, imgui doesn't know the semantic of each entry + bool IsMouseClicked(int button, bool repeat = false); + bool IsMouseDoubleClicked(int button); + bool IsMouseHoveringBox(const ImVec2& box_min, const ImVec2& box_max); + ImVec2 GetMousePos(); + float GetTime(); + int GetFrameCount(); + const char* GetStyleColorName(ImGuiCol idx); + void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); }; // namespace ImGui // Flags for ImGui::Begin() enum ImGuiWindowFlags_ { - // Default: 0 - ImGuiWindowFlags_ShowBorders = 1 << 0, - ImGuiWindowFlags_NoTitleBar = 1 << 1, - ImGuiWindowFlags_NoResize = 1 << 2, - ImGuiWindowFlags_NoMove = 1 << 3, - ImGuiWindowFlags_NoScrollbar = 1 << 4, - ImGuiWindowFlags_ChildWindow = 1 << 5, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 6, // For internal use by BeginChild() - ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 7, // For internal use by BeginChild() - ImGuiWindowFlags_ComboBox = 1 << 8, // For internal use by ComboBox() - ImGuiWindowFlags_Tooltip = 1 << 9, // For internal use by Render() when using Tooltip + // Default: 0 + ImGuiWindowFlags_ShowBorders = 1 << 0, + ImGuiWindowFlags_NoTitleBar = 1 << 1, + ImGuiWindowFlags_NoResize = 1 << 2, + ImGuiWindowFlags_NoMove = 1 << 3, + ImGuiWindowFlags_NoScrollbar = 1 << 4, + ImGuiWindowFlags_ChildWindow = 1 << 5, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitX = 1 << 6, // For internal use by BeginChild() + ImGuiWindowFlags_ChildWindowAutoFitY = 1 << 7, // For internal use by BeginChild() + ImGuiWindowFlags_ComboBox = 1 << 8, // For internal use by ComboBox() + ImGuiWindowFlags_Tooltip = 1 << 9, // For internal use by Render() when using Tooltip }; // Flags for ImGui::InputText() enum ImGuiInputTextFlags_ { - // Default: 0 - ImGuiInputTextFlags_CharsDecimal = 1 << 0, - ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, - ImGuiInputTextFlags_AutoSelectAll = 1 << 2, - ImGuiInputTextFlags_AlignCenter = 1 << 3, + // Default: 0 + ImGuiInputTextFlags_CharsDecimal = 1 << 0, + ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, + ImGuiInputTextFlags_AutoSelectAll = 1 << 2, + ImGuiInputTextFlags_AlignCenter = 1 << 3, }; // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array enum ImGuiKey_ { - ImGuiKey_Tab, - ImGuiKey_LeftArrow, - ImGuiKey_RightArrow, - ImGuiKey_UpArrow, - ImGuiKey_DownArrow, - ImGuiKey_Home, - ImGuiKey_End, - ImGuiKey_Delete, - ImGuiKey_Backspace, - ImGuiKey_Enter, - ImGuiKey_Escape, - ImGuiKey_A, // for CTRL+A: select all - ImGuiKey_C, // for CTRL+C: copy - ImGuiKey_V, // for CTRL+V: paste - ImGuiKey_X, // for CTRL+X: cut - ImGuiKey_Y, // for CTRL+Y: redo - ImGuiKey_Z, // for CTRL+Z: undo - ImGuiKey_COUNT, + ImGuiKey_Tab, + ImGuiKey_LeftArrow, + ImGuiKey_RightArrow, + ImGuiKey_UpArrow, + ImGuiKey_DownArrow, + ImGuiKey_Home, + ImGuiKey_End, + ImGuiKey_Delete, + ImGuiKey_Backspace, + ImGuiKey_Enter, + ImGuiKey_Escape, + ImGuiKey_A, // for CTRL+A: select all + ImGuiKey_C, // for CTRL+C: copy + ImGuiKey_V, // for CTRL+V: paste + ImGuiKey_X, // for CTRL+X: cut + ImGuiKey_Y, // for CTRL+Y: redo + ImGuiKey_Z, // for CTRL+Z: undo + ImGuiKey_COUNT, }; enum ImGuiCol_ { - ImGuiCol_Text, - ImGuiCol_WindowBg, - ImGuiCol_Border, - ImGuiCol_BorderShadow, - ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input - ImGuiCol_TitleBg, - ImGuiCol_TitleBgCollapsed, - ImGuiCol_ScrollbarBg, - ImGuiCol_ScrollbarGrab, - ImGuiCol_ScrollbarGrabHovered, - ImGuiCol_ScrollbarGrabActive, - ImGuiCol_ComboBg, - ImGuiCol_CheckHovered, - ImGuiCol_CheckActive, - ImGuiCol_SliderGrab, - ImGuiCol_SliderGrabActive, - ImGuiCol_Button, - ImGuiCol_ButtonHovered, - ImGuiCol_ButtonActive, - ImGuiCol_Header, - ImGuiCol_HeaderHovered, - ImGuiCol_HeaderActive, - ImGuiCol_Column, - ImGuiCol_ColumnHovered, - ImGuiCol_ColumnActive, - ImGuiCol_ResizeGrip, - ImGuiCol_ResizeGripHovered, - ImGuiCol_ResizeGripActive, - ImGuiCol_CloseButton, - ImGuiCol_CloseButtonHovered, - ImGuiCol_CloseButtonActive, - ImGuiCol_PlotLines, - ImGuiCol_PlotLinesHovered, - ImGuiCol_PlotHistogram, - ImGuiCol_PlotHistogramHovered, - ImGuiCol_TextSelectedBg, - ImGuiCol_TooltipBg, - ImGuiCol_COUNT, + ImGuiCol_Text, + ImGuiCol_WindowBg, + ImGuiCol_Border, + ImGuiCol_BorderShadow, + ImGuiCol_FrameBg, // Background of checkbox, radio button, plot, slider, text input + ImGuiCol_TitleBg, + ImGuiCol_TitleBgCollapsed, + ImGuiCol_ScrollbarBg, + ImGuiCol_ScrollbarGrab, + ImGuiCol_ScrollbarGrabHovered, + ImGuiCol_ScrollbarGrabActive, + ImGuiCol_ComboBg, + ImGuiCol_CheckHovered, + ImGuiCol_CheckActive, + ImGuiCol_SliderGrab, + ImGuiCol_SliderGrabActive, + ImGuiCol_Button, + ImGuiCol_ButtonHovered, + ImGuiCol_ButtonActive, + ImGuiCol_Header, + ImGuiCol_HeaderHovered, + ImGuiCol_HeaderActive, + ImGuiCol_Column, + ImGuiCol_ColumnHovered, + ImGuiCol_ColumnActive, + ImGuiCol_ResizeGrip, + ImGuiCol_ResizeGripHovered, + ImGuiCol_ResizeGripActive, + ImGuiCol_CloseButton, + ImGuiCol_CloseButtonHovered, + ImGuiCol_CloseButtonActive, + ImGuiCol_PlotLines, + ImGuiCol_PlotLinesHovered, + ImGuiCol_PlotHistogram, + ImGuiCol_PlotHistogramHovered, + ImGuiCol_TextSelectedBg, + ImGuiCol_TooltipBg, + ImGuiCol_COUNT, }; enum ImGuiColorEditMode_ { - ImGuiColorEditMode_UserSelect = -1, - ImGuiColorEditMode_RGB = 0, - ImGuiColorEditMode_HSV = 1, - ImGuiColorEditMode_HEX = 2, + ImGuiColorEditMode_UserSelect = -1, + ImGuiColorEditMode_RGB = 0, + ImGuiColorEditMode_HSV = 1, + ImGuiColorEditMode_HEX = 2, }; struct ImGuiStyle { - float Alpha; // Global alpha applies to everything in ImGui - ImVec2 WindowPadding; // Padding within a window - ImVec2 WindowMinSize; // Minimum window size - ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) - ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines - ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) - ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! - ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip) - float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() - float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows - float TreeNodeSpacing; // Horizontal spacing when entering a tree node - float ColumnsMinSpacing; // Minimum horizontal spacing between two columns - float ScrollBarWidth; // Width of the vertical scroll bar - ImVec4 Colors[ImGuiCol_COUNT]; + float Alpha; // Global alpha applies to everything in ImGui + ImVec2 WindowPadding; // Padding within a window + ImVec2 WindowMinSize; // Minimum window size + ImVec2 FramePadding; // Padding within a framed rectangle (used by most widgets) + ImVec2 ItemSpacing; // Horizontal and vertical spacing between widgets/lines + ImVec2 ItemInnerSpacing; // Horizontal and vertical spacing between within elements of a composed widget (e.g. a slider and its label) + ImVec2 TouchExtraPadding; // Expand bounding box for touch-based system where touch position is not accurate enough (unnecessary for mouse inputs). Unfortunately we don't sort widgets so priority on overlap will always be given to the first widget running. So dont grow this too much! + ImVec2 AutoFitPadding; // Extra space after auto-fit (double-clicking on resize grip) + float WindowFillAlphaDefault; // Default alpha of window background, if not specified in ImGui::Begin() + float WindowRounding; // Radius of window corners rounding. Set to 0.0f to have rectangular windows + float TreeNodeSpacing; // Horizontal spacing when entering a tree node + float ColumnsMinSpacing; // Minimum horizontal spacing between two columns + float ScrollBarWidth; // Width of the vertical scroll bar + ImVec4 Colors[ImGuiCol_COUNT]; - ImGuiStyle(); + ImGuiStyle(); }; // This is where your app communicate with ImGui. Call ImGui::GetIO() to access. // Read 'Programmer guide' section in .cpp file for general usage. struct ImGuiIO { - // Settings (fill once) // Default value: - ImVec2 DisplaySize; // // Display size, in pixels. For clamping windows positions. - float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. - float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving. - const char* IniFilename; // = "imgui.ini" // Absolute path to .ini file. - const char* LogFilename; // = "imgui_log.txt" // Absolute path to .log file. - float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. - float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. - int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array - ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). - float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y - bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. - float PixelCenterOffset; // = 0.5f // Set to 0.0f for DirectX <= 9, 0.5f for Direct3D >= 10 and OpenGL. + // Settings (fill once) // Default value: + ImVec2 DisplaySize; // // Display size, in pixels. For clamping windows positions. + float DeltaTime; // = 1.0f/60.0f // Time elapsed since last frame, in seconds. + float IniSavingRate; // = 5.0f // Maximum time between saving .ini file, in seconds. Set to a negative value to disable .ini saving. + const char* IniFilename; // = "imgui.ini" // Absolute path to .ini file. + const char* LogFilename; // = "imgui_log.txt" // Absolute path to .log file. + float MouseDoubleClickTime; // = 0.30f // Time for a double-click, in seconds. + float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. + int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array + ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). + float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y + bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. + float PixelCenterOffset; // = 0.5f // Set to 0.0f for DirectX <= 9, 0.5f for Direct3D >= 10 and OpenGL. - // Settings - Rendering function (REQUIRED) - // See example code if you are unsure of how to implement this. - void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); + // Settings - Rendering function (REQUIRED) + // See example code if you are unsure of how to implement this. + void (*RenderDrawListsFn)(ImDrawList** const draw_lists, int count); - // Settings - Clipboard Support - // Override to provide your clipboard handlers. - // On Windows architecture, defaults to use the native Win32 clipboard, otherwise default to use a ImGui private clipboard. - // NB- for SetClipboardTextFn, the string is *NOT* zero-terminated at 'text_end' - const char* (*GetClipboardTextFn)(); - void (*SetClipboardTextFn)(const char* text, const char* text_end); + // Settings - Clipboard Support + // Override to provide your clipboard handlers. + // On Windows architecture, defaults to use the native Win32 clipboard, otherwise default to use a ImGui private clipboard. + // NB- for SetClipboardTextFn, the string is *NOT* zero-terminated at 'text_end' + const char* (*GetClipboardTextFn)(); + void (*SetClipboardTextFn)(const char* text, const char* text_end); - // Input - Fill before calling NewFrame() - ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) - bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience. - int MouseWheel; // Mouse wheel: -1,0,+1 - bool KeyCtrl; // Keyboard modifier pressed: Control - bool KeyShift; // Keyboard modifier pressed: Shift - bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data) - char InputCharacters[16]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. + // Input - Fill before calling NewFrame() + ImVec2 MousePos; // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.) + bool MouseDown[5]; // Mouse buttons. ImGui itself only uses button 0 (left button) but you can use others as storage for convenience. + int MouseWheel; // Mouse wheel: -1,0,+1 + bool KeyCtrl; // Keyboard modifier pressed: Control + bool KeyShift; // Keyboard modifier pressed: Shift + bool KeysDown[512]; // Keyboard keys that are pressed (in whatever order user naturally has access to keyboard data) + char InputCharacters[16]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. - // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application - bool WantCaptureMouse; // ImGui is using your mouse input (= window is being hovered or widget is active). - bool WantCaptureKeyboard; // imGui is using your keyboard input (= widget is active). + // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application + bool WantCaptureMouse; // ImGui is using your mouse input (= window is being hovered or widget is active). + bool WantCaptureKeyboard; // imGui is using your keyboard input (= widget is active). - // Function - void AddInputCharacter(char c); // Helper to add a new character into InputCharacters[] + // Function + void AddInputCharacter(char c); // Helper to add a new character into InputCharacters[] - // [Internal] ImGui will maintain those fields for you - ImVec2 MousePosPrev; - ImVec2 MouseDelta; - bool MouseClicked[5]; - ImVec2 MouseClickedPos[5]; - float MouseClickedTime[5]; - bool MouseDoubleClicked[5]; - float MouseDownTime[5]; - float KeysDownTime[512]; + // [Internal] ImGui will maintain those fields for you + ImVec2 MousePosPrev; + ImVec2 MouseDelta; + bool MouseClicked[5]; + ImVec2 MouseClickedPos[5]; + float MouseClickedTime[5]; + bool MouseDoubleClicked[5]; + float MouseDownTime[5]; + float KeysDownTime[512]; - ImGuiIO(); + ImGuiIO(); }; //----------------------------------------------------------------------------- @@ -437,59 +437,59 @@ struct ImGuiIO // Helper: execute a block of code once a frame only // Usage: if (IMGUI_ONCE_UPON_A_FRAME) {/*do something once a frame*/) -#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOncePerFrame im = ImGuiOncePerFrame() +#define IMGUI_ONCE_UPON_A_FRAME static ImGuiOncePerFrame im = ImGuiOncePerFrame() struct ImGuiOncePerFrame { - ImGuiOncePerFrame() : LastFrame(-1) {} - operator bool() const { return TryIsNewFrame(); } + ImGuiOncePerFrame() : LastFrame(-1) {} + operator bool() const { return TryIsNewFrame(); } private: - mutable int LastFrame; - bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; } + mutable int LastFrame; + bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; } }; // Helper: Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]" struct ImGuiTextFilter { - struct TextRange - { - const char* b; - const char* e; + struct TextRange + { + const char* b; + const char* e; - TextRange() { b = e = NULL; } - TextRange(const char* _b, const char* _e) { b = _b; e = _e; } - const char* begin() const { return b; } - const char* end() const { return e; } - bool empty() const { return b == e; } - char front() const { return *b; } - static bool isblank(char c) { return c == ' ' && c == '\t'; } - void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; } - void split(char separator, ImVector& out); - }; + TextRange() { b = e = NULL; } + TextRange(const char* _b, const char* _e) { b = _b; e = _e; } + const char* begin() const { return b; } + const char* end() const { return e; } + bool empty() const { return b == e; } + char front() const { return *b; } + static bool isblank(char c) { return c == ' ' && c == '\t'; } + void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; } + void split(char separator, ImVector& out); + }; - char InputBuf[256]; - ImVector Filters; - int CountGrep; + char InputBuf[256]; + ImVector Filters; + int CountGrep; - ImGuiTextFilter(); - void Clear() { InputBuf[0] = 0; Build(); } - void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build - bool PassFilter(const char* val) const; - bool IsActive() const { return !Filters.empty(); } - void Build(); + ImGuiTextFilter(); + void Clear() { InputBuf[0] = 0; Build(); } + void Draw(const char* label = "Filter (inc,-exc)", float width = -1.0f); // Helper calling InputText+Build + bool PassFilter(const char* val) const; + bool IsActive() const { return !Filters.empty(); } + void Build(); }; // Helper: Text buffer for logging/accumulating text struct ImGuiTextBuffer { - ImVector Buf; + ImVector Buf; - ImGuiTextBuffer() { Buf.push_back(0); } - const char* begin() const { return Buf.begin(); } - const char* end() const { return Buf.end()-1; } - size_t size() const { return Buf.size()-1; } - bool empty() { return Buf.empty(); } - void clear() { Buf.clear(); Buf.push_back(0); } - void append(const char* fmt, ...); + ImGuiTextBuffer() { Buf.push_back(0); } + const char* begin() const { return Buf.begin(); } + const char* end() const { return Buf.end()-1; } + size_t size() const { return Buf.size()-1; } + bool empty() { return Buf.empty(); } + void clear() { Buf.clear(); Buf.push_back(0); } + void append(const char* fmt, ...); }; // Helper: Key->value storage @@ -499,16 +499,16 @@ struct ImGuiTextBuffer // Declare your own storage if you want to manipulate the open/close state of a particular sub-tree in your interface. struct ImGuiStorage { - struct Pair { ImU32 key; int val; }; - ImVector Data; + struct Pair { ImU32 key; int val; }; + ImVector Data; - void Clear(); - int GetInt(ImU32 key, int default_val = 0); - void SetInt(ImU32 key, int val); - void SetAllInt(int val); + void Clear(); + int GetInt(ImU32 key, int default_val = 0); + void SetInt(ImU32 key, int val); + void SetAllInt(int val); - int* Find(ImU32 key); - void Insert(ImU32 key, int val); + int* Find(ImU32 key); + void Insert(ImU32 key, int val); }; //----------------------------------------------------------------------------- @@ -518,56 +518,56 @@ struct ImGuiStorage struct ImDrawCmd { - unsigned int vtx_count; - ImVec4 clip_rect; + unsigned int vtx_count; + ImVec4 clip_rect; }; #ifndef IMGUI_FONT_TEX_UV_FOR_WHITE -#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f,0.f) +#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f,0.f) #endif // sizeof() == 20 struct ImDrawVert { - ImVec2 pos; - ImVec2 uv; - ImU32 col; + ImVec2 pos; + ImVec2 uv; + ImU32 col; }; // Draw command list // User is responsible for providing a renderer for this in ImGuiIO::RenderDrawListFn struct ImDrawList { - // This is what you have to render - ImVector commands; // commands - ImVector vtx_buffer; // each command consume ImDrawCmd::vtx_count of those + // This is what you have to render + ImVector commands; // commands + ImVector vtx_buffer; // each command consume ImDrawCmd::vtx_count of those - // [Internal to ImGui] - ImVector clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on) - ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much) + // [Internal to ImGui] + ImVector clip_rect_stack; // [internal] clip rect stack while building the command-list (so text command can perform clipping early on) + ImDrawVert* vtx_write; // [internal] point within vtx_buffer after each add command (to avoid using the ImVector<> operators too much) - ImDrawList() { Clear(); } + ImDrawList() { Clear(); } - void Clear(); - void PushClipRect(const ImVec4& clip_rect); - void PopClipRect(); - void ReserveVertices(unsigned int vtx_count); - void AddVtx(const ImVec2& pos, ImU32 col); - void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col); + void Clear(); + void PushClipRect(const ImVec4& clip_rect); + void PopClipRect(); + void ReserveVertices(unsigned int vtx_count); + void AddVtx(const ImVec2& pos, ImU32 col); + void AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col); - // Primitives - void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); - void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); - void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); - void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); - void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); - void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); - void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris=false, const ImVec2& third_point_offset = ImVec2(0,0)); - void AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end); + // Primitives + void AddLine(const ImVec2& a, const ImVec2& b, ImU32 col); + void AddRect(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); + void AddRectFilled(const ImVec2& a, const ImVec2& b, ImU32 col, float rounding = 0.0f, int rounding_corners=0x0F); + void AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec2& c, ImU32 col); + void AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); + void AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, int num_segments = 12); + void AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, int a_max, bool tris=false, const ImVec2& third_point_offset = ImVec2(0,0)); + void AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end); }; // Optional bitmap font data loader & renderer into vertices -// #define ImFont to ImBitmapFont to use +// #define ImFont to ImBitmapFont to use // Using the .fnt format exported by BMFont // - tool: http://www.angelcode.com/products/bmfont // - file-format: http://www.angelcode.com/products/bmfont/doc/file_format.html @@ -577,71 +577,71 @@ struct ImDrawList struct ImBitmapFont { #pragma pack(push, 1) - struct FntInfo - { - signed short FontSize; - unsigned char BitField; // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved - unsigned char CharSet; - unsigned short StretchH; - unsigned char AA; - unsigned char PaddingUp, PaddingRight, PaddingDown, PaddingLeft; - unsigned char SpacingHoriz, SpacingVert; - unsigned char Outline; - //char FontName[]; - }; + struct FntInfo + { + signed short FontSize; + unsigned char BitField; // bit 0: smooth, bit 1: unicode, bit 2: italic, bit 3: bold, bit 4: fixedHeight, bits 5-7: reserved + unsigned char CharSet; + unsigned short StretchH; + unsigned char AA; + unsigned char PaddingUp, PaddingRight, PaddingDown, PaddingLeft; + unsigned char SpacingHoriz, SpacingVert; + unsigned char Outline; + //char FontName[]; + }; - struct FntCommon - { - unsigned short LineHeight; - unsigned short Base; - unsigned short ScaleW, ScaleH; - unsigned short Pages; - unsigned char BitField; - unsigned char Channels[4]; - }; + struct FntCommon + { + unsigned short LineHeight; + unsigned short Base; + unsigned short ScaleW, ScaleH; + unsigned short Pages; + unsigned char BitField; + unsigned char Channels[4]; + }; - struct FntGlyph - { - unsigned int Id; - unsigned short X, Y; - unsigned short Width, Height; - signed short XOffset, YOffset; - signed short XAdvance; - unsigned char Page; - unsigned char Channel; - }; + struct FntGlyph + { + unsigned int Id; + unsigned short X, Y; + unsigned short Width, Height; + signed short XOffset, YOffset; + signed short XAdvance; + unsigned char Page; + unsigned char Channel; + }; - struct FntKerning - { - unsigned int IdFirst; - unsigned int IdSecond; - signed short Amount; - }; + struct FntKerning + { + unsigned int IdFirst; + unsigned int IdSecond; + signed short Amount; + }; #pragma pack(pop) - unsigned char* Data; // Raw data, content of .fnt file - int DataSize; // - bool DataOwned; // - const FntInfo* Info; // (point into raw data) - const FntCommon* Common; // (point into raw data) - const FntGlyph* Glyphs; // (point into raw data) - size_t GlyphsCount; // - const FntKerning* Kerning; // (point into raw data) - size_t KerningCount; // - int TabCount; // FIXME: mishandled (add fixed amount instead of aligning to column) - ImVector Filenames; // (point into raw data) - ImVector IndexLookup; // (built) + unsigned char* Data; // Raw data, content of .fnt file + int DataSize; // + bool DataOwned; // + const FntInfo* Info; // (point into raw data) + const FntCommon* Common; // (point into raw data) + const FntGlyph* Glyphs; // (point into raw data) + size_t GlyphsCount; // + const FntKerning* Kerning; // (point into raw data) + size_t KerningCount; // + int TabCount; // FIXME: mishandled (add fixed amount instead of aligning to column) + ImVector Filenames; // (point into raw data) + ImVector IndexLookup; // (built) - ImBitmapFont(); - ~ImBitmapFont() { Clear(); } + ImBitmapFont(); + ~ImBitmapFont() { Clear(); } - bool LoadFromMemory(const void* data, int data_size); - bool LoadFromFile(const char* filename); - void Clear(); - void BuildLookupTable(); - const FntGlyph * FindGlyph(unsigned short c) const; - float GetFontSize() const { return (float)Info->FontSize; } + bool LoadFromMemory(const void* data, int data_size); + bool LoadFromFile(const char* filename); + void Clear(); + void BuildLookupTable(); + const FntGlyph * FindGlyph(unsigned short c) const; + float GetFontSize() const { return (float)Info->FontSize; } - ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const; - void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const; + ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const; + void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const; }; From 23d156908d4afb437d645245fa06d10a3216dd31 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:27:34 +0100 Subject: [PATCH 11/44] Added an assertion --- imgui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui.cpp b/imgui.cpp index e8154e88..2d051037 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2495,6 +2495,7 @@ void TextUnformatted(const char* text, const char* text_end) if (window->SkipItems) return; + IM_ASSERT(text != NULL); const char* text_begin = text; if (text_end == NULL) text_end = text + strlen(text); From e807d970899636e797a3d49103b90d54c9b2ff0c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:39:30 +0100 Subject: [PATCH 12/44] Exposed CalcTextSize(), GetCursorScreenPos() for more advanced fiddling --- imgui.cpp | 7 ++++++- imgui.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2d051037..724eefe9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -179,7 +179,6 @@ namespace ImGui static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false); static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); -static ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); @@ -2441,6 +2440,12 @@ void SetCursorPos(const ImVec2& pos) window->DC.CursorPos = window->Pos + pos; } +ImVec2 GetCursorScreenPos() +{ + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.CursorPos; +} + void SetScrollPosHere() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index be1604b9..606a03ae 100644 --- a/imgui.h +++ b/imgui.h @@ -166,8 +166,9 @@ namespace ImGui float GetColumnOffset(int column_index = -1); void SetColumnOffset(int column_index, float offset); float GetColumnWidth(int column_index = -1); - ImVec2 GetCursorPos(); // cursor position is relative to window position + ImVec2 GetCursorPos(); // cursor position relative to window position void SetCursorPos(const ImVec2& pos); // " + ImVec2 GetCursorScreenPos(); // cursor position in screen space void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. float GetTextLineSpacing(); float GetTextLineHeight(); @@ -251,6 +252,7 @@ namespace ImGui int GetFrameCount(); const char* GetStyleColorName(ImGuiCol idx); void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); + ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); }; // namespace ImGui From 67f17a644c7e638d9a58071dabe2c6eda791aa5d Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:45:34 +0100 Subject: [PATCH 13/44] Converted all Tabs to Spaces Argh --- imgui.cpp | 4 ++-- imgui.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 724eefe9..f660f272 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2442,8 +2442,8 @@ void SetCursorPos(const ImVec2& pos) ImVec2 GetCursorScreenPos() { - ImGuiWindow* window = GetCurrentWindow(); - return window->DC.CursorPos; + ImGuiWindow* window = GetCurrentWindow(); + return window->DC.CursorPos; } void SetScrollPosHere() diff --git a/imgui.h b/imgui.h index 606a03ae..667037c8 100644 --- a/imgui.h +++ b/imgui.h @@ -168,7 +168,7 @@ namespace ImGui float GetColumnWidth(int column_index = -1); ImVec2 GetCursorPos(); // cursor position relative to window position void SetCursorPos(const ImVec2& pos); // " - ImVec2 GetCursorScreenPos(); // cursor position in screen space + ImVec2 GetCursorScreenPos(); // cursor position in screen space void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. float GetTextLineSpacing(); float GetTextLineHeight(); @@ -252,7 +252,7 @@ namespace ImGui int GetFrameCount(); const char* GetStyleColorName(ImGuiCol idx); void GetDefaultFontData(const void** fnt_data, unsigned int* fnt_size, const void** png_data, unsigned int* png_size); - ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); + ImVec2 CalcTextSize(const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); }; // namespace ImGui From a3f32381c48a3e83af30b78c0695f36588996450 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 19 Aug 2014 12:51:13 +0100 Subject: [PATCH 14/44] Fix mismatched static declaration warning --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index f660f272..5c6823e5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1574,7 +1574,7 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border)); } -static ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash) +ImVec2 CalcTextSize(const char* text, const char* text_end, const bool hide_text_after_hash) { ImGuiWindow* window = GetCurrentWindow(); From 4bc3642bdb96ab2d58b8cd87ac722dabc98eb1ee Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 20 Aug 2014 10:19:05 +0100 Subject: [PATCH 15/44] Todo list --- imgui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui.cpp b/imgui.cpp index 5c6823e5..4c3e081e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -141,6 +141,7 @@ - text edit: pasting text into a number box should filter the characters the same way direct input does - text edit: allow code to catch user pressing Return (perhaps through disable live edit? so only Return apply the final value, also allow catching Return if value didn't changed) - settings: write more decent code to allow saving/loading new fields + - settings: api for per-tool simple persistant data (bool,int,float) in .ini file - log: be able to right-click and log a window or tree-node into tty/file/clipboard? - filters: set a current filter that tree node can automatically query to hide themselves - filters: handle wildcards (with implicit leading/trailing *), regexps From 5864c45fe383f85b0e86271761b031f50bc97511 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 20 Aug 2014 10:40:31 +0100 Subject: [PATCH 16/44] Fix type conversion compiler warnings (from dadeos) --- imgui.cpp | 83 ++++++++++++++++++++++++++++--------------------------- imgui.h | 4 +-- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5c6823e5..75298d46 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -377,7 +377,7 @@ static ImU32 crc32(const void* data, size_t data_size, ImU32 seed = 0) { ImU32 crc = i; for (ImU32 j = 0; j < 8; j++) - crc = (crc >> 1) ^ (-int(crc & 1) & polynomial); + crc = (crc >> 1) ^ (ImU32(-int(crc & 1)) & polynomial); crc32_lut[i] = crc; } } @@ -395,16 +395,14 @@ static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...) int w = vsnprintf(buf, buf_size, fmt, args); va_end(args); buf[buf_size-1] = 0; - if (w == -1) w = (int)buf_size; - return w; + return (w == -1) ? buf_size : (size_t)w; } static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args) { int w = vsnprintf(buf, buf_size, fmt, args); buf[buf_size-1] = 0; - if (w == -1) w = (int)buf_size; - return w; + return (w == -1) ? buf_size : (size_t)w; } static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in) @@ -899,13 +897,13 @@ void ImGuiTextBuffer::append(const char* fmt, ...) return; const size_t write_off = Buf.size(); - if (write_off + len >= Buf.capacity()) + if (write_off + (size_t)len >= Buf.capacity()) Buf.reserve(Buf.capacity() * 2); Buf.resize(write_off + (size_t)len); va_start(args, fmt); - ImFormatStringV(&Buf[write_off] - 1, len+1, fmt, args); + ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args); va_end(args); } @@ -1051,13 +1049,14 @@ static void LoadSettings() return; if (fseek(f, 0, SEEK_END)) return; - long f_size = ftell(f); - if (f_size == -1) + const long f_size_signed = ftell(f); + if (f_size_signed == -1) return; + size_t f_size = (size_t)f_size_signed; if (fseek(f, 0, SEEK_SET)) return; char* f_data = new char[f_size+1]; - f_size = (long)fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value + f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value fclose(f); if (f_size == 0) { @@ -3008,7 +3007,7 @@ void PushID(const void* ptr_id) window->IDStack.push_back(window->GetID(ptr_id)); } -void PushID(int int_id) +void PushID(const int int_id) { const void* ptr_id = (void*)(intptr_t)int_id; ImGuiWindow* window = GetCurrentWindow(); @@ -3362,7 +3361,7 @@ enum ImGuiPlotType static float PlotGetValue(const float* values, size_t stride, int idx) { - float v = *(float*)((unsigned char*)values + idx * stride); + const float v = *(float*)((unsigned char*)values + (size_t)idx * stride); return v; } @@ -3615,14 +3614,14 @@ void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int idx, int n) bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int idx, const char* new_text, int new_text_len) { char* buf_end = obj->Text + obj->BufSize; - const int text_len = (int)strlen(obj->Text); + const size_t text_len = strlen(obj->Text); if (new_text_len > buf_end - (obj->Text + text_len + 1)) return false; - memmove(obj->Text + idx + new_text_len, obj->Text + idx, text_len - idx); - memcpy(obj->Text + idx, new_text, new_text_len); - obj->Text[text_len + new_text_len] = 0; + memmove(obj->Text + (size_t)idx + new_text_len, obj->Text + (size_t)idx, text_len - (size_t)idx); + memcpy(obj->Text + (size_t)idx, new_text, (size_t)new_text_len); + obj->Text[text_len + (size_t)new_text_len] = 0; return true; } @@ -4065,7 +4064,7 @@ static bool Combo_ArrayGetter(void* data, int idx, const char** out_text) bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items) { - bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items); + const bool value_changed = Combo(label, current_item, Combo_ArrayGetter, (void*)items, items_count, popup_height_items); return value_changed; } @@ -4138,7 +4137,7 @@ bool Combo(const char* label, int* current_item, bool (*items_getter)(void*, int ImGui::SameLine(0, (int)g.Style.ItemInnerSpacing.x); ImGui::TextUnformatted(label, FindTextDisplayEnd(label)); - ImGui::PushID(id); + ImGui::PushID((int)id); bool menu_toggled = false; if (hovered) { @@ -4546,7 +4545,7 @@ float GetColumnOffset(int column_index) if (column_index < 0) column_index = window->DC.ColumnCurrent; - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); + const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); RegisterAliveId(column_id); const float default_t = column_index / (float)window->DC.ColumnsCount; const float t = (float)window->StateStorage.GetInt(column_id, (int)(default_t * 8096)) / 8096; // Cheaply store our floating point value inside the integer (could store an union into the map?) @@ -4562,7 +4561,7 @@ void SetColumnOffset(int column_index, float offset) if (column_index < 0) column_index = window->DC.ColumnCurrent; - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + column_index); + const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(column_index); const float t = (offset - window->DC.ColumnStartX) / (window->Size.x - g.Style.ScrollBarWidth - window->DC.ColumnStartX); window->StateStorage.SetInt(column_id, (int)(t*8096)); } @@ -4612,7 +4611,7 @@ void Columns(int columns_count, const char* id, bool border) { float x = window->Pos.x + GetColumnOffset(i); - const ImGuiID column_id = ImGuiID(window->DC.ColumnsSetID + i); + const ImGuiID column_id = window->DC.ColumnsSetID + ImGuiID(i); const ImGuiAabb column_aabb(ImVec2(x-4,y1),ImVec2(x+4,y2)); if (IsClipped(column_aabb)) @@ -4839,7 +4838,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i if (tris) { - ReserveVertices((a_max-a_min) * 3); + ReserveVertices((unsigned int)(a_max-a_min) * 3); for (int a = a_min; a < a_max; a++) { AddVtx(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, col); @@ -4849,7 +4848,7 @@ void ImDrawList::AddArc(const ImVec2& center, float rad, ImU32 col, int a_min, i } else { - ReserveVertices((a_max-a_min) * 6); + ReserveVertices((unsigned int)(a_max-a_min) * 6); for (int a = a_min; a < a_max; a++) AddVtxLine(center + circle_vtx[a % IM_ARRAYSIZE(circle_vtx)] * rad, center + circle_vtx[(a+1) % IM_ARRAYSIZE(circle_vtx)] * rad, col); } @@ -4960,7 +4959,7 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu if ((col >> 24) == 0) return; - ReserveVertices(num_segments*6); + ReserveVertices((unsigned int)num_segments*6); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) @@ -4976,7 +4975,7 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, if ((col >> 24) == 0) return; - ReserveVertices(num_segments*3); + ReserveVertices((unsigned int)num_segments*3); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) @@ -4998,17 +4997,17 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 text_end = text_begin + strlen(text_begin); // reserve vertices for worse case - const int char_count = (int)(text_end - text_begin); - const int vtx_count_max = char_count * 6; + const unsigned int char_count = (unsigned int)(text_end - text_begin); + const unsigned int vtx_count_max = char_count * 6; const size_t vtx_begin = vtx_buffer.size(); ReserveVertices(vtx_count_max); font->RenderText(font_size, pos, col, clip_rect_stack.back(), text_begin, text_end, vtx_write); - // give unused vertices - vtx_buffer.resize(vtx_write - &vtx_buffer.front()); - const int vtx_count = (int)(vtx_buffer.size() - vtx_begin); - commands.back().vtx_count -= (vtx_count_max - vtx_count); + // give back unused vertices + vtx_buffer.resize((size_t)(vtx_write - &vtx_buffer.front())); + const size_t vtx_count = vtx_buffer.size() - vtx_begin; + commands.back().vtx_count -= (unsigned int)(vtx_count_max - vtx_count); vtx_write -= (vtx_count_max - vtx_count); } @@ -5049,8 +5048,10 @@ bool ImBitmapFont::LoadFromFile(const char* filename) return false; if (fseek(f, 0, SEEK_END)) return false; - if ((DataSize = (int)ftell(f)) == -1) + const long f_size = ftell(f); + if (f_size == -1) return false; + DataSize = (size_t)f_size; if (fseek(f, 0, SEEK_SET)) return false; if ((Data = (unsigned char*)malloc(DataSize)) == NULL) @@ -5058,7 +5059,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename) fclose(f); return false; } - if ((int)fread(Data, 1, DataSize, f) != DataSize) + if (fread(Data, 1, DataSize, f) != DataSize) { fclose(f); free(Data); @@ -5069,7 +5070,7 @@ bool ImBitmapFont::LoadFromFile(const char* filename) return LoadFromMemory(Data, DataSize); } -bool ImBitmapFont::LoadFromMemory(const void* data, int data_size) +bool ImBitmapFont::LoadFromMemory(const void* data, size_t data_size) { Data = (unsigned char*)data; DataSize = data_size; @@ -5357,9 +5358,9 @@ static void SetClipboardTextFn_DefaultImpl(const char* text, const char* text_en } if (!text_end) text_end = text + strlen(text); - GImGui.PrivateClipboard = (char*)malloc(text_end - text + 1); - memcpy(GImGui.PrivateClipboard, text, text_end - text); - GImGui.PrivateClipboard[text_end - text] = 0; + GImGui.PrivateClipboard = (char*)malloc((size_t)(text_end - text) + 1); + memcpy(GImGui.PrivateClipboard, text, (size_t)(text_end - text)); + GImGui.PrivateClipboard[(size_t)(text_end - text)] = 0; } #endif @@ -5455,7 +5456,7 @@ void ShowTestWindow(bool* open) static bool no_scrollbar = false; static float fill_alpha = 0.65f; - const ImU32 layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0); + const ImGuiWindowFlags layout_flags = (no_titlebar ? ImGuiWindowFlags_NoTitleBar : 0) | (no_border ? 0 : ImGuiWindowFlags_ShowBorders) | (no_resize ? ImGuiWindowFlags_NoResize : 0) | (no_move ? ImGuiWindowFlags_NoMove : 0) | (no_scrollbar ? ImGuiWindowFlags_NoScrollbar : 0); ImGui::Begin("ImGui Test", open, ImVec2(550,680), fill_alpha, layout_flags); ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.65f); @@ -5620,7 +5621,7 @@ void ShowTestWindow(bool* open) static bool pause; static ImVector values; if (values.empty()) { values.resize(100); memset(&values.front(), 0, values.size()*sizeof(float)); } - static int values_offset = 0; + static size_t values_offset = 0; if (!pause) { // create dummy data at 60 hz @@ -5634,7 +5635,7 @@ void ShowTestWindow(bool* open) phase += 0.10f*values_offset; } } - ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70)); + ImGui::PlotLines("Frame Times", &values.front(), (int)values.size(), (int)values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,70)); ImGui::SameLine(); ImGui::Checkbox("pause", &pause); ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,70)); @@ -5841,7 +5842,7 @@ void ShowTestWindow(bool* open) ImGui::SameLine(); if (ImGui::Button("Add 1000 lines")) { - for (size_t i = 0; i < 1000; i++) + for (int i = 0; i < 1000; i++) log.append("%i The quick brown fox jumps over the lazy dog\n", lines+i); lines += 1000; } diff --git a/imgui.h b/imgui.h index 667037c8..d1574b6e 100644 --- a/imgui.h +++ b/imgui.h @@ -622,7 +622,7 @@ struct ImBitmapFont #pragma pack(pop) unsigned char* Data; // Raw data, content of .fnt file - int DataSize; // + size_t DataSize; // bool DataOwned; // const FntInfo* Info; // (point into raw data) const FntCommon* Common; // (point into raw data) @@ -637,7 +637,7 @@ struct ImBitmapFont ImBitmapFont(); ~ImBitmapFont() { Clear(); } - bool LoadFromMemory(const void* data, int data_size); + bool LoadFromMemory(const void* data, size_t data_size); bool LoadFromFile(const char* filename); void Clear(); void BuildLookupTable(); From 05f0993616f19210f2e3fba15266318d2af6ba94 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 20 Aug 2014 10:43:08 +0100 Subject: [PATCH 17/44] stb_textedit 1.4 fix signed/unsigned warnings --- stb_textedit.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/stb_textedit.h b/stb_textedit.h index 90dc8fea..872012da 100644 --- a/stb_textedit.h +++ b/stb_textedit.h @@ -1,4 +1,4 @@ -// stb_textedit.h - v1.3 - public domain - Sean Barrett +// stb_textedit.h - v1.4 - public domain - Sean Barrett // Development of this library was sponsored by RAD Game Tools // // This C header file implements the guts of a multi-line text-editing @@ -30,8 +30,9 @@ // // VERSION HISTORY // -// 1.3 (2013-06-19) fix mouse clicking to round to nearest char boundary -// 1.2 (2013-05-27) fix some RAD types that had crept into the new code +// 1.4 (2014-08-17) fix signed/unsigned warnings +// 1.3 (2014-06-19) fix mouse clicking to round to nearest char boundary +// 1.2 (2014-05-27) fix some RAD types that had crept into the new code // 1.1 (2013-12-15) move-by-word (requires STB_TEXTEDIT_IS_SPACE ) // 1.0 (2012-07-26) improve documentation, initial public release // 0.3 (2012-02-24) bugfixes, single-line mode; insert mode @@ -41,7 +42,7 @@ // ADDITIONAL CONTRIBUTORS // // Ulf Winklemann: move-by-word in 1.1 -// Scott Graham: mouse selectiom bugfix in 1.3 +// Scott Graham: mouse selection bugfix in 1.3 // // USAGE // @@ -445,7 +446,7 @@ static void stb_textedit_drag(STB_TEXTEDIT_STRING *str, STB_TexteditState *state static void stb_text_undo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state); static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state); static void stb_text_makeundo_delete(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length); -static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length); +static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length); static void stb_text_makeundo_replace(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int old_length, int new_length); typedef struct @@ -649,7 +650,7 @@ static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state stb_textedit_delete_selection(str,state); // try to insert the characters if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, text, len)) { - stb_text_makeundo_insert(str, state, state->cursor, len); + stb_text_makeundo_insert(state, state->cursor, len); state->cursor += len; state->has_preferred_x = 0; return 1; @@ -684,7 +685,7 @@ retry: } else { stb_textedit_delete_selection(str,state); // implicity clamps if (STB_TEXTEDIT_INSERTCHARS(str, state->cursor, &ch, 1)) { - stb_text_makeundo_insert(str, state, state->cursor, 1); + stb_text_makeundo_insert(state, state->cursor, 1); ++state->cursor; state->has_preferred_x = 0; } @@ -1007,13 +1008,13 @@ static void stb_textedit_discard_undo(StbUndoState *state) int n = state->undo_rec[0].insert_length, i; // delete n characters from all other records state->undo_char_point = state->undo_char_point - (short) n; // vsnet05 - memmove(state->undo_char, state->undo_char + n, state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE)); + memmove(state->undo_char, state->undo_char + n, (size_t) (state->undo_char_point*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=0; i < state->undo_point; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage - (short) n; // vsnet05 // @OPTIMIZE: get rid of char_storage and infer it } --state->undo_point; - memmove(state->undo_rec, state->undo_rec+1, state->undo_point*sizeof(state->undo_rec[0])); + memmove(state->undo_rec, state->undo_rec+1, (size_t) (state->undo_point*sizeof(state->undo_rec[0]))); } } @@ -1031,13 +1032,13 @@ static void stb_textedit_discard_redo(StbUndoState *state) int n = state->undo_rec[k].insert_length, i; // delete n characters from all other records state->redo_char_point = state->redo_char_point + (short) n; // vsnet05 - memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE)); + memmove(state->undo_char + state->redo_char_point, state->undo_char + state->redo_char_point-n, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_char_point)*sizeof(STB_TEXTEDIT_CHARTYPE))); for (i=state->redo_point; i < k; ++i) if (state->undo_rec[i].char_storage >= 0) state->undo_rec[i].char_storage = state->undo_rec[i].char_storage + (short) n; // vsnet05 } ++state->redo_point; - memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0])); + memmove(state->undo_rec + state->redo_point-1, state->undo_rec + state->redo_point, (size_t) ((STB_TEXTEDIT_UNDOSTATECOUNT - state->redo_point)*sizeof(state->undo_rec[0]))); } } @@ -1203,7 +1204,7 @@ static void stb_text_redo(STB_TEXTEDIT_STRING *str, STB_TexteditState *state) s->redo_point++; } -static void stb_text_makeundo_insert(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, int where, int length) +static void stb_text_makeundo_insert(STB_TexteditState *state, int where, int length) { stb_text_createundo(&state->undostate, where, 0, length); } From 6062d18cf91489c8ab101f008db749fd3c7d9f7c Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 20 Aug 2014 17:42:53 +0100 Subject: [PATCH 18/44] Added basic sizes edition in the style editor --- imgui.cpp | 71 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4132a9bf..5a72b2aa 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2344,7 +2344,7 @@ const char* GetStyleColorName(ImGuiCol idx) case ImGuiCol_PlotLines: return "PlotLines"; case ImGuiCol_PlotLinesHovered: return "PlotLinesHovered"; case ImGuiCol_PlotHistogram: return "PlotHistogram"; - case ImGuiCol_PlotHistogramHovered: return "ImGuiCol_PlotHistogramHovered"; + case ImGuiCol_PlotHistogramHovered: return "PlotHistogramHovered"; case ImGuiCol_TextSelectedBg: return "TextSelectedBg"; case ImGuiCol_TooltipBg: return "TooltipBg"; } @@ -5413,34 +5413,53 @@ void ShowStyleEditor(ImGuiStyle* ref) *ref = g.Style; } - ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero. - ImGui::SliderFloat("Rounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); + ImGui::PushItemWidth(ImGui::GetWindowWidth()*0.55f); - static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; - ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB); - ImGui::SameLine(); - ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV); - ImGui::SameLine(); - ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX); - - static ImGuiTextFilter filter; - filter.Draw("Filter colors", 200); - - ImGui::ColorEditMode(edit_mode); - for (int i = 0; i < ImGuiCol_COUNT; i++) + if (ImGui::TreeNode("Sizes")) { - const char* name = GetStyleColorName(i); - if (!filter.PassFilter(name)) - continue; - ImGui::PushID(i); - ImGui::ColorEdit4(name, (float*)&style.Colors[i], true); - if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0) - { - ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i]; - if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; } - } - ImGui::PopID(); + ImGui::SliderFloat("Alpha", &style.Alpha, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI. But application code could have a toggle to switch between zero and non-zero. + ImGui::SliderFloat2("WindowPadding", (float*)&style.WindowPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("WindowRounding", &style.WindowRounding, 0.0f, 16.0f, "%.0f"); + ImGui::SliderFloat2("FramePadding", (float*)&style.FramePadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemSpacing", (float*)&style.ItemSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("ItemInnerSpacing", (float*)&style.ItemInnerSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat2("TouchExtraPadding", (float*)&style.TouchExtraPadding, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("TreeNodeSpacing", &style.TreeNodeSpacing, 0.0f, 20.0f, "%.0f"); + ImGui::SliderFloat("ScrollBarWidth", &style.ScrollBarWidth, 0.0f, 20.0f, "%.0f"); + ImGui::TreePop(); } + + if (ImGui::TreeNode("Colors")) + { + static ImGuiColorEditMode edit_mode = ImGuiColorEditMode_RGB; + ImGui::RadioButton("RGB", &edit_mode, ImGuiColorEditMode_RGB); + ImGui::SameLine(); + ImGui::RadioButton("HSV", &edit_mode, ImGuiColorEditMode_HSV); + ImGui::SameLine(); + ImGui::RadioButton("HEX", &edit_mode, ImGuiColorEditMode_HEX); + + static ImGuiTextFilter filter; + filter.Draw("Filter colors", 200); + + ImGui::ColorEditMode(edit_mode); + for (int i = 0; i < ImGuiCol_COUNT; i++) + { + const char* name = GetStyleColorName(i); + if (!filter.PassFilter(name)) + continue; + ImGui::PushID(i); + ImGui::ColorEdit4(name, (float*)&style.Colors[i], true); + if (memcmp(&style.Colors[i], (ref ? &ref->Colors[i] : &def.Colors[i]), sizeof(ImVec4)) != 0) + { + ImGui::SameLine(); if (ImGui::Button("Revert")) style.Colors[i] = ref ? ref->Colors[i] : def.Colors[i]; + if (ref) { ImGui::SameLine(); if (ImGui::Button("Save")) ref->Colors[i] = style.Colors[i]; } + } + ImGui::PopID(); + } + ImGui::TreePop(); + } + + ImGui::PopItemWidth(); } //----------------------------------------------------------------------------- From e9e1fd2b3c63439e490b22257569a68f1ebf1d88 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 20 Aug 2014 17:46:49 +0100 Subject: [PATCH 19/44] Added screenshot for web --- web/skinning_sample_01.png | Bin 0 -> 18803 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 web/skinning_sample_01.png diff --git a/web/skinning_sample_01.png b/web/skinning_sample_01.png new file mode 100644 index 0000000000000000000000000000000000000000..33227f6364b422bebec9c44a22a5a84319a52691 GIT binary patch literal 18803 zcmYhjcQ~8x`#x@qQB4TaVa19~r`C?dEMhB)($=Q5_SU3`tyTvbqh_oUqjqg=y=$ z$hBaqJHRg*dlelO3W|z&rsIdSz;}kH8uy=3P_VR}|4_0cv_gS{m!G4}o*TM9dG7Pj z^DzbHp`+V#NnNxNulIGyo02lp(mS363JQ&NO_Yj}uhnXXLa9TYSKbW84O)@sl2zfE z%G9)iR5vI;QRG}Fyz5i8=K?vj5VDYBNyzxmL;uOTjTM^i*i~qhHXiu+vNTgk7OgGJ z{Qf;>{$rkRWhf-*^tkn+A_cV#1#@T^E1e=GOA94k3k8gV`X)0k6lH`;{`VJAIxr&z zm1ZcVGzIXf&8f`^_|T#(M;D1O(=2~ObG{y|U!LS(tvM?fNDo{ALMz5#^6GpsC7jU& zRTBB{qN^|%hyL-<*-_WU;0;RPE;cqw%sco;X&Ctn;E=PU8OU`SF5pRWWd4I+{)+s` z9u=MYIljiFTPd5xebVFYQb@o`(SmyWt_3dks`avMpif(mh-bN);z26;Bz^Ka_RFPk)A-epcV_xpQ5;YI8>X%(buv^+)R|l%j-e zjumq)9=r8eZV7x9Cd)~!B4FMz=YdSLsI!QwON((v65v$q13MFR4DYn5VifGGKP!u} zO6a3MVsb4oqHhqcQ)by9JpqGB__Cm#Gitz7cgXq5Bg*@Lj4^F3m633J<%W|Rh6vAj zYu0owEHbf)RZ&QujT?~80Ib_p4tHz#KJHF7;!;o)&RAer#Vhvs1w}IH>F{X$-53(H z*2+Ut$E^{i=%D#9OF;Gxtu4<9wK0_-bo6F2<<38?9>C1tP!)05e+Sg~_)Qr=9XT@P z_Yi7Vbc62Eoh!KIGBYz9{*3(9U2(sa{@h`b*H}{3i9gJLi01;YOseMDhG5!__9cpfAF3zY9u6u zd&2NUJkMffZ#ViF%nBRlr0(O#U)3K$@jtj^5v2toOdJ-alo6LDb_++EDs>nVZ!T|C z8M3BxE2%Ocu~OT89&d+@nS7MTf)_lY>YEFC!Co&oeq* z5*z;NK^i>nJCfkysA+0p>NMwvYtz~{`DApYFd1C5o|~nj6|)`uOCF8Tipa=(7G=N{ z7U{I4@aXXr$+5cMpxIu#07@=cC5}eI$sylNjBlgLc_7k4F`5^s4Y5@J#h$%m&$^b_ zN&%~7q6T%$7ax_BzW(8(<2FGXkRu(6xd&#fmbm4#Q9utr_b*yHFrEQfVLR(U9e)0u z9dKamTuQuf=^N!L>ib!tVFcvnq|)iu3!XqgVJP-gw>)EgMW}{=pDWa5VHFPM*86OF<^pKcC#FW{gJYeO^=i0$m7F+duyYrPR_Xx zi5G3EshMVe%1Li9^#I-P--Q3`9p8 zQ)cFP#1rr5!yJPJ{!ezR^VVv1i#s@z!=AUc$TI(sgigyr`037~u!pF(>M`tIF>n9w zvs#mEZQfw8_II_;Sm@H+Z2AQ{UwhTCU`6*(Z;i7wB5GS&u1ibnAS5XeiM3m1xNPt5 z-?r|S^s?o5&2q7CCNE!9EXcFiGLz&_-9pTmP1v_7*|lBQjWJ}RbA#Z2Y;%Pr429Gr zcx$aGG+W?GejjJpt&{^;l_bSw$u$B}~}%dXds1ofj04PaZ4qcijE_9%%sJOk0w%Ik7Z_H+nktQ1vU44OP3ZR z!eo)anH`?*-`+KZeCjyZ4D%>GHTM@!mVlT}gt(vCPBy?DH!t|{N=ujDrb`8(DO3)X z#Hp@Yw@@CeDQLEc`~p-6#;->mx`BD2d-1JPu=hdI<=5#_89Tnk)ehalQYF>0g;ZTQ zg`TU>QA%{s+6r>6LK_DzY|xZHmAZ@gn2Po0z>kbuOmUm7cOB{@2beJ0e%hH=pIY?EFdPcEGV;Ko)?ExG zO4J`W82tp4NiEo7qAU(rOz^1RMf^2FT(P0wZ-+lcF)gEKVmpVeZy=K|NegiA=MVI*2 zhbw_QdfzkW3OVr6Ea84-oPeq&t7dvM-lU#WzpiiNT0N z@zXuICJ!2I-XAwGL}8Nq5y{|!=TGG>*0k1uI&_dfV-XDpujRLe*xCaR6s6w#t zdb-~RjG$3tWlo8ayTRmIkkWj&N-V{c-kW1m%g@X!_BEJTYp~$oICvpFkiU6Ep5@oEUoZ8is6!)A*``okJrb5na<^ z`BJR)O~nUQ@4`6orsi zd$niT7PLIR2kJ09ikVt}oe$~=cmMNRdi}LD(Jl%T8fNnMFNTGnjHrEDLqQFqMOIM% zteF7RW*+MIa{Go{O==w33S`--Bj&D;utyqMXTbYWKham2c}T%m$!dhzrL8w**9 z&91KB(Ak>Sya^-@d3QKbo(2n8UMw!SAo)WDzM>&;imDh{C&U>Xm>)*&s(v~9-Y~k{+X$kXNLdx0ht+d_r9CU!5wHM}}e2yQ|a%JW(afhV!wQFYzd9{f@-< z_5Ydh-$vJpJ{TdA(vny6wlYumb{+~p)NoZnu(08k|Fg>071q|87gd-CkcAfSxc?g| zaBJ6eBr@@ldwq(Ab9h2A|JU^s1)o&AYO=@ykm|EVvN0B#T9HQetjuuyLHMQsp}h3a zo&lG4k{^luri-1ECPbR<;$xicFM~P)vv*_qV;b}zjO>){77o|3Z4-*f&4Xv#Os}s~ z=w>Jh%b@?J^*a>@8aLgZl6!)JZsQmU`=0Sg01kyzD$`6xAy}di;o#wKpkZ&!RjV|X z0^^f+`d@^7%l@QpDWMTmueT$-w$tJy;kR35{dY2 zH-ACwp*GJj->1B|nnnG~8=8+nOQ4S9r~pop^>In043E3Ju#%Uzht`?IiP7Cq%+;!! z)j7O2LxC#gE(-U%=L`KJ5j$^9RB>~K%B^k}pn=%>_!$=VOr|^*Q_$b1_Lo1dAZO=$M&-;=;lqh<;*+nB7j=Vy zbv3p&OoZ;l_Y0GcorUc~re*~_+)w*XQ?FT_CGgAv$c8r}Yzeu!`Ag|0g}FvK$+iZs zMdb3jZ~x&$1yr(|f~~G<5doA5T6U*Q|DB48llmBx7i ztA-KZwIUl%Dkvi4!OSpOdg>uu8{>!PN5ZDM8Po;Tj)J#{5sj%tG3T@7_o*&MO%-v} z2j5;F$K14Y?P$4$e0Xy_DW3fXTT3|GRw$da&1VW^D;xJn*+9AmDGHmlG4xhu<1zs= zsq4;-I;7JKqm-6rqb`HsU+ZSO3Go4FPuPxvV6zfM6#l=W0)(akv$Wp7nc3i!yFS~D z4U@o9h10!HfCA?p*-{XA=O0Z{o;&>0_0d=4AmQpa80(vbOs=EPy#~s>i_O0m9BLdk ziHUZ;thjTDdWav-3#}fr8yS7I7scp)NTc=a3>3M1JAjLsNm}>#S--2mZgu1 zK9XbL$qUj)Cv2VJ_FJJZY90bc0$Vk5$5z.N$&w9^3P)IA`Pur+0wAa6cXF1*qP z*ow^!IxBvt)1-Rd-d%6+lg3?r?k(W(d!Vv{;7#Z;aXr*@046W6vnjwF@5VPD&(ib! ztHP&WglVIA_@QH?akPP>fvNS~+uY^X&#}70X8?$uhwjRC5eurpn7fp&R~$C41XEKx z%K%_;ZZE_0jEnBB(ClDHfQrnEVf*2wRnCJkU6$k6=GGQY=6h`T;;liYiftki(u61? z?*A%_8w^}}{K?$E^n#uriZ(pVrlsYr^wVg}@$y*nK1eCdNc&7ON^5mpM1SuzxZ0RM z1WRe)%O>(4=f*o*nr7Db!=;@lL1|U`;to8vS+^ik>Q(<;3 z7A6h}6O6~pXEL(>eL36G^8LJ~@GweLW1|ej|It1uSuj2kof4xk(SNv=p>O~T={ysG z`Qk9``kIbR-Idk3qC+6SBWJk%hxfEz^-4`v_C6CSqr(54oXn-xt$!A!ZTJw+Sy zz7{i6gz&UnGVFvh@7USk0aP}HTrP^yQb!zywa&Li004yMyk1G3f0kR8&8p`wdbzst z9F}Vj`BHJo zC%Q0iJ__L4-kmK^2@WSWydpg1E<#Bv0>Bggz)@nu-+s5eaZE>5A06tjcWL|_<6x-> z=hlh`YRJ~**-ORLolzcC)HW?I&Wp;3^`?`JQ{NatsaZN|;2I@eEq2(s!z4!`Wup_( zpbxIYjls6F&jMNKngFNX_i#4=k_f#Km{vhHX4OUm}6GQ230THb0vH&e5Bf(6@6mL zfW8oke=jj<0_u1c#-b_XZS$UsdXf=`2R-@lkvznezaA+xXi@A(#K5owb{&r6GQ3b^V6g zC;|IYMgVV4K^>sNt6PK)!B zbofa3p+$iZboql9q8R%=wbUxjSU+CN{nFK5=|bRE*UJG`)~it7T1!1qD`&^o zE7qJMKqPmx>02ZQtcYDO`Wmc_dJiw+2*uFZQUXo{oXId)-&W>YH&4^9{nsgE#v*I% zVo}h@*_%itRl>OuF`nD)$Li!s>oPP9k6=#}gYTxAlF5wd(qK|%`d_EYS1fAgGJuto zyeuTLd!?6{e9ink`|fK|(BtNgi%u(ussaAoyu0GNiS*f&)b_SER|piL_EZTT_CH!% zPS2ChFPu;CKVxnnx8on5u`}7V!@|OXWRy{@THzxC=Y|~`8J^PHB*qRv7fR|QI~#M< zzc7k8`9k-SJU8Vc=Sj|*=j^v{6FyjA`7!YO^ijh$Ob3FW$i3)zJ!6iq;I((ISJrRN z71?*c(^ArNBxr1D0A2$vzjSt3(;S$qlUXpH=nRH}BQ z@Zmz+tF~y`XY(qLOdbNS9I0tZ3~bbMqOmvcmoz$Zdg{4g!LZpAtpDrz0i-#Z=cAD< zKNrCa2P6oHP>{r%+ChL9Bo0-N6yg%vM88!Uj{xcJNdA%Uf^i$i-b4H50*_WH@RVqF zPKIL11$MkIZoHCgbom}yR`da+tU9nbNI}eAFtgCXH@Hj6S}6YJp!h-Gr}B;85%Y%{ zENA4Si-c}4&IfLR?fmF(LgOYV9{qqjyIsof;p?BA-NdXP8$V@vblLFHFru}>eW5pZ zVa7{0k<5;SIF8W5U3(DP$>&>qZ|UpcimIS&YqeP-ZBFtf^>_IPp0yaWn)|xXZUl?y z8AO}Ci{w0Hu2>HT_-ulPN7}cUhg})B6W0HfRqGs6iI`U)o5*Ibg`mv84_n(8_pbsT zd+FRHZYHIv{)=G^+;XZ93ty#N0jwb3#>N+=f4KD<8ZoHXO%0q|1F-J@Kk6;_Ug=@g zZ=V^9|FpqXjKYm|~3Y3ihCB zhCCKW%5{riW;=3R#brq-#V@WFo2!@9fpA6zB!{M~-&g#B&n+zz0niep8SZ~T82A5% zvlTdF-&yEO`I+EZ>cH~L)MxvPA*UOsVD<(v(La~^36Kuj)0N^k69VZOP5xAa+_`5o z%)aQk-WgT#%*yMEGJ92eRuYk*j=i~EY*buqjNwJ##yT%SYTwlX${`HH9U5kaP!v6D zKQMs^Lpo03x6p_=CXXdiM3Ab(bN~LL=*p6b8GM)(q2Pfh@c~k&Z$UEAe45>GwT!je zaPl?K5P78CFYx5-bTmr08C=25oNJ+1_a6S0O=I9FH)dfsL_`mqv6B)$v7Vo_*Bi_a zrFW6r0W&|I;luFb;DQBj5`59rgz;xr7=g?vnUHAE~Y*BY!8k`Ypt9LEy(nDS- zeFBYst6X+?rpHwgXeJQ>$NNO~LV@Ia#dewRW^Y`V-qQBCSP>#GZ;`5+GfO+-s|f)U zF(MlD+v!bx$hM3nB7Ods@EygD{6^UL0XHqGA!Io0oC~|uK?zvxuJEr6S~h}gsDQs| zPI5>v>IFbtDj;tdA^e#M;>!QP-ruNmOxU}9Ag0&3kzuESst~4BLc<`8q|AR$EeFu$ z?g}GKu;?u1@5ZuVJhetR;%A0_xV0DpiT#QQYm}I{3W8Tk$}cg5>xmj8 z?s2h@`j=FCs?Yh^H^YtFOG!5JyNiDT`iTzoP<#2+#9Kyy$*9-7*gEGdMW-9AV8ZpN zYY*lLe*_Wo8lQp7YHgT&5aR+=``Jc&llENt9a?QUMADG}sDnwPf>zYgMw%wpU-sy#&Zu`5rrze#BlHey%!3)-S!p?!AAR6gT#f-<3>9c$92sKpP0T> zps3?TBqnHu-1YN2^jQe<52*;ztGKVDky;jQGKmU!^$p?KK7xD#R45^L56q5Cd+jC8 zo+~{(lTX}C5D++9`(x*e3d6*_t~JS4M|AFAX+5apf#7{!HQNWe1FarUE!Tj;TYkHW6<#gE+f?sLhRS^UN_@&}3+;(s_Im@J8>1 zWob`c4Ol6do~&WW*8@p{`--&|`O80&)k287?(VujYL?hdS`5lgibiPVTEP7T;f`1G z9CA`G68>;f34W*n;c!OK0Wxc0$IGNy9BC-T`d|caO)iGs0s2PqkrvXml`*&~Rc@@U z;(f7eS+9dXVaynsIr7>a@deKwt-TK19M!Lnt$Ky=Jw#cd5D}DmJE4F>Y-PmnzuvsM zx!5hIUU{>vh7rxXVtz7e-1u0#WO&BlXq4o9pyo2g#}fIXP5G)sdwMa0Mz{TU1FaR2 zsMyEOA{lJgO~-^s738xqvy*&NTBCB~_zU2}2QXhzzR~Qr`MXPQpW@jVQB-q{(Y{%u zYg6;X09PjyeC4k!!FS?OhZS~JlDUeN%(WnHVdpbWPQ4Yu*kSPwsnl7fu^|HB@BR+J zLTa5CR6mu}>$S9?tD297)~A#d7I^m-la9J8R1qxuS)=civxRpmA~q~&KP;@|CDPoi zl>8<+fp&j`F;iL>4+<|*%u)!0{ozkEhza|IvlVa*SgC(IzwS1(QZ{gq55g_7yr}2x zGSx~D3_qX+isd7GZJI0u-#>EnJS#Z~yW`9|_qN9*-1NZcu0VLgyYR39q{mm{M5Cv*rgO?T_1W6x=^p4(lpM{U}OYAurePUcsnb7G~9N{%CdKpNn9ky0OSgj#~ z>i+NUdypV^f1>Nfy4~sH-6}Gvp@sp6)|dmKb>M@16E$|c?D*#?7I?6K?|qh!0XXFp zb;R1FC)2NxXp9+}iV%7{qkEcp3en$z2tm-F&Qh6htPEbYtFO)G(GJsCN^EweL8_(lr*9lAG1)%pXmKE5e8dcFogXAxu!J}InQPRHoc$^dYB43q%i=55&-5S&cp0($LSrX+Q98aBC~D9$q*4gQfrPuLGOPEnL$&GM*XOi82Zj(>_^&P67c8fZh1dUyJEqu_(n zJHj9w9tH$+>(hSqF`M5kiP~ZT?E2W})gw9Zh$=4kpy^`(+{f`&*@i~WWnRZ~Vb@AE z;8k)G*$7DELUisA#u?G8)!q`w-|Tc{U{Vsz0vHAqrnTDA0I)tDN%X1ac@+p+@T9pE z;a3;QcY)g3uYqiFNMESB476v>5xV{gqm^XCKDKATP)2ppFG)ywl^h!JP4QIg4JwG zf4w>g>dE)rO9L!kU)Tl#BT)W&1rZqS{=c~ZRb05S^~@dQemhKwbOhlc9Z7afJ;+6U zI%0q$D+Wf{1jh6{_seG@RHO~sf)6V3|hd)HzLn4B5k zZ7Sdfxgz%0iyB9kQcp#a3~v?RGCG(VGCp%!Qb8E;82{fDQg=)Y-s$T?h)zQW(@E;p zhFWDK86Un@<&2!JV&V5%3{acD8Sdie4Oqvg?5qC_ARRoo17(5KTjKi+#a8z6nSi}! z{EBN~j#_BZ3C1L`ZiHS!(cr{ga9@An0|O2oh^Ej&Xp!?nq!Q;#wu-DXN1m2lRDEv3 z8h2mu57&!~Kv?%r0iKsl=KY9aeC_R%${e2*R}t&poWC{uJrhlWGl;Fd;TIT}9eF;7ki(wlZfLRw7VVmCF}ds3FA zbp9A07&ps9(D4_YgPSMSi%uQ{)^6V)zXvpf6$#~xQ7HuwJdYB(I+7l_=~Z@TktrT5 zzxu^C1>+l75b0O5!wsD1jBA76FiCu!;_i!rv>k)-3lzmd4wpL@B6UYX?EO~+$bl14 z7q=rwIe`uxn;Ejvi<)A;jj+yl9vP$ZNsrquq2B3nfdUu?Dz(ZMHpfkh@=YR&W+rFO zLv#o8f0-Ejd!E8OK59IhKi`#Q`bTyl2NlSM-lsZl=d@p$zXAske86#=ZDBxW19hmu z(jkwlNAKXDMj<-c_6jO0Mz0$oN@A1N4_Y2FUs9ER%5vU{Tj|Al{vt7L2sT{>_`}(& zd>Fe}O!?|Y5iwt1KvTi`R9!Q*EEC$3a2nWpNfi38*CxBVD1dx@a_6^ZQy|h>oi%X% zPRHMVb^9@;!8D&?9OgNGl1=CsbY%or330`ASxr9SXDC!h3@gN1$=Q$1IM1*wKp3%Y zRb(vYFM3W4b#uzQ(o$fh#}M8=f|}-cl1n&bz5+0pZGuo0X{XztO%q_QUpOUKF5z(9 z0o}Kgb}J9q(#l!xnN)|?mmKdt^(EYNlA}a`Ox7LbL6?WX)W|V5QQ~H)Qa49hA@Qj zARIQxo)~#)y=gO;|K~vdtqK77F(W5=XKx?V0p-y*7)%seGJ9z9bpPVnDmE-5ifM9` zQ4HC7dcz)S)AC%6&?Fw-FqX8Z6~Yfqz-l5qIsazvzA5ql?wdby%tDG0$YzJdY|J_;t=wb}%pW3Y;V`1H^dC&EJ)K~976O|Ex zaE}8qK^FA$YS$0kTRJ(AVlGfe?Po7IBT7IFUf1Ku9?!*M`|K82f4|+9lThvwyMvNX zjqG+(mB=!lO;%9Io}9P{#Byo$6+KP{IAfN^U#PxWkE;+w%+q8^4}6W338sDp8-|Cy z!{q9Bl_sLfqa)jdIr#bU%E^@1O}1+0Kf362_-QR(xjC5(9v(Cux8F3>;|A`ZYk~6S z1Yz5R!L8N`?a1#Qi_~)atmj^Y=dlI{<7bJL&*;P3UMkSg0|$Xlq%qA=syFYFf`)&D z2cSQ>=b$STx6e5t8*#vwIxI{Kc5+Avp2 zS?Xy&yfq2If7Zy}6Y?Sk9$&IqGaR0F4KM#RPxRCXRrEP8MQEEfwdG#ec3tmj>i+VFwnPjEDZ+O&5gq9Kp(LOS>$=*ts} zAnPa%b9Hgiy2EF-t(Q7ZsS*RA|5ax5c%?rmiunBZ2+MT-az?q*cOSSac%(Nr+mu*V z42}lDZ8jCoTMyq4RS~qkgRH%vwi07x(pot|&`LVGG3tiYD{M1FK@Vd$PmVGtQQ_=FVV zIi)-|M%C z?Tz*CfC%{*p!h%7-*l0XTW+)dcB}Y8X0U=t*&ro$jsQ^yzucKIsnlPv&$n0=n31Qf zVnl2GH$5YPb-X_?=Jq^)QKI_RGqTx4&CahvKLCy}hQT$^^Nm1Du5qbXad43VwZ;%1 zJ!>9i#t?y%mq1N9S^u$+5Us3oU+Oa4=7mae;s;HV;pSeQGI9^TtKUUdT$@t?2n^o^ z`)qu-R5mfgqG0Re5G4En`982ADRM+>5;;tS-~{I?s>%*G=AXmyX=+dv5K`9lpi<;3 zTf|%-cYu zZhR-B^&+scPFpdc;-Gokd{vJ9UkrP zCKWh0fG@B!(m5Pc{4@+?1j6god3gO)f-Qexd=ksA=ry4~b>q1#cuJ{8fL!f`Cma-dqGhi__E*g|XRL2|n!AmMDGxS0->nR9dOG z#DT=T3*Ud>uenVd$8HsmNtl92mFoC^cV+N1{mZ9h4_#-c62#<5Fs^eqr;Qs2qc`w7 zCX*pG7_;NTz?Yb-;?SF$%7}05k-WT(So4WN{q~!8r;x*S-4BybQg_+)`$>A|7c@es zHFNhZRxC28-%H*c#hEG(es(AW=Pp>V*ah^MldWA>3xKo7u(rt|PC+Pyl{nPNxi#tA z8U2ZT7zToaE2Oybp^dw~ExG?aPyI&jPtM2191Mc_6GvHU)Q{HV4uRYsE-c^Dk{~Sa zMDu~=-Sj6qKdQ4{Z;6kMc)cz>ZD?R7Yo#755I2<_19TkiaGh%$?YL)admD} z9Wm~0v%GyFCv*?%ta{=Mj#9UJ z6;s@n4C6zLjzk}P-`m~M&mGhHk~5*V;#kpT(3zB9t#^HeG>*mGgEFE$70QSo9zR18 zB1?p99q$`A-=1=QTXQ;n+}p%92s8tFp55-@gPvG8fI0*SAkY2B};ot&Ax^SH+#l3*584Hnhsil%JWK!1XI(zB(uKE2Gj^&=H z;w~ktBMIA5V21G(wr#u9Ku4fNUo#G7x3LiUDYX=(4yh0=(-38!FbEJ-S(7OHE5|nl zbPNM%II^2RHo$v$Z-`n)wHTjCK>E4nS|08`^4Lho#S3VK|KeLtWv@s78B8%*dY6YY z3W#c|35@>gF7^TwI8|8z_KL?86m$$Wu~udRv7slMkWDLAR}e|y@cY6Fu!km)Do_k- z=fKjahuL315q#Ut z+kpo#Xeyx9D#T!XS<4(AK5-`;9>;or3?4hK)>qW@$hxp(;*Ei=ZADp4h$yRJaL6-% ze>ZS^#NIuE(JhXg1a+?6B6eRla)#}|rwevK{M_KTofJ%I7g>%P{O;kV!A*mz0bX;^@=AIu00bO+k;e=)>8F2KB7Mjd_? zI3Jw&dLDv^0fb~ZyZ*Nx!K1RxulN7F)f)#80oNN+<}jyrWZOp+-)$?go~qrBAuTxv zF)3b9hYFIQcv~VdU@auVe}w%s4k2$1UE^R}xqb;;C&da|kiyP^ftWMw^a$`KLr`){ zJp7WgLh2{R(faP&CK$l>k!}jK1Pv*PJO~bNHcTszw#+SKFB!yrO2$g0eJ}CTq6t}i zd>yrTn+MeK5D9@Z^n*_7F z8=2V8z78qEJ>w&jL6#7}+Tqa17I{ed{yD^WiH6?f5z4Y(g1LJFI%|@BhDQzecZ|6-#%PpNs!Q-aLz2?x(i+g>uIsn^)m%N?H#&4W zcRkuH3N*nGFq&TA|Gyf;h>Zzr8#3sAi66~PTmo<}pJqO7d9oipq%eRZX4~r54^f&r zPZur)y{mH`S1;?w&~SJuTrrE``9)6$Oz;3zJHFf&9foxRSbjkV3W z4h-(;2}p)_M4TuZ-Tvrop?wosnWyR1u*jjI!; zw~B&O6rE_tRXux~8-p+l0Yg3;gi1b3dFCLAg9a15vMeLN5qiD)w01Sfae=@5uEj*v z{AShb;NTL}u5QJI6++E&xM+$CLoR;a-)`t<&(JXvVHVk#^+A+p=Yv?Y?_fY+!9>(a z`X^#(=7V+eE77vQdmjQc-JywbMO}8yc{OH4p06}Ld=xOvyFE2pY zS|a3P&j=iEMbL0HQQZ8nKBxLvy$mDY6aVmv6j=RgPjY0DnvK)VlI8fJXBKK>Ge%bg zS&dw~6w8P8C*Kqwl#Z$w7XT!W=pKxK!MeYmuakFd6iixiwf;W#so4#JhXi#qtXTvW zbRt0L!}a04RDbV1J8|eJdr7Z7d-{#6g+1B$${f@@Ufg0;is5bAu>}r8?gM6I1DhqD z>EKzTL|Kh;XEn39^miE1aX&np0*c0qDlQ8`30!4aCbkt&{eqyK)aS+EWRo8fZ8m)F z&fJefuC69`PY==SSw(})w&c|iTCcQq+>A?a+#h*FBCYh?wm_7oxZnHBJ*fpxEbd=1 zjOP+{kH2UmGY-93*iBAPx`GcmdZYAY9kYe7(Dm|fOvR~+gBR75(^~vwW^Xq_Sb2D zKki6g)V?$gVh{CQFrc=Ac<9_$AR&GleF#@1WZpiiBi|=F<)==IK^=Lt^wr);eKQnOdSfGzRTt-Wy>xwT z*PiU^Oo(h<&(OFtw>P}#Ds@{w1@r~XII_;&rvKQqNZJNFaQ(@)s!5&I%b z4bubjK=$4*9C#y;JUpqi)A`XAbs@p9LIyN35HY5;>v1qJSECxF4nn)Je)##+l_}4Q zHA@tFy~q6}1|e=a?$8mMx0ZP*K~?zzlN$`OWz~=t^j%-i^Oq-gxsud`hzs7}7jG_D zFrk?x`>+TcIkgfGGCE|j(5r~$547L3kPP>IgUP*JWYIaXTx>9PeexwwrhwiczUnsAT`*qy#L$6P9lY(P@YQNc$ruqX zJFGF|uja9!ipbo&?*i^6@-y}Y`>eEU_xXj?l<=CmD=cV8E@p8IeB3cT_|G7scjzOp zND%o^6v8~{30c$mq}TeVW&Yy!xY1Q{Tgaj#aGXDM5Z_d-2**o>@4^TO;*JwAmEJ1Y z#_Xr1uOsn5XHX6c-`6B-f1iHCebi7LXI^&+Nq9PV%v zjE}|H)qHj-lWw=LS~4SzR@>FN;%w=9N=mmS31(CMDXXy@c;6V4UAxB?jYyeo@7=iE zNFAja4poHE^cOY6@$EA9FgP?g3l8nSdvRR90E~}9%Dmb!nsV1!hu~`tQDi0{Q~7t; z7hrZStNKw~IA`_8FH)=GkVKcv%-}YsRK>#@Z|^Sh%@1csN=kJhrJmROg-h!pxDz13 z3xRNUD-5hb^ii48aTUJ6hP$7|{O$G)`{JC8efg1`-6JYbSFa<L||KhQ=m>l!s(8k6mqOE^7!{u3C*(-JG+*qd;gRJF^8S-1lxIdYqp&SH_imlNxyRw7r zTZy%Y&$UsI7oC;WwhZ5gdOm>KwcnebNFX0B6~jMU`h%&X-Q|PGfb)@mARkFQmS+lw zAP4TonE*U5(Oz7g5&a{?Dqg}}wNYQdjg7H7ynb*b%&EWK>9q?HxP}<==h+)kF4g{Y zbK0}ZX_k$dBypsEaan#AKQ4UCj+};aXOEi1W#52&o(UjjYSFB|o>vgl@1rp#A*e(S zx(2;9->IoXi{d2)P%O7Iy`O;4g+YSQ-nGn%cYM%Iwx8A1Ykh9fwb-Du1%+=d6Kx~`(%>woOEr~9Fw1?YvI;SRxvU-P@TIVrwgU@P3p& z9%ukKGf~F#I73XGd5EhP{EYo(AFNA6ltixGpo+^>r)W81ZD!{mF?~m&d5A-|>(b^t!wKx?1G;s~KBW1h@b7 z01iq%=;?OSWyk)@!dPV1CFR3kfmK9|uTWc2gP3V{@!{|@mS<_PjjQLzA0LV6g#0d? z1Bhr{FZjt5IKaqkJYi;L$IqN@rtuulQvaJB36PdP-X0eY|8=NkNB@cFZMMDopRkMX z#rx8!i*XA^g#GLnl#yG?FA;s97&Ca|7NVSYj%0I ze5L%PNsBS763ESB>$ACEhlRvk_QG#5FefpG_2s+sQYW8Ax-aW+eUw0eWG|?2xF-TXU-;ndEmb2M8>#cX zmd-5_a2Ylj2jTVi)8%@-m361H!D%ajPTwy)@r6hTo%GZbbA|GJAf}%@h!viAt9NhT zSBgi94KGK3N;CJ!*`X}TOL*Gxig?WVyt421O4Ls5mjADZO2%R%TKV z&n^ucze4?)AOD)#Z3msx*HNf@-G5!RhXA3oIfh`q$Bs|!qL9eK7k%sJO}^w+ z6#OnVE}oAxBz=~As>{hp_IFvbeQ?onCt2dckC?kzR7u9(b9Pu;_ECqfi0a2keOBgT zOaYOhFRy+gO=Y>5Fn!1_O(az(6?UDDj}Dg($|BARPpy}#n?^dV$r8gv=|>fb@`~ZD z*6SN%p1>}+9I89Xrx{5mEWRSGF{e{VTLrf4F{=@hsipYbgWjA#p~WN53(rgjFsC0U#^C}SA+hECgY;Xx zm)+Z2B#?;#3b#0zS9)cbBXJ0)#3C`{}R&U&eqzP9TEGi_x+F_hy|E*zIeU`S9%^e3Skt&*&8HqHiU*{o$tx` zvFc0WPCxdsOW19lHI$LIMCb7O(M-Kg zU;{m-tjp?~VSC9Sk=lmX^`?J9^5EY%er8MiUDLtkmYN$3MxRXY7}wnW!s0dTf^g*#IlDjcl44qu zB1Y_&)BpaR00#b0W+zvk*0hDU}G!4>=LuEn zPQ`M&RlCEZ!$XHJ8WS#^Z!`yX+`hHe%XM#HIVV;NVY6g2tJwJk%)dze(K@~wTW$#p z&`Wo|IPi$=-bJ*N=uE8^OWN&p|NF~H({`dumz+?*Gfh8+a8ZM z3(YSaI(P+=F41cU-EN|xK6(i3Ha9!*|La1CzXEs&v7u1}xanTWmd*reOnOtAU0XMHTlya|5 z*}iIi2a}W4)Cn)X&$|(?CbG4iaqW>6pCT`Lx1XDKIEVGowT`C4Z*0}urSdOHZVv{n z^4D|!RJA7GN%NpJ>zpr_+ok`s?oUeuCR>)pmA2Q|6Iu>EUmrQSxk{4V-~%ggQ8-ik zb@jPVKPS|16as^(fE|CL1%~=w6&?RB}wY;`zJ8nA?fWG0 z5O5LT1}0|U;VltE1=iC7~b75S6XtcSt zjF`5xQOuMjMzC3XF?c?G9uO@)cv2f^W^ac)}atJj7 zH8Aj`7z(%m_bMq&U;)jjK1i470Iu|cbJZn0kh%K}CkS)4Ff}*`0d+Ps${Pd-A#qoE zD2OnyOad8Gz;i{3)2`oEMyAI2y!mIK>Ij#n4yKI>rkp@;EtJ^M#o|<`;Sk}uX%Y)_ zdh!8fA>fwODsGk!b9wEK&Hu;_TH(LNBj(P3Pg^$8<;;`*IvxT}940)70j^0tB;>0g zlH)6=3Tnm*@oechBC;^y_scs|xmJf9ljC{Q-8fU}VV}k!Gm(ay;s!mu$;@o$4jssu zm?6fc)V;ZZ<0GiN^ygV4(5bi3LFXF_pYW_g;I@Q>gsC1S+^q2~a~VB4+6&p3s}m1s z3(Z>}U0fME|M)jEx1Z-f{rBze{~!nqsNKM2=Rf`#oy==)vhCpnMGWZl7YzX~Q2Fd2 z3fzUw(5M35(ZF%kPf=#uhNVF91D6d@HZ(lSeAT;mjRk1?3@0;iyNODKFStVP&?pN^ j%Sl|yfvyF(o$Noq&SO6HzCX+}8Gyjk)z4*}Q$iB}nNNO+ literal 0 HcmV?d00001 From 3b8d1ec207088c993cabea330d67b58288fcb451 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 20 Aug 2014 17:56:23 +0100 Subject: [PATCH 20/44] Update README.md - skinning --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 3062cdb4..566c4276 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,14 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This - [Jari Komppa's tutorial on building an ImGui library](http://iki.fi/sol/imgui/). - [Casey Muratori's original video that popularized the concept](https://mollyrocket.com/861). +Frequently Asked Question +------------------------- +Can you reskin the look of ImGui? + +Yes, you can alter the look of the interface to some degree: changing colors, sizes and padding, font. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. The example below uses modified settings to create a more compact UI: + +![skinning screenshot 1](/web/skinning_sample_01.png?raw=true) + Credits ------- From 1ff104641abd0e29f5ad67a9a927e86b5d7d7f92 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 20 Aug 2014 18:12:08 +0100 Subject: [PATCH 21/44] Web FAQ --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 566c4276..97e5442e 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,17 @@ The Immediate Mode GUI paradigm may at first appear unusual to some users. This Frequently Asked Question ------------------------- +How do you use ImGui on a platform that may not have a mouse and keyboard? + +I recommend using [Synergy](http://synergy-project.org) and the uSynergy.c micro client to share your mouse and keyboard. This way you can seemingly use your PC input devices on a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate. + +Can you create elaborate/serious tools with ImGui? + +Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is very programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. + Can you reskin the look of ImGui? -Yes, you can alter the look of the interface to some degree: changing colors, sizes and padding, font. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. The example below uses modified settings to create a more compact UI: +Yes, you can alter the look of the interface to some degree: changing colors, sizes and padding, font. However, as ImGui is designed and optimised to create debug tools, the amount of skinning you can apply is limited. There is only so much you can stray away from the default look and feel of the interface. The example below uses modified settings to create a more compact UI with different colors: ![skinning screenshot 1](/web/skinning_sample_01.png?raw=true) From 7bd507d266044e3052a1bce4b0abe89c8645cb98 Mon Sep 17 00:00:00 2001 From: Dale Kim Date: Fri, 22 Aug 2014 16:00:38 -0500 Subject: [PATCH 22/44] Disable client state in OpenGL example after rendering. Using the example code in another application that has other rendering code can cause rendering bugs or memory access errors if client state is not disabled. --- examples/opengl_example/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index d2c76fa8..7fe45c1a 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -61,6 +61,9 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c } } glDisable(GL_SCISSOR_TEST); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); } static const char* ImImpl_GetClipboardTextFn() From 882072cf30c902030dcc00252c791950a104fd79 Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Sun, 24 Aug 2014 03:51:00 +0200 Subject: [PATCH 23/44] Fixed resource leaks --- imgui.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5a72b2aa..5e9add54 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1049,13 +1049,22 @@ static void LoadSettings() if ((f = fopen(filename, "rt")) == NULL) return; if (fseek(f, 0, SEEK_END)) - return; + { + fclose(f); + return; + } const long f_size_signed = ftell(f); if (f_size_signed == -1) - return; + { + fclose(f); + return; + } size_t f_size = (size_t)f_size_signed; if (fseek(f, 0, SEEK_SET)) - return; + { + fclose(f); + return; + } char* f_data = new char[f_size+1]; f_size = fread(f_data, 1, f_size, f); // Text conversion alter read size so let's not be fussy about return value fclose(f); From addfa75eb03cecea3a5640f50e40e2fa471ee8aa Mon Sep 17 00:00:00 2001 From: Martin Ettl Date: Sun, 24 Aug 2014 07:32:27 +0200 Subject: [PATCH 24/44] Do not update a variable, which is not used. --- imgui.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index ff7d7a5b..564da42a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3464,7 +3464,6 @@ static void Plot(ImGuiPlotType plot_type, const char* label, const float* values else if (plot_type == ImGuiPlotType_Histogram) window->DrawList->AddRectFilled(ImLerp(graph_bb.Min, graph_bb.Max, p0), ImLerp(graph_bb.Min, graph_bb.Max, ImVec2(p1.x, 1.0f))+ImVec2(-1,0), v_hovered == v_idx ? col_hovered : col_base); - v0 = v1; t0 = t1; p0 = p1; } From d17a5867389c0da39b248a7bb9dc00cdd23612b2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 25 Aug 2014 17:19:04 +0100 Subject: [PATCH 25/44] Fixed ImGuiTextFilter triming of leading/trailing blanks. Documented "Filtering" section of demo better. --- imgui.cpp | 10 +++++++++- imgui.h | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5e9add54..c54ac6ca 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -725,6 +725,7 @@ static void RegisterAliveId(const ImGuiID& id) //----------------------------------------------------------------------------- +// Helper: Key->value storage void ImGuiStorage::Clear() { Data.clear(); @@ -797,6 +798,7 @@ void ImGuiStorage::SetAllInt(int v) //----------------------------------------------------------------------------- +// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" ImGuiTextFilter::ImGuiTextFilter() { InputBuf[0] = 0; @@ -888,6 +890,7 @@ bool ImGuiTextFilter::PassFilter(const char* val) const //----------------------------------------------------------------------------- +// Helper: Text buffer for logging/accumulating text void ImGuiTextBuffer::append(const char* fmt, ...) { va_list args; @@ -5854,7 +5857,12 @@ void ShowTestWindow(bool* open) if (ImGui::CollapsingHeader("Filtering")) { static ImGuiTextFilter filter; - filter.Draw(); + ImGui::Text("Filter usage:\n" + " \"\" display all lines\n" + " \"xxx\" display lines containing \"xxx\"\n" + " \"xxx,yyy\" display lines containing \"xxx\" or \"yyy\"\n" + " \"-xxx\" hide lines containing \"xxx\""); + filter.Draw(); const char* lines[] = { "aaa1.c", "bbb1.c", "ccc1.c", "aaa2.cpp", "bbb2.cpp", "ccc2.cpp", "abc.h", "hello, world" }; for (size_t i = 0; i < IM_ARRAYSIZE(lines); i++) if (filter.PassFilter(lines[i])) diff --git a/imgui.h b/imgui.h index d1574b6e..0f6ed9d1 100644 --- a/imgui.h +++ b/imgui.h @@ -107,7 +107,7 @@ public: // Helpers at bottom of the file: // - if (IMGUI_ONCE_UPON_A_FRAME) // Execute a block of code once per frame only -// - struct ImGuiTextFilter // Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]" +// - struct ImGuiTextFilter // Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" // - struct ImGuiTextBuffer // Text buffer for logging/accumulating text // - struct ImGuiStorage // Custom key value storage (if you need to alter open/close states manually) // - struct ImDrawList // Draw command list @@ -449,7 +449,7 @@ private: bool TryIsNewFrame() const { const int current_frame = ImGui::GetFrameCount(); if (LastFrame == current_frame) return false; LastFrame = current_frame; return true; } }; -// Helper: Parse and apply text filter. In format "aaaaa[,bbbb][,ccccc]" +// Helper: Parse and apply text filters. In format "aaaaa[,bbbb][,ccccc]" struct ImGuiTextFilter { struct TextRange @@ -463,7 +463,7 @@ struct ImGuiTextFilter const char* end() const { return e; } bool empty() const { return b == e; } char front() const { return *b; } - static bool isblank(char c) { return c == ' ' && c == '\t'; } + static bool isblank(char c) { return c == ' ' || c == '\t'; } void trim_blanks() { while (b < e && isblank(*b)) b++; while (e > b && isblank(*(e-1))) e--; } void split(char separator, ImVector& out); }; From d2b43f31e3bf4107faf6dbd77adbaf304d613c9f Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 25 Aug 2014 17:27:42 +0100 Subject: [PATCH 26/44] Updated URL to new ProggyFonts site --- README.md | 2 +- imgui.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 97e5442e..a59d44f3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Credits Developed by [Omar Cornut](http://www.miracleworld.net). The library was developed with the support of [Media Molecule](http://www.mediamolecule.com) and first used internally on the game [Tearaway](http://tearaway.mediamolecule.com). -Embeds [proggy_clean](http://www.proggyfonts.net/) font by Tristan Grimmer (also MIT license). +Embeds [proggy_clean](http://upperbounds.net) font by Tristan Grimmer (also MIT license). Inspiration, feedback, and testing: Casey Muratori, Atman Binstock, Mikko Mononen, Emmanuel Briney, Stefan Kamoda, Anton Mikhailov, Matt Willis. Thanks! diff --git a/imgui.cpp b/imgui.cpp index c54ac6ca..ff7d7a5b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5896,7 +5896,8 @@ void ShowTestWindow(bool* open) //----------------------------------------------------------------------------- // Font data -// Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://www.proggyfonts.net +// Bitmap exported from proggy_clean.fon (c) by Tristan Grimmer http://upperbounds.net/ +// Also available on unofficial ProggyFonts mirror http://www.proggyfonts.net //----------------------------------------------------------------------------- /* // Copyright (c) 2004, 2005 Tristan Grimmer From 681ac5f777ce91952e5c02e33b51c5d8e6f15336 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 26 Aug 2014 16:56:20 +0100 Subject: [PATCH 27/44] Fixed size/padding of slider grab box for vertical symetry (was 1 pixel too high) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 564da42a..1e805f7b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3284,7 +3284,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch // Draw const float grab_x = ImLerp(slider_effective_x1, slider_effective_x2, grab_t); - const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-1.0f)); + const ImGuiAabb grab_bb(ImVec2(grab_x-grab_size_in_pixels*0.5f,frame_bb.Min.y+2.0f), ImVec2(grab_x+grab_size_in_pixels*0.5f,frame_bb.Max.y-2.0f)); window->DrawList->AddRectFilled(grab_bb.Min, grab_bb.Max, window->Color(g.ActiveId == id ? ImGuiCol_SliderGrabActive : ImGuiCol_SliderGrab)); } From 5f6b261c9be5c83851a49fd88139adfa6389e500 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 26 Aug 2014 18:14:04 +0100 Subject: [PATCH 28/44] Fixed uninitialised fields in ImBitmapFont (were unused when uninitialised, but still dodgy) --- imgui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 1e805f7b..a2f48a63 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5030,11 +5030,14 @@ void ImDrawList::AddText(ImFont font, float font_size, const ImVec2& pos, ImU32 ImBitmapFont::ImBitmapFont() { Data = NULL; + DataSize = 0; DataOwned = false; Info = NULL; Common = NULL; Glyphs = NULL; GlyphsCount = 0; + Kerning = NULL; + KerningCount = 0; TabCount = 4; } From 80dd1e1065cbbbc3f12ebe3bbaa38d7d843c6842 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 26 Aug 2014 18:27:10 +0100 Subject: [PATCH 29/44] Added comments --- examples/directx9_example/main.cpp | 5 ++++- examples/opengl_example/main.cpp | 9 ++++++--- imgui.cpp | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index f302db66..63760eb5 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -20,7 +20,10 @@ struct CUSTOMVERTEX }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) -// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer) +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { size_t total_vtx_count = 0; diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 7fe45c1a..1f316475 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -11,14 +11,17 @@ static GLFWwindow* window; static GLuint fontTex; -// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structuer) -// We are using the fixed pipeline. -// A faster way would be to collate all vertices from all cmd_lists into a single vertex buffer +// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) +// If text or lines are blurry when integrating ImGui in your engine: +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f +// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { if (cmd_lists_count == 0) return; + // We are using the OpenGL fixed pipeline to make the example code simpler to read! + // A probable faster way to render would be to collate all vertices from all cmd_lists into a single vertex buffer. // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers. glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/imgui.cpp b/imgui.cpp index a2f48a63..9180e7ce 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -53,7 +53,7 @@ - every frame: 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the 'Input' data, then call ImGui::NewFrame(). 2/ use any ImGui function you want between NewFrame() and Render() - 3/ ImGui::Render() to render all the accumulated command-lists. it will cack your RenderDrawListFn handler set in the IO structure. + 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure. - all rendering information are stored into command-lists until ImGui::Render() is called. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations. - a typical application skeleton may be: @@ -87,6 +87,10 @@ // swap video buffer, etc. } + - if text or lines are blurry when integrating ImGui in your engine: + - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f + - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) + - some widgets carry state and requires an unique ID to do so. - unique ID are typically derived from a string label, an indice or a pointer. - use PushID/PopID to easily create scopes and avoid ID conflicts. A Window is also an implicit scope. From 51f8e33eb40d32659c894c356adb3d858567d8c7 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 26 Aug 2014 18:29:58 +0100 Subject: [PATCH 30/44] Added FAQ entry --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a59d44f3..1237e817 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,14 @@ Frequently Asked Question I recommend using [Synergy](http://synergy-project.org) and the uSynergy.c micro client to share your mouse and keyboard. This way you can seemingly use your PC input devices on a video game console or a tablet. ImGui was also designed to function with touch inputs if you increase the padding of widgets to compensate for the lack of precision of touch devices, but it is recommended you use a mouse to allow optimising for screen real-estate. +I integrated ImGui in my engine and the text or lines are blurry.. + +- Try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f. +- In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). + Can you create elaborate/serious tools with ImGui? -Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is very programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. +Yes. I have written data browsers, debuggers, profilers and all sort of non-trivial tools with the library. There's no reason you cannot, and in my experience the simplicity of the API is very empowering. However note that ImGui is programmer centric and the immediate-mode GUI paradigm might requires a bit of adaptation before you can realize its full potential. Can you reskin the look of ImGui? From b90d0c558d488003a552548a6bfb895bc589ed05 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 26 Aug 2014 19:22:09 +0100 Subject: [PATCH 31/44] Minor text alignment --- examples/opengl_example/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 1f316475..7f698ab3 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -149,10 +149,10 @@ void InitImGui() glfwGetWindowSize(window, &w, &h); ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. - io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.5f; // Align OpenGL texels - io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. + io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. + io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) + io.PixelCenterOffset = 0.5f; // Align OpenGL texels + io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP; From 5a9639b423d2d1600fcc29c4df4fd07db593c156 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 27 Aug 2014 11:38:26 +0100 Subject: [PATCH 32/44] Fixed collapsing header border (if borders are enabled) being off the clip rectangle. Tweak demo window. --- imgui.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9180e7ce..8326cc7c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2887,8 +2887,8 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_ ImGuiAabb bb = ImGuiAabb(pos_min, ImVec2(pos_max.x, pos_min.y + text_size.y)); if (display_frame) { - bb.Min.x -= window_padding.x*0.5f; - bb.Max.x += window_padding.x*0.5f; + bb.Min.x -= window_padding.x*0.5f - 1; + bb.Max.x += window_padding.x*0.5f - 1; bb.Max.y += style.FramePadding.y * 2; } @@ -5510,10 +5510,10 @@ void ShowTestWindow(bool* open) if (ImGui::CollapsingHeader("Window options")) { - ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(200); - ImGui::Checkbox("no border", &no_border); ImGui::SameLine(400); + ImGui::Checkbox("no titlebar", &no_titlebar); ImGui::SameLine(150); + ImGui::Checkbox("no border", &no_border); ImGui::SameLine(300); ImGui::Checkbox("no resize", &no_resize); - ImGui::Checkbox("no move", &no_move); ImGui::SameLine(200); + ImGui::Checkbox("no move", &no_move); ImGui::SameLine(150); ImGui::Checkbox("no scrollbar", &no_scrollbar); ImGui::SliderFloat("fill alpha", &fill_alpha, 0.0f, 1.0f); if (ImGui::TreeNode("Style Editor")) @@ -5596,6 +5596,9 @@ void ShowTestWindow(bool* open) ImGui::EndTooltip(); } + ImGui::Separator(); + ImGui::Text("^ Horizontal separator"); + static int item = 1; ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0"); From bd26de062833c64efa3940e07c4abfd2f2ad190d Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 27 Aug 2014 17:54:11 +0100 Subject: [PATCH 33/44] Collapse triangle don't have a shadow unless borders are enabled. Fixed cross that appears when hovering window close button to be perfectly 45 degrees. --- imgui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8326cc7c..ad4a4312 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -154,6 +154,7 @@ - input: support trackpad style scrolling & slider edit. - misc: not thread-safe - misc: double-clicking on title bar to minimize isn't consistent, perhaps move to single-click on left-most collapse icon? + - style editor: add a button to print C code. - optimisation/render: use indexed rendering - optimisation/render: move clip-rect to vertex data? would allow merging all commands - optimisation/render: merge command-list of all windows into one command-list? @@ -1585,7 +1586,7 @@ static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, c = center + ImVec2(-0.500f,-0.866f)*r; } - if (shadow) + if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0) window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), window->Color(ImGuiCol_BorderShadow)); window->DrawList->AddTriangleFilled(a, b, c, window->Color(ImGuiCol_Border)); } @@ -2766,7 +2767,7 @@ static bool CloseWindowButton(bool* open) const ImGuiID id = window->GetID("##CLOSE"); const float title_bar_height = window->TitleBarHeight(); - const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+3.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f)); + const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+2.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f)); bool hovered, held; bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); @@ -2775,7 +2776,7 @@ static bool CloseWindowButton(bool* open) const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,title_bar_height*0.5f-4), col, 16); - const float cross_padding = 4; + const float cross_padding = 4.0f; if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2) { window->DrawList->AddLine(bb.GetTL()+ImVec2(+cross_padding,+cross_padding), bb.GetBR()+ImVec2(-cross_padding,-cross_padding), window->Color(ImGuiCol_Text)); @@ -2924,7 +2925,7 @@ bool CollapsingHeader(const char* label, const char* str_id, const bool display_ { if ((held && hovered) || hovered) RenderFrame(bb.Min, bb.Max, col, false); - RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f); + RenderCollapseTriangle(bb.Min + ImVec2(style.FramePadding.x, window->FontSize()*0.15f), opened, 0.70f, false); RenderText(bb.Min + ImVec2(window->FontSize() + style.FramePadding.x*2,0), label); } From 1f63e01cc60461f0d5214547858259bd8938c3c5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 27 Aug 2014 22:16:55 +0100 Subject: [PATCH 34/44] Minor fixes to scrollbar rendering, close button and made checkbox/radio button padding more consistent. --- imgui.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index ad4a4312..ba5746f3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -183,10 +183,12 @@ namespace ImGui { static bool ButtonBehaviour(const ImGuiAabb& bb, const ImGuiID& id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false); -static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); -static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); +static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, const bool hide_text_after_hash = true); +static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); +static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false); + static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); static void PushColumnClipRect(int column_index = -1); @@ -1563,7 +1565,7 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, } } -static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale = 1.0f, bool shadow = false) +static void RenderCollapseTriangle(ImVec2 p_min, bool open, float scale, bool shadow) { ImGuiWindow* window = GetCurrentWindow(); @@ -2071,8 +2073,7 @@ bool Begin(const char* name, bool* open, ImVec2 size, float fill_alpha, ImGuiWin ImGuiAabb scrollbar_bb(window->Aabb().Max.x - style.ScrollBarWidth, title_bar_aabb.Max.y+1, window->Aabb().Max.x, window->Aabb().Max.y-1); //window->DrawList->AddLine(scrollbar_bb.GetTL(), scrollbar_bb.GetBL(), g.Colors[ImGuiCol_Border]); window->DrawList->AddRectFilled(scrollbar_bb.Min, scrollbar_bb.Max, window->Color(ImGuiCol_ScrollbarBg)); - scrollbar_bb.Max.x -= 3; - scrollbar_bb.Expand(ImVec2(0,-3)); + scrollbar_bb.Expand(ImVec2(-3,-3)); const float grab_size_y_norm = ImSaturate(window->Size.y / ImMax(window->SizeContentsFit.y, window->Size.y)); const float grab_size_y = scrollbar_bb.GetHeight() * grab_size_y_norm; @@ -2766,15 +2767,15 @@ static bool CloseWindowButton(bool* open) ImGuiWindow* window = GetCurrentWindow(); const ImGuiID id = window->GetID("##CLOSE"); - const float title_bar_height = window->TitleBarHeight(); - const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-title_bar_height+2.0f,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,+title_bar_height-2.0f)); + const float size = window->TitleBarHeight() - 4.0f; + const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-2.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,2.0f+size)); bool hovered, held; bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); // Render const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); - window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,title_bar_height*0.5f-4), col, 16); + window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,size*0.5f-2.0f), col, 16); const float cross_padding = 4.0f; if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2) @@ -3526,7 +3527,7 @@ void Checkbox(const char* label, bool* v) RenderFrame(check_bb.Min, check_bb.Max, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg)); if (*v) { - window->DrawList->AddRectFilled(check_bb.Min+ImVec2(4,4), check_bb.Max-ImVec2(4,4), window->Color(ImGuiCol_CheckActive)); + window->DrawList->AddRectFilled(check_bb.Min+ImVec2(3,3), check_bb.Max-ImVec2(3,3), window->Color(ImGuiCol_CheckActive)); } if (g.LogEnabled) @@ -3579,7 +3580,7 @@ bool RadioButton(const char* label, bool active) window->DrawList->AddCircleFilled(center, radius, window->Color(hovered ? ImGuiCol_CheckHovered : ImGuiCol_FrameBg), 16); if (active) - window->DrawList->AddCircleFilled(center, radius-2, window->Color(ImGuiCol_CheckActive), 16); + window->DrawList->AddCircleFilled(center, radius-3.0f, window->Color(ImGuiCol_CheckActive), 16); if (window->Flags & ImGuiWindowFlags_ShowBorders) { From 88c33ecc2926fa992a4a3e46907cd8daed60c45a Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 14:52:10 +0100 Subject: [PATCH 35/44] Fixes to allow clean 1-pixel thick lines in more use cases. PixelCenterOffset not the same as previously! --- examples/directx9_example/main.cpp | 4 +- examples/opengl_example/main.cpp | 4 +- imgui.cpp | 77 +++++++++++++++++------------- imgui.h | 2 +- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index 63760eb5..28630ab5 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -22,8 +22,8 @@ struct CUSTOMVERTEX // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: -// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { size_t total_vtx_count = 0; @@ -82,7 +82,7 @@ static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_c D3DXMatrixIdentity(&mat); g_pd3dDevice->SetTransform(D3DTS_WORLD, &mat); g_pd3dDevice->SetTransform(D3DTS_VIEW, &mat); - D3DXMatrixOrthoOffCenterLH(&mat, 0.0f, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 0.0f, -1.0f, +1.0f); + D3DXMatrixOrthoOffCenterLH(&mat, 0.5f, ImGui::GetIO().DisplaySize.x+0.5f, ImGui::GetIO().DisplaySize.y+0.5f, 0.5f, -1.0f, +1.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat); // Render command lists diff --git a/examples/opengl_example/main.cpp b/examples/opengl_example/main.cpp index 7f698ab3..53e05399 100644 --- a/examples/opengl_example/main.cpp +++ b/examples/opengl_example/main.cpp @@ -13,8 +13,8 @@ static GLuint fontTex; // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure) // If text or lines are blurry when integrating ImGui in your engine: -// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f // - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) +// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f static void ImImpl_RenderDrawLists(ImDrawList** const cmd_lists, int cmd_lists_count) { if (cmd_lists_count == 0) @@ -151,7 +151,7 @@ void InitImGui() ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)w, (float)h); // Display size, in pixels. For clamping windows positions. io.DeltaTime = 1.0f/60.0f; // Time elapsed since last frame, in seconds (in this sample app we'll override this every frame because our timestep is variable) - io.PixelCenterOffset = 0.5f; // Align OpenGL texels + io.PixelCenterOffset = 0.0f; // Align OpenGL texels io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT; io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT; diff --git a/imgui.cpp b/imgui.cpp index ba5746f3..a634dd3b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -88,8 +88,8 @@ } - if text or lines are blurry when integrating ImGui in your engine: - - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) + - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f - some widgets carry state and requires an unique ID to do so. - unique ID are typically derived from a string label, an indice or a pointer. @@ -280,7 +280,7 @@ ImGuiIO::ImGuiIO() LogFilename = "imgui_log.txt"; Font = NULL; FontAllowScaling = false; - PixelCenterOffset = 0.5f; + PixelCenterOffset = 0.0f; MousePos = ImVec2(-1,-1); MousePosPrev = ImVec2(-1,-1); MouseDoubleClickTime = 0.30f; @@ -1560,8 +1560,10 @@ static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, window->DrawList->AddRectFilled(p_min, p_max, fill_col, rounding); if (border && (window->Flags & ImGuiWindowFlags_ShowBorders)) { - window->DrawList->AddRect(p_min+ImVec2(1,1), p_max+ImVec2(1,1), window->Color(ImGuiCol_BorderShadow), rounding); - window->DrawList->AddRect(p_min, p_max, window->Color(ImGuiCol_Border), rounding); + // FIXME: I have no idea how this is working correctly but it is the best I've found that works on multiple rendering + const float offset = GImGui.IO.PixelCenterOffset; + window->DrawList->AddRect(p_min+ImVec2(1.5f-offset,1.5f-offset), p_max+ImVec2(1.0f-offset*2,1.0f-offset*2), window->Color(ImGuiCol_BorderShadow), rounding); + window->DrawList->AddRect(p_min+ImVec2(0.5f-offset,0.5f-offset), p_max+ImVec2(0.0f-offset*2,0.0f-offset*2), window->Color(ImGuiCol_Border), rounding); } } @@ -2768,20 +2770,21 @@ static bool CloseWindowButton(bool* open) const ImGuiID id = window->GetID("##CLOSE"); const float size = window->TitleBarHeight() - 4.0f; - const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-2.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-2.0f,2.0f+size)); + const ImGuiAabb bb(window->Aabb().GetTR() + ImVec2(-3.0f-size,2.0f), window->Aabb().GetTR() + ImVec2(-3.0f,2.0f+size)); bool hovered, held; bool pressed = ButtonBehaviour(bb, id, &hovered, &held, true); // Render const ImU32 col = window->Color((held && hovered) ? ImGuiCol_CloseButtonActive : hovered ? ImGuiCol_CloseButtonHovered : ImGuiCol_CloseButton); - window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f,size*0.5f-2.0f), col, 16); + const ImVec2 center = bb.GetCenter(); + window->DrawList->AddCircleFilled(center, ImMax(2.0f,size*0.5f), col, 16); - const float cross_padding = 4.0f; - if (hovered && bb.GetWidth() >= (cross_padding+1)*2 && bb.GetHeight() >= (cross_padding+1)*2) + const float cross_extent = (size * 0.5f * 0.7071f) - 1.0f; + if (hovered) { - window->DrawList->AddLine(bb.GetTL()+ImVec2(+cross_padding,+cross_padding), bb.GetBR()+ImVec2(-cross_padding,-cross_padding), window->Color(ImGuiCol_Text)); - window->DrawList->AddLine(bb.GetBL()+ImVec2(+cross_padding,-cross_padding), bb.GetTR()+ImVec2(-cross_padding,+cross_padding), window->Color(ImGuiCol_Text)); + window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), window->Color(ImGuiCol_Text)); + window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), window->Color(ImGuiCol_Text)); } if (open != NULL && pressed) @@ -4815,16 +4818,18 @@ void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) void ImDrawList::AddVtxLine(const ImVec2& a, const ImVec2& b, ImU32 col) { - const ImVec2 n = (b - a) / ImLength(b - a); - const ImVec2 hn = ImVec2(n.y, -n.x) * 0.5f; + const float offset = GImGui.IO.PixelCenterOffset; + const ImVec2 hn = (b - a) * (0.50f / ImLength(b - a)); // half normal + const ImVec2 hp0 = ImVec2(offset - hn.y, offset + hn.x); // half perpendiculars + user offset + const ImVec2 hp1 = ImVec2(offset + hn.y, offset - hn.x); - AddVtx(a - hn, col); - AddVtx(b - hn, col); - AddVtx(a + hn, col); - - AddVtx(b - hn, col); - AddVtx(b + hn, col); - AddVtx(a + hn, col); + // Two triangles makes up one line. Using triangles allows us to make draw calls. + AddVtx(a + hp0, col); + AddVtx(b + hp0, col); + AddVtx(a + hp1, col); + AddVtx(b + hp0, col); + AddVtx(b + hp1, col); + AddVtx(a + hp1, col); } void ImDrawList::AddLine(const ImVec2& a, const ImVec2& b, ImU32 col) @@ -4966,10 +4971,12 @@ void ImDrawList::AddTriangleFilled(const ImVec2& a, const ImVec2& b, const ImVec if ((col >> 24) == 0) return; + const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); + ReserveVertices(3); - AddVtx(a, col); - AddVtx(b, col); - AddVtx(c, col); + AddVtx(a + offset, col); + AddVtx(b + offset, col); + AddVtx(c + offset, col); } void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int num_segments) @@ -4977,13 +4984,15 @@ void ImDrawList::AddCircle(const ImVec2& centre, float radius, ImU32 col, int nu if ((col >> 24) == 0) return; + const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); + ReserveVertices((unsigned int)num_segments*6); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtxLine(centre + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col); + AddVtxLine(centre + offset + ImVec2(cos(a0),sin(a0))*radius, centre + ImVec2(cos(a1),sin(a1))*radius, col); a0 = a1; } } @@ -4993,15 +5002,17 @@ void ImDrawList::AddCircleFilled(const ImVec2& centre, float radius, ImU32 col, if ((col >> 24) == 0) return; + const ImVec2 offset(GImGui.IO.PixelCenterOffset,GImGui.IO.PixelCenterOffset); + ReserveVertices((unsigned int)num_segments*3); const float a_step = 2*PI/(float)num_segments; float a0 = 0.0f; for (int i = 0; i < num_segments; i++) { const float a1 = (i + 1) == num_segments ? 0.0f : a0 + a_step; - AddVtx(centre + ImVec2(cos(a0),sin(a0))*radius, col); - AddVtx(centre + ImVec2(cos(a1),sin(a1))*radius, col); - AddVtx(centre, col); + AddVtx(centre + offset + ImVec2(cos(a0),sin(a0))*radius, col); + AddVtx(centre + offset + ImVec2(cos(a1),sin(a1))*radius, col); + AddVtx(centre + offset, col); a0 = a1; } } @@ -5231,13 +5242,11 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c const float outline = (float)Info->Outline; // Align to be pixel perfect - pos.x = (float)(int)pos.x + 0.5f; - pos.y = (float)(int)pos.y + 0.5f; + pos.x = (float)(int)pos.x; + pos.y = (float)(int)pos.y; const ImVec4 clip_rect = clip_rect_ref; - const float uv_offset = GImGui.IO.PixelCenterOffset; - float x = pos.x; float y = pos.y; for (const char* s = text_begin; s < text_end; s++) @@ -5274,10 +5283,10 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c continue; } - const float s1 = (uv_offset + glyph->X) * tex_scale_x; - const float t1 = (uv_offset + glyph->Y) * tex_scale_y; - const float s2 = (uv_offset + glyph->X + glyph->Width) * tex_scale_x; - const float t2 = (uv_offset + glyph->Y + glyph->Height) * tex_scale_y; + const float s1 = (glyph->X) * tex_scale_x; + const float t1 = (glyph->Y) * tex_scale_y; + const float s2 = (glyph->X + glyph->Width) * tex_scale_x; + const float t2 = (glyph->Y + glyph->Height) * tex_scale_y; out_vertices[0].pos = ImVec2(x1, y1); out_vertices[0].uv = ImVec2(s1, t1); diff --git a/imgui.h b/imgui.h index 0f6ed9d1..7ca519ad 100644 --- a/imgui.h +++ b/imgui.h @@ -391,7 +391,7 @@ struct ImGuiIO ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. - float PixelCenterOffset; // = 0.5f // Set to 0.0f for DirectX <= 9, 0.5f for Direct3D >= 10 and OpenGL. + float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry // Settings - Rendering function (REQUIRED) // See example code if you are unsure of how to implement this. From 7adad7104207c4958cda2503e1ef3d67bc705bf9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 14:53:41 +0100 Subject: [PATCH 36/44] Moved IMGUI_FONT_TEX_UV_FOR_WHITE define to a variable so font can be changed at runtime --- imgui.cpp | 5 +++-- imgui.h | 5 +---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a634dd3b..da69ba37 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -105,7 +105,7 @@ - if you want to use a different font than the default - create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(), set ImGui::GetIO().FontHeight - - load your texture yourself. texture *MUST* have white pixel at UV coordinate 'IMGUI_FONT_TEX_UV_FOR_WHITE' (you can #define it in imconfig.h), this is used by solid objects. + - load your texture yourself. texture *MUST* have white pixel at UV coordinate Imgui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes. - tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. @@ -279,6 +279,7 @@ ImGuiIO::ImGuiIO() IniFilename = "imgui.ini"; LogFilename = "imgui_log.txt"; Font = NULL; + FontTexUvForWhite = ImVec2(0.0f,0.0f); FontAllowScaling = false; PixelCenterOffset = 0.0f; MousePos = ImVec2(-1,-1); @@ -4812,7 +4813,7 @@ void ImDrawList::AddVtx(const ImVec2& pos, ImU32 col) { vtx_write->pos = pos; vtx_write->col = col; - vtx_write->uv = IMGUI_FONT_TEX_UV_FOR_WHITE; + vtx_write->uv = GImGui.IO.FontTexUvForWhite; vtx_write++; } diff --git a/imgui.h b/imgui.h index 7ca519ad..5e3ff74b 100644 --- a/imgui.h +++ b/imgui.h @@ -390,6 +390,7 @@ struct ImGuiIO int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y + ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture. bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry @@ -524,10 +525,6 @@ struct ImDrawCmd ImVec4 clip_rect; }; -#ifndef IMGUI_FONT_TEX_UV_FOR_WHITE -#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f,0.f) -#endif - // sizeof() == 20 struct ImDrawVert { From cd3d027df0adb0fd602928b089c9588124532288 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 14:54:22 +0100 Subject: [PATCH 37/44] Delete obsolete comments in imconfig.h --- imconfig.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/imconfig.h b/imconfig.h index aeb8d542..0f5357cd 100644 --- a/imconfig.h +++ b/imconfig.h @@ -15,10 +15,6 @@ //---- Don't implement default clipboard handlers for Windows (so as not to link with OpenClipboard(), etc.) //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS -//---- If you are loading a custom font, ImGui expect to find a pure white pixel at (0,0) -// Change it's UV coordinate here if you can't have a white pixel at (0,0) -//#define IMGUI_FONT_TEX_UV_FOR_WHITE ImVec2(0.f/256.f,0.f/256.f) - //---- Define implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. /* #define IM_VEC2_CLASS_EXTRA \ From 2fb63b6068264960707d3018fa57145a9f0ff415 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 28 Aug 2014 17:32:03 +0100 Subject: [PATCH 38/44] Checkbox() return true when pressed --- imgui.cpp | 13 ++++++++----- imgui.h | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index da69ba37..dedda758 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3495,12 +3495,12 @@ void PlotHistogram(const char* label, const float* values, int values_count, int ImGui::Plot(ImGuiPlotType_Histogram, label, values, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, stride); } -void Checkbox(const char* label, bool* v) +bool Checkbox(const char* label, bool* v) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) - return; + return false; const ImGuiStyle& style = g.Style; const ImGuiID id = window->GetID(label); @@ -3516,7 +3516,7 @@ void Checkbox(const char* label, bool* v) const ImGuiAabb total_bb(ImMin(check_bb.Min, text_bb.Min), ImMax(check_bb.Max, text_bb.Max)); if (ClipAdvance(total_bb)) - return; + return false; const bool hovered = (g.HoveredWindow == window) && (g.HoveredId == 0) && IsMouseHoveringBox(total_bb); const bool pressed = hovered && g.IO.MouseClicked[0]; @@ -3537,16 +3537,19 @@ void Checkbox(const char* label, bool* v) if (g.LogEnabled) LogText(text_bb.GetTL(), *v ? "[x]" : "[ ]"); RenderText(text_bb.GetTL(), label); + + return pressed; } -void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) +bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) { bool v = (*flags & flags_value) ? true : false; - ImGui::Checkbox(label, &v); + bool pressed = ImGui::Checkbox(label, &v); if (v) *flags |= flags_value; else *flags &= ~flags_value; + return pressed; } bool RadioButton(const char* label, bool active) diff --git a/imgui.h b/imgui.h index 5e3ff74b..ee497e73 100644 --- a/imgui.h +++ b/imgui.h @@ -197,8 +197,8 @@ namespace ImGui bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format = "%.0f"); void PlotLines(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); void PlotHistogram(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0), size_t stride = sizeof(float)); - void Checkbox(const char* label, bool* v); - void CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); + bool Checkbox(const char* label, bool* v); + bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); bool RadioButton(const char* label, bool active); bool RadioButton(const char* label, int* v, int v_button); bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1); From dd5d25127302b138df7b1555947f4fb9202e2739 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 29 Aug 2014 13:36:31 +0100 Subject: [PATCH 39/44] Added SetCursorPosX, SetCursorPosY shortcuts --- imgui.cpp | 12 ++++++++++++ imgui.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index dedda758..8cb59e05 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2461,6 +2461,18 @@ void SetCursorPos(const ImVec2& pos) window->DC.CursorPos = window->Pos + pos; } +void SetCursorPosX(float x) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.x = window->Pos.x + x; +} + +void SetCursorPosY(float y) +{ + ImGuiWindow* window = GetCurrentWindow(); + window->DC.CursorPos.y = window->Pos.y + y; +} + ImVec2 GetCursorScreenPos() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index ee497e73..7ffc7dab 100644 --- a/imgui.h +++ b/imgui.h @@ -168,6 +168,8 @@ namespace ImGui float GetColumnWidth(int column_index = -1); ImVec2 GetCursorPos(); // cursor position relative to window position void SetCursorPos(const ImVec2& pos); // " + void SetCursorPosX(float x); // " + void SetCursorPosY(float y); // " ImVec2 GetCursorScreenPos(); // cursor position in screen space void AlignFirstTextHeightToWidgets(); // call once if the first item on the line is a Text() item and you want to vertically lower it to match higher widgets. float GetTextLineSpacing(); From 8fc50f5ed3cc31e62333ce53028e95d08a9e4847 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Aug 2014 18:43:26 +0100 Subject: [PATCH 40/44] Remove IO.FontHeight, cached automatically. Added assertions. --- imgui.cpp | 11 +++++++---- imgui.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8cb59e05..a1115188 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -104,8 +104,8 @@ e.g. "##Foobar" display an empty label and uses "##Foobar" as ID - if you want to use a different font than the default - - create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(), set ImGui::GetIO().FontHeight - - load your texture yourself. texture *MUST* have white pixel at UV coordinate Imgui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes. + - create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(). + - load your texture yourself. texture *MUST* have white pixel at UV coordinate ImGui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes. - tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. @@ -604,6 +604,8 @@ struct ImGuiState bool Initialized; ImGuiIO IO; ImGuiStyle Style; + float FontSize; // == IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y + float Time; int FrameCount; int FrameCountRendered; @@ -709,7 +711,7 @@ public: ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); } ImFont Font() const { return GImGui.IO.Font; } - float FontSize() const { return GImGui.IO.FontHeight * FontScale; } + float FontSize() const { return GImGui.FontSize * FontScale; } ImVec2 CursorPos() const { return DC.CursorPos; } float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; } ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); } @@ -1197,14 +1199,15 @@ void NewFrame() ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL); g.IO.Font = new ImBitmapFont(); g.IO.Font->LoadFromMemory(fnt_data, fnt_size); - g.IO.FontHeight = g.IO.Font->GetFontSize(); } g.Initialized = true; } + IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded()); // Font not loaded g.Time += g.IO.DeltaTime; g.FrameCount += 1; g.Tooltip[0] = '\0'; + g.FontSize = g.IO.Font->GetFontSize(); // Update inputs state if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0) diff --git a/imgui.h b/imgui.h index 7ffc7dab..f75a68e7 100644 --- a/imgui.h +++ b/imgui.h @@ -391,7 +391,6 @@ struct ImGuiIO float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). - float FontHeight; // // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture. bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry @@ -642,6 +641,7 @@ struct ImBitmapFont void BuildLookupTable(); const FntGlyph * FindGlyph(unsigned short c) const; float GetFontSize() const { return (float)Info->FontSize; } + bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; } ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const; void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const; From 3b339efeb2ac8e1f8299213def138c197366079e Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Aug 2014 20:02:10 +0100 Subject: [PATCH 41/44] Added IO.FontYOffset. Added asserts. --- imgui.cpp | 10 ++++++++-- imgui.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a1115188..632e278a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -279,6 +279,7 @@ ImGuiIO::ImGuiIO() IniFilename = "imgui.ini"; LogFilename = "imgui_log.txt"; Font = NULL; + FontYOffset = 0.0f; FontTexUvForWhite = ImVec2(0.0f,0.0f); FontAllowScaling = false; PixelCenterOffset = 0.0f; @@ -1199,6 +1200,7 @@ void NewFrame() ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL); g.IO.Font = new ImBitmapFont(); g.IO.Font->LoadFromMemory(fnt_data, fnt_size); + g.IO.FontYOffset = +1; } g.Initialized = true; } @@ -5093,6 +5095,8 @@ void ImBitmapFont::Clear() bool ImBitmapFont::LoadFromFile(const char* filename) { + IM_ASSERT(!IsLoaded()); // Call Clear() + // Load file FILE* f; if ((f = fopen(filename, "rb")) == NULL) @@ -5123,7 +5127,9 @@ bool ImBitmapFont::LoadFromFile(const char* filename) bool ImBitmapFont::LoadFromMemory(const void* data, size_t data_size) { - Data = (unsigned char*)data; + IM_ASSERT(!IsLoaded()); // Call Clear() + + Data = (unsigned char*)data; DataSize = data_size; // Parse data @@ -5262,7 +5268,7 @@ void ImBitmapFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& c // Align to be pixel perfect pos.x = (float)(int)pos.x; - pos.y = (float)(int)pos.y; + pos.y = (float)(int)pos.y + GImGui.IO.FontYOffset; const ImVec4 clip_rect = clip_rect_ref; diff --git a/imgui.h b/imgui.h index f75a68e7..c8ffeedb 100644 --- a/imgui.h +++ b/imgui.h @@ -391,6 +391,7 @@ struct ImGuiIO float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels. int KeyMap[ImGuiKey_COUNT]; // // Map of indices into the KeysDown[512] entries array ImFont Font; // // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font). + float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis. ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture. bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel. float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry From 2c677c45c736fea6ff445e536ba4c2cf2b22bacd Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Aug 2014 20:02:55 +0100 Subject: [PATCH 42/44] Added sample fonts data --- extra_fonts/ProggyClean.zip | Bin 0 -> 4825 bytes extra_fonts/ProggySmall.zip | Bin 0 -> 4238 bytes extra_fonts/README.txt | 71 ++++++++++++++++++++++++++++++++ extra_fonts/courier_new_16.fnt | Bin 0 -> 3906 bytes extra_fonts/courier_new_16.png | Bin 0 -> 1393 bytes extra_fonts/courier_new_18.fnt | Bin 0 -> 3906 bytes extra_fonts/courier_new_18.png | Bin 0 -> 2655 bytes extra_fonts/proggy_clean_13.fnt | Bin 0 -> 4647 bytes extra_fonts/proggy_clean_13.png | Bin 0 -> 1557 bytes extra_fonts/proggy_small_12.fnt | Bin 0 -> 4647 bytes extra_fonts/proggy_small_12.png | Bin 0 -> 949 bytes extra_fonts/proggy_small_14.fnt | Bin 0 -> 4647 bytes extra_fonts/proggy_small_14.png | Bin 0 -> 949 bytes 13 files changed, 71 insertions(+) create mode 100644 extra_fonts/ProggyClean.zip create mode 100644 extra_fonts/ProggySmall.zip create mode 100644 extra_fonts/README.txt create mode 100644 extra_fonts/courier_new_16.fnt create mode 100644 extra_fonts/courier_new_16.png create mode 100644 extra_fonts/courier_new_18.fnt create mode 100644 extra_fonts/courier_new_18.png create mode 100644 extra_fonts/proggy_clean_13.fnt create mode 100644 extra_fonts/proggy_clean_13.png create mode 100644 extra_fonts/proggy_small_12.fnt create mode 100644 extra_fonts/proggy_small_12.png create mode 100644 extra_fonts/proggy_small_14.fnt create mode 100644 extra_fonts/proggy_small_14.png diff --git a/extra_fonts/ProggyClean.zip b/extra_fonts/ProggyClean.zip new file mode 100644 index 0000000000000000000000000000000000000000..06108e1dd406a9d62839262191b7c4a5ee7a3c54 GIT binary patch literal 4825 zcmZ{ocTf{tm&WP62>}E`7my}ZK@1=e1PRi6l^RMY0fdNvN=c|ecme6X_udI4bm>M! z0g{(WNOD9? zLh_i6goOFesZoF*6#7&P=H}#k%iYhnFY{>_0LnG`IXZ^-ZH&R9xuw2SYz_K4T(8L& zJ}k%Z>H&>QcN>76{Lu>!f$yRp%IdwBtA}ew5W*J2^b0&S&VAJupt;b`Cv|OaL%k{c z_s^#%G4$H%mm4i%N0dAR8Z9ec zoxUyc;X%tt?{en_iN4vmH?b6a?`ulU2|7bZG%u;dGJRBRG(`WdW#S$eU%z|6StL3P z;PQBPdA;=wNzdLSR7!-+QJ*MfQ{^s?KmMR9Ch`{FeRAfEp;1uXUX0&+5~uCsV7b)l zo9ocwSqQLG@ra4adEd|}zWmqBE zk7OQ%uJI5|Psx`Ve|{?;?pwQD#g-KE*S~P;1ART z2Jfx8pE88;Mv#RJsAHSot~<;!GDiv7(Ium59+Tyh&Y&!DIjemHxl^(*o(R$qtoYcZ zVZu3%d`*bpBn*3*CrddK$+LRf|N07ZLA1=^$(j;@GZUY}amS8iV)Yu!z{X=q5W55c zm>IKxy|=36&w!y)M}8hu7YH}7adi@xLg{Go+c7OU0jmih1ZD5F6>|QVnZb_LZ~kJr z(Sh=wDN)n|bO=S*3rQzxeVk%14by<_n&>G-7%hgnAE~Z&9@(nQ*}aPOm#clrl22jy z(tGtIfwlA63X{$no?w1@ZJFsg>M1>bJ-kUpkadg7Ck>0{|*Yxec4 z(RE~w^n}e#%7y8Jo2_*_(XuNJON1nSG&){!m|Q%<2O#{Zv<&9|D~O5lxMea8}t!2^<r?G@ zWDKmmc##stjQZ#{LH3pS>zBnLHMaVuRZG9y5?XP|efLX;;@)>enWngB&BB~)=-Hf` z!qu2?zo|I;IMKXDlO;`0qi_`ZtO)pO&w|DzgLj5h=(V2qlt~s$t@8VnST)A+A?WUC z0|mU*>#*?VeIs4aL3L&`sOZsVL83;xA@UW`mnbjPZqw{bRFN=^drcCPDtO{KK}i3W$%{AmeG$SEzZLSu~ZfB z-(=5DMPmGmWoD-i6-s7D(YLuDO)6_jX=ye-e~KMKdj)d`?V zjw{OUXexTu3UK0|lyoA;L*|=o_t{Of+ar6O69d3=5@Ruk;eGbX3Gr`D^+EGv_%a7m zu|?;}NUsb%_EZlE+8j>lES8lDyJk&AJpB#Te4ptYmW~;{1h7K(?732GGDY5#Rxq4u z`_l(d?hbF)21v4u`kS(LR*>Zv+DRx-p@1FrD4%ME&Qw5pL^v zaqbjM)v}7_Sz)KnkL`Np^u1efj+S{raA7eTl!mZj9!T}I^O>#$%!4~Oj~jn!E?K|d zpST%3VNqVTF`DB(GdYRP%F0rRsPAd-(wXtymi3{l5VuqEjyKB8c=y;x8s%m3+~(J^ z-0bH9Wmw?%j{)es+!<%s@krK3Ie7P6MOV4+g-ZThV$!Evhb*W#14L#1J()#Avu*XS zN@Hv_F?DR(n8rbQW=dPEt1FG6D`IuFi2MofR101BgS(U6MR%XFPsoejZTI@EyP>N^ z=^;%7+@EOJFh+^e*v`JCk7WBUW_Tsorjrmy`}*r>o%H1NP+!j%LOB zz0!ctB|d0ylh|^x-F((g)wH!eeZr^Lh}g_eW%(Q)0TCX zQHk$Qy}%h$VpQr}lpyHbXz3Q_Z)*>6U zl)O3OxN)~@vc#p9YOUdQmXcrEEn0@Ae>pz5qB8n#LJ-4*$geo#FM2ps=T2wHx= zfqpQzzd>R5!_&t=bKU{s>!78q44$l% z7e4xtgsq*69iUo3lMqdIRR6=?SkmFB8rtVa#9U+UW!68#DEYZV$*~v1j+bx5@;+la z{8n;KHv7`1I6sLjMze?m)o%?sT|>%ThUhzej9@!r)VBcI}$Hm>D^jfAq5uMCr_<=Jmgc)VG*s1k=M zPKqQmW)t*Q7Gr&b0;ubdSPi56merwQE;k}Xd z7^E^~1#XyaE`eS)79ty0L$K-PLJ{C$w4VnX2%NFnhl~?M-P|~_5@y3ugB=athJlD) zM*e{cg82nY$SS`s7jkQ0km!N1N{#^W^fYo>u7&~!?!kG~68zRHPRTFH@rpxHvoWJW z$$>;gyF|HO5}847f@m)%{~#yP{(|-S2)vY&XI)U45jrsHZWqm)IgsGb=sTp*%U>{L z>3=UGq2C3|s%3?^Zm~wBA((;aXSCU6u!_Fedjvt?uo8jog6|3mj}(-*iknA}h5DE zxdF#R@C~CV80{biUeI0*r?N2;AAj*znZ}wnvTIeY#&mKw4B8UZfLOUO{{9iiId?8+ zEKvvHpas3kS5>74Rj#>Ma=m1!kslUkZczd4Zz^Oko?EoS2~ ztCU0?AA6No5APo*cUzhQR1iWMVk9h-fOiz%e8*n9(|uc1^O zZps&^~7>m%;LYYmW`}_S~~zKt2#{Q&4V0 z6Z$S%ObibX>KV^Wfpi@S%cMia$0SE?>Xbq?3`+M=6C&xU=|Q*6P4FUl?e^w1FVs?6&cHy1kx%ssxywuu6icj~QUU8oU z&u?4p;om+TQhgqCllFBYT=b4DP0!NxADs!IH*Y-zDjUH>(SPaEbl5y$^PDK>_R+o9 zA*$Y2($JAL$<166w+EUbPKIBehC*l+CM4MtL}pSKdbxVJBM!?30zrL2@5u0Ymgz@| zT03#|8;w&F=GmZ0n`f)p4u-AAafzlu@>8u{T5K+J+I10?@Ji#?(v!a)A=ze={_+n8 z8RIvrGQlWHdqx2X|9S7i)kDR_2yh8$$d&%?LQy(&B& z28@&Mq}_$M2Dwe@zs?NjS9t2)cBAVq8)Qp(!lbV1Q$P0=vcD@J{WUNXP31%)H3Sf-` zdgjKu#u-UMu55W#!f|JZ?oAzZj57wp{fdsC;b7N7yODRB>&S- z+4~a}-ZX7!`I3>4$WoAy(EsVD`kpRszAkRJf)GLWCXRlKvMkRV-tGIZSEU!%XScuZ z%Nlyo_6m#^-;le(LMmtbe=b(W?|pw&65uu*b0kV>>F?V_8FtMM@DbncMo4 zrty3>b6lU=qfq-%HUs%v#1aa!p~w_6i}16>3-AZEtMVTKvhRoXakZgPvL2c9N<%wx z@j=~OSpEBceun;XPL1D449-{eAwXKDwv8@fX1|$|yV*Hp*bO02O1`S7Kmje#2O9co zUhe((Uj8J0)-49({Tb4n{Or1XnwYy7D{6;iVY%yvye*iX1clOo;uz#oeDR)JBNAKk1HE^p~*MuI1M%V)2TfU5l-7K)805 z0H=4+E3@?bkxCL+Zz0>jtolaRz!ds6$YVh>ja>R0Zboud;O_CPXfNTK=FOW0f$98ri(tujf>$2zAc8 zKk^nzl@=O zivKT4{7=>2Vj-G;6aRx5|C!_es*JyLkpAld0e`Hif7FQ)gp%s-OY%Rn`%k20{d@Nx D@s=Uh literal 0 HcmV?d00001 diff --git a/extra_fonts/ProggySmall.zip b/extra_fonts/ProggySmall.zip new file mode 100644 index 0000000000000000000000000000000000000000..f7e267184590d49cdafbe8be688c27b310def6d7 GIT binary patch literal 4238 zcmZ{o2QVC5yT=g;qIZ%NHPMCWEeY03qW6}K=-p~7qP|gATOlEOw1_O0C5tEDiAVv8;(tnRx%uBB zBGRWLBBH%M)%O8AIlVFRuyJ=6a|C3(YV2|LQ!d&;d9H{Cp;c^WJ_z)xJ9;jRN`1w-xPCl}PJ(ND%dhZgUyd7`^JWTCN~hv{EoLK z`!~;*HTEwQHj902w%$)`4PhfnQ(E{rr;$1)+n@C=aAdcU;mNHRghE>(BCR!)2dqbnD)`9+@@XXFg%{hy0+^XZqO8{~ zCvW19`-14!*LZf>!SD54pt`$a<5+H`aJGoa#2aiK5>oqjbQh%NI)mzwJ>IQ-$hC}Pp9>(iU7^_Hf+N_us7 z^>C1Y9jUaG7oY;G(`!q!i@p80Z32Jq5KnE&I>6af$9Xv!NvD?=sVoP{VeQkHsue4Z%RFJg>iB`xoaq)rcvx? z%lK!5M!v=%zXux@6`eFXx->d^#>azYKXyt+W+3iwg+g75#Pk*%4fOS8-GtAcV$q-JQ z#sixW6*5nT+-3MzJC@BRrm{+OnSjSeeVVg(n^-af)0(??YX=O~`-ZdA8x`d9Ew}1R zEX1sHb8<3W=|J^Tl9I|HFIE^NHMX6;r@Otgs(z!iBL#6}IVjCQS^D)JPOwY$-Igxs zI`jkCxw`tB?y^dIlpVTB@eCwr9&c9Ndh7O_%ckqWD>8G2$zm^F*y}AABN~pVK9Z=6 zGf1`$u`##v9rptz>#3u7o#Ty5H(5W!bxnAA1S%q6V{;iVf*g_4z{dPzAe`V%F;NiOZ{#7rE4qdijAPYMhLFD#L+ zQwqQbP6Z!sYLC^%fM~6<8=+Tao5$}CC?r0!7y(!0Is4Z#93jOe^dT^#7xjA2tr~EJ zXjr|8`ex}yEoxN*xLw-tP5XX^f&$y8qM2cd6IKySaL_Lw7xgpcZyH)>-<()T4}v~_ z5k;e?8>@%h)S7C}n!jVyOJs6ZJ~}=9F$&O>2x{;!Iaty(-5`Bt>$46y}= z^wGJ79YHbqqo%PKwaAYof)oP;x6z#R#mRVC!NA|r-2WbGN7}*yBWUomAH@ZGFE?DR zsXuzTZQ34H1=UDaAC5C`ZiE$<@)Kw_BZkKhKcBl-StVya?CUR8Vx0ga69v7;2N zu>6kqOA6cayKdD77Pgh$#c~iiSw?z!k4x|T*AsJ=St1xOYVXKVZvZzpy*CuVKpz8z zYC<(XXhuRcHG#&OFSvQUvqR=jbEZJMAI?j!HXu*7t9J*S<}yOSpdZJthxj7Jz1CoK z{83_P`~^cHWa_J_1Zpn}qbmamIW)Hc@8&7%Z_XS2Le7ir1Y)0pT_*CH(5EOv!Ycx< z>e3Z#jU<$}q{g#~>a9)gwMLwArxLH^oVh8fJU|P?b6?FGNIx1`EjuGtTeej`r$_1o zMRSB?M(SzyIQ>8CXH&SaZdltkRYG+(nT||#@ zO8VoR*3%7z;3TRI+i81&K)jRV2ux z%O@{{06M?O!5HP@EA}|hm;w9^N%Or|y5{C_E9MlmZbMOh>n&RXcI3QlZS;VSHMuC? zI;b$7Sk{ZumiVlYI;piqXc<*0=rTS-RxxaEL*b*UjS#!z90-s+P@?m z9J9MGdDTqCBC>R4Czxh;U#U!;Ri==vqA-Cw;T4sJ7t<#!Q~x3lVu5U?Sri&mM{sT{ z^s2o5rc5oeT%drKnF>qyxSc<}ovD9;1l=M1JJRJhMPbxMlD`s6w=6p8qd~L(wmOAL zW4u9dBt>xadpv_R_7MVWHq$QB+c6X7xA3gaJc8(Mhz*00i+<>J=Nj;4 z`@ErT9#XYF1mr(n;4IzIvh7^ZOY_CS^tUz63a&!en>cLS%_G7Mz zsv`x`f-Lcf0!&LP{E~cZXsR}HReWF1clyyyd!)O3-2!u&U$Sd?#c$`*TDY@-G5f6> z8QrV}DSSrH43k4Z8F~EnIYV=d1M6Lq#-&rZNXg>ghZ2mKT1d_sruKM}JpvePov0~P z537aS(5x$s3WGpm!oc{TagQO$n23t&OtosowC7JW(8%bE-4w3grYjpLB4iDhhS{Nh z9ciZU@s6mjv6gN_m>A!v1oKfWqlVlb7*q$C`ZsYzi}VKfLB?O;4zb$#^WyG@@jl1`acA)57#XL>7z9?Bo1XTZzhTMj4}2WgU`s z5+&l|s*r(?D@@G{24FqS@17{vFol@#9v+V7*nr?i(7ZI4nlNCL>N(1GVmO4{uODb4 zQz`UAS?O3jDwR3^@y|f%q5$)CLkdBmgYb=wSGqYOKEN1IW@m{Hiq&Tio0h z&p@<&zxmKAuz#lh92zugp{v~Mll!B=5liQ(VK&A3dSFfFM1K|}e6c=mmY6Nm^omU# zG;QL?9XH+|)H*3VP21k&bGBv>v-QUfLf(8BC&e4w*Jf%AzrDScN}wg1Bg>dZq-`k2 z7vO#6iAM2+)~9_ujg6a5<2)?Sc|Fzd#9G?Ro0?*V#?nH_##CJ3XYft;M{dd46`8qa z7GgDz??HY@6cY2~9Q?BC$H5uG)?k2P)RDrq zniPdRJRLZ#Wm>Tbu9y!@Bq(0~jX}&m5+r+&ST#=)A|i28A|lFb25Gz4Ie6MRi1`Kh zfefv|zr^XnDn@s`mcFJIATnz{Hf6N`iFyZw31TJqX!eNQi8#M{_7?4@V6dK-giYldk?zHUwibYb28I33OA8(- zl+Vl}X~FU+CFd$X;QB-X@Nfz|ACnm0Xyi=fWLT#%*c~9w%FQg#C6AIvo0Gjv;+0@K z;;2S9#7h?W6huW&#}(ilDlr4kywoqJbOgTg7FX9*mEf&v-zrGWO?!W1jT`^xhntTxlM_blWoq^&T;o{UO1429pj0s5x!?tg4ug7WWd72D@u7EsV)B5 zn2={>a7dcYBrR&styS~|!c&mIcMZkVC{yZBV&S~TVAm_$eXNKEBD49LOu1pi`dY*! zOqBnB{eJy7uLsw^*8fw@|2_CWIjjGU`YX8bFTeG_t$@GztiNmgr_A_EgZN(;;HUma Yp6F}cycQ)Qx^X@0uXprc?FOR%0&Dsy{r~^~ literal 0 HcmV?d00001 diff --git a/extra_fonts/README.txt b/extra_fonts/README.txt new file mode 100644 index 00000000..f0b80733 --- /dev/null +++ b/extra_fonts/README.txt @@ -0,0 +1,71 @@ + +Extra fonts for ImGui. +THOSE FONTS ARE OPTIONAL. + +ImGui embeds a copy of 'proggy_clean' that you can use without any external files. +Export your own font with bmfont (www.angelcode.com/products/bmfont). + +bmfont reads fonts (.ttf, .fon, etc.) and output a .fnt file and a texture file, e.g: + + proggy_clean.fon --> [bmfont] ---> proggy_clean_13.fnt + proggy_clean_13.png + +Configure bmfont: + + - Export .fnt as Binary + - Tip: uncheck "Render from TrueType outline" and "Font Smoothing" for best result with non-anti-aliased type fonts. + But you can experiment with other settings if you want anti-aliased fonts. + + +(A) Use font data embedded in ImGui + + // Access embedded font data + const void* fnt_data; // pointer to FNT data + unsigned fnt_size; // size of FNT data + const void* png_data; // pointer to PNG data + unsigned int png_size; // size of PNG data + ImGui::GetDefaultFontData(&fnt_data, &fnt_size, &png_data, &png_size); + + 1. Load the .FNT data from 'fnt_data' (NB: this is done for you by default if you don't do anything) + + ImGuiIO& io = ImGui::GetIO(); + io.Font = new ImBitmapFont(); + io.Font->LoadFromMemory(fnt_data, fnt_size); + + 2. Load the .PNG data from 'png_data' into a texture + + + +(B) Use fonts from external files + + ImGuiIO& io = ImGui::GetIO(); + + 1. Load the .FNT data, e.g. + + // proggy_clean_13 [default] + io.Font->LoadFromFile("proggy_clean_13.fnt"); + io.FontTexUvForWhite = ImVec2(0.0f/256.0f,0.0f/128); + io.FontYOffset = +1; + + // proggy_small_12 + io.Font = new ImBitmapFont(); + io.Font->LoadFromFile("proggy_small_12.fnt"); + io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); + io.FontYOffset = +2; + + // proggy_small_14 + io.Font = new ImBitmapFont(); + io.Font->LoadFromFile("proggy_small_14.fnt"); + io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); + io.FontYOffset = +3; + + // courier_new_16 + io.Font->LoadFromFile("courier_new_16.fnt"); + io.FontTexUvForWhite = ImVec2(1.0f/256.0f,4.0f/128); + + // courier_new_18 + io.Font->LoadFromFile("courier_new_18.fnt"); + io.FontTexUvForWhite = ImVec2(4.0f/256.0f,5.0f/256); + + 2. Load the matching .PNG data into a texture + diff --git a/extra_fonts/courier_new_16.fnt b/extra_fonts/courier_new_16.fnt new file mode 100644 index 0000000000000000000000000000000000000000..bd5c7fba35632c2c4dc049ecd0d6592a7ce8f293 GIT binary patch literal 3906 zcmZA4eN5F=9LMo<0g)O5a&u$V8mSdg*(HjoED4S10iwbptsoJFG9XH!2bq6ZYt@>o z%~fkn?Lm6*AxpHv(lj%ve5%B(pe(Uev{ceG>3x2j-#Yi>_Vf4qzV7#&^F8OD-?>^) zTo@lY)fkgz^35a@;mJfIW=#FG#@gz}jFRdm6PFr%oXiI^ZGz2-AIe`<14$Ki)lC)I zxfRio4RupY!rl~PGWc}A8EfL{w!hz)Bx6#~#8S*Snx~lro~;ezK7_nMSe&!r+$WkG zlZe@&Y~Bd&3&~6H^3K8%UE474Y;3;tcTUj9z_{_jvq{b5ew4g8uay{TuEAb?=M!%w&(1e&djVD}^B9TsxiP|8F2p9gF~WI7vFD|2HdZOMT!f96wmDdt z*u~gd>F*M(Lo637kufgC4w+#w-$x#{McQ75Z5O*7J4kz8f=zWA@;P`wOEmi zTZEO0U56#hJg&!{lm2eNYNYLr*o%@^j5SMM31mPfA`XHdp$)8GAwU zZVB>Y*Ys9wfwV2dmPp%i*b1@RFuOK>eYX>@m%MUplh_?tr`ULGj;!eftjF!Ya8KTe zt;6j367H9~u$?Y1w7aocuD{SKu&G>r&6ULQoOS-bzXwZaUHo%nBDTua%wurYRdHV= z>o*B&jbo#66+Yv&V> zkXl~FjGVErA%n$U$MR%uZ(zw%^8zeI+O}fHsM-JReiO6jw!hAA1$j9!d2eGwrN4Ku z*{&8IgLh^j_tPbB5tbW#{{LCGnArYX!XI}DaXahc*Y|Fa6ML>L#a2t+d)QL3_c0^y z{<6RZ`m>Ko{F|nYdm8KF@4w~P$!<*txx5wJcQA(CFX7(!0P7O_5L+&_e1r{`b!o?{ zxcoI(No>zb-##X`XTEQr5YJ`||95p2wp;ebYOGuAQ*5T#8mwGwEtVnn8I~@#4m*v@ zukUl>ESc|mEL-dgEKh6$Hd?F$D-`<@%W`WFo|9i;QL(SFT(OPVD6vggv5c`98^Yz! zZ42>FT>gI9N^HmR?HgjdHokpJY`;(6?3rfY5#P2Ew^E<~E_7n{UH9|06VDO*p7;r| z9mFkSKM-fizW)(R60>tHlXdCBCWv)oM%w<29FhI<3wA(kC)O(VE7lH3i5iseat|6uuI$FL%?<5;QK XzgW5039Ql?k3lW{-0k=7zYG5XSjZd2 literal 0 HcmV?d00001 diff --git a/extra_fonts/courier_new_16.png b/extra_fonts/courier_new_16.png new file mode 100644 index 0000000000000000000000000000000000000000..3e9f99e8e647fd97d7625c73f5d9b0b050bce951 GIT binary patch literal 1393 zcmV-%1&;cOP)OKp0x zuFce|O(P_35qPExx zwTK{%=#4FcqrMui#$7k;3?F`T2F{{3JcDW`hYfO(HYNgV zQD4Tg<0ed?gwJWi@n_89f9E`)Y|UnpF(CBS$;qv{fyxmu(g^fc)d9xv82gqJ zl`=P(Ou|RIPixvw8ZhR17k$_F{bW*S6qt-L2nazd_OqoO#)T>90RwP>?a_7pitgJ& z&!(;YdI1GtG0`Viv=sk zL~1vqBA26}+b|4~(;Zx}Bw+Y~08i##P;?C)q4aR4@Pv0v)Kb9Ap60;Yp>U1{U0y$KwEW?BgnX%q->) z!ti?;)6>kA$`8k`jb-NUKypD)e+dv1fIz^shc%Hd@U9qS5F4rqOP{bTapeN>`}#-Z z%@LV*Ntb74+TMBZei9}eeZq0XUa@3={UkTn$z1&Oa-4mXbn=_HjT}3a%ZZBAx}^zm zZbjDIU`M%SpLK0Gtbry3^b{MB6KXteMiiL>#dalNlr@afHQ7P*f&QgK#^aqM4NHMD z%qhqk4cV;Ww-MHtFVBu$-8gvtz|Ffejk&pZlN3;b3NRB@7#@-FP{qKLhN&DYQrRw! z+QI-gsaDxVR2;UEl*&N;;BN~LKUhtHIh7hynEnNq#*VcEq7U1`42Z@BU6rr~5@I%p zTx?1yPz22THo*1n$yD?3D>!uT=GoG*cI)2F6BIl<|NpBn$2+;kjm-6PiR~JWL>ii@ z9f~xFvBngaH|#gPuz%^pb#){OYZK#ED0C7MDk+51u1rF4I*>83%+%1~3 z8~Nr0FCgS0^!52xbV?t)&@obIa#1aV3byfimxBL@o)N5U zq*fr;3_h(D$h8903e;Lb z4k(+3B}v>!>^SX42YtB$D|UVM<4woLIP-lOg{8Xsyp6`vrHw1GOtCRon$&j{mMw7^ zSe~?THTIktJ75knvGb+AvDjjn2o|o#c&v!|3)lQwtVHZOtWqosds^Df z#`0wx*JJiCp1JRTnuHu)rpX*kz^bK<8?Z%UH)1bJ*<5V7*iG13l#L7aP#(5a>YIqQ zO4*ySI*GdlYY>}+HHl5e;xXH<{j+;~3eR<<&~7E)DrNJreXcKluN7b&5_cQcDRw(H zPS)cN?0}5zPApNr^SiJjQn*G_$&Z$COv8-W-N<;cLaapkau0UU?Y~&w?Y!K}GsVUE zZ}2{Bi;MGfFdaK8ox~7^f^519zv$dyv)T;kiu`Zq%S|P?88_)DcozNRW*fH4~PhiHBbKfNzzbBtWcDp!l)z~vq-*Rl1i}QEw3T(f$QHxE-!aH;& zwm|G z95K81P8Vw?znc{9gU`tqFy8QN+KjD}dESC;6#D|(Dz+8dDfT6{M{FC`F7_36NX(uO zonqTDgN1$Gft)9M{A;XM_RvnOMC==^P;3{LC-yCtCH5VbBkS9WWk{Tz_hhl}F?)-K zR4Qmnm8EX}5$J)ex!8*kDW1V8Z zV)pC^_w#S$<76!lU_+VH@LoNL&5&_)V6(*zVP#^6vH4<0u&2a+#}>@TcQ>^Qbw>~Czd*a>XASQnNoefbAV6Z;p-5bMUW#CotivH!4q R*?%XoLW%3e>|BRu&i{iEEwlgt literal 0 HcmV?d00001 diff --git a/extra_fonts/courier_new_18.png b/extra_fonts/courier_new_18.png new file mode 100644 index 0000000000000000000000000000000000000000..d23c96cd8d48dc52f4e4ad25e49c76df7a75d79f GIT binary patch literal 2655 zcmc&#dpHw*7yr)onrllpUBvozk>nOXiEIev6+@EisD6ZUiEgwTy8K=uCHGrOM$O1= z&25CpWaOvCgvuH*lgpN^ZLj`+|9{UP=bYy}=Q+=LKIb`~&wt!pkE^R}R{;R1JDsri z006RLZcS6C2{TbHx}5k6aMBpDq^%g))wixKLE( zB@M8z{xCzKPx%&$oU5bl71|&^MJb3_=1JfPch6HGkps2rauqrrM7gc>;LNR{oWO&i|u{w&mHLPxJ!lw^h$t<9Oei1EJJMph)5llonU3%`$S1Y#RqFcq;|+0*=!H7j)^ z@FJ=VAQENR<7nh5dM0F&B&4irw@oj78=LFp`#solV7dK+05T;pVhv&6{nWMzWj>w# zuCfpJMyL0v5j(Bori8HN*7RMid;7(2SHc!%Ri)pXPq6A9wyr%~G?W~ggu)J=>2GSU zGKf8uecSRoY6I*QRz}-7VKg$AO4Ygqm*=g>Q1f|iXWXwXt&CYQ9`I$&$#YdVXIc61 zuA0SjSw0l?{fsA;-k8WBDw*LXu8IlKpFLvYZO(i0YTXMV)!QJx<&i1Rzq_Umvx;n} zBO7H@Qg|d#efa8@^N`8-irQA#Zay8G{3vAjior4~I=sBDr_5z2^TGytL`Bh95$dYf z<(*lo_<^hvB$qWJ3~JH9zkL)Sfj{HtLy#VoCH+!&D9{@E)5jGk1@{5Fe2l*7-Zj!_ z5`7$NC){H33yy!_Wc_L#PYC{ar_T48sn|EmWdSd<>T+<_@vmJd!MqK`xTpOc*!g@FbdZpZ0hTL6m-@`s^{Qw?>v7U=%Q5m!pv@7 z=9Kb%Y6(ZP>CE~RXGM=_7lWa{W>zn0uqu7p-n)F3JZl|-+Az$#Ko0%r;;rCjX=)bX z&Lf=(NAf$&_u`f0QOqDwvA$U#7*}qUw7)@^j>HVmTf2F zB*_>E4ly|}rP*qHY+Yx{Li5ndeL&iqDb~eEY*8pFbPZ~7;?(I6BLYU9)l$Y^WQTuQ z3DPh>@0`OCPIXh-C;n+cM~uq)Fb>IIf|w4xflZV-E%>wA}gTY*P& zYVGR~Aiz4VeW+(CkB|Q(6-NKMD!;_hrlw6VVJG5Mhje4Ar(iNiYj?CiLsozZ}7i9rJmZCZ00$mPeA; z$Vi81n8BTe$Nk3kx21dRN7E_r#k4pjgil<3Gxv!eZO9S zsmq&+1o?f{)Yq|JTC=7Sn=3yC$`8;MMO<`X9&U$4*|lfqi<_r3U69NK3!_X|=yVt< z>{LlT-mJa_>g?W& zn}JxfkdRE&->|FGwU}tai*MYsmqsvuK-1)vsDZf2Qc{7A2trrc4$a%vvRJeay#Otp(HS%Ht=hV5T3>4wdX}1 zbmL?`7N?HE>u(X(J!jDSFto%*-YgP>}C1a zIb?J=c!eDW(F;zTDrLaQKnr0cg0NZ6yil;d6GoESO0s(Ul+3$0%t8psm|Jv?FUx5* w2k9Eyf8W)HN`IOFfD$16Z}+?B|7Hbz^g?Lzs+TEB_In2>2UmNlT~OkG0nR)6X#fBK literal 0 HcmV?d00001 diff --git a/extra_fonts/proggy_clean_13.fnt b/extra_fonts/proggy_clean_13.fnt new file mode 100644 index 0000000000000000000000000000000000000000..126ff7f01d681e29958d2844fbc73e2c70e0919b GIT binary patch literal 4647 zcmZA43s6*59LMp)Log#K3Zo*X!mPF;$U-Y$VG&lM6q1oqtNbK{=ysR8DfQoTS9k z;zASJZ~?#ZNi>lroObOe+?Xg^FU9mRT`+rZEtu=e5*OnAEzX2FaiLg@3A8R)f>;=q zEJhyFLEaGBv-xb^u3R&vFXv!Gq%MOtm15^&<4l?fb;cHfO%$^uf5m5=V=_^ZSiYE@ z-V~XG^RX;n|G4$`*-mS&STxo`dv%XMqhi}dixT~ zwO(>uf^GJhf1d5mnj-C8hD{TT!|W%9ahy8and5TG%f;d;-yn7c{Va?{BwFWwnXB3V#hIepI(E7N#1L*m6G>5tVYa(&6K>?W3$BU z_zzMy*je)%vAGhLh=uz4;$M%Ou!RzrgjI2rTtchk`Lh4+#b#snx#r*Z z_hGeC_kL`=h+&de}ug0%MlW+d-}NTk?9-l)L$LMB!qeHo5< zr0xi;SmGYWCW$?QrAggKu?mUH!ZIZ;8=EWh{1{d)<9!_4BXJ|KsS=liZIryZ*cs~D z=Yjv6=V8;O?kMavvC-IDVq>t`V)@uSu>x$7SRuAl>cZ3ASFW6x$^B6t-2Y4BH_#0oyG$5v%Zx!@nL+V|yiT61Gol zGPX{}F$Fs;apl-Cv1hP0v1c*+L~x(k&v`BI-S|8fCUF&5cj?Pi%$^7LJ^i9LF3@IR z_O!ZjZz3D{x;B%tT_@M(QJy9?pYk5D1(dtV^L`-~A>&wtMT;%QX35yz!$yiN!MaM0 z_pw-MuM%6vn!A5vF2zPjdmmskWRHJ{#Y=n3u+!9a&%#GoDqnZ5swnrD9MxD)vE^8a z?N@p>@a4}UnnZ!21^zD7E2e~f@O%+V~b^twqnc0wqccG z-(el}&t2aJY@5vU_t+L0$98PH*bZ#B*iOtN>-z(CK;m{`tzti76*AsN?1aSa#%vaM z5B-FMi~Wp6igiA#0_*-l+%B1eCahBWvKMQTxMr+I;(o_041>@1cg_CK=fRpbBw literal 0 HcmV?d00001 diff --git a/extra_fonts/proggy_clean_13.png b/extra_fonts/proggy_clean_13.png new file mode 100644 index 0000000000000000000000000000000000000000..19922df338881788d0fcbbb9e7054c2c7ac8c81e GIT binary patch literal 1557 zcmV+w2I~2VP)HRVAz)n~>&KhWI z4id_yC|VqeirK|3U_BZ`06a2ip1k%f);hiqCSX050M>#B$G_mw@tgasX9B+uCIA+| zDG~;Q!2keQEEYHXh@jsDSAE`qyZm?Y!{tc$xY%<7c(25*5uqGM|1eW&$ZmlfH)k=G~m>ojgtB?eipEB z#auE=SiMVhWlp_>;JR>%0Ko9u9bi9dP`V3(0E(q%(d+-Vw^0TQc-9l&ASLoUzn06hF~qDjDlrM}w%CRq*LsL8`a z(GyU+d!!lNQp&;Px!weZa!z=$K&=|;E!PdD#|&u1Im*qC!IP$y6d}v zHV)1O>?v-8${rEHe*XPir^u(P!)vT1yrps+EMcEsz>YUpu>x{}TAp|gyjD_{36RSL z5podVJc0oGS*vM;Ajdf+d*k&0M|sgV28~ls|0|lLLk-T-e%huoQ3=;FVy*R@j;fmN z)6v+WK#2up4e%k}$)$-TKN|w9dZ~9>=1Xy|S1n!-VdE!=l7J|mRk=2LG!D>(b#KMjw(BhI_5g@nL&B3M5uIum=Toxz`Va4*gb4 z{lLWkDF&1ldWzu>GoZ}3Q0=&jcQt8|$2B*U>j^m^X5$O0*T4$NLh0`(CkgQ44gy?L z+C~Dr=u4uMtC6VU#}d#~SrMF$tPS2Gz+F{$Pv}{I&(glyEU)Pn2VhHpy;X_x!QM^#@a4~g`vCu)cj1fW!@d=(0SnvhZwqatx!rz8M1Dc9!DDcb-1Q<%#@I3*#?Fr!A835EOYqLcS>mmW4r+{wtkY#j9-KNpDR9V1RxzvNP^YGQE{R#YxUs7}VjH50KLA){|3Z|4Rq+%a504ZOQs=fz6%ZwiRu+|sJ7oegL zrg=;yW!|Bm0(I$MSYzP3&qiWIt*it%QK05Dggwv`0F}v}fJ|L2lP3MF6Owc9*kIxp zMi%6%VEh*6AqyR}1W-g-8~qam_^?(wYLlwLSyVHsjDNEOj(vyD#{h#Wd32T= zdAcA?0*Fmib9C=MXC6hG{My9PoIB+j0kkp?EO0$Q3%m(^Ck-MAc#Ebe`O3j*ff&Yl(j0Ncysxoc5jVR6t_S*PnO!hiAWi&tC;N=N>O z3U$GW!Gz-`PW4@RYxkzUatHAZ6i*~ea^AxNsF!3JL@%oikpfN-^z7rP1Y~*=v2u(C$6Ma%|M=8IV;4|;{z-d` z*ueroN@FGW1V|Z#ZMOqh-YYpLt?S+)z+l1Ka(bzQ3k0Y>Pk?wclxqYe$cz`42!LV> zHxO{-=g%QP>{Eay1=jgLHJz@Z%Kf&g63D?a{_KCE>4#{e5+tHx+NftI(txa z0k;wW#FfyNEdlPDOc`#8Ka=GG0k=b{1_SenA%MlhcfeB#kOGE)=fR*KOu(do)!UN^ zm=ySv7y<@^!C){L3T00000NkvXX Hu0mjfG#kbD literal 0 HcmV?d00001 diff --git a/extra_fonts/proggy_small_12.fnt b/extra_fonts/proggy_small_12.fnt new file mode 100644 index 0000000000000000000000000000000000000000..f645aabc9eaa67305fd0686cfdf9d9a5687ef17d GIT binary patch literal 4647 zcmZA33s6->9LMqHsS$-46qYfTR77e>rdAY4MwE{zu?#KHNTd)6EU}axV^h=6L_^~= zF*Q(U3-JfAQc4h$JH!k7@-F4cr`9yI)|HDAu6`E%p^xQ-X|=Q>p^fa`3rK(33# z$YV;yn2gyZb_&<^Vs@mhVyAN5BNoiHEs{Hr(>yV*osLCIoGov>*eGnhi7)|9t!!Ce zFtNrDv$eGK8_lsy>`d&Wi88)UTqtIU^LP3SL#ic*UDg`0v#|v7>*k~abB}KYn0?Y7xNbzi`ntGwK|XMRQh)<0?QT~hZTvPk9Cs6j?eBVJH87z z*2(zBW6hrVdTSbqwTfMc<;mW?2y4Lt$zeY>$Hg2wBySY9S@K?jRf*aApk4A_igk)j z!1mJCuCKSw6R|Fdn}i+ljKv#w8P+XvF<6JpV=}f)#utlqN!;aFkJuFKnAjEAaj~h` zfY>z5Fg~}Y(~&^2E3sg)tFQx}`Fhv~kqb zECHJ;HUom?@DHb7?g^d?mhDC|l_x64n^SxLeX5UfXd+h|_R$=qS3b8b? z)mXaNLs+KR!`KeSVt+Gu_r@A*h?R5Sjcc(j5@&x$ zY{Uksvzx>Imb7<`JKxul7p1={Y^3CU1Iw0mdlQS3xXoC!w?f8CTd`!Z8m!CH)}QkcJVxH-m@D(B#h#M3?_v8e_xH>D*iq@P4r`aV z53o?_??bFW@@~W0h_rjx`z)!)ilkNzSfuo~9V?XnKEftQ+{ajq*bZ!pSR*!F>=SIQ z;!-AbK@Y_8V*W^hE&0U+i>t5Kq zYYk0?kPKf`*=*W%(iFj1R@jTVHlCK&SJi=ZRNb>SBw5T@Qyl9_)asBqeKF~~!7M4o zC{p?d`eFmYXu+^TZ3lxy*Lpseq+WvC@?v8f``&TK^W2B$_uP*=`1fNi2TcD2_&-En z4j9V;^Irx=_&Z}w#xjqEl2FT!Xdrm+~17I`rZvtbt(Rw;@koLa=J{~>=4d@W*GZpqa zI&>yGgvUnU><^jmD>E0;Km8Jw>M#L=Nw?Zd8o)FN&&M!pyQG9v1k~urfdPP_CbW(Wf|kkxNa-Q` z5-3xY&A4_UV_n*6^_+dI_|S(TnlP`RP2gk zRg|ZSnr8K~!dlwt*kNil2Of++mF0d}J};}ORWB>2XWyvspNAV*1@DhLWSN|C4UiIE znvHOcIp7-y0!mhJ=7HXx2VdoZtby${Rfj6sNP}|%v=n!T!U6^>cqryokSf+X_>bfT X42d-$NI#9e00000NkvXXu0mjfsrtHe literal 0 HcmV?d00001 diff --git a/extra_fonts/proggy_small_14.fnt b/extra_fonts/proggy_small_14.fnt new file mode 100644 index 0000000000000000000000000000000000000000..546f8fb97575069b2d2481a39cdf84387243ac13 GIT binary patch literal 4647 zcmZA34Nz4@7{>8MJ~SdRgTgY#l8Q(TiPVY`$%yhJN-RSQG!iL90!u6#G4G`!{J2gL^XEECEP(4m zG4hxaF(zX+i=D=GotPbIi`eO0cZ&saZHwg2;|x!XYa_8JiL>RME;b6=V8V^RQ!886 z7fg)t#cVBY{YG;v6*~(%Wg^WmCoTjt#Q8b>g(6jw!!B#J*g06aCkLlPdBZpkvX(yd zXV=hAIwkH3tXnJ=J1%x5c0z0l z)-N^{GmOuz=`?$ls>}u?wXTIJwzXogd)XKZQaag#ty%y`i?EU7AyAF$zIQv|R z7K_KGh|R#_#1gOsvFovHv6_#kIED2jGb`!Qu*7s(tmpHcuv#XJ?_2F z7i0d?b_o_Jb`KUTmVt$c-HVM8TZ)B?Wn$ySmSK@%_Pu>T#(W=^i`jRS_a3|-n<x!6>(2e3G?JZy$oK9(r95(|ver zY&Di9_Ar(q_6W96Z+xM{jnEU(Xee9U@SBtet z+y_{Q^!Fi_FL}3Ptwh?r>wT8gVTDqwdMrZv+kq8Ge;;8JB<^D@T5Km4E7pKb6Z-^P zD>-&ykBfbZJt_7XRxJHBVzb3|W65HlV<}>LumxgYV2i|>uynC6u?(?hY?;_zEL&_J zRwQ$4!B$G#eyl+3D{PHeE4EJTYizw(8@AiCH#i;IyWenZ5IcZ9C*%7T+aT7CJuf*r zuu_RTh@IrmeQq4$x=i8@V-;dYuu8E`tV--CRxNf6s}=hWs~7toYY^+g>ZC5+Sfj-K zfHjHzh_#6QgtdwFU}L3zKVy3^_Ze{<+laZ(uwSr9Y5OZyBXPZ0hvfYY>lFJP>k>PG z^@#m}^@{ajePVxNrSe&PBAFC7_z-q<*!Rp2AK5G#B7b}ulox&O=ZV)Sx G=j4A6c5hw) literal 0 HcmV?d00001 diff --git a/extra_fonts/proggy_small_14.png b/extra_fonts/proggy_small_14.png new file mode 100644 index 0000000000000000000000000000000000000000..7954a6ec6c5106803d1528293685115d25fd4331 GIT binary patch literal 949 zcmV;m14{gfP)8V*W^hE&0U+i>t5Kq zYYk0?kPKf`*=*W%(iFj1R@jTVHlCK&SJi=ZRNb>SBw5T@Qyl9_)asBqeKF~~!7M4o zC{p?d`eFmYXu+^TZ3lxy*Lpseq+WvC@?v8f``&TK^W2B$_uP*=`1fNi2TcD2_&-En z4j9V;^Irx=_&Z}w#xjqEl2FT!Xdrm+~17I`rZvtbt(Rw;@koLa=J{~>=4d@W*GZpqa zI&>yGgvUnU><^jmD>E0;Km8Jw>M#L=Nw?Zd8o)FN&&M!pyQG9v1k~urfdPP_CbW(Wf|kkxNa-Q` z5-3xY&A4_UV_n*6^_+dI_|S(TnlP`RP2gk zRg|ZSnr8K~!dlwt*kNil2Of++mF0d}J};}ORWB>2XWyvspNAV*1@DhLWSN|C4UiIE znvHOcIp7-y0!mhJ=7HXx2VdoZtby${Rfj6sNP}|%v=n!T!U6^>cqryokSf+X_>bfT X42d-$NI#9e00000NkvXXu0mjfsrtHe literal 0 HcmV?d00001 From e20077fbd0370697092c57184f5d5306fcf5a170 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sat, 30 Aug 2014 20:06:53 +0100 Subject: [PATCH 43/44] Using spaces instead of tab for web readability --- extra_fonts/README.txt | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/extra_fonts/README.txt b/extra_fonts/README.txt index f0b80733..6acb278d 100644 --- a/extra_fonts/README.txt +++ b/extra_fonts/README.txt @@ -43,29 +43,29 @@ Configure bmfont: 1. Load the .FNT data, e.g. // proggy_clean_13 [default] - io.Font->LoadFromFile("proggy_clean_13.fnt"); - io.FontTexUvForWhite = ImVec2(0.0f/256.0f,0.0f/128); - io.FontYOffset = +1; + io.Font->LoadFromFile("proggy_clean_13.fnt"); + io.FontTexUvForWhite = ImVec2(0.0f/256.0f,0.0f/128); + io.FontYOffset = +1; // proggy_small_12 - io.Font = new ImBitmapFont(); - io.Font->LoadFromFile("proggy_small_12.fnt"); - io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); - io.FontYOffset = +2; + io.Font = new ImBitmapFont(); + io.Font->LoadFromFile("proggy_small_12.fnt"); + io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); + io.FontYOffset = +2; // proggy_small_14 - io.Font = new ImBitmapFont(); - io.Font->LoadFromFile("proggy_small_14.fnt"); - io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); - io.FontYOffset = +3; - - // courier_new_16 - io.Font->LoadFromFile("courier_new_16.fnt"); - io.FontTexUvForWhite = ImVec2(1.0f/256.0f,4.0f/128); - - // courier_new_18 - io.Font->LoadFromFile("courier_new_18.fnt"); - io.FontTexUvForWhite = ImVec2(4.0f/256.0f,5.0f/256); + io.Font = new ImBitmapFont(); + io.Font->LoadFromFile("proggy_small_14.fnt"); + io.FontTexUvForWhite = ImVec2(84.0f/256.0f,20.0f/64); + io.FontYOffset = +3; + + // courier_new_16 + io.Font->LoadFromFile("courier_new_16.fnt"); + io.FontTexUvForWhite = ImVec2(1.0f/256.0f,4.0f/128); + + // courier_new_18 + io.Font->LoadFromFile("courier_new_18.fnt"); + io.FontTexUvForWhite = ImVec2(4.0f/256.0f,5.0f/256); 2. Load the matching .PNG data into a texture From 43448d9c89eed20f2956e9819b58fa6ac50f2ca8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 31 Aug 2014 08:23:55 +0100 Subject: [PATCH 44/44] Added FAQ/comments --- imgui.cpp | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 632e278a..cc9528a7 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -56,10 +56,11 @@ 3/ ImGui::Render() to render all the accumulated command-lists. it will call your RenderDrawListFn handler that you set in the IO structure. - all rendering information are stored into command-lists until ImGui::Render() is called. - effectively it means you can create widgets at any time in your code, regardless of "update" vs "render" considerations. + - refer to the examples applications in the examples/ folder for instruction on how to setup your code. - a typical application skeleton may be: // Application init - // TODO: Fill all 'Settings' fields of the io structure + // TODO: Fill all settings fields of the io structure ImGuiIO& io = ImGui::GetIO(); io.DisplaySize.x = 1920.0f; io.DisplaySize.y = 1280.0f; @@ -87,14 +88,33 @@ // swap video buffer, etc. } + TROUBLESHOOTING & FREQUENTLY ASKED QUESTIONS + - if text or lines are blurry when integrating ImGui in your engine: - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f) - try adjusting ImGui::GetIO().PixelCenterOffset to 0.5f or 0.375f - - some widgets carry state and requires an unique ID to do so. - - unique ID are typically derived from a string label, an indice or a pointer. - - use PushID/PopID to easily create scopes and avoid ID conflicts. A Window is also an implicit scope. - - when creating trees, ID are particularly important because you want to preserve the opened/closed state of tree nodes. + - if you can only see text but no solid shapes or lines: + - make sure io.FontTexUvForWhite is set to the texture coordinates of a pure white pixel in your texture. + (this is done for you if you are using the default font) + (ImGui is using this texture coordinate to draw solid objects so text and solid draw calls can be merged into one.) + + - if you want to use a different font than the default: + - create bitmap font data using BMFont, make sure that BMFont is exporting the .fnt file in Binary mode. + io.Font = new ImBitmapFont(); + io.Font->LoadFromFile("path_to_your_fnt_file.fnt"); + - load your texture yourself. texture *MUST* have white pixel at UV coordinate io.FontTexUvForWhite. This is used to draw all solid shapes. + - the extra_fonts/ folder provides examples of using external fonts. + + - if you are confused about the meaning or use of ID in ImGui: + - some widgets requires state to be carried over multiple frames (most typically ImGui often wants remember what is the "active" widget). + to do so they need an unique ID. unique ID are typically derived from a string label, an indice or a pointer. + when you call Button("OK") the button shows "OK" and also use "OK" as an ID. + - ID are uniquely scoped within Windows so no conflict can happen if you have two buttons called "OK" in two different Windows. + within a same Window, use PushID() / PopID() to easily create scopes and avoid ID conflicts. + so if you have a loop creating "multiple" items, you can use PushID() / PopID() with the index of each item, or their pointer, etc. + some functions like TreeNode() implicitly creates a scope for you by calling PushID() + - when dealing with trees, ID are important because you want to preserve the opened/closed state of tree nodes. depending on your use cases you may want to use strings, indices or pointers as ID. experiment and see what makes more sense! e.g. When displaying a single object, using a static string as ID will preserve your node open/closed state when the targetted object change e.g. When displaying a list of objects, using indices or pointers as ID will preserve the node open/closed state per object @@ -102,14 +122,12 @@ e.g. "Label" display "Label" and uses "Label" as ID e.g. "Label##Foobar" display "Label" and uses "Label##Foobar" as ID e.g. "##Foobar" display an empty label and uses "##Foobar" as ID - - - if you want to use a different font than the default - - create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(). - - load your texture yourself. texture *MUST* have white pixel at UV coordinate ImGui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes. + - read articles about the imgui principles (see web links) to understand the requirement and use of ID. - tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code. - tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function. - - tip: you can create widgets without a Begin/End block, they will go in an implicit window called "Debug" + - tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug" + - tip: read the ShowTestWindow() code for more example of how to use ImGui! ISSUES AND TODO-LIST