From 4786321754cf2c69dc6a0a1e803d18a726ce05ef Mon Sep 17 00:00:00 2001 From: Gerry Hernandez Date: Sun, 4 Feb 2018 21:47:08 -0500 Subject: [PATCH 1/5] Fix iOS code; fixes entire XCode build for Apple example --- .gitignore | 1 + examples/apple_example/imguiex-ios/debug_hud.cpp | 9 +++++++-- examples/apple_example/imguiex-ios/debug_hud.h | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5761abcfd --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/examples/apple_example/imguiex-ios/debug_hud.cpp b/examples/apple_example/imguiex-ios/debug_hud.cpp index 002d6bac4..28722b56d 100644 --- a/examples/apple_example/imguiex-ios/debug_hud.cpp +++ b/examples/apple_example/imguiex-ios/debug_hud.cpp @@ -22,6 +22,11 @@ void DebugHUD_InitDefaults( DebugHUD *hud ) hud->cubeColor2[1] = 0.4f; hud->cubeColor2[2] = 0.4f; hud->cubeColor2[3] = 1.0f; + + hud->clearColor[0] = 0.45f; + hud->clearColor[1] = 0.55f; + hud->clearColor[2] = 0.60f; + hud->clearColor[3] = 1.00f; } void DebugHUD_DoInterface(DebugHUD *hud) @@ -33,7 +38,7 @@ void DebugHUD_DoInterface(DebugHUD *hud) static int counter = 0; ImGui::Text("Hello, world!"); // Display some text (you can use a format string too) ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f - ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color + ImGui::ColorEdit3("clear color", hud->clearColor); // Edit 3 floats representing a color ImGui::Checkbox("Demo Window", &hud->show_demo_window); // Edit bools storing our windows open/close state ImGui::Checkbox("Another Window", &hud->show_another_window); @@ -49,7 +54,7 @@ void DebugHUD_DoInterface(DebugHUD *hud) // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows. if (hud->show_another_window) { - ImGui::Begin("Another Window", &hud-?show_another_window); + ImGui::Begin("Another Window", &hud->show_another_window); ImGui::Text("Hello from another window!"); ImGui::ColorEdit3("Cube 1 Color", hud->cubeColor1); ImGui::ColorEdit3("Cube 2 Color", hud->cubeColor2); diff --git a/examples/apple_example/imguiex-ios/debug_hud.h b/examples/apple_example/imguiex-ios/debug_hud.h index 89b79a411..4ef535729 100644 --- a/examples/apple_example/imguiex-ios/debug_hud.h +++ b/examples/apple_example/imguiex-ios/debug_hud.h @@ -11,6 +11,7 @@ typedef struct DebugHUD float rotation_speed; float cubeColor1[4]; float cubeColor2[4]; + float clearColor[4]; } DebugHUD; #if __cplusplus From a33b86dac7bd44826ca02616c9573dd330d2764f Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 5 Feb 2018 09:14:33 +0100 Subject: [PATCH 2/5] Removed root .gitignore. (#1594) --- .gitignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5761abcfd..000000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.o From cf6b39600bfbceb0c404cb8607b49f30a8fdc4e6 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 5 Feb 2018 11:21:06 +0100 Subject: [PATCH 3/5] imgui_freetype: comments about correct blending and sRGB (#618, #578) --- misc/freetype/README.md | 6 ++++++ misc/freetype/imgui_freetype.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/misc/freetype/README.md b/misc/freetype/README.md index 8b5d01d43..ad0e4d3b3 100644 --- a/misc/freetype/README.md +++ b/misc/freetype/README.md @@ -17,6 +17,12 @@ ImGuiFreeType::BuildFontAtlas(io.Fonts, flags); io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); ``` +**Gamma Correct Blending** +FreeType assumes blending in linear space rather than gamma space. +See FreeType note for [FT_Render_Glyph](https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph). +For correct results you need to be using sRGB and convert to linear space in the pixel shader output. +The default imgui styles will be impacted by this change (alpha values will need tweaking). + **Test code Usage** ```cpp #include "misc/freetype/imgui_freetype.h" diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 9a04ed89e..9e373c7dd 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -10,6 +10,12 @@ // - v0.54: (2018/01/22) fix for addition of ImFontAtlas::TexUvscale member // - v0.55: (2018/02/04) moved to main imgui repository (away from http://www.github.com/ocornut/imgui_club) +// Gamma Correct Blending: +// FreeType assumes blending in linear space rather than gamma space. +// See https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph +// For correct results you need to be using sRGB and convert to linear space in the pixel shader output. +// The default imgui styles will be impacted by this change (alpha values will need tweaking). + // TODO: // - Output texture has excessive resolution (lots of vertical waste) // - FreeType's memory allocator is not overridden. From bed55a41e1e5ef2242d2f1a3a1d93254ffd1953b Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 5 Feb 2018 14:51:28 +0100 Subject: [PATCH 4/5] Internals: ImRect: Added IsInverted() helper. --- imgui_internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui_internal.h b/imgui_internal.h index 37a31bff5..f904cbcf7 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -285,6 +285,7 @@ struct IMGUI_API ImRect void ClipWithFull(const ImRect& r) { Min = ImClamp(Min, r.Min, r.Max); Max = ImClamp(Max, r.Min, r.Max); } // Full version, ensure both points are fully clipped. void Floor() { Min.x = (float)(int)Min.x; Min.y = (float)(int)Min.y; Max.x = (float)(int)Max.x; Max.y = (float)(int)Max.y; } void FixInverted() { if (Min.x > Max.x) ImSwap(Min.x, Max.x); if (Min.y > Max.y) ImSwap(Min.y, Max.y); } + bool IsInverted() const { return Min.x > Max.x || Min.y > Max.y; } bool IsFinite() const { return Min.x != FLT_MAX; } }; From 3f297e74e4f25c6307a49a1c50348708c7a332f4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 5 Feb 2018 14:52:28 +0100 Subject: [PATCH 5/5] Merging the minor/shallow changes from Navigation branch. --- imgui.cpp | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9dd9eb778..536580698 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -23,7 +23,7 @@ - ISSUES & TODO LIST - FREQUENTLY ASKED QUESTIONS (FAQ), TIPS - How can I help? - - How can I dipslay an image? What is ImTextureID, how does it works? + - How can I display an image? What is ImTextureID, how does it works? - How can I have multiple widgets with the same label? Can I have widget without a label? (Yes). A primer on labels and the ID stack. - How can I tell when Dear ImGui wants my mouse/keyboard inputs VS when I can pass them to my application? - How can I load a different font than the default? @@ -2135,9 +2135,8 @@ bool ImGui::FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop if (window->FocusIdxAllCounter == window->FocusIdxAllRequestCurrent) return true; - if (allow_keyboard_focus) - if (window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent) - return true; + if (allow_keyboard_focus && window->FocusIdxTabCounter == window->FocusIdxTabRequestCurrent) + return true; return false; } @@ -3831,10 +3830,8 @@ static ImGuiWindow* GetFrontMostModalRootWindow() static void ClosePopupToLevel(int remaining) { ImGuiContext& g = *GImGui; - if (remaining > 0) - ImGui::FocusWindow(g.OpenPopupStack[remaining-1].Window); - else - ImGui::FocusWindow(g.OpenPopupStack[0].ParentWindow); + ImGuiWindow* focus_window = (remaining > 0) ? g.OpenPopupStack[remaining-1].Window : g.OpenPopupStack[0].ParentWindow; + ImGui::FocusWindow(focus_window); g.OpenPopupStack.resize(remaining); } @@ -4029,12 +4026,14 @@ bool ImGui::BeginChild(const char* str_id, const ImVec2& size_arg, bool border, bool ImGui::BeginChild(ImGuiID id, const ImVec2& size_arg, bool border, ImGuiWindowFlags extra_flags) { + IM_ASSERT(id != 0); return BeginChildEx(NULL, id, size_arg, border, extra_flags); } void ImGui::EndChild() { - ImGuiWindow* window = GetCurrentWindow(); + ImGuiContext& g = *GImGui; + ImGuiWindow* window = g.CurrentWindow; IM_ASSERT(window->Flags & ImGuiWindowFlags_ChildWindow); // Mismatched BeginChild()/EndChild() callss if (window->BeginCount > 1) @@ -4051,7 +4050,7 @@ void ImGui::EndChild() sz.y = ImMax(4.0f, sz.y); End(); - ImGuiWindow* parent_window = GetCurrentWindow(); + ImGuiWindow* parent_window = g.CurrentWindow; ImRect bb(parent_window->DC.CursorPos, parent_window->DC.CursorPos + sz); ItemSize(sz); ItemAdd(bb, 0); @@ -4473,6 +4472,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Automatically disable manual moving/resizing when NoInputs is set if (flags & ImGuiWindowFlags_NoInputs) flags |= ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize; + //if (flags & ImGuiWindowFlags_NavFlattened) // IM_ASSERT(flags & ImGuiWindowFlags_ChildWindow); @@ -4578,9 +4578,9 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window->RootWindow = parent_window->RootWindow; if (parent_window && !(flags & ImGuiWindowFlags_Modal) && (flags & (ImGuiWindowFlags_ChildWindow | ImGuiWindowFlags_Popup))) window->RootNonPopupWindow = parent_window->RootNonPopupWindow; - //window->RootNavWindow = window; - //while (window->RootNavWindow->Flags & ImGuiWindowFlags_NavFlattened) - // window->RootNavWindow = window->RootNavWindow->ParentWindow; + //window->NavRootWindow = window; + //while (window->NavRootWindow->Flags & ImGuiWindowFlags_NavFlattened) + // window->NavRootWindow = window->NavRootWindow->ParentWindow; window->Active = true; window->BeginOrderWithinParent = 0; @@ -4796,12 +4796,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) const float window_border_size = window->WindowBorderSize; ImRect title_bar_rect = window->TitleBarRect(); const bool window_is_focused = want_focus || (g.NavWindow && window->RootNonPopupWindow == g.NavWindow->RootNonPopupWindow); + ImU32 title_bar_col = GetColorU32(window->Collapsed ? ImGuiCol_TitleBgCollapsed : window_is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg); if (window->Collapsed) { // Title bar only float backup_border_size = style.FrameBorderSize; g.Style.FrameBorderSize = window->WindowBorderSize; - RenderFrame(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(ImGuiCol_TitleBgCollapsed), true, window_rounding); + RenderFrame(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, true, window_rounding); g.Style.FrameBorderSize = backup_border_size; } else @@ -4817,7 +4818,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Title bar if (!(flags & ImGuiWindowFlags_NoTitleBar)) - window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, GetColorU32(window_is_focused ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImDrawCornerFlags_Top); + window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawCornerFlags_Top); // Menu bar if (flags & ImGuiWindowFlags_MenuBar) @@ -6449,7 +6450,7 @@ bool ImGui::InvisibleButton(const char* str_id, const ImVec2& size_arg) return pressed; } -// Upper-right button to close a window. +// Button to close a window bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos, float radius) { ImGuiWindow* window = GetCurrentWindow(); @@ -6471,7 +6472,6 @@ bool ImGui::CloseButton(ImGuiID id, const ImVec2& pos, float radius) window->DrawList->AddLine(center + ImVec2(+cross_extent,+cross_extent), center + ImVec2(-cross_extent,-cross_extent), GetColorU32(ImGuiCol_Text)); window->DrawList->AddLine(center + ImVec2(+cross_extent,-cross_extent), center + ImVec2(-cross_extent,+cross_extent), GetColorU32(ImGuiCol_Text)); } - return pressed; } @@ -7647,14 +7647,11 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s float adjust_delta = 0.0f; if (IsMousePosValid()) { - //if (g.ActiveIdSource == ImGuiInputSource_Mouse) - { - adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x; - if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f) - adjust_delta *= g.DragSpeedScaleFast; - if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) - adjust_delta *= g.DragSpeedScaleSlow; - } + adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x; + if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f) + adjust_delta *= g.DragSpeedScaleFast; + if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f) + adjust_delta *= g.DragSpeedScaleSlow; g.DragLastMouseDelta.x = mouse_drag_delta.x; } adjust_delta *= v_speed; @@ -9786,7 +9783,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled) g.NavWindow = backed_nav_window; bool want_open = false, want_close = false; - if (window->DC.LayoutType != ImGuiLayoutType_Horizontal) // (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) + if (window->DC.LayoutType == ImGuiLayoutType_Vertical) // (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) { // Implement http://bjk5.com/post/44698559168/breaking-down-amazons-mega-dropdown to avoid using timers, so menus feels more reactive. bool moving_within_opened_triangle = false; @@ -11771,8 +11768,12 @@ void ImGui::ShowMetricsWindow(bool* p_open) { if (!ImGui::TreeNode(window, "%s '%s', %d @ 0x%p", label, window->Name, window->Active || window->WasActive, window)) return; + ImGuiWindowFlags flags = window->Flags; NodeDrawList(window, window->DrawList, "DrawList"); ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), SizeContents (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->SizeContents.x, window->SizeContents.y); + ImGui::BulletText("Flags: 0x%08X (%s%s%s%s%s%s..)", flags, + (flags & ImGuiWindowFlags_ChildWindow) ? "Child " : "", (flags & ImGuiWindowFlags_Tooltip) ? "Tooltip " : "", (flags & ImGuiWindowFlags_Popup) ? "Popup " : "", + (flags & ImGuiWindowFlags_Modal) ? "Modal " : "", (flags & ImGuiWindowFlags_ChildMenu) ? "ChildMenu " : "", (flags & ImGuiWindowFlags_NoSavedSettings) ? "NoSavedSettings " : ""); ImGui::BulletText("Scroll: (%.2f/%.2f,%.2f/%.2f)", window->Scroll.x, GetScrollMaxX(window), window->Scroll.y, GetScrollMaxY(window)); ImGui::BulletText("Active: %d, WriteAccessed: %d", window->Active, window->WriteAccessed); if (window->RootWindow != window) NodeWindow(window->RootWindow, "RootWindow");