From 6c684ae39bf0b174fbbf58fd37f93eebd3c3c3a2 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 17 May 2018 18:10:20 +0200 Subject: [PATCH 01/11] Fixed GCC pre-8 build. (#1822) + added bonus the non-ASCII character pasted from GCC breaks my SourceTree/Git combo --- imgui.cpp | 4 +++- imgui_draw.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3e53f1f5..48bf8749 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -705,7 +705,9 @@ #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 -#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 +#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 #endif // Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 52908d87..7419eec4 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -54,7 +54,9 @@ #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 "-Wclass-memaccess" // warning: ‘memset/memcpy’ clearing/writing an object of type ‘xxxx’ with no trivial copy-assignment; use assignment or value-initialization instead +#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 #endif //------------------------------------------------------------------------- From 7c7e96e1aa8ea972931d71f2cc6e986fef6ca6d6 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 18 May 2018 20:33:00 +0200 Subject: [PATCH 02/11] ImVector: added erase(it first, it last) helper. Added erase_unsorted(it) helper. + todo fixes/additions --- TODO.txt | 23 +++++++++++++---------- imgui.h | 6 ++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/TODO.txt b/TODO.txt index 5987bcbf..19ff8d4d 100644 --- a/TODO.txt +++ b/TODO.txt @@ -31,10 +31,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i !- 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) - - drawdata: make it easy to clone (or swap?) a ImDrawData so user can easily save that data if they use threaded renderering. + - 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. - drawlist: maintaining bounding box per command would allow to merge draw command when clipping isn't relied on (typical non-scrolling window or non-overflowing column would merge with previous command). - - drawlist: primtiives/helpers to manipulate vertices post submission, so e.g. a quad/rect can be resized to fit later submitted content, _without_ using the ChannelSplit api + - drawlist: primitives/helpers to manipulate vertices post submission, so e.g. a quad/rect can be resized to fit later submitted content, _without_ using the ChannelSplit api - 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). @@ -50,7 +50,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - widgets: display mode: widget-label, label-widget (aligned on column or using fixed size), label-newline-tab-widget etc. (#395) - widgets: clean up widgets internal toward exposing everything and stabilizing imgui_internals.h. - - widgets: add visauls for Disabled/ReadOnly mode and expose publicly (#211) + - widgets: add visuals for Disabled/ReadOnly mode and expose publicly (#211) - widgets: add always-allow-overlap mode. - widgets: alignment options in style (e.g. center Selectable, Right-Align within Button, etc.) #1260 - widgets: activate by identifier (trigger button, focus given id) @@ -67,13 +67,14 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - input text: add ImGuiInputTextFlags_EnterToApply? (off #218) - 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 dependant). actually a very old bug but no one appears to have noticed it. + - 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 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 @@ -86,12 +87,12 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - layout: more generic alignment state (left/right/centered) for single items? - layout: clean up the InputFloatN/SliderFloatN/ColorEdit4 layout code. item width should include frame padding. - layout: BeginGroup() needs a border option. (~#1496) - - layout: vertical alignement of mixed height items (e.g. buttons) within a same line (#1284) + - layout: vertical alignment of mixed height items (e.g. buttons) within a same line (#1284) - columns: sizing policy (e.g. for each column: fixed size, %, fill, distribute default size among fills) (#513, #125) - columns: add a conditional parameter to SetColumnOffset() (#513, #125) - columns: headers. reorderable. (#513, #125) - - columns: optional sorting modifiers (up/down), sort list so sorting can be done multi-critera. notify user when sort order changed. + - columns: optional sorting modifiers (up/down), sort list so sorting can be done multi-criteria. notify user when sort order changed. - columns: option to alternate background colors on odd/even scanlines. - columns: allow columns to recurse. - columns: allow a same columns set to be interrupted by e.g. CollapsingHeader and resume with columns in sync when moving them. @@ -104,7 +105,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - 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 verticles (currently issues with averaging normals) + - plot: PlotLines() should use the polygon-stroke facilities, less vertices (currently issues with averaging normals) - plot: make it easier for user to draw extra stuff into the graph (e.g: draw basis, highlight certain points, 2d plots, multiple plots) - plot: "smooth" automatic scale over time, user give an input 0.0(full user scale) 1.0(full derived from value) - plot: option/feature: draw the zero line @@ -161,7 +162,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - popups: border options. richer api like BeginChild() perhaps? (#197) - 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: allow tooltips with timers? or general timer policy? (instaneous vs timed) + - tooltip: allow tooltips with timers? or general timer policy? (instantaneous vs timed) - 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. @@ -229,7 +230,7 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i !- font: better CalcTextSizeA() API, at least for simple use cases. current one is horrible (perhaps have simple vs extended versions). - font: a CalcTextHeight() helper could run faster than CalcTextSize().y - font: enforce monospace through ImFontConfig (for icons?) + create dual ImFont output from same input, reusing rasterized data but with different glyphs/AdvanceX - - font: finish CustomRectRegister() to allow mapping unicode codepoint to custom texture data + - font: finish CustomRectRegister() to allow mapping Unicode codepoint to custom texture data - font: PushFontSize API (#1018) - font/atlas: incremental updates - font/atlas: dynamic font atlas to avoid baking huge ranges into bitmap and make scaling easier. @@ -276,8 +277,10 @@ It's mostly a bunch of personal notes, probably incomplete. Feel free to query i - misc: PushItemFlag(): add a flag to disable keyboard capture when used with mouse? (#1682) - misc: use more size_t in public api? - misc: ImVector: erase_unsorted() helper -- misc: imgui_cpp: perhaps a misc/ header file with more friendly helper (e.g. type-infer versions of DragScalar, vector<> variants if appropriate for some functions). + - misc: imgui_cpp: perhaps a misc/ header file with more friendly helper (e.g. type-infer versions of DragScalar, vector<> variants if appropriate for some functions). + - backend: bgfx? https://gist.github.com/RichardGale/6e2b74bc42b3005e08397236e4be0fd0 + - backend: freeglut (#801, #795) - 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) diff --git a/imgui.h b/imgui.h index 39cdc19f..920be306 100644 --- a/imgui.h +++ b/imgui.h @@ -1191,7 +1191,7 @@ namespace ImGui //----------------------------------------------------------------------------- // Helper: Lightweight std::vector<> like class to avoid dragging dependencies (also: Windows implementation of STL with debug enabled is absurdly slow, so let's bypass it so our code runs fast in debug). -// *Important* Our implementation does NOT call C++ constructors/destructors. This is intentional, we do not require it but you have to be mindful of that. Do not use this class as a straight std::vector replacement in your code! +// *Important* Our implementation does NOT call C++ constructors/destructors. This is intentional, we do not require it but you have to be mindful of that. Do _not_ use this class as a std::vector replacement in your code! template class ImVector { @@ -1243,11 +1243,13 @@ public: Capacity = new_capacity; } - // NB: &v cannot be pointing inside the ImVector Data itself! e.g. v.push_back(v[10]) is forbidden. + // NB: It is forbidden to call push_back/push_front/insert with a reference pointing inside the ImVector data itself! e.g. v.push_back(v[10]) is forbidden. inline void push_back(const value_type& v) { if (Size == Capacity) reserve(_grow_capacity(Size + 1)); memcpy(&Data[Size], &v, sizeof(v)); Size++; } inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline void push_front(const value_type& v) { if (Size == 0) push_back(v); else insert(Data, v); } inline iterator erase(const_iterator it) { IM_ASSERT(it >= Data && it < Data+Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(value_type)); Size--; return Data + off; } + inline iterator erase(const_iterator it, const_iterator it_last){ IM_ASSERT(it >= Data && it < Data+Size && it_last > it && it_last <= Data+Size); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + count, ((size_t)Size - (size_t)off - count) * sizeof(value_type)); Size -= (int)count; return Data + off; } + inline iterator erase_unsorted(const_iterator it) { IM_ASSERT(it >= Data && it < Data+Size); const ptrdiff_t off = it - Data; if (it < Data+Size-1) memcpy(Data + off, Data + Size - 1, sizeof(value_type)); Size--; return Data + off; } inline iterator insert(const_iterator it, const value_type& v) { IM_ASSERT(it >= Data && it <= Data+Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(value_type)); memcpy(&Data[off], &v, sizeof(v)); Size++; return Data + off; } inline bool contains(const value_type& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } }; From bf56b6b9a579084c9aa1115c43a3402064916d1b Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 May 2018 10:13:21 +0200 Subject: [PATCH 03/11] ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826) --- CHANGELOG.txt | 1 + imgui.cpp | 6 ++++-- imgui.h | 23 ++++++++++++----------- imgui_demo.cpp | 4 +++- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7a1f8157..57669081 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -45,6 +45,7 @@ Other Changes: - Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787) - TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless. + - ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826) ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 48bf8749..9c98399a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11815,7 +11815,8 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), rounding); // Color button are often in need of some sort of border // Drag and Drop Source - if (g.ActiveId == id && BeginDragDropSource()) // NB: The ActiveId test is merely an optional micro-optimization + // NB: The ActiveId test is merely an optional micro-optimization, BeginDragDropSource() does the same test. + if (g.ActiveId == id && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropSource()) { if (flags & ImGuiColorEditFlags_NoAlpha) SetDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F, &col, sizeof(float) * 3, ImGuiCond_Once); @@ -12106,7 +12107,8 @@ bool ImGui::ColorEdit4(const char* label, float col[4], ImGuiColorEditFlags flag EndGroup(); // Drag and Drop Target - if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && BeginDragDropTarget()) // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test. + // NB: The flag test is merely an optional micro-optimization, BeginDragDropTarget() does the same test. + if ((window->DC.LastItemStatusFlags & ImGuiItemStatusFlags_HoveredRect) && !(flags & ImGuiColorEditFlags_NoDragDrop) && BeginDragDropTarget()) { if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) { diff --git a/imgui.h b/imgui.h index 920be306..5989164b 100644 --- a/imgui.h +++ b/imgui.h @@ -933,19 +933,20 @@ enum ImGuiColorEditFlags_ ImGuiColorEditFlags_NoTooltip = 1 << 6, // // ColorEdit, ColorPicker, ColorButton: disable tooltip when hovering the preview. ImGuiColorEditFlags_NoLabel = 1 << 7, // // ColorEdit, ColorPicker: disable display of inline text label (the label is still forwarded to the tooltip and picker). ImGuiColorEditFlags_NoSidePreview = 1 << 8, // // ColorPicker: disable bigger color preview on right side of the picker, use small colored square preview instead. + ImGuiColorEditFlags_NoDragDrop = 1 << 9, // // ColorEdit: disable drag and drop target. ColorButton: disable drag and drop source. // User Options (right-click on widget to change some of them). You can set application defaults using SetColorEditOptions(). The idea is that you probably don't want to override them in most of your calls, let the user choose and/or call SetColorEditOptions() during startup. - ImGuiColorEditFlags_AlphaBar = 1 << 9, // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker. - ImGuiColorEditFlags_AlphaPreview = 1 << 10, // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque. - ImGuiColorEditFlags_AlphaPreviewHalf= 1 << 11, // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque. - ImGuiColorEditFlags_HDR = 1 << 12, // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well). - ImGuiColorEditFlags_RGB = 1 << 13, // [Inputs] // ColorEdit: choose one among RGB/HSV/HEX. ColorPicker: choose any combination using RGB/HSV/HEX. - ImGuiColorEditFlags_HSV = 1 << 14, // [Inputs] // " - ImGuiColorEditFlags_HEX = 1 << 15, // [Inputs] // " - ImGuiColorEditFlags_Uint8 = 1 << 16, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255. - ImGuiColorEditFlags_Float = 1 << 17, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers. - ImGuiColorEditFlags_PickerHueBar = 1 << 18, // [PickerMode] // ColorPicker: bar for Hue, rectangle for Sat/Value. - ImGuiColorEditFlags_PickerHueWheel = 1 << 19, // [PickerMode] // ColorPicker: wheel for Hue, triangle for Sat/Value. + ImGuiColorEditFlags_AlphaBar = 1 << 16, // // ColorEdit, ColorPicker: show vertical alpha bar/gradient in picker. + ImGuiColorEditFlags_AlphaPreview = 1 << 17, // // ColorEdit, ColorPicker, ColorButton: display preview as a transparent color over a checkerboard, instead of opaque. + ImGuiColorEditFlags_AlphaPreviewHalf= 1 << 18, // // ColorEdit, ColorPicker, ColorButton: display half opaque / half checkerboard, instead of opaque. + ImGuiColorEditFlags_HDR = 1 << 19, // // (WIP) ColorEdit: Currently only disable 0.0f..1.0f limits in RGBA edition (note: you probably want to use ImGuiColorEditFlags_Float flag as well). + ImGuiColorEditFlags_RGB = 1 << 20, // [Inputs] // ColorEdit: choose one among RGB/HSV/HEX. ColorPicker: choose any combination using RGB/HSV/HEX. + ImGuiColorEditFlags_HSV = 1 << 21, // [Inputs] // " + ImGuiColorEditFlags_HEX = 1 << 22, // [Inputs] // " + ImGuiColorEditFlags_Uint8 = 1 << 23, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0..255. + ImGuiColorEditFlags_Float = 1 << 24, // [DataType] // ColorEdit, ColorPicker, ColorButton: _display_ values formatted as 0.0f..1.0f floats instead of 0..255 integers. No round-trip of value via integers. + ImGuiColorEditFlags_PickerHueBar = 1 << 25, // [PickerMode] // ColorPicker: bar for Hue, rectangle for Sat/Value. + ImGuiColorEditFlags_PickerHueWheel = 1 << 26, // [PickerMode] // ColorPicker: wheel for Hue, triangle for Sat/Value. // [Internal] Masks ImGuiColorEditFlags__InputsMask = ImGuiColorEditFlags_RGB|ImGuiColorEditFlags_HSV|ImGuiColorEditFlags_HEX, diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 63bfd29a..1d7d7a20 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -862,13 +862,15 @@ void ImGui::ShowDemoWindow(bool* p_open) static bool alpha_preview = true; static bool alpha_half_preview = false; + static bool drag_and_drop = true; static bool options_menu = true; static bool hdr = false; ImGui::Checkbox("With Alpha Preview", &alpha_preview); ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview); + ImGui::Checkbox("With Drag and Drop", &drag_and_drop); ImGui::Checkbox("With Options Menu", &options_menu); ImGui::SameLine(); ShowHelpMarker("Right-click on the individual color widget to show options."); ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); ShowHelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets."); - int misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions); + int misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (drag_and_drop ? 0 : ImGuiColorEditFlags_NoDragDrop) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions); ImGui::Text("Color widget:"); ImGui::SameLine(); ShowHelpMarker("Click on the colored square to open a color picker.\nCTRL+click on individual component to input value.\n"); From e8a72d3e72de751d77f6d0254425b0f8fb40bb43 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Mon, 21 May 2018 07:35:09 +0800 Subject: [PATCH 04/11] Examples: GLFW* Make subsequent window creation possible. --- examples/opengl2_example/imgui_impl_glfw_gl2.cpp | 1 + examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/opengl2_example/imgui_impl_glfw_gl2.cpp b/examples/opengl2_example/imgui_impl_glfw_gl2.cpp index 5cc60ec3..ebdf785e 100644 --- a/examples/opengl2_example/imgui_impl_glfw_gl2.cpp +++ b/examples/opengl2_example/imgui_impl_glfw_gl2.cpp @@ -233,6 +233,7 @@ static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) bool ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks) { g_Window = window; + g_Time = 0; // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 163b5db3..49b41134 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -358,6 +358,7 @@ static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const char* glsl_version) { g_Window = window; + g_Time = 0; // Store GL version string so we can refer to it later in case we recreate shaders. if (glsl_version == NULL) From 663e2c923756ea50cedca01515748fc32ec48b58 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 May 2018 10:36:50 +0200 Subject: [PATCH 05/11] Examples: GLFW: Made it possible to Shutdown/Init the backend again (by reseting the time storage properly). Changelog. Added to Vulkan example. (#1827) --- CHANGELOG.txt | 1 + examples/opengl2_example/imgui_impl_glfw_gl2.cpp | 4 ++-- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 4 ++-- examples/vulkan_example/imgui_impl_glfw_vulkan.cpp | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 57669081..705d25de 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -46,6 +46,7 @@ Other Changes: - Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787) - TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless. - ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826) + - Examples: GLFW: Made it possible to Shutdown/Init the backend again (by reseting the time storage properly). (#1827) [@ice1000] ----------------------------------------------------------------------- diff --git a/examples/opengl2_example/imgui_impl_glfw_gl2.cpp b/examples/opengl2_example/imgui_impl_glfw_gl2.cpp index ebdf785e..5ad2d61a 100644 --- a/examples/opengl2_example/imgui_impl_glfw_gl2.cpp +++ b/examples/opengl2_example/imgui_impl_glfw_gl2.cpp @@ -49,7 +49,7 @@ // GLFW data static GLFWwindow* g_Window = NULL; -static double g_Time = 0.0f; +static double g_Time = 0.0; static bool g_MouseJustPressed[3] = { false, false, false }; static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; @@ -233,7 +233,7 @@ static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) bool ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks) { g_Window = window; - g_Time = 0; + g_Time = 0.0; // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 49b41134..0c6ff0c7 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -52,7 +52,7 @@ // GLFW data static GLFWwindow* g_Window = NULL; -static double g_Time = 0.0f; +static double g_Time = 0.0; static bool g_MouseJustPressed[3] = { false, false, false }; static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; @@ -358,7 +358,7 @@ static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window) bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const char* glsl_version) { g_Window = window; - g_Time = 0; + g_Time = 0.0; // Store GL version string so we can refer to it later in case we recreate shaders. if (glsl_version == NULL) diff --git a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp index 2f49b10f..73c86eb9 100644 --- a/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp +++ b/examples/vulkan_example/imgui_impl_glfw_vulkan.cpp @@ -41,7 +41,7 @@ // GLFW data static GLFWwindow* g_Window = NULL; -static double g_Time = 0.0f; +static double g_Time = 0.0; static bool g_MouseJustPressed[3] = { false, false, false }; static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = { 0 }; @@ -769,6 +769,7 @@ bool ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, Im g_CheckVkResult = init_data->check_vk_result; g_Window = window; + g_Time = 0.0; // Setup back-end capabilities flags ImGuiIO& io = ImGui::GetIO(); From bef0a132833346e934599228eec1813008bd45f4 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 21 May 2018 11:28:30 +0200 Subject: [PATCH 06/11] Examples: Comments about GLSL version not being the same as GL context version. (#1828) --- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 2 +- examples/opengl3_example/imgui_impl_glfw_gl3.h | 4 ++++ examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 2 +- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 0c6ff0c7..94b352cc 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -360,7 +360,7 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const g_Window = window; g_Time = 0.0; - // Store GL version string so we can refer to it later in case we recreate shaders. + // 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. if (glsl_version == NULL) glsl_version = "#version 150"; IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersion)); diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.h b/examples/opengl3_example/imgui_impl_glfw_gl3.h index 33b5329d..e30fcd97 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.h +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.h @@ -11,6 +11,10 @@ // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui +// About GLSL version: +// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. +// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! + struct GLFWwindow; IMGUI_API bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks, const char* glsl_version = NULL); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index 727914a7..da71258d 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -358,7 +358,7 @@ void ImGui_ImplSdlGL3_InvalidateDeviceObjects() bool ImGui_ImplSdlGL3_Init(SDL_Window* window, const char* glsl_version) { - // Store GL version string so we can refer to it later in case we recreate shaders. + // 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. if (glsl_version == NULL) glsl_version = "#version 150"; IM_ASSERT((int)strlen(glsl_version) + 2 < IM_ARRAYSIZE(g_GlslVersion)); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h index c694a481..35076ad4 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.h @@ -12,6 +12,10 @@ // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. // https://github.com/ocornut/imgui +// About GLSL version: +// The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. +// Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! + struct SDL_Window; typedef union SDL_Event SDL_Event; From 09ea376a6a0119eceab620fda421fbeb7f20ee15 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 23 May 2018 22:57:54 +0200 Subject: [PATCH 07/11] BeginCombo(), BeginMainMenuBar(), BeginChildFrame(): restore modified style at end of Begin instead of End so doesn't affect child windows, BeginTooltip() etc.. (allowed since 7b6b7038c57c9c38ecf0d42b4ab37c47896fac9d) --- imgui.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9c98399a..f850f54a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5320,14 +5320,15 @@ bool ImGui::BeginChildFrame(ImGuiID id, const ImVec2& size, ImGuiWindowFlags ext PushStyleVar(ImGuiStyleVar_ChildRounding, style.FrameRounding); PushStyleVar(ImGuiStyleVar_ChildBorderSize, style.FrameBorderSize); PushStyleVar(ImGuiStyleVar_WindowPadding, style.FramePadding); - return BeginChild(id, size, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags); + bool ret = BeginChild(id, size, true, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysUseWindowPadding | extra_flags); + PopStyleVar(3); + PopStyleColor(); + return ret; } void ImGui::EndChildFrame() { EndChild(); - PopStyleVar(3); - PopStyleColor(); } // Save and compare stack sizes on Begin()/End() to detect usage errors @@ -11065,13 +11066,13 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF } // Horizontally align ourselves with the framed text - PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(style.FramePadding.x, style.WindowPadding.y)); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_Popup | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings; - if (!Begin(name, NULL, window_flags)) + PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(style.FramePadding.x, style.WindowPadding.y)); + bool ret = Begin(name, NULL, window_flags); + PopStyleVar(); + if (!ret) { EndPopup(); - PopStyleVar(); IM_ASSERT(0); // This should never happen as we tested for IsPopupOpen() above return false; } @@ -11081,7 +11082,6 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImGuiComboF void ImGui::EndCombo() { EndPopup(); - PopStyleVar(); } // Old API, prefer using BeginCombo() nowadays if you can. @@ -11436,11 +11436,11 @@ bool ImGui::BeginMainMenuBar() PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0)); ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar; bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar(); + PopStyleVar(2); g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f); if (!is_open) { End(); - PopStyleVar(2); return false; } return true; @@ -11456,7 +11456,6 @@ void ImGui::EndMainMenuBar() FocusFrontMostActiveWindow(g.NavWindow); End(); - PopStyleVar(2); } bool ImGui::BeginMenuBar() From b88fbd69cc64ce6330aa6cf1102bfd5359ec6ff5 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 23 May 2018 23:18:12 +0200 Subject: [PATCH 08/11] Drag and Drop: BeginDragDropSource(): Offset tooltip position so it is off the mouse cursor, but also closer to it than regular tooltips, and not clamped by viewport. (#1739) --- CHANGELOG.txt | 2 ++ imgui.cpp | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 705d25de..c570a948 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -46,6 +46,8 @@ Other Changes: - Nav: To keep the navigated item in view we also attempt to scroll the parent window as well as the current window. (#787) - TreeNode: Fixed nodes with ImGuiTreeNodeFlags_Leaf flag always returning true which was meaningless. - ColorEdit3, ColorEdit4, ColorButton: Added ImGuiColorEditFlags_NoDragDrop flag to disable ColorEditX as drag target and ColorButton as drag source. (#1826) + - BeginDragDropSource(): Offset tooltip position so it is off the mouse cursor, but also closer to it than regular tooltips, and not clamped by viewport. (#1739) + - BeginCombo(), BeginMainMenuBar(), BeginChildFrame(): Temporary style modification are restored at the end of BeginXXX instead of EndXXX, to not affect tooltips and child windows. - Examples: GLFW: Made it possible to Shutdown/Init the backend again (by reseting the time storage properly). (#1827) [@ice1000] ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index f850f54a..9934660d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13203,7 +13203,11 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) // FIXME-DRAG //SetNextWindowPos(g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding); //PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This is better but e.g ColorButton with checkboard has issue with transparent colors :( - SetNextWindowPos(g.IO.MousePos); + + // The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor) + // In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor. + ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale); + SetNextWindowPos(tooltip_pos); PushStyleColor(ImGuiCol_PopupBg, GetStyleColorVec4(ImGuiCol_PopupBg) * ImVec4(1.0f, 1.0f, 1.0f, 0.6f)); BeginTooltip(); } From 5fd23eeb742516bbcc2b3d3b6907f7f11297344b Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 24 May 2018 17:42:50 +0200 Subject: [PATCH 09/11] Examples: iOS: Fixed missing call to CreateContext() + various shallow coding style tweaks. (#1835) --- .../imguiex-ios/GameViewController.m | 179 +++++++++--------- .../apple_example/imguiex-ios/debug_hud.h | 12 +- .../imguiex-ios/imgui_impl_ios.mm | 29 ++- 3 files changed, 104 insertions(+), 116 deletions(-) diff --git a/examples/apple_example/imguiex-ios/GameViewController.m b/examples/apple_example/imguiex-ios/GameViewController.m index 316fbd6c..83444e98 100644 --- a/examples/apple_example/imguiex-ios/GameViewController.m +++ b/examples/apple_example/imguiex-ios/GameViewController.m @@ -8,11 +8,9 @@ #import "imgui_impl_ios.h" #import "debug_hud.h" -#define BUFFER_OFFSET(i) ((char *)NULL + (i)) - -#define SERVERNAME_KEY @"ServerName" - -#define SERVERNAME_ALERT_TAG (10) +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) +#define SERVERNAME_KEY @"ServerName" +#define SERVERNAME_ALERT_TAG 10 // Uniform index. enum @@ -20,85 +18,80 @@ enum UNIFORM_MODELVIEWPROJECTION_MATRIX, UNIFORM_NORMAL_MATRIX, UNIFORM_DIFFUSE_COLOR, - - NUM_UNIFORMS + UNIFORM_COUNT_ }; -GLint uniforms[NUM_UNIFORMS]; +static GLint uniforms[UNIFORM_COUNT_]; // Attribute index. enum { ATTRIB_VERTEX, ATTRIB_NORMAL, - NUM_ATTRIBUTES + ATTRIB_COUNT_ }; -GLfloat gCubeVertexData[216] = +static const GLfloat gCubeVertexData[216] = { // Data layout for each line below is: - // positionX, positionY, positionZ, normalX, normalY, normalZ, - 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + // pos x/y/z, normal x/y/z, + 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, + -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, + 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, + -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f + 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, + -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f }; @interface GameViewController () { - GLuint _program; - - GLKMatrix4 _modelViewProjectionMatrix; - GLKMatrix3 _normalMatrix; - float _rotation; - - GLuint _vertexArray; - GLuint _vertexBuffer; - - DebugHUD _hud; + GLuint _program; + GLKMatrix4 _modelViewProjectionMatrix; + GLKMatrix3 _normalMatrix; + float _rotation; + GLuint _vertexArray; + GLuint _vertexBuffer; + DebugHUD _hud; } -@property (strong, nonatomic) EAGLContext *context; -@property (strong, nonatomic) GLKBaseEffect *effect; -@property (strong, nonatomic) ImGuiHelper *imgui; -@property (weak, nonatomic) IBOutlet UIButton *btnServername; - -@property (strong, nonatomic) NSString *serverName; +@property (strong, nonatomic) EAGLContext* context; +@property (strong, nonatomic) GLKBaseEffect* effect; +@property (strong, nonatomic) ImGuiHelper* imgui; +@property (weak, nonatomic) IBOutlet UIButton* btnServername; +@property (strong, nonatomic) NSString* serverName; - (IBAction)onServernameTapped:(id)sender; @@ -106,7 +99,7 @@ GLfloat gCubeVertexData[216] = - (void)tearDownGL; - (BOOL)loadShaders; -- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file; +- (BOOL)compileShader:(GLuint*)shader type:(GLenum)type file:(NSString*)file; - (BOOL)linkProgram:(GLuint)prog; - (BOOL)validateProgram:(GLuint)prog; @end @@ -119,9 +112,8 @@ GLfloat gCubeVertexData[216] = self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - if (!self.context) { + if (!self.context) NSLog(@"Failed to create ES context"); - } GLKView *view = (GLKView *)self.view; view.context = self.context; @@ -140,30 +132,29 @@ GLfloat gCubeVertexData[216] = [self.imgui connectServer: self.serverName ]; } - DebugHUD_InitDefaults( &_hud ); + DebugHUD_InitDefaults(&_hud); } - (void)dealloc { [self tearDownGL]; - if ([EAGLContext currentContext] == self.context) { + if ([EAGLContext currentContext] == self.context) [EAGLContext setCurrentContext:nil]; - } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; - if ([self isViewLoaded] && ([[self view] window] == nil)) { + if ([self isViewLoaded] && ([[self view] window] == nil)) + { self.view = nil; [self tearDownGL]; - if ([EAGLContext currentContext] == self.context) { + if ([EAGLContext currentContext] == self.context) [EAGLContext setCurrentContext:nil]; - } self.context = nil; } @@ -171,7 +162,8 @@ GLfloat gCubeVertexData[216] = } -- (BOOL)prefersStatusBarHidden { +- (BOOL)prefersStatusBarHidden +{ return YES; } @@ -185,7 +177,7 @@ GLfloat gCubeVertexData[216] = - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - if ((buttonIndex==0)&&(alertView.tag==SERVERNAME_ALERT_TAG)) + if ((buttonIndex==0) && (alertView.tag == SERVERNAME_ALERT_TAG)) { // This is really janky. I usually just hardcode the servername since I'm building it anyway. // If you want to properly handle updating the server, you'll want to tear down and recreate @@ -193,7 +185,8 @@ GLfloat gCubeVertexData[216] = BOOL serverNameWasSet = self.serverName.length > 0; NSString *serverName = [[alertView textFieldAtIndex:0] text]; - if ([serverName length] > 0) { + if ([serverName length] > 0) + { self.serverName = serverName; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; [userDefaults setObject:serverName forKey:SERVERNAME_KEY ]; @@ -202,7 +195,8 @@ GLfloat gCubeVertexData[216] = [self.btnServername setTitle:self.serverName forState:UIControlStateNormal]; // If we hadn't previously connected, try now - if (!serverNameWasSet) { + if (!serverNameWasSet) + { [self.imgui connectServer:self.serverName]; } else @@ -241,8 +235,6 @@ GLfloat gCubeVertexData[216] = glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); glBindVertexArrayOES(0); - - } - (void)tearDownGL @@ -254,7 +246,8 @@ GLfloat gCubeVertexData[216] = self.effect = nil; - if (_program) { + if (_program) + { glDeleteProgram(_program); _program = 0; } @@ -285,9 +278,7 @@ GLfloat gCubeVertexData[216] = modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix); _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL); - _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix); - _rotation += self.timeSinceLastUpdate * (_hud.rotation_speed * (M_PI / 180.0)); } @@ -359,7 +350,8 @@ GLfloat gCubeVertexData[216] = glBindAttribLocation(_program, GLKVertexAttribNormal, "normal"); // Link program. - if (![self linkProgram:_program]) { + if (![self linkProgram:_program]) + { NSLog(@"Failed to link program: %d", _program); if (vertShader) { @@ -384,11 +376,13 @@ GLfloat gCubeVertexData[216] = uniforms[UNIFORM_DIFFUSE_COLOR] = glGetUniformLocation(_program, "diffuseColor"); // Release vertex and fragment shaders. - if (vertShader) { + if (vertShader) + { glDetachShader(_program, vertShader); glDeleteShader(vertShader); } - if (fragShader) { + if (fragShader) + { glDetachShader(_program, fragShader); glDeleteShader(fragShader); } @@ -402,7 +396,8 @@ GLfloat gCubeVertexData[216] = const GLchar *source; source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String]; - if (!source) { + if (!source) + { NSLog(@"Failed to load vertex shader"); return NO; } @@ -423,7 +418,8 @@ GLfloat gCubeVertexData[216] = #endif glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); - if (status == 0) { + if (status == 0) + { glDeleteShader(*shader); return NO; } @@ -439,7 +435,8 @@ GLfloat gCubeVertexData[216] = #if defined(DEBUG) GLint logLength; glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength); - if (logLength > 0) { + if (logLength > 0) + { GLchar *log = (GLchar *)malloc(logLength); glGetProgramInfoLog(prog, logLength, &logLength, log); NSLog(@"Program link log:\n%s", log); @@ -448,10 +445,8 @@ GLfloat gCubeVertexData[216] = #endif glGetProgramiv(prog, GL_LINK_STATUS, &status); - if (status == 0) { + if (status == 0) return NO; - } - return YES; } @@ -469,10 +464,8 @@ GLfloat gCubeVertexData[216] = } glGetProgramiv(prog, GL_VALIDATE_STATUS, &status); - if (status == 0) { + if (status == 0) return NO; - } - return YES; } diff --git a/examples/apple_example/imguiex-ios/debug_hud.h b/examples/apple_example/imguiex-ios/debug_hud.h index 4ef53572..0a905911 100644 --- a/examples/apple_example/imguiex-ios/debug_hud.h +++ b/examples/apple_example/imguiex-ios/debug_hud.h @@ -6,12 +6,12 @@ typedef struct DebugHUD { - bool show_demo_window; - bool show_another_window; - float rotation_speed; - float cubeColor1[4]; - float cubeColor2[4]; - float clearColor[4]; + bool show_demo_window; + bool show_another_window; + float rotation_speed; + float cubeColor1[4]; + float cubeColor2[4]; + float clearColor[4]; } DebugHUD; #if __cplusplus diff --git a/examples/apple_example/imguiex-ios/imgui_impl_ios.mm b/examples/apple_example/imguiex-ios/imgui_impl_ios.mm index 440b586a..20ee14b8 100644 --- a/examples/apple_example/imguiex-ios/imgui_impl_ios.mm +++ b/examples/apple_example/imguiex-ios/imgui_impl_ios.mm @@ -277,8 +277,7 @@ void ImGui_KeyboardCallback(uSynergyCookie cookie, uint16_t key, // If this key maps to a character input, apply it int charForKeycode = (modifiers & USYNERGY_MODIFIER_SHIFT) ? g_keycodeCharShifted[scanCode] : g_keycodeCharUnshifted[scanCode]; io.AddInputCharacter((unsigned short)charForKeycode); - } - + } } void ImGui_JoystickCallback(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY) @@ -461,14 +460,15 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat - (void)setupImGuiHooks { - ImGuiIO &io = ImGui::GetIO(); + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); [self setupKeymaps]; // Account for retina display for glScissor g_displayScale = [[UIScreen mainScreen] scale]; - ImGuiStyle &style = ImGui::GetStyle(); + ImGuiStyle& style = ImGui::GetStyle(); style.TouchExtraPadding = ImVec2( 4.0, 4.0 ); io.RenderDrawListsFn = ImGui_ImplIOS_RenderDrawLists; @@ -532,9 +532,8 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat // Create a background thread for synergy _synergyQueue = dispatch_queue_create( "imgui-usynergy", NULL ); dispatch_async( _synergyQueue, ^{ - while (1) { - uSynergyUpdate( &_synergyCtx ); - } + while (1) + uSynergyUpdate(&_synergyCtx); }); } @@ -569,24 +568,20 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat - (void)newFrame { ImGuiIO& io = ImGui::GetIO(); - ImGuiStyle &style = ImGui::GetStyle(); + ImGuiStyle& style = ImGui::GetStyle(); if (!g_FontTexture) - { ImGui_ImplIOS_CreateDeviceObjects(); - } - io.DisplaySize = ImVec2( _view.bounds.size.width, _view.bounds.size.height ); + io.DisplaySize = ImVec2(_view.bounds.size.width, _view.bounds.size.height); io.MouseDrawCursor = g_synergyPtrActive; if (g_synergyPtrActive) { - style.TouchExtraPadding = ImVec2( 0.0, 0.0 ); - io.MousePos = ImVec2( g_mousePosX, g_mousePosY ); + style.TouchExtraPadding = ImVec2(0.0, 0.0); + io.MousePos = ImVec2(g_mousePosX, g_mousePosY); for (int i=0; i < 3; i++) - { io.MouseDown[i] = g_MousePressed[i]; - } // This is an arbitrary scaling factor that works for me. Not sure what units these mousewheel values from synergy are supposed to be in. io.MouseWheel = g_mouseWheelY / 500.0; @@ -595,8 +590,8 @@ void ImGui_ClipboardCallback(uSynergyCookie cookie, enum uSynergyClipboardFormat else { // Synergy not active, use touch events - style.TouchExtraPadding = ImVec2( 4.0, 4.0 ); - io.MousePos = ImVec2(_touchPos.x, _touchPos.y ); + style.TouchExtraPadding = ImVec2(4.0, 4.0); + io.MousePos = ImVec2(_touchPos.x, _touchPos.y); if ((_mouseDown) || (_mouseTapped)) { io.MouseDown[0] = true; From 251f178a6f29d8c9346ba6cc02e4267fc0ae1d9f Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 24 May 2018 18:05:27 +0200 Subject: [PATCH 10/11] Drag and Drop: Source doesn't report as hovered (at a lower-level). Source disable AllowOverlap flag if any set. (#143) --- imgui.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 9934660d..bdfefb40 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -7685,8 +7685,12 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool bool pressed = false; bool hovered = ItemHoverable(bb, id); + // Drag source doesn't report as hovered + if (hovered && g.DragDropActive && g.DragDropPayload.SourceId == id) + hovered = false; + // Special mode for Drag and Drop where holding button pressed for a long time while dragging another item triggers the button - if ((flags & ImGuiButtonFlags_PressedOnDragDropHold) && g.DragDropActive && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) + if (g.DragDropActive && (flags & ImGuiButtonFlags_PressedOnDragDropHold) && !(g.DragDropSourceFlags & ImGuiDragDropFlags_SourceNoHoldToOpenOthers)) if (IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) { hovered = true; @@ -11825,7 +11829,6 @@ bool ImGui::ColorButton(const char* desc_id, const ImVec4& col, ImGuiColorEditFl SameLine(); TextUnformatted("Color"); EndDragDropSource(); - hovered = false; } // Tooltip @@ -13172,6 +13175,10 @@ bool ImGui::BeginDragDropSource(ImGuiDragDropFlags flags) if (g.ActiveId == source_id) // Allow the underlying widget to display/return hovered during the mouse release frame, else we would get a flicker. g.ActiveIdAllowOverlap = is_hovered; } + else + { + g.ActiveIdAllowOverlap = false; + } if (g.ActiveId != source_id) return false; source_parent_id = window->IDStack.back(); @@ -13655,8 +13662,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT); ImGui::Text("HoveredWindow: '%s'", g.HoveredWindow ? g.HoveredWindow->Name : "NULL"); ImGui::Text("HoveredRootWindow: '%s'", g.HoveredRootWindow ? g.HoveredRootWindow->Name : "NULL"); - ImGui::Text("HoveredId: 0x%08X/0x%08X (%.2f sec)", g.HoveredId, g.HoveredIdPreviousFrame, g.HoveredIdTimer); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not - ImGui::Text("ActiveId: 0x%08X/0x%08X (%.2f sec), ActiveIdSource: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, input_source_names[g.ActiveIdSource]); + ImGui::Text("HoveredId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredId, g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Data is "in-flight" so depending on when the Metrics window is called we may see current frame information or not + ImGui::Text("ActiveId: 0x%08X/0x%08X (%.2f sec), AllowOverlap: %d, Source: %s", g.ActiveId, g.ActiveIdPreviousFrame, g.ActiveIdTimer, g.ActiveIdAllowOverlap, input_source_names[g.ActiveIdSource]); ImGui::Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); ImGui::Text("MovingWindow: '%s'", g.MovingWindow ? g.MovingWindow->Name : "NULL"); ImGui::Text("NavWindow: '%s'", g.NavWindow ? g.NavWindow->Name : "NULL"); From 9770c8b21dbfb380e39fdcba4f62cf462da99d68 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 25 May 2018 12:08:08 +0200 Subject: [PATCH 11/11] Examples: OpenGL3: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state. (#1836) --- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 3 +-- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 94b352cc..a1e58a99 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -13,6 +13,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state. // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors and ImGuiBackendFlags_HasSetMousePos flags + honor ImGuiConfigFlags_NoMouseCursorChange flag. // 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplGlfwGL3_Init() so user can override the GLSL version e.g. "#version 150". // 2018-02-23: OpenGL: Create the VAO in the render function so the setup can more easily be used with multiple shared GL context. @@ -84,7 +85,6 @@ void ImGui_ImplGlfwGL3_RenderDrawData(ImDrawData* draw_data) GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); - GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); @@ -173,7 +173,6 @@ void ImGui_ImplGlfwGL3_RenderDrawData(ImDrawData* draw_data) glActiveTexture(last_active_texture); glBindVertexArray(last_vertex_array); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index da71258d..8dee20e6 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -14,6 +14,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2018-05-25: OpenGL: Removed unnecessary backup/restore of GL_ELEMENT_ARRAY_BUFFER_BINDING since this is part of the VAO state. // 2018-05-09: Misc: Fixed clipboard paste memory leak (we didn't call SDL_FreeMemory on the data returned by SDL_GetClipboardText). // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag. // 2018-03-06: OpenGL: Added const char* glsl_version parameter to ImGui_ImplSdlGL3_Init() so user can override the GLSL version e.g. "#version 150". @@ -82,7 +83,6 @@ void ImGui_ImplSdlGL3_RenderDrawData(ImDrawData* draw_data) GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); GLint last_sampler; glGetIntegerv(GL_SAMPLER_BINDING, &last_sampler); GLint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &last_array_buffer); - GLint last_element_array_buffer; glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &last_element_array_buffer); GLint last_vertex_array; glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &last_vertex_array); GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); @@ -171,7 +171,6 @@ void ImGui_ImplSdlGL3_RenderDrawData(ImDrawData* draw_data) glActiveTexture(last_active_texture); glBindVertexArray(last_vertex_array); glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, last_element_array_buffer); glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha); glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha); if (last_enable_blend) glEnable(GL_BLEND); else glDisable(GL_BLEND);