From fd2a90ee60c1b766af5a5ae167f38d601414141f Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 2 Aug 2018 16:53:51 +0200 Subject: [PATCH 01/17] Update CONTRIBUTING.md --- .github/CONTRIBUTING.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 2820e28a..6cacb69a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,19 +14,25 @@ You may use the Issue Tracker to submit bug reports, feature requests or suggest **Guidelines to report an issue or ask a question:** - Please provide your imgui version number. -- If you are discussing an assert or a crash, please provide a debugger callstack. Never state "it crashes" without additional information. +- Try to be explicit with your expectations and what you have tried. What you have in mind or in your code is not obvious to other people. +- If you are discussing an assert or a crash, please provide a debugger callstack. Never state "it crashes" without additional information. If you don't know how to use a debugger and retrieve a callstack, learning about it will be useful. +- Please make sure that your compilation settings have asserts enabled. Calls to IM_ASSERT() are scattered in the code to help catch common issues. By default IM_ASSERT() calls the standard assert() function. To verify that your asserts are enabled, add the line `IM_ASSERT(false);` in your main() function. Your application should display an error message and abort. If your application report an error, it means that your asserts are disabled. Please make sure they are enabled. - Please state if you have made substantial modifications to your copy of imgui. -- When discussing issues related to rendering or inputs, please state the OS/back-end/renderer you are using. Please state if you are using a vanilla copy of one of the back-end (imgui_impl_xxx files), or a modified one, or if you built your own. -- Try to be explicit with your expectations and what you have tried. +- When discussing issues related to rendering or inputs, please state the OS/back-end/renderer you are using. Please state if you are using a vanilla copy of the example back-ends (imgui_impl_xxx files), or a modified one, or if you built your own. - Please provide a Minimal, Complete and Verifiable Example ([MCVE](https://stackoverflow.com/help/mcve)) to demonstrate your problem. An ideal submission includes a small piece of code that anyone can paste in one of the examples/ application (e.g. in main.cpp or imgui_demo.cpp) to understand and reproduce it. Narrowing your problem to its shortest and purest form is the easiest way to understand it. Please test your shortened code to ensure it actually exhibit the problem. Often while creating the MCVE you will end up solving the problem! Many questions that are missing a standalone verifiable example are missing the actual cause of their issue in the description, which ends up wasting everyone's time. - Try to attach screenshots to clarify the context. They often convey useful information that are omitted by the description. You can drag pictures/files here (prefer github attachments over 3rd party hosting). - When requesting a new feature, please describe the usage context (how you intend to use it, why you need it, etc.). -- Due to frequent abuse of this service from a certain category of users, if your GitHub account is anonymous and was created five minutes ago please understand that your post will receive more scrutiny and less patience for incomplete questions. -If you have been using dear imgui for a while or have been using C/C++ for several years or have demonstrated good behavior here, it is ok to not fullfill every item to the letter. Those are guidelines and experienced users of dear imgui will know what information are useful in a given context. +**Some unfortunate words of warning** +- If you are or were involved in cheating schemes (e.g. DLL injection) for competitive online multi-player games, please don't post here. We won't answer and you will be blocked. We've had too many of you. Please stop. +- Due to frequent abuse of this service from aforementioned users, if your GitHub account is anonymous and was created five minutes ago please understand that your post will receive more scrutiny and incomplete questions may be dismissed. + +If you have been using dear imgui for a while or have been using C/C++ for several years or have demonstrated good behavior here, it is ok to not fullfill every item to the letter. Those are guidelines and experienced users or members of the community will know what information are useful in a given context. ## How to create an Pull Request - When adding a feature, please describe the usage context (how you intend to use it, why you need it, etc.). - When fixing a warning or compilation problem, please post the compiler log and specify the version and OS you are using. - Try to attach screenshots to clarify the context and demonstrate the feature at a glance. You can drag pictures/files here (prefer github attachments over 3rd party hosting). - Make sure you create a branch for the pull request. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR (we can still cherry-pick individual commits). + +Thank you for reading! From 498c0dcb4c2a404ce8ef7c60b3f4148875c96d2f Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 Aug 2018 11:40:58 +0200 Subject: [PATCH 02/17] Using limits.h LLONG_MIN etc. to increase old-compiler compatibility (as ll and ull prefixes were not standard). Not tested much on old compilers, relying on Clang/GCC warnings. --- imgui.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 0ae620e2..69c00ce2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -848,14 +848,14 @@ #endif #endif -static const ImS32 IM_S32_MIN = 0x80000000; // INT_MIN; -static const ImS32 IM_S32_MAX = 0x7FFFFFFF; // INT_MAX; +static const ImS32 IM_S32_MIN = INT_MIN; // (-2147483647 - 1), (0x80000000); +static const ImS32 IM_S32_MAX = INT_MAX; // (2147483647), (0x7FFFFFFF) static const ImU32 IM_U32_MIN = 0; -static const ImU32 IM_U32_MAX = 0xFFFFFFFF; -static const ImS64 IM_S64_MIN = -9223372036854775807ll - 1ll; -static const ImS64 IM_S64_MAX = 9223372036854775807ll; +static const ImU32 IM_U32_MAX = UINT_MAX; // (0xFFFFFFFF) +static const ImS64 IM_S64_MIN = LLONG_MIN; // (-9223372036854775807ll - 1ll); +static const ImS64 IM_S64_MAX = LLONG_MAX; // (9223372036854775807ll); static const ImU64 IM_U64_MIN = 0; -static const ImU64 IM_U64_MAX = 0xFFFFFFFFFFFFFFFFull; +static const ImU64 IM_U64_MAX = ULLONG_MAX; // (0xFFFFFFFFFFFFFFFFull); // When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch. static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the highlight and screen dimming starts fading in From 00e29832d4ce37673bfcc4054014ccc95a2fc79a Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 Aug 2018 15:04:35 +0200 Subject: [PATCH 03/17] Examples: OpenGL2: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications. (#1996) --- CHANGELOG.txt | 1 + examples/imgui_impl_opengl2.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 55948c31..7b5987b9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -75,6 +75,7 @@ Other Changes: - Examples: OpenGL3: Tweaked the imgui_impl_opengl3.cpp to work as-is with Emscripten + WebGL 2.0. (#1941). [@o-micron] - Examples: OpenGL3: Made the example app default to GL 3.0 + GLSL 130 (instead of GL 3.2 + GLSL 150) unless on Mac. - Examples: OpenGL3: Added error output when shaders fail to compile/link. + - Examples: OpenGL2: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications. (#1996) - Examples: DirectX10, DirectX11: Fixed unreleased resources in Init and Shutdown functions. (#1944) - Examples: DirectX11: Querying for IDXGIFactory instead of IDXGIFactory1 to increase compatibility. (#1989) [@matt77hias] - Examples: Win32, Glfw, SDL: Added support for the ImGuiMouseCursor_Hand cursor. diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index e584c072..c70d9fe6 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -18,6 +18,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-08-03: OpenGL: Disabling/restoring GL_LIGHTING and GL_COLOR_MATERIAL to increase compatibility with legacy OpenGL applications. // 2018-06-08: Misc: Extracted imgui_impl_opengl2.cpp/.h away from the old combined GLFW/SDL+OpenGL2 examples. // 2018-06-08: OpenGL: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle. // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplGlfwGL2_RenderDrawData() in the .h file so you can call it yourself. @@ -90,6 +91,8 @@ void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); glEnable(GL_SCISSOR_TEST); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); From bc6ac8b2aee0614debd940e45bc9cd0d9b355c86 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 3 Aug 2018 18:12:36 +0200 Subject: [PATCH 04/17] Metrics: Changed io.MetricsActiveWindows to reflect the number of active windows (!= from visible windows), which is useful for lazy/idle render mechanisms as new windows are typically not visible for one frame. Metrics: Added io.MetricsRenderWindow to reflect the number of visible windows. --- CHANGELOG.txt | 3 +++ imgui.cpp | 12 ++++++++---- imgui.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7b5987b9..35dbbff4 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -64,6 +64,9 @@ Other Changes: - Fixed horizontal mouse wheel not forwarding the request to the parent window if ImGuiWindowFlags_NoScrollWithMouse is set. (#1463, #1380, #1502) - Fixed a include build issue for Cygwin in non-POSIX (Win32) mode. (#1917, #1319, #276) - OS/Windows: Fixed missing ImmReleaseContext() call in the default Win32 IME handler. (#1932) [@vby] + - Metrics: Changed io.MetricsActiveWindows to reflect the number of active windows (!= from visible windows), which is useful + for lazy/idle render mechanisms as new windows are typically not visible for one frame. + - Metrics: Added io.MetricsRenderWindow to reflect the number of visible windows. - Demo: Added basic Drag and Drop demo. (#143) - Demo: Clarified the use of IsItemHovered()/IsItemActive() right after being in the "Active, Focused, Hovered & Focused Tests" section. - Examples: Tweaked the main.cpp of each example. diff --git a/imgui.cpp b/imgui.cpp index 69c00ce2..4cc0e622 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4356,6 +4356,8 @@ static void AddDrawListToDrawData(ImVector* out_list, ImDrawList* d static void AddWindowToDrawData(ImVector* out_render_list, ImGuiWindow* window) { + ImGuiContext& g = *GImGui; + g.IO.MetricsRenderWindows++; AddDrawListToDrawData(out_render_list, window->DrawList); for (int i = 0; i < window->DC.ChildWindows.Size; i++) { @@ -4368,7 +4370,6 @@ static void AddWindowToDrawData(ImVector* out_render_list, ImGuiWin static void AddWindowToDrawDataSelectLayer(ImGuiWindow* window) { ImGuiContext& g = *GImGui; - g.IO.MetricsActiveWindows++; if (window->Flags & ImGuiWindowFlags_Tooltip) AddWindowToDrawData(&g.DrawDataBuilder.Layers[1], window); else @@ -4518,6 +4519,7 @@ void ImGui::EndFrame() IM_ASSERT(g.Windows.Size == g.WindowsSortBuffer.Size); // we done something wrong g.Windows.swap(g.WindowsSortBuffer); + g.IO.MetricsActiveWindows = g.WindowsActiveCount; // Unlock font atlas g.IO.Fonts->Locked = false; @@ -4541,7 +4543,7 @@ void ImGui::Render() g.FrameCountRendered = g.FrameCount; // Gather windows to render - g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsActiveWindows = 0; + g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsRenderWindows = 0; g.DrawDataBuilder.Clear(); ImGuiWindow* windows_to_render_front_most[2]; windows_to_render_front_most[0] = (g.NavWindowingTarget && !(g.NavWindowingTarget->Flags & ImGuiWindowFlags_NoBringToFrontOnFocus)) ? g.NavWindowingTarget->RootWindow : NULL; @@ -14037,9 +14039,11 @@ void ImGui::ShowMetricsWindow(bool* p_open) { static bool show_draw_cmd_clip_rects = true; static bool show_window_begin_order = false; + ImGuiIO& io = ImGui::GetIO(); ImGui::Text("Dear ImGui %s", ImGui::GetVersion()); - ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); - ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3); + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate); + ImGui::Text("%d vertices, %d indices (%d triangles)", io.MetricsRenderVertices, io.MetricsRenderIndices, io.MetricsRenderIndices / 3); + ImGui::Text("%d active windows (%d visible)", io.MetricsActiveWindows, io.MetricsRenderWindows); ImGui::Text("%d allocations", (int)GImAllocatorActiveAllocationsCount); ImGui::Checkbox("Show clipping rectangles when hovering draw commands", &show_draw_cmd_clip_rects); ImGui::Checkbox("Ctrl shows window begin order", &show_window_begin_order); diff --git a/imgui.h b/imgui.h index 9c73471f..e28d8832 100644 --- a/imgui.h +++ b/imgui.h @@ -1158,7 +1158,8 @@ struct ImGuiIO float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames int MetricsRenderVertices; // Vertices output during last call to Render() int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 - int MetricsActiveWindows; // Number of visible root windows (exclude child windows) + int MetricsRenderWindows; // Number of visible windows + int MetricsActiveWindows; // Number of active windows ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are invalid (-FLT_MAX,-FLT_MAX), so a disappearing/reappearing mouse won't have a huge delta. //------------------------------------------------------------------ From 9e9c8a8991a50e49ce4179caec7ad11f563414eb Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 5 Aug 2018 18:13:15 +0200 Subject: [PATCH 05/17] Update to Contributing, and Issue/PR templates. --- .github/CONTRIBUTING.md | 5 +++-- .github/issue_template.md | 9 +++++---- .github/pull_request_template.md | 4 ++-- README.md | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6cacb69a..3a18c89a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -14,11 +14,11 @@ You may use the Issue Tracker to submit bug reports, feature requests or suggest **Guidelines to report an issue or ask a question:** - Please provide your imgui version number. +- Please state if you have made substantial modifications to your copy of imgui. - Try to be explicit with your expectations and what you have tried. What you have in mind or in your code is not obvious to other people. - If you are discussing an assert or a crash, please provide a debugger callstack. Never state "it crashes" without additional information. If you don't know how to use a debugger and retrieve a callstack, learning about it will be useful. - Please make sure that your compilation settings have asserts enabled. Calls to IM_ASSERT() are scattered in the code to help catch common issues. By default IM_ASSERT() calls the standard assert() function. To verify that your asserts are enabled, add the line `IM_ASSERT(false);` in your main() function. Your application should display an error message and abort. If your application report an error, it means that your asserts are disabled. Please make sure they are enabled. -- Please state if you have made substantial modifications to your copy of imgui. -- When discussing issues related to rendering or inputs, please state the OS/back-end/renderer you are using. Please state if you are using a vanilla copy of the example back-ends (imgui_impl_xxx files), or a modified one, or if you built your own. +- When discussing issues related to rendering or inputs, please state the OS/back-end/renderer you are using. Please state if you are using a vanilla copy of the example back-ends (imgui_impl_XXX files), or a modified one, or if you built your own. - Please provide a Minimal, Complete and Verifiable Example ([MCVE](https://stackoverflow.com/help/mcve)) to demonstrate your problem. An ideal submission includes a small piece of code that anyone can paste in one of the examples/ application (e.g. in main.cpp or imgui_demo.cpp) to understand and reproduce it. Narrowing your problem to its shortest and purest form is the easiest way to understand it. Please test your shortened code to ensure it actually exhibit the problem. Often while creating the MCVE you will end up solving the problem! Many questions that are missing a standalone verifiable example are missing the actual cause of their issue in the description, which ends up wasting everyone's time. - Try to attach screenshots to clarify the context. They often convey useful information that are omitted by the description. You can drag pictures/files here (prefer github attachments over 3rd party hosting). - When requesting a new feature, please describe the usage context (how you intend to use it, why you need it, etc.). @@ -33,6 +33,7 @@ If you have been using dear imgui for a while or have been using C/C++ for sever - When adding a feature, please describe the usage context (how you intend to use it, why you need it, etc.). - When fixing a warning or compilation problem, please post the compiler log and specify the version and OS you are using. - Try to attach screenshots to clarify the context and demonstrate the feature at a glance. You can drag pictures/files here (prefer github attachments over 3rd party hosting). +- Make sure your code follows the coding style already used in imgui (spaces instead of tabs, "local_variable", "FunctionName", "MemberName", etc.). We don't use modern C++ idioms and can compile without C++11. - Make sure you create a branch for the pull request. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR (we can still cherry-pick individual commits). Thank you for reading! diff --git a/.github/issue_template.md b/.github/issue_template.md index 0bcd63b4..9fe05553 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -1,11 +1,12 @@ You may use the Issue Tracker to ask for help and submit bug reports, feature requests or suggestions. -PLEASE CAREFULLY READ THIS DOCUMENT before doing so: -[CONTRIBUTING.md](https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md). +PLEASE CAREFULLY READ THIS DOCUMENT before submitting any issue: +https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md +(Click "Preview" to turn the URL above into a clickable link) -SELECT "PREVIEW CHANGES" TO TURN THE URL ABOVE INTO A CLICKABLE LINK. +PLEASE MAKE SURE that you have: read the FAQ in imgui.cpp; explored the contents of ShowDemoWindow() including the Examples menu; searched among Issues; used your IDE to search for keywords in all sources and text files; and read the CONTRIBUTING.md file linked above. -(Delete everything above this section before submitting your issue. Please read the CONTRIBUTING.md file!) +(Delete everything above this section before submitting your issue.) ---- diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 9e00ae82..56f612ed 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,8 @@ +- Please read https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md - When adding a feature, please describe the usage context (how you intend to use it, why you need it, etc.). - When fixing a warning or compilation problem, please post the compiler log and specify the version and OS you are using. - Try to attach screenshots to clarify the context and demonstrate the feature at a glance. -- Make sure your code follows the coding style already used in imgui (spaces instead of tabs, "local_variable", "FunctionName", "MemberName", etc.). +- Make sure your code follows the coding style already used in imgui (spaces instead of tabs, "local_variable", "FunctionName", "MemberName", etc.). We don't use modern C++ idioms and can compile without C++11. - Make sure you create a branch for the pull request. In Git, 1 PR is associated to 1 branch. If you keep pushing to the same branch after you submitted the PR, your new commits will appear in the PR. -- You can read [CONTRIBUTING.md](https://github.com/ocornut/imgui/blob/master/.github/CONTRIBUTING.md) for more details. (Clear this form before submitting your PR) diff --git a/README.md b/README.md index 14e11cf1..51bf6017 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ User screenshots:
[Gallery Part 3](https://github.com/ocornut/imgui/issues/772) (Aug 2016 to Jan 2017)
[Gallery Part 4](https://github.com/ocornut/imgui/issues/973) (Jan 2017 to Aug 2017)
[Gallery Part 5](https://github.com/ocornut/imgui/issues/1269) (Aug 2017 to Feb 2018) -
[Gallery Part 6](https://github.com/ocornut/imgui/issues/1607) (Feb 2018 onward) +
[Gallery Part 6](https://github.com/ocornut/imgui/issues/1607) (Feb 2018 to June 2018)
[Gallery Part 7](https://github.com/ocornut/imgui/issues/1902) (June 2018 onward)
Also see the [Mega screenshots](https://github.com/ocornut/imgui/issues/1273) for an idea of the available features. From 0905202f44308f6bcc8464f2bf8df2d2ac936547 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 5 Aug 2018 18:13:24 +0200 Subject: [PATCH 06/17] Internals: Minor renaming for consistency. --- imgui.cpp | 10 +++++----- imgui_internal.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 4cc0e622..acc8cc0d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2128,7 +2128,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* context, const char* name) Active = WasActive = false; WriteAccessed = false; Collapsed = false; - CollapseToggleWanted = false; + WantCollapseToggle = false; SkipItems = false; Appearing = false; Hidden = false; @@ -6407,8 +6407,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar. ImRect title_bar_rect = window->TitleBarRect(); if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max) && g.IO.MouseDoubleClicked[0]) - window->CollapseToggleWanted = true; - if (window->CollapseToggleWanted) + window->WantCollapseToggle = true; + if (window->WantCollapseToggle) { window->Collapsed = !window->Collapsed; MarkIniSettingsDirty(window); @@ -6419,7 +6419,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) { window->Collapsed = false; } - window->CollapseToggleWanted = false; + window->WantCollapseToggle = false; // SIZE @@ -6729,7 +6729,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Collapse button if (!(flags & ImGuiWindowFlags_NoCollapse)) if (CollapseButton(window->GetID("#COLLAPSE"), window->Pos)) - window->CollapseToggleWanted = true; // Defer collapsing to next frame as we are too far in the Begin() function + window->WantCollapseToggle = true; // Defer collapsing to next frame as we are too far in the Begin() function // Close button if (p_open != NULL) diff --git a/imgui_internal.h b/imgui_internal.h index 1d932a55..adf45c39 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -983,7 +983,7 @@ struct IMGUI_API ImGuiWindow bool WasActive; bool WriteAccessed; // Set to true when any widget access the current window bool Collapsed; // Set when collapsing window to become only title-bar - bool CollapseToggleWanted; + bool WantCollapseToggle; bool SkipItems; // Set when items can safely be all clipped (e.g. window not visible or collapsed) bool Appearing; // Set during the frame where the window is appearing (or re-appearing) bool Hidden; // Do not display (== (HiddenFramesForResize > 0) || From 9d8a0374d35cdba7e2d17a1ed342efe48a1c1849 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 6 Aug 2018 13:07:19 +0200 Subject: [PATCH 07/17] Use literals in place of LLONG_MIN, LLONG_MAX ULLONG_MAX if they are not available. Amend 498c0dcb4c2a404ce8ef7c60b3f4148875c96d2f. We prefer using the defines if available in limits.h because they somehow tend to work without warnings when enabling strict C++03 compilation. The 3 literals are fallbacks.. (#1926). --- imgui.cpp | 9 +++++++++ imgui_demo.cpp | 23 +++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index acc8cc0d..8c6e96ed 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -852,10 +852,19 @@ static const ImS32 IM_S32_MIN = INT_MIN; // (-2147483647 - 1), (0x80000000); static const ImS32 IM_S32_MAX = INT_MAX; // (2147483647), (0x7FFFFFFF) static const ImU32 IM_U32_MIN = 0; static const ImU32 IM_U32_MAX = UINT_MAX; // (0xFFFFFFFF) +#ifdef LLONG_MIN static const ImS64 IM_S64_MIN = LLONG_MIN; // (-9223372036854775807ll - 1ll); static const ImS64 IM_S64_MAX = LLONG_MAX; // (9223372036854775807ll); +#else +static const ImS64 IM_S64_MIN = -9223372036854775807LL - 1; +static const ImS64 IM_S64_MAX = 9223372036854775807LL; +#endif static const ImU64 IM_U64_MIN = 0; +#ifdef ULLONG_MAX static const ImU64 IM_U64_MAX = ULLONG_MAX; // (0xFFFFFFFFFFFFFFFFull); +#else +static const ImU64 IM_U64_MAX = (2ULL * 9223372036854775807LL + 1); +#endif // When using CTRL+TAB (or Gamepad Square+L/R) we delay the visual a little in order to reduce visual noise doing a fast switch. static const float NAV_WINDOWING_HIGHLIGHT_DELAY = 0.20f; // Time before the highlight and screen dimming starts fading in diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4d8113d9..ff262107 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1022,14 +1022,25 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::TreeNode("Data Types")) { - // The DragScalar, InputScalar, SliderScalar functions allow manipulating most common data types: signed/unsigned int/long long and float/double - // To avoid polluting the public API with all possible combinations, we use the ImGuiDataType enum to pass the type, and argument-by-values are turned into argument-by-address. + // The DragScalar/InputScalar/SliderScalar functions allow various data types: signed/unsigned int/long long and float/double + // To avoid polluting the public API with all possible combinations, we use the ImGuiDataType enum to pass the type, + // and passing all arguments by address. // This is the reason the test code below creates local variables to hold "zero" "one" etc. for each types. - // In practice, if you frequently use a given type that is not covered by the normal API entry points, you may want to wrap it yourself inside a 1 line function - // which can take typed values argument instead of void*, and then pass their address to the generic function. For example: - // bool SliderU64(const char *label, u64* value, u64 min = 0, u64 max = 0, const char* format = "%lld") { return SliderScalar(label, ImGuiDataType_U64, value, &min, &max, format); } - // Below are helper variables we can take the address of to work-around this: + // In practice, if you frequently use a given type that is not covered by the normal API entry points, you can wrap it + // yourself inside a 1 line function which can take typed argument as value instead of void*, and then pass their address + // to the generic function. For example: + // bool MySliderU64(const char *label, u64* value, u64 min = 0, u64 max = 0, const char* format = "%lld") + // { + // return SliderScalar(label, ImGuiDataType_U64, value, &min, &max, format); + // } + + // Limits (as helper variables that we can take the address of) // Note that the SliderScalar function has a maximum usable range of half the natural type maximum, hence the /2 below. + #ifndef LLONG_MIN + ImS64 LLONG_MIN = -9223372036854775807LL - 1; + ImS64 LLONG_MAX = 9223372036854775807LL; + ImU64 ULLONG_MAX = (2ULL * 9223372036854775807LL + 1); + #endif const ImS32 s32_zero = 0, s32_one = 1, s32_fifty = 50, s32_min = INT_MIN/2, s32_max = INT_MAX/2, s32_hi_a = INT_MAX/2 - 100, s32_hi_b = INT_MAX/2; const ImU32 u32_zero = 0, u32_one = 1, u32_fifty = 50, u32_min = 0, u32_max = UINT_MAX/2, u32_hi_a = UINT_MAX/2 - 100, u32_hi_b = UINT_MAX/2; const ImS64 s64_zero = 0, s64_one = 1, s64_fifty = 50, s64_min = LLONG_MIN/2, s64_max = LLONG_MAX/2, s64_hi_a = LLONG_MAX/2 - 100, s64_hi_b = LLONG_MAX/2; From 0065fe16a2a3c87955167d247628a319dab44c67 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 8 Aug 2018 16:03:13 +0200 Subject: [PATCH 08/17] Nav: Made CTRL+TAB skip menus + skip the current navigation window if is has the ImGuiWindow_NoNavFocus set. (#787) While it was previously possible, you won't be able to CTRL-TAB out and immediately back in a window with the ImGuiWindow_NoNavFocus flag. --- CHANGELOG.txt | 4 +++- imgui.cpp | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 35dbbff4..eada3b56 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -45,7 +45,9 @@ Other Changes: - ArrowButton: Fixed to honor PushButtonRepeat() setting (and internals' ImGuiItemFlags_ButtonRepeat). - ArrowButton: Setup current line text baseline so that ArrowButton() + SameLine() + Text() are aligned properly. - - Nav: Added a CTRL+TAB window list and changed the highlight system accordingly. This is designed to allow CTRL+TAB between Tabs in the future. (#787) + - Nav: Added a CTRL+TAB window list and changed the highlight system accordingly. The change is motivated by upcoming Docking features. (#787) + - Nav: Made CTRL+TAB skip menus + skip the current navigation window if is has the ImGuiWindow_NoNavFocus set. (#787) + While it was previously possible, you won't be able to CTRL-TAB out and immediately back in a window with the ImGuiWindow_NoNavFocus flag. - Window: Allow menu and popups windows from ignoring the style.WindowMinSize values so short menus/popups are not padded. (#1909) - Window: Added global io.OptResizeWindowsFromEdges option to enable resizing windows from their edges and from the lower-left corner. (#1495) - Window: Collapse button shows hovering highlight + clicking and dragging on it allows to drag the window as well. diff --git a/imgui.cpp b/imgui.cpp index 8c6e96ed..e9da99da 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3012,7 +3012,7 @@ static int FindWindowIndex(ImGuiWindow* window) // FIXME-OPT O(N) return -1; } -static ImGuiWindow* FindWindowNavigable(int i_start, int i_stop, int dir) // FIXME-OPT O(N) +static ImGuiWindow* FindWindowNavFocusable(int i_start, int i_stop, int dir) // FIXME-OPT O(N) { ImGuiContext& g = *GImGui; for (int i = i_start; i >= 0 && i < g.Windows.Size && i != i_stop; i += dir) @@ -3084,9 +3084,9 @@ static void NavUpdateWindowingHighlightWindow(int focus_change_dir) return; const int i_current = FindWindowIndex(g.NavWindowingTarget); - ImGuiWindow* window_target = FindWindowNavigable(i_current + focus_change_dir, -INT_MAX, focus_change_dir); + ImGuiWindow* window_target = FindWindowNavFocusable(i_current + focus_change_dir, -INT_MAX, focus_change_dir); if (!window_target) - window_target = FindWindowNavigable((focus_change_dir < 0) ? (g.Windows.Size - 1) : 0, i_current, focus_change_dir); + window_target = FindWindowNavFocusable((focus_change_dir < 0) ? (g.Windows.Size - 1) : 0, i_current, focus_change_dir); if (window_target) // Don't reset windowing target if there's a single window in the list g.NavWindowingTarget = g.NavWindowingTargetAnim = window_target; g.NavWindowingToggleLayer = false; @@ -3118,7 +3118,7 @@ static void ImGui::NavUpdateWindowing() bool start_windowing_with_gamepad = !g.NavWindowingTarget && IsNavInputPressed(ImGuiNavInput_Menu, ImGuiInputReadMode_Pressed); bool start_windowing_with_keyboard = !g.NavWindowingTarget && g.IO.KeyCtrl && IsKeyPressedMap(ImGuiKey_Tab) && (g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard); if (start_windowing_with_gamepad || start_windowing_with_keyboard) - if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavigable(g.Windows.Size - 1, -INT_MAX, -1)) + if (ImGuiWindow* window = g.NavWindow ? g.NavWindow : FindWindowNavFocusable(g.Windows.Size - 1, -INT_MAX, -1)) { g.NavWindowingTarget = g.NavWindowingTargetAnim = window; g.NavWindowingTimer = g.NavWindowingHighlightAlpha = 0.0f; @@ -7436,8 +7436,7 @@ bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags) // Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext) bool ImGui::IsWindowNavFocusable(ImGuiWindow* window) { - ImGuiContext& g = *GImGui; - return window->Active && window == window->RootWindow && (!(window->Flags & ImGuiWindowFlags_NoNavFocus) || window == g.NavWindow); + return window->Active && window == window->RootWindow && !(window->Flags & ImGuiWindowFlags_NoNavFocus); } float ImGui::GetWindowWidth() @@ -12172,7 +12171,9 @@ bool ImGui::BeginMenu(const char* label, bool enabled) { // Sub-menus are ChildWindow so that mouse can be hovering across them (otherwise top-most popup menu would steal focus and not allow hovering on parent menu) SetNextWindowPos(popup_pos, ImGuiCond_Always); - ImGuiWindowFlags flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ((window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) ? ImGuiWindowFlags_ChildMenu|ImGuiWindowFlags_ChildWindow : ImGuiWindowFlags_ChildMenu); + ImGuiWindowFlags flags = ImGuiWindowFlags_ChildMenu | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNavFocus; + if (window->Flags & (ImGuiWindowFlags_Popup|ImGuiWindowFlags_ChildMenu)) + flags |= ImGuiWindowFlags_ChildWindow; menu_is_open = BeginPopupEx(id, flags); // menu_is_open can be 'false' when the popup is completely clipped (e.g. zero size display) } From 35124cdd076b63a550aeea05c7eccf22849f92d6 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 8 Aug 2018 17:38:18 +0200 Subject: [PATCH 09/17] imgui_impl_opengl3.cpp Using GLES3 on IOS instead of gl3w. (#2002, #1873) Not modifying the main.cpp yet because we need to test GL ES 3 context creation on iOS (only imgui_impl_opengl3.cpp was tested). --- examples/imgui_impl_opengl3.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 90358f6d..1cd8c051 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -57,8 +57,11 @@ #else #include // intptr_t #endif +#if defined(__APPLE__) +#include "TargetConditionals.h" +#endif -#ifdef __EMSCRIPTEN__ +#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__EMSCRIPTEN__)) #include // Use GL ES 3 #else // About OpenGL function loaders: From e3eb4111cc8e4e7c7b58934b5da41c81820beaef Mon Sep 17 00:00:00 2001 From: luk1337 Date: Wed, 8 Aug 2018 18:55:09 +0200 Subject: [PATCH 10/17] Examples: Fix 'How to build' instructions for SDL2 examples (#2012) --- examples/example_sdl_opengl2/README.md | 6 +++--- examples/example_sdl_opengl3/README.md | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/example_sdl_opengl2/README.md b/examples/example_sdl_opengl2/README.md index a8bfc880..dfbfa7b6 100644 --- a/examples/example_sdl_opengl2/README.md +++ b/examples/example_sdl_opengl2/README.md @@ -5,18 +5,18 @@ ``` set SDL2DIR=path_to_your_sdl2_folder -cl /Zi /MD /I %SDL2DIR%\include /I ..\.. main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl2.cpp ..\..\imgui*.cpp /link /LIBPATH:%SDL2DIR%\lib SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +cl /Zi /MD /I %SDL2DIR%\include /I .. /I ..\.. main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl2.cpp ..\..\imgui*.cpp /link /LIBPATH:%SDL2DIR%\lib SDL2.lib SDL2main.lib opengl32.lib /subsystem:console ``` - On Linux and similar Unixes ``` -c++ `sdl2-config --cflags` -I ../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL +c++ `sdl2-config --cflags` -I .. -I ../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL ``` - On Mac OS X ``` brew install sdl2 -c++ `sdl2-config --cflags` -I ../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl +c++ `sdl2-config --cflags` -I .. -I ../.. main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl2.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl ``` diff --git a/examples/example_sdl_opengl3/README.md b/examples/example_sdl_opengl3/README.md index 3de6666a..f029ce71 100644 --- a/examples/example_sdl_opengl3/README.md +++ b/examples/example_sdl_opengl3/README.md @@ -5,18 +5,18 @@ ``` set SDL2DIR=path_to_your_sdl2_folder -cl /Zi /MD /I ..\.. /I ..\libs\gl3w /I %SDL2DIR%\include main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /link /libpath:%SDL2DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +cl /Zi /MD /I .. /I ..\.. /I ..\libs\gl3w /I %SDL2DIR%\include main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_opengl3.cpp ..\..\imgui*.cpp ..\libs\gl3w\GL\gl3w.c /link /libpath:%SDL2DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console ``` - On Linux and similar Unixes ``` -c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -lGL -ldl +c++ `sdl2-config --cflags` -I .. -I ../.. -I ../libs/gl3w main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -lGL -ldl ``` - On Mac OS X ``` brew install sdl2 -c++ `sdl2-config --cflags` -I ../.. -I ../libs/gl3w main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -framework OpenGl -framework CoreFoundation +c++ `sdl2-config --cflags` -I .. -I ../.. -I ../libs/gl3w main.cpp ../imgui_impl_sdl.cpp ../imgui_impl_opengl3.cpp ../../imgui*.cpp ../libs/gl3w/GL/gl3w.c `sdl2-config --libs` -framework OpenGl -framework CoreFoundation ``` From 34203d50089b52c7ee3bf6b2572f9a04856b6ef9 Mon Sep 17 00:00:00 2001 From: Ryan Crandall Date: Thu, 9 Aug 2018 08:32:31 -0700 Subject: [PATCH 11/17] imgui_impl_win32: Don't redefine WIN32_LEAN_AND_MEAN if already defined (#2014) --- examples/imgui_impl_win32.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 86873084..e713b8d3 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -8,7 +8,9 @@ #include "imgui.h" #include "imgui_impl_win32.h" +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include #include From d5793102db4b2e2acde2d3d3c48b3af1fdbda395 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Aug 2018 17:42:53 +0200 Subject: [PATCH 12/17] imgui_impl_opengl3: Advertised as a ES2/ES3 renderer. Defaults to ES3 on Android. Default on "#version 300 es" on ES 3. (#2002, #1873) --- README.md | 2 +- examples/README.txt | 6 +++--- examples/imgui_impl_opengl3.cpp | 25 +++++++++++++++++++------ examples/imgui_impl_opengl3.h | 7 ++++--- imgui.cpp | 3 ++- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 51bf6017..91a50748 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ Languages: (third-party bindings) - Swift [swift-imgui](https://github.com/mnmly/Swift-imgui) Frameworks: -- Renderers: DirectX 9, DirectX 10, DirectX 11, DirectX 12, Metal, OpenGL2, OpenGL3+, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) +- Renderers: DirectX 9, DirectX 10, DirectX 11, DirectX 12, Metal, OpenGL2, OpenGL3+/ES2/ES3, Vulkan: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Platform: GLFW, SDL, Win32, OSX, Freeglut: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Framework: Allegro 5, Marmalade: [examples/](https://github.com/ocornut/imgui/tree/master/examples) - Unmerged PR: SDL2 + OpenGLES + Emscripten: [#336](https://github.com/ocornut/imgui/pull/336) diff --git a/examples/README.txt b/examples/README.txt index e84fae8b..e5764250 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -111,7 +111,7 @@ List of Renderer Bindings in this repository: imgui_impl_dx12.cpp ; DirectX12 imgui_impl_metal.mm ; Metal (with ObjC) imgui_impl_opengl2.cpp ; OpenGL2 (legacy, fixed pipeline <- don't use with modern OpenGL context) - imgui_impl_opengl3.cpp ; OpenGL3 (modern programmable pipeline) + imgui_impl_opengl3.cpp ; OpenGL3, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline) imgui_impl_vulkan.cpp ; Vulkan List of high-level Frameworks Bindings in this repository: (combine Platform + Renderer) @@ -185,7 +185,7 @@ example_glfw_opengl2/ = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp example_glfw_opengl3/ - GLFW (Win32, Mac, Linux) + OpenGL3+ example (programmable pipeline, binding modern functions with GL3W). + GLFW (Win32, Mac, Linux) + OpenGL3+/ES2/ES3 example (programmable pipeline, binding modern functions with GL3W). This uses more modern OpenGL calls and custom shaders. Prefer using that if you are using modern OpenGL in your application (anything with shaders). = main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp @@ -206,7 +206,7 @@ example_sdl_opengl2/ = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp example_sdl_opengl3/ - SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+ example. + SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. This uses more modern OpenGL calls and custom shaders. Prefer using that if you are using modern OpenGL in your application (anything with shaders). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 1cd8c051..c00f3c77 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -1,4 +1,4 @@ -// ImGui Renderer for: OpenGL3 (modern OpenGL with shaders / programmatic pipeline) +// ImGui Renderer for: OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) @@ -11,6 +11,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-08-09: OpenGL: Default to OpenGL ES 3 on iOS and Android. GLSL version default to "#version 300 ES". // 2018-07-30: OpenGL: Support for GLSL 300 ES and 410 core. Fixes for Emscripten compilation. // 2018-07-10: OpenGL: Support for more GLSL versions (based on the GLSL version string). Added error output when shaders fail to compile/link. // 2018-06-08: Misc: Extracted imgui_impl_opengl3.cpp/.h away from the old combined GLFW/SDL+OpenGL3 examples. @@ -61,13 +62,20 @@ #include "TargetConditionals.h" #endif -#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__EMSCRIPTEN__)) +// iOS, Android and Emscripten can use GL ES 3 +// Call ImGui_ImplOpenGL3_Init() with "#version 300 es" +#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) || (defined(__EMSCRIPTEN__)) +#define USE_GL_ES3 +#endif + +#ifdef USE_GL_ES3 +// OpenGL ES 3 #include // Use GL ES 3 #else -// About OpenGL function loaders: -// Modern OpenGL requires individual functions to be loaded manually. Helper libraries are often used for this purpose. -// Here we are using gl3w.h, which requires a call to gl3wInit(). -// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc. +// OpenGL Regular +// (About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual functions to be loaded manually. +// Helper libraries are often used for this purpose! Here we are using gl3w.h, which requires a call to gl3wInit(). +// You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc.) #include //#include //#include @@ -86,8 +94,13 @@ static unsigned int g_VboHandle = 0, g_ElementsHandle = 0; bool ImGui_ImplOpenGL3_Init(const char* glsl_version) { // Store GLSL version string so we can refer to it later in case we recreate shaders. Note: GLSL version is NOT the same as GL version. Leave this to NULL if unsure. +#ifdef USE_GL_ES3 + if (glsl_version == NULL) + glsl_version = "#version 300 es"; +#else if (glsl_version == NULL) glsl_version = "#version 130"; +#endif IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersionString)); strcpy(g_GlslVersionString, glsl_version); strcat(g_GlslVersionString, "\n"); diff --git a/examples/imgui_impl_opengl3.h b/examples/imgui_impl_opengl3.h index 825a09c1..8593b9f5 100644 --- a/examples/imgui_impl_opengl3.h +++ b/examples/imgui_impl_opengl3.h @@ -1,4 +1,4 @@ -// ImGui Renderer for: OpenGL3 (modern OpenGL with shaders / programmatic pipeline) +// ImGui Renderer for: OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) @@ -15,8 +15,9 @@ // You may use another any other loader/header of your choice, such as glew, glext, glad, glLoadGen, etc. // About GLSL version: -// The 'glsl_version' initialization parameter defaults to "#version 130" if NULL. -// Only override if your GL version doesn't handle this GLSL version (see table at the top of imgui_impl_opengl3.cpp). Keep NULL if unsure! +// The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. +// On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" +// Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); diff --git a/imgui.cpp b/imgui.cpp index e9da99da..a8b4dca3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13929,8 +13929,9 @@ void ImGui::EndDragDropTarget() //----------------------------------------------------------------------------- #if defined(_WIN32) && !defined(_WINDOWS_) && (!defined(IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS) || !defined(IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS)) -#undef WIN32_LEAN_AND_MEAN +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #ifndef __MINGW32__ #include #else From 9c0805010f268eb182728cf6c188cf628a9088a2 Mon Sep 17 00:00:00 2001 From: Ryan Crandall Date: Thu, 9 Aug 2018 08:44:29 -0700 Subject: [PATCH 13/17] imgui_impl_dx12: Cast to ImTextureID instead of void* to enable redefinition of ImTextureID (#2015, #301) --- examples/imgui_impl_dx12.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/imgui_impl_dx12.cpp b/examples/imgui_impl_dx12.cpp index af80c1de..a8b1c708 100644 --- a/examples/imgui_impl_dx12.cpp +++ b/examples/imgui_impl_dx12.cpp @@ -365,7 +365,7 @@ static void ImGui_ImplDX12_CreateFontsTexture() // Store our identifier static_assert(sizeof(ImTextureID) >= sizeof(g_hFontSrvGpuDescHandle.ptr), "Can't pack descriptor handle into TexID, 32-bit not supported yet."); - io.Fonts->TexID = (void *)g_hFontSrvGpuDescHandle.ptr; + io.Fonts->TexID = (ImTextureID)g_hFontSrvGpuDescHandle.ptr; } bool ImGui_ImplDX12_CreateDeviceObjects() From 421dc1979864b05d1d95f29deb3dadd947767d5d Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Aug 2018 17:49:48 +0200 Subject: [PATCH 14/17] Examples: Cast to ImTextureID instead of void* when assigning to TexId. Applied to all examples. (#2015) --- examples/imgui_impl_dx10.cpp | 5 +++-- examples/imgui_impl_dx11.cpp | 5 +++-- examples/imgui_impl_dx9.cpp | 5 +++-- examples/imgui_impl_marmalade.cpp | 2 +- examples/imgui_impl_metal.mm | 2 +- examples/imgui_impl_opengl2.cpp | 2 +- examples/imgui_impl_opengl3.cpp | 2 +- examples/imgui_impl_vulkan.cpp | 2 +- imgui.cpp | 4 ++-- misc/fonts/binary_to_compressed_c.cpp | 2 +- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/examples/imgui_impl_dx10.cpp b/examples/imgui_impl_dx10.cpp index d93f02eb..d0734efc 100644 --- a/examples/imgui_impl_dx10.cpp +++ b/examples/imgui_impl_dx10.cpp @@ -213,7 +213,8 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data) ctx->RSSetScissorRects(1, &r); // Bind texture, Draw - ctx->PSSetShaderResources(0, 1, (ID3D10ShaderResourceView**)&pcmd->TextureId); + ID3D10ShaderResourceView* texture_srv = (ID3D10ShaderResourceView*)pcmd->TextureId; + ctx->PSSetShaderResources(0, 1, &texture_srv); ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset); } idx_offset += pcmd->ElemCount; @@ -279,7 +280,7 @@ static void ImGui_ImplDX10_CreateFontsTexture() } // Store our identifier - io.Fonts->TexID = (void *)g_pFontTextureView; + io.Fonts->TexID = (ImTextureID)g_pFontTextureView; // Create texture sampler { diff --git a/examples/imgui_impl_dx11.cpp b/examples/imgui_impl_dx11.cpp index eda8ce47..2f6f5a79 100644 --- a/examples/imgui_impl_dx11.cpp +++ b/examples/imgui_impl_dx11.cpp @@ -218,7 +218,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data) ctx->RSSetScissorRects(1, &r); // Bind texture, Draw - ctx->PSSetShaderResources(0, 1, (ID3D11ShaderResourceView**)&pcmd->TextureId); + ID3D11ShaderResourceView* texture_srv = (ID3D11ShaderResourceView*)pcmd->TextureId; + ctx->PSSetShaderResources(0, 1, &texture_srv); ctx->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset); } idx_offset += pcmd->ElemCount; @@ -286,7 +287,7 @@ static void ImGui_ImplDX11_CreateFontsTexture() } // Store our identifier - io.Fonts->TexID = (void *)g_pFontTextureView; + io.Fonts->TexID = (ImTextureID)g_pFontTextureView; // Create texture sampler { diff --git a/examples/imgui_impl_dx9.cpp b/examples/imgui_impl_dx9.cpp index 9ee56db0..d5bbc280 100644 --- a/examples/imgui_impl_dx9.cpp +++ b/examples/imgui_impl_dx9.cpp @@ -177,7 +177,8 @@ void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data) else { const RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) }; - g_pd3dDevice->SetTexture(0, (LPDIRECT3DTEXTURE9)pcmd->TextureId); + const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->TextureId; + g_pd3dDevice->SetTexture(0, texture); g_pd3dDevice->SetScissorRect(&r); g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, idx_offset, pcmd->ElemCount/3); } @@ -228,7 +229,7 @@ static bool ImGui_ImplDX9_CreateFontsTexture() g_FontTexture->UnlockRect(0); // Store our identifier - io.Fonts->TexID = (void *)g_FontTexture; + io.Fonts->TexID = (ImTextureID)g_FontTexture; return true; } diff --git a/examples/imgui_impl_marmalade.cpp b/examples/imgui_impl_marmalade.cpp index 6d78a1a9..23ced8ff 100644 --- a/examples/imgui_impl_marmalade.cpp +++ b/examples/imgui_impl_marmalade.cpp @@ -190,7 +190,7 @@ bool ImGui_Marmalade_CreateDeviceObjects() g_FontTexture->Upload(); // Store our identifier - io.Fonts->TexID = (void *)g_FontTexture; + io.Fonts->TexID = (ImTextureID)g_FontTexture; return true; } diff --git a/examples/imgui_impl_metal.mm b/examples/imgui_impl_metal.mm index a4d235c9..678cd269 100644 --- a/examples/imgui_impl_metal.mm +++ b/examples/imgui_impl_metal.mm @@ -98,7 +98,7 @@ bool ImGui_ImplMetal_CreateFontsTexture(id device) [g_sharedMetalContext makeFontTextureWithDevice:device]; ImGuiIO& io = ImGui::GetIO(); - io.Fonts->TexID = (__bridge void *)g_sharedMetalContext.fontTexture; + io.Fonts->TexID = (__bridge void *)g_sharedMetalContext.fontTexture; // ImTextureID == void* return (g_sharedMetalContext.fontTexture != nil); } diff --git a/examples/imgui_impl_opengl2.cpp b/examples/imgui_impl_opengl2.cpp index c70d9fe6..3ff1cf72 100644 --- a/examples/imgui_impl_opengl2.cpp +++ b/examples/imgui_impl_opengl2.cpp @@ -182,7 +182,7 @@ bool ImGui_ImplOpenGL2_CreateFontsTexture() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Store our identifier - io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture; // Restore state glBindTexture(GL_TEXTURE_2D, last_texture); diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index c00f3c77..5f7095ca 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -279,7 +279,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture() glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); // Store our identifier - io.Fonts->TexID = (void *)(intptr_t)g_FontTexture; + io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontTexture; // Restore state glBindTexture(GL_TEXTURE_2D, last_texture); diff --git a/examples/imgui_impl_vulkan.cpp b/examples/imgui_impl_vulkan.cpp index 7d6f7499..9ec0a127 100644 --- a/examples/imgui_impl_vulkan.cpp +++ b/examples/imgui_impl_vulkan.cpp @@ -461,7 +461,7 @@ bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer) } // Store our identifier - io.Fonts->TexID = (void *)(intptr_t)g_FontImage; + io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontImage; return true; } diff --git a/imgui.cpp b/imgui.cpp index a8b4dca3..1f29a71a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1671,7 +1671,7 @@ void* ImFileLoadToMemory(const char* filename, const char* file_open_mode, size_ return NULL; } if (padding_bytes > 0) - memset((void *)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); + memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); fclose(f); if (out_file_size) @@ -8476,7 +8476,7 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I // Default to using texture ID as ID. User can still push string/integer prefixes. // We could hash the size/uv to create a unique ID but that would prevent the user from animating UV. - PushID((void *)user_texture_id); + PushID((void*)user_texture_id); const ImGuiID id = window->GetID("#image"); PopID(); diff --git a/misc/fonts/binary_to_compressed_c.cpp b/misc/fonts/binary_to_compressed_c.cpp index e373e69c..08b102d4 100644 --- a/misc/fonts/binary_to_compressed_c.cpp +++ b/misc/fonts/binary_to_compressed_c.cpp @@ -71,7 +71,7 @@ bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_b if (fseek(f, 0, SEEK_END) || (data_sz = (int)ftell(f)) == -1 || fseek(f, 0, SEEK_SET)) { fclose(f); return false; } char* data = new char[data_sz+4]; if (fread(data, 1, data_sz, f) != (size_t)data_sz) { fclose(f); delete[] data; return false; } - memset((void *)(((char*)data) + data_sz), 0, 4); + memset((void*)(((char*)data) + data_sz), 0, 4); fclose(f); // Compress From fda9dc8e182827bc979b7ebae42750bd4cfbd8b3 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Aug 2018 18:07:49 +0200 Subject: [PATCH 15/17] Internals: Extracted RenderMouseCursor() out of EndFrame(). Moved to imgui_draw.cpp along with RenderArrowPointingAt(). Comments. (#2013) --- imgui.cpp | 31 ++++--------------------------- imgui_draw.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- imgui_internal.h | 9 ++++++--- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1f29a71a..3fc94950 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4551,7 +4551,7 @@ void ImGui::Render() ImGui::EndFrame(); g.FrameCountRendered = g.FrameCount; - // Gather windows to render + // Gather ImDrawList to render (for each active window) g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsRenderWindows = 0; g.DrawDataBuilder.Clear(); ImGuiWindow* windows_to_render_front_most[2]; @@ -4569,19 +4569,9 @@ void ImGui::Render() g.DrawDataBuilder.FlattenIntoSingleLayer(); // Draw software mouse cursor if requested - ImVec2 offset, size, uv[4]; - if (g.IO.MouseDrawCursor && g.IO.Fonts->GetMouseCursorTexData(g.MouseCursor, &offset, &size, &uv[0], &uv[2])) - { - const ImVec2 pos = g.IO.MousePos - offset; - const ImTextureID tex_id = g.IO.Fonts->TexID; - const float sc = g.Style.MouseCursorScale; - g.OverlayDrawList.PushTextureID(tex_id); - g.OverlayDrawList.AddImage(tex_id, pos + ImVec2(1,0)*sc, pos+ImVec2(1,0)*sc + size*sc, uv[2], uv[3], IM_COL32(0,0,0,48)); // Shadow - g.OverlayDrawList.AddImage(tex_id, pos + ImVec2(2,0)*sc, pos+ImVec2(2,0)*sc + size*sc, uv[2], uv[3], IM_COL32(0,0,0,48)); // Shadow - g.OverlayDrawList.AddImage(tex_id, pos, pos + size*sc, uv[2], uv[3], IM_COL32(0,0,0,255)); // Black border - g.OverlayDrawList.AddImage(tex_id, pos, pos + size*sc, uv[0], uv[1], IM_COL32(255,255,255,255)); // White fill - g.OverlayDrawList.PopTextureID(); - } + if (g.IO.MouseDrawCursor) + RenderMouseCursor(&g.OverlayDrawList, g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor); + if (!g.OverlayDrawList.VtxBuffer.empty()) AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.OverlayDrawList); @@ -4787,19 +4777,6 @@ void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding) } } -// Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. -void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) -{ - switch (direction) - { - case ImGuiDir_Left: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), pos, col); return; - case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return; - case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return; - case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return; - case ImGuiDir_None: case ImGuiDir_COUNT: break; // Fix warnings - } -} - // Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state void ImGui::RenderArrow(ImVec2 p_min, ImGuiDir dir, float scale) { diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 2f45c9d7..073c1c8a 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -6,6 +6,7 @@ // - ImDrawList // - ImDrawData // - ImFontAtlas +// - Internal Render Helpers // - ImFont // - Default font data @@ -2786,8 +2787,51 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col } //----------------------------------------------------------------------------- -// Internals Drawing Helpers +// Internals Render Helpers +// (progressively moved from imgui.cpp to here when they are redesigned to stop accessing ImGui global state) //----------------------------------------------------------------------------- +// RenderMouseCursor() +// RenderArrowPointingAt() +// RenderRectFilledRangeH() +//----------------------------------------------------------------------------- + +void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor) +{ + if (mouse_cursor == ImGuiMouseCursor_None) + return; + IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); + + const ImU32 col_shadow = IM_COL32(0, 0, 0, 48); + const ImU32 col_border = IM_COL32(0, 0, 0, 255); // Black + const ImU32 col_fill = IM_COL32(255, 255, 255, 255); // White + + ImFontAtlas* font_atlas = draw_list->_Data->Font->ContainerAtlas; + ImVec2 offset, size, uv[4]; + if (font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) + { + pos -= offset; + const ImTextureID tex_id = font_atlas->TexID; + draw_list->PushTextureID(tex_id); + draw_list->AddImage(tex_id, pos + ImVec2(1,0)*scale, pos + ImVec2(1,0)*scale + size*scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos + ImVec2(2,0)*scale, pos + ImVec2(2,0)*scale + size*scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos, pos + size*scale, uv[2], uv[3], col_border); + draw_list->AddImage(tex_id, pos, pos + size*scale, uv[0], uv[1], col_fill); + draw_list->PopTextureID(); + } +} + +// Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. +void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) +{ + switch (direction) + { + case ImGuiDir_Left: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), pos, col); return; + case ImGuiDir_Right: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), pos, col); return; + case ImGuiDir_Up: draw_list->AddTriangleFilled(ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), pos, col); return; + case ImGuiDir_Down: draw_list->AddTriangleFilled(ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), pos, col); return; + case ImGuiDir_None: case ImGuiDir_COUNT: break; // Fix warnings + } +} static inline float ImAcos01(float x) { diff --git a/imgui_internal.h b/imgui_internal.h index adf45c39..d6dc79e2 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1166,7 +1166,7 @@ namespace ImGui // Render helpers // AVOID USING OUTSIDE OF IMGUI.CPP! NOT FOR PUBLIC CONSUMPTION. THOSE FUNCTIONS ARE A MESS. THEIR SIGNATURE AND BEHAVIOR WILL CHANGE, THEY NEED TO BE REFACTORED INTO SOMETHING DECENT. - // NB: All position are in absolute pixels coordinates (never using window coordinates internally) + // NB: All position are in absolute pixels coordinates (we are never using window coordinates internally) IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL); @@ -1174,13 +1174,16 @@ namespace ImGui IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); IMGUI_API void RenderArrow(ImVec2 pos, ImGuiDir dir, float scale = 1.0f); - IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderBullet(ImVec2 pos); IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col, float sz); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight - IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. + // Render helpers (those functions don't access any ImGui state!) + IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor = ImGuiMouseCursor_Arrow); + IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); + IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); + // Widgets IMGUI_API bool ButtonEx(const char* label, const ImVec2& size_arg = ImVec2(0,0), ImGuiButtonFlags flags = 0); IMGUI_API bool CloseButton(ImGuiID id, const ImVec2& pos, float radius); From d4cd121ae1a2a323f4f05082c63ed9d59d70ccd8 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 9 Aug 2018 21:03:17 +0200 Subject: [PATCH 16/17] TODO + added missing _None enum for some internals flags. --- TODO.txt | 41 ++++++++++++++++++++--------------------- imgui_internal.h | 3 +++ 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/TODO.txt b/TODO.txt index b8d15c01..b4c1de6e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -40,9 +40,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - drawlist: make it easier to toggle AA per primitive, so we can use e.g. non-AA fill + AA borders more naturally - drawlist: non-AA strokes have gaps between points (#593, #288), especially RenderCheckmark(). - drawlist: would be good to be able to deep copy of ImDrawData (we have a deep copy of ImDrawList now). - - drawlist/opt: AddRect() axis aligned pixel aligned (no-aa) could use 8 triangles instead of 16 and no normal calculation. - drawlist: rendering: provide a way for imgui to output to a single/global vertex buffer, re-order indices only at the end of the frame (ref: https://gist.github.com/floooh/10388a0afbe08fce9e617d8aefa7d302) - drawlist: callback: add an extra void* in ImDrawCallback to allow passing render-local data to the callback (would break API). + - drawlist/opt: store rounded corners in texture to use 1 quad per corner (filled and wireframe) to lower the cost of rounding. (#1962) + - drawlist/opt: AddRect() axis aligned pixel aligned (no-aa) could use 8 triangles instead of 16 and no normal calculation. - main: considering adding an Init() function? some constructs are awkward in the implementation because of the lack of them. - main: find a way to preserve relative orders of multiple reappearing windows (so an app toggling between "modes" e.g. fullscreen vs all tools) won't lose relative ordering. @@ -54,6 +55,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h. - widgets: add visuals for Disabled/ReadOnly mode and expose publicly (#211) - widgets: add always-allow-overlap mode. + - widgets: start exposing PushItemFlag() and ImGuiItemFlags - widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260 - widgets: activate by identifier (trigger button, focus given id) - widgets: a way to represent "mixed" values, so e.g. all values replaced with **, including check-boxes, colors, etc. with support for multi-components widgets (e.g. SliderFloat3, make only "Y" mixed) @@ -70,13 +72,13 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: easier ways to update buffer (from source char*) while owned. preserve some sort of cursor position for multi-line text. - input text: add discard flag (e.g. ImGuiInputTextFlags_DiscardActiveBuffer) or make it easier to clear active focus for text replacement during edition (#725) - input text: display bug when clicking a drag/slider after an input text in a different window has all-selected text (order dependent). actually a very old bug but no one appears to have noticed it. + - input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position. + - input text: what's the easiest way to implement a nice IP/Mac address input editor? - input text multi-line: don't directly call AddText() which does an unnecessary vertex reserve for character count prior to clipping. and/or more line-based clipping to AddText(). and/or reorganize TextUnformatted/RenderText for more efficiency for large text (e.g TextUnformatted could clip and log separately, etc). - input text multi-line: support for cut/paste without selection (cut/paste the current line) - input text multi-line: line numbers? status bar? (follow up on #200) - input text multi-line: behave better when user changes input buffer while editing is active (even though it is illegal behavior). namely, the change of buffer can create a scrollbar glitch (#725) - input text multi-line: better horizontal scrolling support (#383, #1224) - - input text: allow centering/positioning text so that ctrl+clicking Drag or Slider keeps the textual value at the same pixel position. - - input text: what's the easiest way to implement a nice IP/Mac address input editor? - input number: optional range min/max for Input*() functions - input number: holding [-]/[+] buttons could increase the step speed non-linearly (or user-controlled) - input number: use mouse wheel to step up/down @@ -104,7 +106,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i !- color: the color conversion helpers/types are a mess and needs sorting out. - color: (api breaking) ImGui::ColorConvertXXX functions should be loose ImColorConvertXX to match imgui_internals.h - - coloredit: it is still somehow awkward to copy colors around (unless going through Hex mode). - plot: full featured plot/graph api w/ scrolling, zooming etc. all bell & whistle. why not! - plot: PlotLines() should use the polygon-stroke facilities, less vertices (currently issues with averaging normals) @@ -126,17 +127,17 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tabs: re-ordering, close buttons, context menu, persistent order (#261, #351) - - ext: stl-ish friendly extension (imgui_stl.h) that has wrapped for std::string, std::vector etc. + - ext: stl-ish friendly extension (imgui_stl.h) that has wrapper for std::string, std::vector etc. - button: provide a button that looks framed. - image/image button: misalignment on padded/bordered button? - image/image button: parameters are confusing, image() has tint_col,border_col whereas imagebutton() has bg_col/tint_col. Even thou they are different parameters ordering could be more consistent. can we fix that? - image button: not taking an explicit id is odd. - slider: allow using the [-]/[+] buttons used by InputFloat()/InputInt() - - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). + - slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar). (#1946) - slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate. - slider: tint background based on value (e.g. v_min -> v_max, or use 0.0f either side of the sign) - - slider: precision dragging + - slider: relative dragging? + precision dragging - slider: step option (#1183) - slider style: fill % of the bar instead of positioning a drag. - knob: rotating knob widget (#942) @@ -168,12 +169,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed) (#1485) - menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207) - - menus: menu bars inside modals windows are acting weird. - - statusbar: add a per-window status bar helper similar to what menubar does. + - menus: menu bars inside modal windows are acting weird. + - status-bar: add a per-window status bar helper similar to what menu-bar does. - shortcuts: local-style shortcut api, e.g. parse "&Save" - shortcuts,menus: global-style shortcut api e.g. "Save (CTRL+S)" -> explicit flag for recursing into closed menu - shortcuts: programmatically access shortcuts "Focus("&Save")) - - menus: menubars: main menu-bar could affect clamping of windows position (~ akin to modifying DisplayMin) + - menus: menu-bar: main menu-bar could affect clamping of windows position (~ akin to modifying DisplayMin) - menus: hovering from menu to menu on a menu-bar has 1 frame without any menu, which is a little annoying. ideally either 0 either longer. - text: selectable text (for copy) as a generic feature (ItemFlags?) @@ -198,7 +199,6 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i !- style: better default styles. (#707) - style: add a highlighted text color (for headers, etc.) - style: border types: out-screen, in-screen, etc. (#447) - - style/optimization: store rounded corners in texture to use 1 quad per corner (filled and wireframe) to lower the cost of rounding. - style: add window shadow (fading away from the window. Paint-style calculation of vertices alpha after drawlist would be easier) - style: a concept of "compact style" that the end-user can easily rely on (e.g. PushStyleCompact()?) that maps to other settings? avoid implementing duplicate helpers such as SmallCheckbox(), etc. - style: try to make PushStyleVar() more robust to incorrect parameters (to be more friendly to edit & continues situation). @@ -214,15 +214,15 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - log: let user copy any window content to clipboard easily (CTRL+C on windows? while moving it? context menu?). code is commented because it fails with multiple Begin/End pairs. - filters: set a current filter that tree node can automatically query to hide themselves - - filters: handle wildcards (with implicit leading/trailing *), regexps + - filters: handle wild-cards (with implicit leading/trailing *), reg-exprs - filters: fuzzy matches (may use code at blog.forrestthewoods.com/4cffeed33fdb) - - drag and drop: add demo. (#143, #479) - - drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov + - drag and drop: have some way to know when a drag begin from BeginDragDropSource() pov. + - drag and drop: allow preview tooltip to be submitted from a different place than the drag source. (#1725) - drag and drop: allow using with other mouse buttons (where activeid won't be set). (#1637) - drag and drop: make it easier and provide a demo to have tooltip both are source and target site, with a more detailed one on target site (tooltip ordering problem) - drag and drop: test with reordering nodes (in a list, or a tree node). (#143) - - drag and drop: test integrating with os drag and drop. + - drag and drop: test integrating with os drag and drop (make it easy to do a naive WM_DROPFILE integration) - drag and drop: make payload optional? (#143) - node/graph editor (#306) - pie menus patterns (#434) @@ -251,15 +251,16 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - font: fix AddRemapChar() to work before font has been built. - font: (api breaking) removed "TTF" from symbol names. also because it now supports OTF. - - nav: wrap around logic to allow e.g. grid based layout (pressing NavRight on the right-most element would go to the next row, etc.) + - nav: wrap around logic to allow e.g. grid based layout (pressing NavRight on the right-most element would go to the next row, etc.). see internal's NavMoveRequestTryWrapping(). - nav: patterns to make it possible for arrows key to update selection + - nav: restore/find nearest navid when current one disappear (e.g. pressed a button that disappear, or perhaps auto restoring when current button change name) - nav: SetItemDefaultFocus() level of priority, so widget like Selectable when inside a popup could claim a low-priority default focus on the first selected iem - nav: allow input system to be be more tolerant of io.DeltaTime=0.0f - nav: ESC within a menu of a child window seems to exit the child window. - nav: NavFlattened: ESC on a flattened child should select something. - nav: NavFlattened: broken: in typical usage scenario, the items of a fully clipped child are currently not considered to enter into a NavFlattened child. - nav: NavFlattened: init request doesn't select items that are part of a NavFlattened child - - nav: NavFlattened: cannot access menubar of a flattened child window with Alt/menu key (not a very common use case..). + - nav: NavFlattened: cannot access menu-bar of a flattened child window with Alt/menu key (not a very common use case..). - nav: Left within a tree node block as a fallback (ImGuiTreeNodeFlags_NavLeftJumpsBackHere by default?) - nav: menus: pressing left-right on a vertically clipped menu bar tends to jump to the collapse/close buttons. - nav: menus: allow pressing Menu to leave a sub-menu. @@ -290,19 +291,17 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - backend: bgfx? https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 - web/emscriptem: refactor some examples to facilitate integration with emscripten main loop system. (#1713, #336) - - web/emscriptem: tweak OpenGL renderers to support OpenGL ES. (#1713, #336) - web/emscriptem: with refactored examples, we could provide a direct imgui_impl_emscripten platform layer (see eg. https://github.com/floooh/sokol-samples/blob/master/html5/imgui-emsc.cc#L42) - remote: make a system like RemoteImGui first-class citizen/project (#75) - demo: find a way to demonstrate textures in the examples application, as it such a a common issue for new users. - - demo: add drag and drop demo. - demo: add vertical separator demo - demo: add virtual scrolling example? - demo: demonstration Plot offset - examples: window minimize, maximize (#583) - - examples: provide a zero-framerate/idle example. - - examples: apple: apple_example should be using modern GL3. + - examples: provide a zero frame-rate/idle example. + - examples: apple: example_apple should be using modern GL3. - examples: glfw: could go idle when minimized? if (glfwGetWindowAttrib(window, GLFW_ICONIFIED)) { glfwWaitEvents(); continue; } // issue: DeltaTime will be super high on resume, perhaps provide a way to let impl know (#440) - optimization: replace vsnprintf with stb_printf? or enable the defines/infrastructure to allow it (#1038) - optimization: add clipping for multi-component widgets (SliderFloatX, ColorEditX, etc.). one problem is that nav branch can't easily clip parent group when there is a move request. diff --git a/imgui_internal.h b/imgui_internal.h index d6dc79e2..74aef002 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -313,6 +313,7 @@ enum ImGuiInputReadMode enum ImGuiNavHighlightFlags_ { + ImGuiNavHighlightFlags_None = 0, ImGuiNavHighlightFlags_TypeDefault = 1 << 0, ImGuiNavHighlightFlags_TypeThin = 1 << 1, ImGuiNavHighlightFlags_AlwaysDraw = 1 << 2, @@ -321,6 +322,7 @@ enum ImGuiNavHighlightFlags_ enum ImGuiNavDirSourceFlags_ { + ImGuiNavDirSourceFlags_None = 0, ImGuiNavDirSourceFlags_Keyboard = 1 << 0, ImGuiNavDirSourceFlags_PadDPad = 1 << 1, ImGuiNavDirSourceFlags_PadLStick = 1 << 2 @@ -328,6 +330,7 @@ enum ImGuiNavDirSourceFlags_ enum ImGuiNavMoveFlags_ { + ImGuiNavMoveFlags_None = 0, ImGuiNavMoveFlags_LoopX = 1 << 0, // On failed request, restart from opposite side ImGuiNavMoveFlags_LoopY = 1 << 1, ImGuiNavMoveFlags_WrapX = 1 << 2, // On failed request, request from opposite side one line down (when NavDir==right) or one line up (when NavDir==left) From caaa746424e6a338cf00fbfbb8b5e9a8817c75c4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 13 Aug 2018 17:29:20 -0700 Subject: [PATCH 17/17] Nav: NavWindowingList doesn't save to .ini file. TODO entries. --- TODO.txt | 5 ++++- imgui.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/TODO.txt b/TODO.txt index b4c1de6e..23049480 100644 --- a/TODO.txt +++ b/TODO.txt @@ -32,6 +32,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - window: investigate better auto-positioning for new windows. - scrolling: allow immediately effective change of scroll after Begin() if we haven't appended items yet. - scrolling/clipping: separator on the initial position of a window is not visible (cursorpos.y <= clippos.y). (2017-08-20: can't repro) + - scrolling/style: shadows on scrollable areas to denote that there is more contents - drawdata: make it easy to clone (or swap?) a ImDrawData so user can easily save that data if they use threaded rendering. - drawlist: end-user probably can't call Clear() directly because we expect a texture to be pushed in the stack. @@ -158,6 +159,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - listbox: scrolling should track modified selection. !- popups/menus: clarify usage of popups id, how MenuItem/Selectable closing parent popups affects the ID, etc. this is quite fishy needs improvement! (#331, #402) + - popups/modal: make modal title bar blink when trying to click outside the modal - popups: reopening context menu at new position should be the behavior by default? (equivalent to internal OpenPopupEx() with reopen_existing=true) (~#1497) - popups: if the popup functions took explicit ImGuiID it would allow the user to manage the scope of those ID. (#331) - popups: clicking outside (to close popup) and holding shouldn't drag window below. @@ -166,7 +168,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - tooltip: drag and drop with tooltip near monitor edges lose/changes its last direction instead of locking one. The drag and drop tooltip should always follow without changing direction. - tooltip: tooltip that doesn't fit in entire screen seems to lose their "last preferred direction" and may teleport when moving mouse. - tooltip: allow to set the width of a tooltip to allow TextWrapped() etc. while keeping the height automatic. - - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed) (#1485) + - tooltip: tooltips with delay timers? or general timer policy? (instantaneous vs timed): IsItemHovered() with timer + implicit aabb-id for items with no ID. (#1485) - menus: calling BeginMenu() twice with a same name doesn't append as Begin() does for regular windows (#1207) - menus: menu bars inside modal windows are acting weird. @@ -224,6 +226,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - drag and drop: test with reordering nodes (in a list, or a tree node). (#143) - drag and drop: test integrating with os drag and drop (make it easy to do a naive WM_DROPFILE integration) - drag and drop: make payload optional? (#143) + - drag and drop: feedback when hovering a modal (cursor?) - node/graph editor (#306) - pie menus patterns (#434) - markup: simple markup language for color change? (#902) diff --git a/imgui.cpp b/imgui.cpp index 3fc94950..885c79e3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3250,7 +3250,7 @@ void ImGui::NavUpdateWindowingList() SetNextWindowSizeConstraints(ImVec2(g.IO.DisplaySize.x * 0.20f, g.IO.DisplaySize.y * 0.20f), ImVec2(FLT_MAX, FLT_MAX)); SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Always, ImVec2(0.5f, 0.5f)); PushStyleVar(ImGuiStyleVar_WindowPadding, g.Style.WindowPadding * 2.0f); - Begin("###NavWindowingList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize); + Begin("###NavWindowingList", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings); for (int n = g.Windows.Size - 1; n >= 0; n--) { ImGuiWindow* window = g.Windows[n];