From 004e8637271a72e0284b42b5a904a658f0adb216 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 27 Nov 2016 18:32:24 +0100 Subject: [PATCH 01/16] Split SliderBehaviorCalcRatioFromValue() out from SliderBehavior() --- imgui.cpp | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e4d6789b..fc640be9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6446,6 +6446,28 @@ float ImGui::RoundScalar(float value, int decimal_precision) return negative ? -value : value; } +static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos) +{ + const bool is_non_linear = (power < 1.0f-0.00001f) && (power > 1.0f-0.00001f); + const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min); + if (is_non_linear) + { + if (v_clamped < 0.0f) + { + const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min); + return (1.0f - powf(f, 1.0f/power)) * linear_zero_pos; + } + else + { + const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); + return linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); + } + } + + // Linear slider + return (v_clamped - v_min) / (v_max - v_min); +} + bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_min, float v_max, float power, int decimal_precision, ImGuiSliderFlags flags) { ImGuiContext& g = *GImGui; @@ -6539,26 +6561,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v } // Calculate slider grab positioning - float v_clamped = (v_min < v_max) ? ImClamp(*v, v_min, v_max) : ImClamp(*v, v_max, v_min); - float grab_t; - if (is_non_linear) - { - if (v_clamped < 0.0f) - { - const float f = 1.0f - (v_clamped - v_min) / (ImMin(0.0f,v_max) - v_min); - grab_t = (1.0f - powf(f, 1.0f/power)) * linear_zero_pos; - } - else - { - const float f = (v_clamped - ImMax(0.0f,v_min)) / (v_max - ImMax(0.0f,v_min)); - grab_t = linear_zero_pos + powf(f, 1.0f/power) * (1.0f - linear_zero_pos); - } - } - else - { - // Linear slider - grab_t = (v_clamped - v_min) / (v_max - v_min); - } + float grab_t = SliderBehaviorCalcRatioFromValue(*v, v_min, v_max, power, linear_zero_pos); // Draw if (!is_horizontal) From 0a483379af3c0cd7f0c6856aba0faacfd70670e3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 27 Nov 2016 18:34:46 +0100 Subject: [PATCH 02/16] Split SliderBehaviorCalcRatioFromValue() out of SliderBehavior(), fix + Not using fabsf() anymore --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fc640be9..1f34d15d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6448,7 +6448,7 @@ float ImGui::RoundScalar(float value, int decimal_precision) static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos) { - const bool is_non_linear = (power < 1.0f-0.00001f) && (power > 1.0f-0.00001f); + const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min); if (is_non_linear) { @@ -6477,7 +6477,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v // Draw frame RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); - const bool is_non_linear = fabsf(power - 1.0f) > 0.0001f; + const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); const bool is_horizontal = (flags & ImGuiSliderFlags_Vertical) == 0; const float grab_padding = 2.0f; From 94c77edfa52c64431d6731377b7f2e65b27b4f50 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 28 Nov 2016 11:03:48 +0100 Subject: [PATCH 03/16] SliderInt, SliderFloat() Better display support for v_min==v_max range. (#919) --- imgui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 1f34d15d..42396eeb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6448,6 +6448,9 @@ float ImGui::RoundScalar(float value, int decimal_precision) static inline float SliderBehaviorCalcRatioFromValue(float v, float v_min, float v_max, float power, float linear_zero_pos) { + if (v_min == v_max) + return 0.0f; + const bool is_non_linear = (power < 1.0f-0.00001f) || (power > 1.0f+0.00001f); const float v_clamped = (v_min < v_max) ? ImClamp(v, v_min, v_max) : ImClamp(v, v_max, v_min); if (is_non_linear) From 449c47c789302f5bb9287bfacfa7640c35abbc67 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 28 Nov 2016 11:05:24 +0100 Subject: [PATCH 04/16] SliderInt, SliderFloat() interacting enforce modifying to the value to be consistent with other widget behaviors (#919) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 42396eeb..23ed4ca4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6551,7 +6551,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v // Round past decimal precision new_value = RoundScalar(new_value, decimal_precision); - if (*v != new_value && (v_min != v_max)) + if (*v != new_value) { *v = new_value; value_changed = true; From bbd0a37bd282c8cb79d20522db446e4989f83661 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 28 Nov 2016 20:30:36 +0100 Subject: [PATCH 05/16] ImFileOpen: MinGW uses _wfopen() codepath to support UTF-8 filenames (#917) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 23ed4ca4..81055351 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1295,7 +1295,7 @@ void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float& FILE* ImFileOpen(const char* filename, const char* mode) { -#ifdef _MSC_VER +#if defined(_WIN32) && !defined(__CYGWIN__) // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can) const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1; const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1; From ca9a91853584c0095be233a19a7b3705914457bc Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 28 Nov 2016 20:43:11 +0100 Subject: [PATCH 06/16] SliderInt(): Fixed reverse direction mode when (v_max-v_min)==-1 (#854) (+ ref #919) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 81055351..aba57ed0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6489,7 +6489,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v if (decimal_precision > 0) grab_sz = ImMin(style.GrabMinSize, slider_sz); else - grab_sz = ImMin(ImMax(1.0f * (slider_sz / (v_max-v_min+1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit + grab_sz = ImMin(ImMax(1.0f * (slider_sz / ((v_min < v_max ? v_max - v_min : v_min - v_max) + 1.0f)), style.GrabMinSize), slider_sz); // Integer sliders, if possible have the grab size represent 1 unit const float slider_usable_sz = slider_sz - grab_sz; const float slider_usable_pos_min = (is_horizontal ? frame_bb.Min.x : frame_bb.Min.y) + grab_padding + grab_sz*0.5f; const float slider_usable_pos_max = (is_horizontal ? frame_bb.Max.x : frame_bb.Max.y) - grab_padding - grab_sz*0.5f; From 9235e0da468b35249474e981eb44ee43a56a2376 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 29 Nov 2016 21:07:26 +0100 Subject: [PATCH 07/16] SliderInt, SliderFloat(): Fixed edge case where style.GrabMinSize being bigger than slider width can lead to a division by zero (#919) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index aba57ed0..6c259478 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6516,7 +6516,7 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v if (g.IO.MouseDown[0]) { const float mouse_abs_pos = is_horizontal ? g.IO.MousePos.x : g.IO.MousePos.y; - float clicked_t = ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f); + float clicked_t = (slider_usable_sz > 0.0f) ? ImClamp((mouse_abs_pos - slider_usable_pos_min) / slider_usable_sz, 0.0f, 1.0f) : 0.0f; if (!is_horizontal) clicked_t = 1.0f - clicked_t; From 0b6211f90786edb3dfb770aa35a1e025a9019be8 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 29 Nov 2016 21:46:21 +0100 Subject: [PATCH 08/16] Fixed clicking on a window's void while staying still overzealously marking .ini settings as dirty (#923) --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 6c259478..7598c24e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2220,7 +2220,7 @@ void ImGui::NewFrame() if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoMove)) { g.MovedWindow->PosFloat += g.IO.MouseDelta; - if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoSavedSettings)) + if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoSavedSettings) && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)) MarkSettingsDirty(); } FocusWindow(g.MovedWindow); From 55d651812d435d660e14aaede0916b65d4c3994c Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 29 Nov 2016 21:55:20 +0100 Subject: [PATCH 09/16] Renaming and massaging internal Settings/Ini functions (#923) --- imgui.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 7598c24e..5a45931f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -684,9 +684,9 @@ static void AddWindowToSortedBuffer(ImVector& out_sort static ImGuiIniData* FindWindowSettings(const char* name); static ImGuiIniData* AddWindowSettings(const char* name); -static void LoadSettings(); -static void SaveSettings(); -static void MarkSettingsDirty(); +static void LoadIniSettingsFromDisk(const char* ini_filename); +static void SaveIniSettingsToDisk(const char* ini_filename); +static void MarkIniSettingsDirty(); static void PushColumnClipRect(int column_index = -1); static ImRect GetVisibleRect(); @@ -2135,7 +2135,7 @@ void ImGui::NewFrame() IM_PLACEMENT_NEW(g.LogClipboard) ImGuiTextBuffer(); IM_ASSERT(g.Settings.empty()); - LoadSettings(); + LoadIniSettingsFromDisk(g.IO.IniFilename); g.Initialized = true; } @@ -2221,7 +2221,7 @@ void ImGui::NewFrame() { g.MovedWindow->PosFloat += g.IO.MouseDelta; if (!(g.MovedWindow->Flags & ImGuiWindowFlags_NoSavedSettings) && (g.IO.MouseDelta.x != 0.0f || g.IO.MouseDelta.y != 0.0f)) - MarkSettingsDirty(); + MarkIniSettingsDirty(); } FocusWindow(g.MovedWindow); } @@ -2243,7 +2243,7 @@ void ImGui::NewFrame() { g.SettingsDirtyTimer -= g.IO.DeltaTime; if (g.SettingsDirtyTimer <= 0.0f) - SaveSettings(); + SaveIniSettingsToDisk(g.IO.IniFilename); } // Find the window we are hovering. Child windows can extend beyond the limit of their parent so we need to derive HoveredRootWindow from HoveredWindow @@ -2370,7 +2370,7 @@ void ImGui::Shutdown() if (!g.Initialized) return; - SaveSettings(); + SaveIniSettingsToDisk(g.IO.IniFilename); for (int i = 0; i < g.Windows.Size; i++) { @@ -2450,15 +2450,14 @@ static ImGuiIniData* AddWindowSettings(const char* name) // Zero-tolerance, poor-man .ini parsing // FIXME: Write something less rubbish -static void LoadSettings() +static void LoadIniSettingsFromDisk(const char* ini_filename) { ImGuiContext& g = *GImGui; - const char* filename = g.IO.IniFilename; - if (!filename) + if (!ini_filename) return; int file_size; - char* file_data = (char*)ImLoadFileToMemory(filename, "rb", &file_size, 1); + char* file_data = (char*)ImLoadFileToMemory(ini_filename, "rb", &file_size, 1); if (!file_data) return; @@ -2496,11 +2495,11 @@ static void LoadSettings() ImGui::MemFree(file_data); } -static void SaveSettings() +static void SaveIniSettingsToDisk(const char* ini_filename) { ImGuiContext& g = *GImGui; - const char* filename = g.IO.IniFilename; - if (!filename) + g.SettingsDirtyTimer = 0.0f; + if (!ini_filename) return; // Gather data from windows that were active during this session @@ -2517,7 +2516,7 @@ static void SaveSettings() // Write .ini file // If a window wasn't opened in this session we preserve its settings - FILE* f = ImFileOpen(filename, "wt"); + FILE* f = ImFileOpen(ini_filename, "wt"); if (!f) return; for (int i = 0; i != g.Settings.Size; i++) @@ -2538,7 +2537,7 @@ static void SaveSettings() fclose(f); } -static void MarkSettingsDirty() +static void MarkIniSettingsDirty() { ImGuiContext& g = *GImGui; if (g.SettingsDirtyTimer <= 0.0f) @@ -4010,7 +4009,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us { window->Collapsed = !window->Collapsed; if (!(flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); + MarkIniSettingsDirty(); FocusWindow(window); } } @@ -4085,7 +4084,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us if (window->AutoFitFramesY > 0) window->SizeFull.y = window->AutoFitOnlyGrows ? ImMax(window->SizeFull.y, size_auto_fit.y) : size_auto_fit.y; if (!(flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); + MarkIniSettingsDirty(); } } @@ -4214,7 +4213,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us // Manual auto-fit when double-clicking ApplySizeFullWithConstraint(window, size_auto_fit); if (!(flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); + MarkIniSettingsDirty(); SetActiveID(0); } else if (held) @@ -4222,7 +4221,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us // We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position ApplySizeFullWithConstraint(window, (g.IO.MousePos - g.ActiveIdClickOffset + resize_rect.GetSize()) - window->Pos); if (!(flags & ImGuiWindowFlags_NoSavedSettings)) - MarkSettingsDirty(); + MarkIniSettingsDirty(); } window->Size = window->SizeFull; From 36d78e05651877c69eab0e4aea48cd20d4ce8f9c Mon Sep 17 00:00:00 2001 From: Nicolas Guillemot Date: Sun, 4 Dec 2016 12:54:31 -0800 Subject: [PATCH 10/16] const correctness for Combo and ListBox Since Combo and ListBox only read and display the list of items, they should not modify the pointers inside the array of pointers passed in. Adding "const" here makes it possible to call these functions with such an array of const pointers. Previously, a cast to "const char**" was required as a workaround, otherwise there was a compile error. --- imgui.cpp | 6 +++--- imgui.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5a45931f..09b2ae77 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -8399,7 +8399,7 @@ bool ImGui::InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_fla static bool Items_ArrayGetter(void* data, int idx, const char** out_text) { - const char** items = (const char**)data; + const char* const* items = (const char* const*)data; if (out_text) *out_text = items[idx]; return true; @@ -8426,7 +8426,7 @@ static bool Items_SingleStringGetter(void* data, int idx, const char** out_text) } // Combo box helper allowing to pass an array of strings. -bool ImGui::Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items) +bool ImGui::Combo(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items) { const bool value_changed = Combo(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_in_items); return value_changed; @@ -8703,7 +8703,7 @@ void ImGui::ListBoxFooter() EndGroup(); } -bool ImGui::ListBox(const char* label, int* current_item, const char** items, int items_count, int height_items) +bool ImGui::ListBox(const char* label, int* current_item, const char* const* items, int items_count, int height_items) { const bool value_changed = ListBox(label, current_item, Items_ArrayGetter, (void*)items, items_count, height_items); return value_changed; diff --git a/imgui.h b/imgui.h index 776b4d5c..40e21580 100644 --- a/imgui.h +++ b/imgui.h @@ -265,7 +265,7 @@ namespace ImGui IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); IMGUI_API bool RadioButton(const char* label, bool active); IMGUI_API bool RadioButton(const char* label, int* v, int v_button); - IMGUI_API bool Combo(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1); + IMGUI_API bool Combo(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items = -1); IMGUI_API bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int height_in_items = -1); // separate items with \0, end item-list with \0\0 IMGUI_API bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); IMGUI_API bool ColorButton(const ImVec4& col, bool small_height = false, bool outline_border = true); @@ -339,7 +339,7 @@ namespace ImGui // Widgets: Selectable / Lists IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); - IMGUI_API bool ListBox(const char* label, int* current_item, const char** items, int items_count, int height_in_items = -1); + IMGUI_API bool ListBox(const char* label, int* current_item, const char* const* items, int items_count, int height_in_items = -1); IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); IMGUI_API bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0,0)); // use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards. IMGUI_API bool ListBoxHeader(const char* label, int items_count, int height_in_items = -1); // " From 52308a54f86c367ba79af84225fb17bc30bbfc9e Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 12 Dec 2016 11:05:41 +0100 Subject: [PATCH 11/16] Demo: comments --- imgui_demo.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index e30a004e..d42d1486 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1123,7 +1123,8 @@ void ImGui::ShowTestWindow(bool* p_open) ImGui::BeginChild("scrolling", ImVec2(0, ImGui::GetItemsLineHeightWithSpacing()*7 + 30), true, ImGuiWindowFlags_HorizontalScrollbar); for (int line = 0; line < lines; line++) { - // Display random stuff + // Display random stuff (for the sake of this trivial demo we are using basic Button+SameLine. If you want to create your own time line for a real application you may be better off + // manipulating the cursor position yourself, aka using SetCursorPos/SetCursorScreenPos to position the widgets yourself. You may also want to use the lower-level ImDrawList API) int num_buttons = 10 + ((line & 1) ? line * 9 : line * 3); for (int n = 0; n < num_buttons; n++) { @@ -1181,6 +1182,8 @@ void ImGui::ShowTestWindow(bool* p_open) const char* names[] = { "Bream", "Haddock", "Mackerel", "Pollock", "Tilefish" }; static bool toggles[] = { true, false, false, false, false }; + // Simple selection popup + // (If you want to show the current selection inside the Button itself, you may want to build a string using the "###" operator to preserve a constant ID with a variable label) if (ImGui::Button("Select..")) ImGui::OpenPopup("select"); ImGui::SameLine(); @@ -1195,6 +1198,7 @@ void ImGui::ShowTestWindow(bool* p_open) ImGui::EndPopup(); } + // Showing a menu with toggles if (ImGui::Button("Toggle..")) ImGui::OpenPopup("toggle"); if (ImGui::BeginPopup("toggle")) @@ -1229,8 +1233,8 @@ void ImGui::ShowTestWindow(bool* p_open) } if (ImGui::Button("Popup Menu..")) - ImGui::OpenPopup("popup from button"); - if (ImGui::BeginPopup("popup from button")) + ImGui::OpenPopup("FilePopup"); + if (ImGui::BeginPopup("FilePopup")) { ShowExampleMenuFile(); ImGui::EndPopup(); From d74a3349e90308be9a24daf774bfd50662e04d62 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 19 Dec 2016 23:15:38 +0100 Subject: [PATCH 12/16] Examples: DirectX9: Explicitely setting viewport to match that other examples are doing (#937) --- examples/directx9_example/imgui_impl_dx9.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 82e638ef..93472f65 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -94,6 +94,15 @@ void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) g_pd3dDevice->SetIndices(g_pIB); g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); + // Setup viewport + D3DVIEWPORT9 vp; + vp.X = vp.Y = 0; + vp.Width = (DWORD)io.DisplaySize.x; + vp.Height = (DWORD)io.DisplaySize.y; + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; + g_pd3dDevice->SetViewport(&vp); + // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing g_pd3dDevice->SetPixelShader(NULL); g_pd3dDevice->SetVertexShader(NULL); From baa2e3b45184290c6bab2e37b0483390e5642454 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 21 Dec 2016 18:42:52 +0100 Subject: [PATCH 13/16] Minor documentation tweaks --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 5a45931f..75dd64e0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5,6 +5,7 @@ // Newcomers, read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui // Releases change-log at https://github.com/ocornut/imgui/releases +// Gallery (please post your screenshots/video there!): https://github.com/ocornut/imgui/issues/772 // Developed by Omar Cornut and every direct or indirect contributors to the GitHub. // This library is free but I need your support to sustain development and maintenance. // If you work for a company, please consider financial support, e.g: https://www.patreon.com/imgui @@ -280,7 +281,6 @@ Check the "API BREAKING CHANGES" sections for a list of occasional API breaking changes. If you have a problem with a function, search for its name in the code, there will likely be a comment about it. Please report any issue to the GitHub page! - Q: What is ImTextureID and how do I display an image? A: ImTextureID is a void* used to pass renderer-agnostic texture references around until it hits your render function. ImGui knows nothing about what those bits represent, it just passes them around. It is up to you to decide what you want the void* to carry! @@ -464,7 +464,7 @@ ISSUES & TODO-LIST ================== Issue numbers (#) refer to github issues listed at https://github.com/ocornut/imgui/issues - The list below consist mostly of notes of things to do before they are requested/discussed by users (at that point it usually happens on the github) + The list below consist mostly of ideas noted down before they are requested/discussed by users (at which point it usually moves to the github) - doc: add a proper documentation+regression testing system (#435) - window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list. perhaps a lightweight explicit cleanup pass. From 1396659b7282c11edbe126bf36202c18661fd399 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 21 Dec 2016 20:12:43 +0100 Subject: [PATCH 14/16] Examples: Speculative fix for OSX Makefile to make Travis happy (re #812) --- examples/opengl2_example/Makefile | 4 ++-- examples/opengl3_example/Makefile | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/opengl2_example/Makefile b/examples/opengl2_example/Makefile index bd79d1ba..631abe4b 100644 --- a/examples/opengl2_example/Makefile +++ b/examples/opengl2_example/Makefile @@ -29,11 +29,11 @@ endif ifeq ($(UNAME_S), Darwin) #APPLE ECHO_MESSAGE = "Mac OS X" LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo - LIBS += -L/usr/local/lib -lglfw3 + #LIBS += -L/usr/local/lib -lglfw3 + LIBS += -L/usr/local/lib -lglfw CXXFLAGS = -I../../ -I/usr/local/include CXXFLAGS += -Wall -Wformat -# CXXFLAGS += -D__APPLE__ CFLAGS = $(CXXFLAGS) endif diff --git a/examples/opengl3_example/Makefile b/examples/opengl3_example/Makefile index c824f99a..5d91708a 100644 --- a/examples/opengl3_example/Makefile +++ b/examples/opengl3_example/Makefile @@ -31,12 +31,11 @@ endif ifeq ($(UNAME_S), Darwin) #APPLE ECHO_MESSAGE = "Mac OS X" LIBS = -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo - LIBS += -L/usr/local/lib -lglfw3 - #LIBS += -L/usr/local/lib -lglfw + #LIBS += -L/usr/local/lib -lglfw3 + LIBS += -L/usr/local/lib -lglfw CXXFLAGS = -I../../ -I../libs/gl3w -I/usr/local/include CXXFLAGS += -Wall -Wformat -# CXXFLAGS += -D__APPLE__ CFLAGS = $(CXXFLAGS) endif From f4f0ee750f554de8c9aa52a1bd12c819de380032 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 21 Dec 2016 21:13:43 +0100 Subject: [PATCH 15/16] Update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 1e0d1bc4..9c352696 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,40 @@ Binaries/Demo You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at the features of ImGui, you can download Windows binaries of the demo app here. - [imgui-demo-binaries-20161113.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20161113.zip) (Windows binaries, ImGui 1.49+ 2016/11/13, 5 executables, 588 KB) +Bindings +-------- + +_NB: those third-party bindings may be more or less maintained, more or less close to the spirit of original API. People who create language bindings sometimes haven't used the C++ API themselves. ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, always check the original C++ version first!_ + +Languages: +- cimgui: thin c-api wrapper for ImGui https://github.com/Extrawurst/cimgui +- ImGui.NET: An ImGui wrapper for .NET Core https://github.com/mellinoe/ImGui.NET +- imgui-rs: Rust bindings for dear imgui https://github.com/Gekkio/imgui-rs +- DerelictImgui: Dynamic bindings for the D programming language: https://github.com/Extrawurst/DerelictImgui +- CyImGui: Python bindings for dear imgui using Cython: https://github.com/chromy/cyimgui +- pyimgui: Another Python bindings for dear imgui: https://github.com/swistakm/pyimgui +- LUA: https://github.com/patrickriordan/imgui_lua_bindings + +Frameworks: +- Main ImGui repository include examples for DirectX9, DirectX10, DirectX11, OpenGL2/3, Vulkan, Allegro 5, SDL+GL2/3, iOS and Marmalade: https://github.com/ocornut/imgui/tree/master/examples +- Unmerged PR: DirectX12 example (with issues) https://github.com/ocornut/imgui/pull/301 +- Unmerged PR: SDL2 + OpenGLES + Emscripten example https://github.com/ocornut/imgui/pull/336 +- Unmerged PR: FreeGlut + OpenGL2 example https://github.com/ocornut/imgui/pull/801 +- Unmerged PR: Native Win32 and OSX example https://github.com/ocornut/imgui/pull/281 +- Unmerged PR: Android Example https://github.com/ocornut/imgui/pull/421 +- Cinder backend for dear imgui https://github.com/simongeilfus/Cinder-ImGui +- FlexGUI: Flexium/SFML backend for dear imgui https://github.com/DXsmiley/FlexGUI +- IrrIMGUI: Irrlicht backend for dear imgui https://github.com/ZahlGraf/IrrIMGUI +- LÖVE backend for dear imgui https://github.com/slages/love-imgui +- Ogre backend for dear imgui https://bitbucket.org/LMCrashy/ogreimgui/src +- ofxImGui: openFrameworks backend for dear imgui https://github.com/jvcleave/ofxImGui +- SFML backend for dear imgui https://github.com/EliasD/imgui-sfml +- SFML backend for dear imgui https://github.com/Mischa-Alff/imgui-backends +- cocos2d-x with imgui https://github.com/c0i/imguix https://github.com/ocornut/imgui/issues/551 +- NanoRT: software raytraced version https://github.com/syoyo/imgui/tree/nanort/examples/raytrace_example + +For other bindings: see [this page](https://github.com/ocornut/imgui/wiki/Links/). +Please contact me with the Issues tracker or Twitter to fix/update this list. Gallery ------- From db593220fc419547b80e188b104051d39fc1a8e3 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 23 Dec 2016 11:34:23 +0100 Subject: [PATCH 16/16] Comments, clarified use of io.MouseDelta (#942) (ImGuiIO structure layout changed) --- imgui.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/imgui.h b/imgui.h index 40e21580..38ce2d2d 100644 --- a/imgui.h +++ b/imgui.h @@ -788,29 +788,29 @@ struct ImGuiIO ImWchar InputCharacters[16+1]; // List of characters input (translated by user from keypress+keyboard state). Fill using AddInputCharacter() helper. // Functions - IMGUI_API void AddInputCharacter(ImWchar c); // Helper to add a new character into InputCharacters[] - IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Helper to add new characters into InputCharacters[] from an UTF-8 string - inline void ClearInputCharacters() { InputCharacters[0] = 0; } // Helper to clear the text input buffer + IMGUI_API void AddInputCharacter(ImWchar c); // Add new character into InputCharacters[] + IMGUI_API void AddInputCharactersUTF8(const char* utf8_chars); // Add new characters into InputCharacters[] from an UTF-8 string + inline void ClearInputCharacters() { InputCharacters[0] = 0; } // Clear the text input buffer manually //------------------------------------------------------------------ - // Output - Retrieve after calling NewFrame(), you can use them to discard inputs or hide them from the rest of your application + // Output - Retrieve after calling NewFrame() //------------------------------------------------------------------ - bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input) - bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input) - bool WantTextInput; // Some text input widget is active, which will read input characters from the InputCharacters array. - float Framerate; // Framerate estimation, in frame per second. Rolling average estimation based on IO.DeltaTime over 120 frames + bool WantCaptureMouse; // Mouse is hovering a window or widget is active (= ImGui will use your mouse input). Use to hide mouse from the rest of your application + bool WantCaptureKeyboard; // Widget is active (= ImGui will use your keyboard input). Use to hide keyboard from the rest of your application + bool WantTextInput; // Some text input widget is active, which will read input characters from the InputCharacters array. Use to activate on screen keyboard if your system needs one + float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames int MetricsAllocs; // Number of active memory allocations int MetricsRenderVertices; // Vertices output during last call to Render() int MetricsRenderIndices; // Indices output during last call to Render() = number of triangles * 3 - int MetricsActiveWindows; // Number of visible windows (exclude child windows) + int MetricsActiveWindows; // Number of visible root windows (exclude child windows) + ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative, so a disappearing/reappearing mouse won't have a huge delta for one frame. //------------------------------------------------------------------ // [Private] ImGui will maintain those fields. Forward compatibility not guaranteed! //------------------------------------------------------------------ - ImVec2 MousePosPrev; // Previous mouse position - ImVec2 MouseDelta; // Mouse delta. Note that this is zero if either current or previous position are negative to allow mouse enabling/disabling. + ImVec2 MousePosPrev; // Previous mouse position temporary storage (nb: not for public use, set to MousePos in NewFrame()) bool MouseClicked[5]; // Mouse button went from !Down to Down ImVec2 MouseClickedPos[5]; // Position at time of clicking float MouseClickedTime[5]; // Time of last click (used to figure out double-click)