From e9b92d1cef0cea3e3d5520e03333efd8325e32c3 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 17 Jun 2019 11:32:00 +0200 Subject: [PATCH 1/8] Disable -Wpragmas warning in GCC to avoid relying on version checks, as unusual/forks/mods don't appear to always have same warning<>version. (#2618) + Fix version number in imgui.h --- imgui.cpp | 6 +++--- imgui.h | 9 +++++---- imgui_demo.cpp | 5 ++--- imgui_draw.cpp | 5 ++--- imgui_internal.h | 5 ++--- imgui_widgets.cpp | 5 ++--- misc/freetype/imgui_freetype.cpp | 1 + 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a56500a3..8eb37670 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1020,6 +1020,8 @@ CODE #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. #endif #elif defined(__GNUC__) +// We disable -Wpragmas because GCC doesn't provide an has_warning equivalent and some forks/patches may not following the warning/version association. +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size #pragma GCC diagnostic ignored "-Wformat" // warning: format '%p' expects argument of type 'void*', but argument 6 has type 'ImGuiWindow*' @@ -1027,9 +1029,7 @@ CODE #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked #pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when assuming that (X - c) > X is always false -#if __GNUC__ >= 8 -#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead -#endif +#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #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. diff --git a/imgui.h b/imgui.h index 769d2786..8131ac36 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.71 WIP +// dear imgui, v1.72 WIP // (headers) // See imgui.cpp file for documentation. @@ -83,9 +83,10 @@ Index of this file: #if __has_warning("-Wzero-as-null-pointer-constant") #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" #endif -#elif defined(__GNUC__) && __GNUC__ >= 8 +#elif defined(__GNUC__) #pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wclass-memaccess" +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind +#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif //----------------------------------------------------------------------------- @@ -2201,7 +2202,7 @@ struct ImFont #if defined(__clang__) #pragma clang diagnostic pop -#elif defined(__GNUC__) && __GNUC__ >= 8 +#elif defined(__GNUC__) #pragma GCC diagnostic pop #endif diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 30dd5acb..e4b89499 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -89,13 +89,12 @@ Index of this file: #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning : macro name is a reserved identifier // #endif #elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wint-to-pointer-cast" // warning: cast to pointer from integer of different size #pragma GCC diagnostic ignored "-Wformat-security" // warning : format string is not a string literal (potentially insecure) #pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value -#if (__GNUC__ >= 6) -#pragma GCC diagnostic ignored "-Wmisleading-indentation" // warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub. -#endif +#pragma GCC diagnostic ignored "-Wmisleading-indentation" // [__GNUC__ >= 6] warning: this 'if' clause does not guard this statement // GCC 6.0+ only. See #883 on GitHub. #endif // Play it nice with Windows users. Notepad in 2017 still doesn't display text data with Unix-style \n. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 478819cc..288d95ae 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -72,13 +72,12 @@ Index of this file: #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. #endif #elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used #pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value #pragma GCC diagnostic ignored "-Wstack-protector" // warning: stack protector not protecting local variables: variable length buffer -#if __GNUC__ >= 8 -#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead -#endif +#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif //------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 60787bcb..81f9bf9a 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -56,9 +56,8 @@ Index of this file: #endif #elif defined(__GNUC__) #pragma GCC diagnostic push -#if __GNUC__ >= 8 -#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead -#endif +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind +#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif //----------------------------------------------------------------------------- diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 03882993..3490586b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -63,10 +63,9 @@ Index of this file: #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. #endif #elif defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked -#if __GNUC__ >= 8 -#pragma GCC diagnostic ignored "-Wclass-memaccess" // warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead -#endif +#pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead #endif //------------------------------------------------------------------------- diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index a184d78b..d0d2580d 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -36,6 +36,7 @@ #endif #if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used #endif From ae2c9f71014727b8f80f74adfc18e701fe173403 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 10 Jun 2019 21:43:05 +0200 Subject: [PATCH 2/8] Internals: Columns: Poke into WorkRect and use them in the GetContentRegionMax() functions. This should be a no-op, but preparing us to transition toward using WorkRect instead of ContentRegionRect. Removed one use of ContentsRegionRect. --- imgui.cpp | 35 ++++++++++++++++++++++++----------- imgui_internal.h | 3 ++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 8eb37670..11bd76ea 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2249,8 +2249,8 @@ static void SetCursorPosYAndSetupDummyPrevLine(float pos_y, float line_height) ImGuiWindow* window = ImGui::GetCurrentWindow(); window->DC.CursorPosPrevLine.y = window->DC.CursorPos.y - line_height; // Setting those fields so that SetScrollHereY() can properly function after the end of our clipper usage. window->DC.PrevLineSize.y = (line_height - GImGui->Style.ItemSpacing.y); // If we end up needing more accurate data (to e.g. use SameLine) we may as well make the clipper have a fourth step to let user process and display the last item in their list. - if (window->DC.CurrentColumns) - window->DC.CurrentColumns->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly + if (ImGuiColumns* columns = window->DC.CurrentColumns) + columns->LineMinY = window->DC.CursorPos.y; // Setting this so that cell Y position are set properly } // Use case A: Begin() called from constructor with items_height<0, then called again from Sync() in StepNo 1 @@ -3423,7 +3423,7 @@ void ImGui::UpdateMouseWheel() const bool scroll_allowed = !(window->Flags & ImGuiWindowFlags_NoScrollWithMouse) && !(window->Flags & ImGuiWindowFlags_NoMouseInputs); if (scroll_allowed && (g.IO.MouseWheel != 0.0f || g.IO.MouseWheelH != 0.0f) && !g.IO.KeyCtrl) { - ImVec2 max_step = (window->ContentsRegionRect.GetSize() + window->WindowPadding * 2.0f) * 0.67f; + ImVec2 max_step = window->InnerRect.GetSize() * 0.67f; // Vertical Mouse Wheel Scrolling (hold Shift to scroll horizontally) if (g.IO.MouseWheel != 0.0f && !g.IO.KeyShift) @@ -5872,7 +5872,7 @@ void ImGui::End() ImGuiWindow* window = g.CurrentWindow; - if (window->DC.CurrentColumns != NULL) + if (window->DC.CurrentColumns) EndColumns(); PopClipRect(); // Inner window clip rectangle @@ -6649,7 +6649,7 @@ ImVec2 ImGui::GetContentRegionMax() ImGuiWindow* window = GImGui->CurrentWindow; ImVec2 mx = window->ContentsRegionRect.Max - window->Pos; if (window->DC.CurrentColumns) - mx.x = GetColumnOffset(window->DC.CurrentColumns->Current + 1) - window->WindowPadding.x; + mx.x = window->WorkRect.Max.x - window->Pos.x; return mx; } @@ -6659,7 +6659,7 @@ ImVec2 ImGui::GetContentRegionMaxAbs() ImGuiWindow* window = GImGui->CurrentWindow; ImVec2 mx = window->ContentsRegionRect.Max; if (window->DC.CurrentColumns) - mx.x = window->Pos.x + GetColumnOffset(window->DC.CurrentColumns->Current + 1) - window->WindowPadding.x; + mx.x = window->WorkRect.Max.x; return mx; } @@ -6672,19 +6672,19 @@ ImVec2 ImGui::GetContentRegionAvail() // In window space (not screen space!) ImVec2 ImGui::GetWindowContentRegionMin() { - ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiWindow* window = GImGui->CurrentWindow; return window->ContentsRegionRect.Min - window->Pos; } ImVec2 ImGui::GetWindowContentRegionMax() { - ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiWindow* window = GImGui->CurrentWindow; return window->ContentsRegionRect.Max - window->Pos; } float ImGui::GetWindowContentRegionWidth() { - ImGuiWindow* window = GetCurrentWindowRead(); + ImGuiWindow* window = GImGui->CurrentWindow; return window->ContentsRegionRect.GetWidth(); } @@ -8655,7 +8655,13 @@ void ImGui::NextColumn() window->DC.CurrLineTextBaseOffset = 0.0f; PushColumnClipRect(columns->Current); // FIXME-COLUMNS: Could it be an overwrite? - PushItemWidth(GetColumnWidth() * 0.65f); // FIXME-COLUMNS: Move on columns setup + + // FIXME-COLUMNS: Share code with BeginColumns() - move code on columns setup. + float offset_0 = GetColumnOffset(columns->Current); + float offset_1 = GetColumnOffset(columns->Current + 1); + float width = offset_1 - offset_0; + PushItemWidth(width * 0.65f); + window->WorkRect.Max.x = window->Pos.x + offset_1 - window->WindowPadding.x; } int ImGui::GetColumnIndex() @@ -8851,6 +8857,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag columns->HostCursorPosY = window->DC.CursorPos.y; columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; columns->HostClipRect = window->ClipRect; + columns->HostWorkRect = window->WorkRect; columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y; window->DC.ColumnsOffset.x = 0.0f; window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); @@ -8888,7 +8895,12 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag window->DrawList->ChannelsSetCurrent(1); PushColumnClipRect(0); } - PushItemWidth(GetColumnWidth() * 0.65f); + + float offset_0 = GetColumnOffset(columns->Current); + float offset_1 = GetColumnOffset(columns->Current + 1); + float width = offset_1 - offset_0; + PushItemWidth(width * 0.65f); + window->WorkRect.Max.x = window->Pos.x + offset_1 - window->WindowPadding.x; } void ImGui::EndColumns() @@ -8960,6 +8972,7 @@ void ImGui::EndColumns() } columns->IsBeingResized = is_being_resized; + window->WorkRect = columns->HostWorkRect; window->DC.CurrentColumns = NULL; window->DC.ColumnsOffset.x = 0.0f; window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); diff --git a/imgui_internal.h b/imgui_internal.h index 81f9bf9a..599f360f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -703,6 +703,7 @@ struct ImGuiColumns float HostCursorPosY; // Backup of CursorPos at the time of BeginColumns() float HostCursorMaxPosX; // Backup of CursorMaxPos at the time of BeginColumns() ImRect HostClipRect; // Backup of ClipRect at the time of BeginColumns() + ImRect HostWorkRect; // Backup of WorkRect at the time of BeginColumns() ImVector Columns; ImGuiColumns() { Clear(); } @@ -1298,7 +1299,7 @@ struct IMGUI_API ImGuiWindow // The best way to understand what those rectangles are is to use the 'Metrics -> Tools -> Show windows rectangles' viewer. // The main 'OuterRect', omitted as a field, is window->Rect(). ImRect OuterRectClipped; // == Window->Rect() just after setup in Begin(). == window->Rect() for root window. - ImRect InnerRect; // Inner rectangle (omit title bar, menu bar) + ImRect InnerRect; // Inner rectangle (omit title bar, menu bar, scroll bar) ImRect InnerClipRect; // == InnerRect shrunk by WindowPadding*0.5f on each side, clipped within viewport or parent clip rect. ImRect WorkRect; // Cover the whole scrolling region, shrunk by WindowPadding*1.0f on each side. This is meant to replace ContentsRegionRect over time (from 1.71+ onward). ImRect ClipRect; // Current clipping/scissoring rectangle, evolve as we are using PushClipRect(), etc. == DrawList->clip_rect_stack.back(). From 0e37eaff8ae78ca1508e3a7da7217aac30cb349e Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Mon, 17 Jun 2019 15:17:24 +0200 Subject: [PATCH 3/8] Updated Ogre bindings (#2619) And support python --- docs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5987c79a..241eaadd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -127,7 +127,7 @@ Languages: (third-party bindings) - Odin: [odin-dear_imgui](https://github.com/ThisDrunkDane/odin-dear_imgui) - Pascal: [imgui-pas](https://github.com/dpethes/imgui-pas) - PureBasic: [pb-cimgui](https://github.com/hippyau/pb-cimgui) -- Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy) +- Python: [pyimgui](https://github.com/swistakm/pyimgui) or [bimpy](https://github.com/podgorskiy/bimpy) or [ogre-imgui](https://github.com/OGRECave/ogre-imgui) - Ruby: [ruby-imgui](https://github.com/vaiorabbit/ruby-imgui) - Rust: [imgui-rs](https://github.com/Gekkio/imgui-rs) or [imgui-rust](https://github.com/nsf/imgui-rust) - Swift [swift-imgui](https://github.com/mnmly/Swift-imgui) @@ -142,7 +142,7 @@ Frameworks: - Flexium: [FlexGUI](https://github.com/DXsmiley/FlexGUI) - GML/GameMakerStudio2: [ImGuiGML](https://marketplace.yoyogames.com/assets/6221/imguigml) - Irrlicht: [IrrIMGUI](https://github.com/ZahlGraf/IrrIMGUI) -- Ogre: [ogreimgui](https://bitbucket.org/LMCrashy/ogreimgui/src) +- Ogre: [ogre-imgui](https://github.com/OGRECave/ogre-imgui) - OpenFrameworks: [ofxImGui](https://github.com/jvcleave/ofxImGui) - OpenSceneGraph/OSG: [gist](https://gist.github.com/fulezi/d2442ca7626bf270226014501357042c) - ORX: [ImGuiOrx](https://github.com/thegwydd/ImGuiOrx), [#1843](https://github.com/ocornut/imgui/pull/1843) From 342751c89e461530c4a0d3136c87cb80e10bd38e Mon Sep 17 00:00:00 2001 From: Vincent Hamm Date: Tue, 18 Jun 2019 01:55:33 -0700 Subject: [PATCH 4/8] Fiedx OpenGL ES 3.0 include for iOS and tvOS (#2631) --- examples/imgui_impl_opengl3.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_opengl3.cpp b/examples/imgui_impl_opengl3.cpp index 2bf4ea85..9585215c 100644 --- a/examples/imgui_impl_opengl3.cpp +++ b/examples/imgui_impl_opengl3.cpp @@ -77,7 +77,7 @@ // Auto-detect GL version #if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) -#if (defined(__APPLE__) && TARGET_OS_IOS) || (defined(__ANDROID__)) +#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" #elif defined(__EMSCRIPTEN__) #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" @@ -87,7 +87,11 @@ #if defined(IMGUI_IMPL_OPENGL_ES2) #include #elif defined(IMGUI_IMPL_OPENGL_ES3) +#if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) +#include // Use GL ES 3 +#else #include // Use GL ES 3 +#endif #else // About Desktop OpenGL function loaders: // Modern desktop OpenGL doesn't have a standard portable header file to load OpenGL function pointers. From 70fe409338b00940d8c811494a0e993875fbc4f8 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 17 Jun 2019 17:03:54 +0200 Subject: [PATCH 5/8] Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71). --- docs/CHANGELOG.txt | 1 + imgui.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6ee2083a..d19dc530 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -42,6 +42,7 @@ Breaking Changes: the new names and equivalent. Other Changes: +- Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71). - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] - ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between channel 0 and 1. (#2624) diff --git a/imgui.cpp b/imgui.cpp index 11bd76ea..53289533 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5618,7 +5618,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) float top_border_size = (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize); window->InnerClipRect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(ImFloor(window->WindowPadding.x * 0.5f), window->WindowBorderSize)); window->InnerClipRect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y + top_border_size); - window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(ImFloor(window->WindowPadding.y * 0.5f), window->WindowBorderSize)); + window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(ImFloor(window->WindowPadding.x * 0.5f), window->WindowBorderSize)); window->InnerClipRect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y - window->WindowBorderSize); window->InnerClipRect.ClipWithFull(host_rect); From cc4d76cc239fbb3f2da8b1e00200a72470ef1ded Mon Sep 17 00:00:00 2001 From: Vincent Hamm Date: Sun, 16 Jun 2019 16:11:32 -0700 Subject: [PATCH 6/8] Implement SDL/dx11 sample --- .../example_sdl_directx11.vcxproj | 171 ++++++++++++++ .../example_sdl_directx11.vcxproj.filters | 57 +++++ examples/example_sdl_directx11/main.cpp | 220 ++++++++++++++++++ examples/imgui_impl_sdl.cpp | 8 + examples/imgui_impl_sdl.h | 1 + 5 files changed, 457 insertions(+) create mode 100644 examples/example_sdl_directx11/example_sdl_directx11.vcxproj create mode 100644 examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters create mode 100644 examples/example_sdl_directx11/main.cpp diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj new file mode 100644 index 00000000..ce1c5749 --- /dev/null +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj @@ -0,0 +1,171 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9E1987E3-1F19-45CA-B9C9-D31E791836D8} + example_win32_directx11 + 8.1 + example_sdl_directx11 + + + + Application + true + Unicode + v140 + + + Application + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + Application + false + true + Unicode + v140 + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level4 + Disabled + ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + + + true + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 + Console + + + + + Level4 + Disabled + ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + + + true + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + false + + + true + true + true + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 + Console + + + + + Level4 + MaxSpeed + true + true + ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + false + + + true + true + true + SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) + $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 + Console + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters new file mode 100644 index 00000000..b2345067 --- /dev/null +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj.filters @@ -0,0 +1,57 @@ + + + + + {0587d7a3-f2ce-4d56-b84f-a0005d3bfce6} + + + {08e36723-ce4f-4cff-9662-c40801cf1acf} + + + + + imgui + + + imgui + + + imgui + + + sources + + + sources + + + + + imgui + + + sources + + + imgui + + + imgui + + + sources + + + imgui + + + sources + + + + + + sources + + + \ No newline at end of file diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp new file mode 100644 index 00000000..bf470d78 --- /dev/null +++ b/examples/example_sdl_directx11/main.cpp @@ -0,0 +1,220 @@ +// dear imgui: standalone example application for SDL2 + OpenGL +// If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. +// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) + +#include "imgui.h" +#include "imgui_impl_sdl.h" +#include "imgui_impl_dx11.h" +#include +#include +#include +#include + +// Data +static ID3D11Device* g_pd3dDevice = NULL; +static ID3D11DeviceContext* g_pd3dDeviceContext = NULL; +static IDXGISwapChain* g_pSwapChain = NULL; +static ID3D11RenderTargetView* g_mainRenderTargetView = NULL; + +// Forward declarations of helper functions +bool CreateDeviceD3D(HWND hWnd); +void CleanupDeviceD3D(); +void CreateRenderTarget(); +void CleanupRenderTarget(); + +int main(int, char**) +{ + // Setup SDL + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) + { + printf("Error: %s\n", SDL_GetError()); + return -1; + } + + // Create window with graphics context + SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); + SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+DirectX11 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); + + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); + + HWND hwnd = (HWND)wmInfo.info.win.window; + + // Initialize Direct3D + if (!CreateDeviceD3D(hwnd)) + { + CleanupDeviceD3D(); + return 1; + } + + // Setup Dear ImGui context + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); (void)io; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + //io.ConfigViewportsNoAutoMerge = true; + //io.ConfigViewportsNoTaskBarIcon = true; + + // Setup Dear ImGui style + ImGui::StyleColorsDark(); + //ImGui::StyleColorsClassic(); + + // Setup Platform/Renderer bindings + ImGui_ImplSDL2_InitForD3D(window); + ImGui_ImplDX11_Init(g_pd3dDevice, g_pd3dDeviceContext); + + // Load Fonts + // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. + // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. + // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). + // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. + // - Read 'misc/fonts/README.txt' for more instructions and details. + // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! + //io.Fonts->AddFontDefault(); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); + //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); + //IM_ASSERT(font != NULL); + + bool show_demo_window = true; + bool show_another_window = false; + ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); + + // Main loop + bool done = false; + while (!done) + { + // Poll and handle events (inputs, window resize, etc.) + // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. + // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. + // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. + // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. + SDL_Event event; + while (SDL_PollEvent(&event)) + { + ImGui_ImplSDL2_ProcessEvent(&event); + if (event.type == SDL_QUIT) + done = true; + if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window)) + done = true; + } + + // Start the Dear ImGui frame + ImGui_ImplDX11_NewFrame(); + ImGui_ImplSDL2_NewFrame(window); + ImGui::NewFrame(); + + // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). + if (show_demo_window) + ImGui::ShowDemoWindow(&show_demo_window); + + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. + { + static float f = 0.0f; + static int counter = 0; + + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. + + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) + ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state + ImGui::Checkbox("Another Window", &show_another_window); + + 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 + + if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) + counter++; + ImGui::SameLine(); + ImGui::Text("counter = %d", counter); + + ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); + ImGui::End(); + } + + // 3. Show another simple window. + if (show_another_window) + { + ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) + ImGui::Text("Hello from another window!"); + if (ImGui::Button("Close Me")) + show_another_window = false; + ImGui::End(); + } + + // Rendering + ImGui::Render(); + g_pd3dDeviceContext->OMSetRenderTargets(1, &g_mainRenderTargetView, NULL); + g_pd3dDeviceContext->ClearRenderTargetView(g_mainRenderTargetView, (float*)&clear_color); + ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); + + g_pSwapChain->Present(1, 0); // Present with vsync + //g_pSwapChain->Present(0, 0); // Present without vsync + } + + // Cleanup + ImGui_ImplDX11_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + + CleanupDeviceD3D(); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} + +// Helper functions +bool CreateDeviceD3D(HWND hWnd) +{ + // Setup swap chain + DXGI_SWAP_CHAIN_DESC sd; + ZeroMemory(&sd, sizeof(sd)); + sd.BufferCount = 2; + sd.BufferDesc.Width = 0; + sd.BufferDesc.Height = 0; + sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + sd.BufferDesc.RefreshRate.Numerator = 60; + sd.BufferDesc.RefreshRate.Denominator = 1; + sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + sd.OutputWindow = hWnd; + sd.SampleDesc.Count = 1; + sd.SampleDesc.Quality = 0; + sd.Windowed = TRUE; + sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + + UINT createDeviceFlags = 0; + //createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; + D3D_FEATURE_LEVEL featureLevel; + const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, }; + if (D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &featureLevel, &g_pd3dDeviceContext) != S_OK) + return false; + + CreateRenderTarget(); + return true; +} + +void CleanupDeviceD3D() +{ + CleanupRenderTarget(); + if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; } + if (g_pd3dDeviceContext) { g_pd3dDeviceContext->Release(); g_pd3dDeviceContext = NULL; } + if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } +} + +void CreateRenderTarget() +{ + ID3D11Texture2D* pBackBuffer; + g_pSwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer)); + g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_mainRenderTargetView); + pBackBuffer->Release(); +} + +void CleanupRenderTarget() +{ + if (g_mainRenderTargetView) { g_mainRenderTargetView->Release(); g_mainRenderTargetView = NULL; } +} diff --git a/examples/imgui_impl_sdl.cpp b/examples/imgui_impl_sdl.cpp index 1922068e..0cf937a4 100644 --- a/examples/imgui_impl_sdl.cpp +++ b/examples/imgui_impl_sdl.cpp @@ -190,6 +190,14 @@ bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window) return ImGui_ImplSDL2_Init(window); } +bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window) +{ +#if !defined(_WIN32) + IM_ASSERT(0 && "Unsupported"); +#endif + return ImGui_ImplSDL2_Init(window); +} + void ImGui_ImplSDL2_Shutdown() { g_Window = NULL; diff --git a/examples/imgui_impl_sdl.h b/examples/imgui_impl_sdl.h index 39cc98e5..376e622c 100644 --- a/examples/imgui_impl_sdl.h +++ b/examples/imgui_impl_sdl.h @@ -21,6 +21,7 @@ typedef union SDL_Event SDL_Event; IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); +IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window); IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); From 516c3dee802d67c87487572a2d44d8e2d285efd6 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 18 Jun 2019 11:28:26 +0200 Subject: [PATCH 7/8] Examples: SDL+DX11: Changelog, readme, batch files, fixed vcxproj, minor stylistic fixes + minor sync of other main.cpp files. (#2632) --- docs/CHANGELOG.txt | 6 +- examples/README.txt | 7 +++ examples/example_glfw_metal/main.mm | 1 + examples/example_glfw_opengl2/main.cpp | 1 + examples/example_glfw_opengl3/main.cpp | 1 + examples/example_glfw_vulkan/main.cpp | 1 + examples/example_glut_opengl2/main.cpp | 2 + examples/example_marmalade/main.cpp | 1 + .../example_sdl_directx11/build_win32.bat | 8 +++ .../example_sdl_directx11.vcxproj | 58 +++++++++++-------- examples/example_sdl_directx11/main.cpp | 19 +++--- examples/example_sdl_opengl2/main.cpp | 2 + examples/example_sdl_opengl3/main.cpp | 2 + examples/example_sdl_vulkan/main.cpp | 4 +- examples/example_win32_directx11/main.cpp | 1 + 15 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 examples/example_sdl_directx11/build_win32.bat diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d19dc530..f575242f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,7 +44,11 @@ Breaking Changes: Other Changes: - Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71). - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] -- ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between channel 0 and 1. (#2624) +- ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between + channel 0 and 1. (#2624) +- Backends: SDL2: Added dummy ImGui_ImplSDL2_InitForD3D() function to make D3D support more visible. + (#2482, #2632) [@josiahmanson] +- Examples: Added SDL2+DirectX11 example application. (#2632, #2612, #2482) [@vincenthamm] ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index 116ef6b5..5028583b 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -201,6 +201,7 @@ example_glfw_vulkan/ GLFW (Win32, Mac, Linux) + Vulkan example. = main.cpp + imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp This is quite long and tedious, because: Vulkan. + For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp. example_glut_opengl2/ GLUT (e.g., FreeGLUT on Linux/Windows, GLUT framework on OSX) + OpenGL2. @@ -217,6 +218,11 @@ example_null This is used to quickly test compilation of core imgui files in as many setups as possible. Because this application doesn't create a window nor a graphic context, there's no graphics output. +example_sdl_directx11/ + SDL2 + DirectX11 example, Windows only. + = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp + This to demonstrate usage of DirectX with SDL. + example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp @@ -240,6 +246,7 @@ example_sdl_vulkan/ SDL2 (Win32, Mac, Linux, etc.) + Vulkan example. = main.cpp + imgui_impl_sdl.cpp + imgui_impl_vulkan.cpp This is quite long and tedious, because: Vulkan. + For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp. example_win32_directx9/ DirectX9 example, Windows only. diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 3b162afb..3a25a9de 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -74,6 +74,7 @@ int main(int, char**) MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor new]; + // Our state bool show_demo_window = true; bool show_another_window = false; float clear_color[4] = {0.45f, 0.55f, 0.60f, 1.00f}; diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 57841ffa..0a7aa3c3 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -69,6 +69,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index dffd46c9..76174a1f 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -112,6 +112,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index 2d1c4e00..fc3c1efb 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -440,6 +440,7 @@ int main(int, char**) ImGui_ImplVulkan_DestroyFontUploadObjects(); } + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 764ea092..75e48ca2 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -18,6 +18,7 @@ #pragma warning (disable: 4505) // unreferenced local function has been removed #endif +// Our state static bool show_demo_window = true; static bool show_another_window = false; static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -105,6 +106,7 @@ int main(int argc, char** argv) glutDisplayFunc(glut_display_func); // Setup Dear ImGui context + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls diff --git a/examples/example_marmalade/main.cpp b/examples/example_marmalade/main.cpp index e844a4c9..27a4acd9 100644 --- a/examples/example_marmalade/main.cpp +++ b/examples/example_marmalade/main.cpp @@ -44,6 +44,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_directx11/build_win32.bat b/examples/example_sdl_directx11/build_win32.bat new file mode 100644 index 00000000..8fc702bb --- /dev/null +++ b/examples/example_sdl_directx11/build_win32.bat @@ -0,0 +1,8 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +set OUT_DIR=Debug +set OUT_EXE=example_sdl_directx11 +set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" +set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_dx11.cpp ..\..\imgui*.cpp +set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib +mkdir %OUT_DIR% +cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj index ce1c5749..e28a5d25 100644 --- a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj @@ -20,7 +20,7 @@ {9E1987E3-1F19-45CA-B9C9-D31E791836D8} - example_win32_directx11 + example_sdl_directx11 8.1 example_sdl_directx11 @@ -28,28 +28,28 @@ Application true - Unicode - v140 + MultiByte + v110 Application true - Unicode - v140 + MultiByte + v110 Application false true - Unicode - v140 + MultiByte + v110 Application false true - Unicode - v140 + MultiByte + v110 @@ -70,43 +70,49 @@ $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) Level4 Disabled - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 Console + msvcrt.lib Level4 Disabled - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 Console + msvcrt.lib @@ -115,16 +121,18 @@ MaxSpeed true true - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false true true true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 Console + + @@ -133,25 +141,20 @@ MaxSpeed true true - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false true true true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 Console + + - - - - - - - @@ -161,6 +164,13 @@ + + + + + + + diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index bf470d78..ae523fe9 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -1,4 +1,4 @@ -// dear imgui: standalone example application for SDL2 + OpenGL +// dear imgui: standalone example application for SDL2 + DirectX 11 // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. // (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) @@ -22,6 +22,7 @@ void CleanupDeviceD3D(); void CreateRenderTarget(); void CleanupRenderTarget(); +// Main code int main(int, char**) { // Setup SDL @@ -31,14 +32,12 @@ int main(int, char**) return -1; } - // Create window with graphics context + // Setup window SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+DirectX11 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); - - SDL_SysWMinfo wmInfo; - SDL_VERSION(&wmInfo.version); - SDL_GetWindowWMInfo(window, &wmInfo); - + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); HWND hwnd = (HWND)wmInfo.info.win.window; // Initialize Direct3D @@ -52,10 +51,8 @@ int main(int, char**) IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - //io.ConfigViewportsNoAutoMerge = true; - //io.ConfigViewportsNoTaskBarIcon = true; // Setup Dear ImGui style ImGui::StyleColorsDark(); @@ -80,6 +77,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -168,6 +166,7 @@ int main(int, char**) } // Helper functions + bool CreateDeviceD3D(HWND hWnd) { // Setup swap chain diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 7b3e853a..1222c250 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -13,6 +13,7 @@ #include #include +// Main code int main(int, char**) { // Setup SDL @@ -64,6 +65,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 38b9ebd5..ae1ef5b3 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -22,6 +22,7 @@ #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif +// Main code int main(int, char**) { // Setup SDL @@ -104,6 +105,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index 6ac67b82..12c262e9 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -322,7 +322,7 @@ int main(int, char**) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); - return 1; + return -1; } // Setup window @@ -353,6 +353,7 @@ int main(int, char**) SetupVulkanWindow(wd, surface, w, h); // Setup Dear ImGui context + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls @@ -423,6 +424,7 @@ int main(int, char**) ImGui_ImplVulkan_DestroyFontUploadObjects(); } + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 9523728d..0a8f09b2 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -146,6 +146,7 @@ int main(int, char**) //g_pSwapChain->Present(0, 0); // Present without vsync } + // Cleanup ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); From dd41df3e98e85030bd478d0c68404667072ec5f1 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 18 Jun 2019 12:50:34 +0200 Subject: [PATCH 8/8] Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d). --- docs/CHANGELOG.txt | 2 ++ imgui_draw.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index f575242f..d1e0b820 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,6 +43,8 @@ Breaking Changes: Other Changes: - Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71). +- Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because + of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d). - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] - ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between channel 0 and 1. (#2624) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 288d95ae..e54a5fdc 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2692,7 +2692,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c } // We ignore blank width at the end of the line (they can be skipped) - if (line_width + word_width >= wrap_width) + if (line_width + word_width > wrap_width) { // Words that cannot possibly fit within an entire line will be cut anywhere. if (word_width < wrap_width)