From c38526d14b38eff269032ac2b00a748ee16964c6 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sun, 1 Oct 2017 23:40:29 -0400 Subject: [PATCH 01/12] Completely clear font when rebuilding atlas. Previously, IndexLookup was not cleared on each font, causing FindGlyph to return old glyphs when using MergeMode. --- imgui_draw.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 736476891..b45cc1ffd 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1540,7 +1540,6 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float off_x = cfg.GlyphOffset.x; const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); - dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable() for (int i = 0; i < tmp.RangesCount; i++) { stbtt_pack_range& range = tmp.Ranges[i]; @@ -1582,14 +1581,16 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f { if (!font_config->MergeMode) { - font->ContainerAtlas = atlas; - font->ConfigData = font_config; - font->ConfigDataCount = 0; + ImVec2 display_offset = font->DisplayOffset; + + font->Clear(); + font->FontSize = font_config->SizePixels; + font->DisplayOffset = display_offset; + font->ConfigData = font_config; + font->ContainerAtlas = atlas; font->Ascent = ascent; font->Descent = descent; - font->Glyphs.resize(0); - font->MetricsTotalSurface = 0; } font->ConfigDataCount++; } From 839067fda9e2ffa34c2e8bfc36be2c94fddcab53 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Tue, 17 Oct 2017 12:37:21 +0200 Subject: [PATCH 02/12] Capture/release window in DX9 implementation This helps a lot when the user drags a slider but carries the cursor offscreen before releasing the button - without the capturing, the slider will "stick" to the mouse cursor even after the button has been released. (This should generally be added to all Windows implementations - I won't mind doing it if you think it's a good idea.) --- examples/directx9_example/imgui_impl_dx9.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 490120126..d1062560b 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -177,21 +177,27 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LP switch (msg) { case WM_LBUTTONDOWN: + SetCapture( hWnd ); io.MouseDown[0] = true; return true; case WM_LBUTTONUP: + ReleaseCapture(); io.MouseDown[0] = false; return true; case WM_RBUTTONDOWN: + SetCapture( hWnd ); io.MouseDown[1] = true; return true; case WM_RBUTTONUP: + ReleaseCapture(); io.MouseDown[1] = false; return true; case WM_MBUTTONDOWN: + SetCapture( hWnd ); io.MouseDown[2] = true; return true; case WM_MBUTTONUP: + ReleaseCapture(); io.MouseDown[2] = false; return true; case WM_MOUSEWHEEL: From fce41d0b5569ceaf9e7901a013efc68980d57662 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:21:49 +0200 Subject: [PATCH 03/12] Demo: Fixed Fonts "set as default button" not having collading id on collapsed nodes. --- imgui_demo.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 404dcbdbc..35ee618b9 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1951,6 +1951,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) for (int i = 0; i < atlas->Fonts.Size; i++) { ImFont* font = atlas->Fonts[i]; + ImGui::PushID(font); bool font_details_opened = ImGui::TreeNode(font, "Font %d: \'%s\', %.2f px, %d glyphs", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size); ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font; if (font_details_opened) @@ -2011,6 +2012,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) } ImGui::TreePop(); } + ImGui::PopID(); } static float window_scale = 1.0f; ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this window From 7f880674e5c3e594ac034215252b7d1455a1579f Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:24:56 +0200 Subject: [PATCH 04/12] Font: Renamed ImFont::Clear() to ImFont::ClearOutputData() for consistency with what ImFontAtlas does. DisplayOffset is set by constructor but not reset by ClearOutputData. (#1349) --- imgui.h | 2 +- imgui_draw.cpp | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/imgui.h b/imgui.h index e281b4f1a..c865d3578 100644 --- a/imgui.h +++ b/imgui.h @@ -1500,7 +1500,7 @@ struct ImFont // Methods IMGUI_API ImFont(); IMGUI_API ~ImFont(); - IMGUI_API void Clear(); + IMGUI_API void ClearOutputData(); IMGUI_API void BuildLookupTable(); IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const; IMGUI_API void SetFallbackChar(ImWchar c); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 302c338bb..c3a5f3d5c 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1618,12 +1618,8 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f { if (!font_config->MergeMode) { - ImVec2 display_offset = font->DisplayOffset; - - font->Clear(); - + font->ClearOutputData(); font->FontSize = font_config->SizePixels; - font->DisplayOffset = display_offset; font->ConfigData = font_config; font->ContainerAtlas = atlas; font->Ascent = ascent; @@ -1904,7 +1900,8 @@ ImFont::ImFont() { Scale = 1.0f; FallbackChar = (ImWchar)'?'; - Clear(); + DisplayOffset = ImVec2(0.0f, 1.0f); + ClearOutputData(); } ImFont::~ImFont() @@ -1917,13 +1914,12 @@ ImFont::~ImFont() if (g.Font == this) g.Font = NULL; */ - Clear(); + ClearOutputData(); } -void ImFont::Clear() +void ImFont::ClearOutputData() { FontSize = 0.0f; - DisplayOffset = ImVec2(0.0f, 1.0f); Glyphs.clear(); IndexAdvanceX.clear(); IndexLookup.clear(); From b177f2432dd9ab90f765adf39a6376e4ddea7bb9 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:36:22 +0200 Subject: [PATCH 05/12] MenuItem(): Tweak to not draw over all horizontal space when in horizontal layout mode. (#1387) --- imgui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 15a4e5cd3..c3e97846e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9083,7 +9083,8 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); - bool pressed = Selectable(label, false, ImGuiSelectableFlags_MenuItem | ImGuiSelectableFlags_DrawFillAvailWidth | (enabled ? 0 : ImGuiSelectableFlags_Disabled), ImVec2(w, 0.0f)); + ImGuiSelectableFlags flags = ImGuiSelectableFlags_MenuItem | (enabled ? 0 : ImGuiSelectableFlags_Disabled) | (window->DC.LayoutType == ImGuiLayoutType_Vertical ? ImGuiSelectableFlags_DrawFillAvailWidth : 0); + bool pressed = Selectable(label, false, flags, ImVec2(w, 0.0f)); if (shortcut_size.x > 0.0f) { PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); From 1bc17516706652ae662d8837374473fd93f5ac6e Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:54:53 +0200 Subject: [PATCH 06/12] MenuItem(): Tweaks to mimic exact spacing of BeginMenu() when inside a menu bar, which is a little misleading imho but may be useful. (#1387) --- imgui.cpp | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c3e97846e..8ad739fa0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9077,24 +9077,38 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo return false; ImGuiContext& g = *GImGui; + ImGuiStyle& style = g.Style; ImVec2 pos = window->DC.CursorPos; ImVec2 label_size = CalcTextSize(label, NULL, true); - ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); - float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame - float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); - ImGuiSelectableFlags flags = ImGuiSelectableFlags_MenuItem | (enabled ? 0 : ImGuiSelectableFlags_Disabled) | (window->DC.LayoutType == ImGuiLayoutType_Vertical ? ImGuiSelectableFlags_DrawFillAvailWidth : 0); - bool pressed = Selectable(label, false, flags, ImVec2(w, 0.0f)); - if (shortcut_size.x > 0.0f) + ImGuiSelectableFlags flags = ImGuiSelectableFlags_MenuItem | (enabled ? 0 : ImGuiSelectableFlags_Disabled); + bool pressed; + if (window->DC.LayoutType == ImGuiLayoutType_Horizontal) { - PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); - RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); - PopStyleColor(); + // Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful + // Note that in this situation we render neither the shortcut neither the selected tick mark + float w = label_size.x; + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * 0.5f); + PushStyleVar(ImGuiStyleVar_ItemSpacing, style.ItemSpacing * 2.0f); + pressed = Selectable(label, false, flags, ImVec2(w, 0.0f)); + PopStyleVar(); + window->DC.CursorPos.x += (float)(int)(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar(). + } + else + { + ImVec2 shortcut_size = shortcut ? CalcTextSize(shortcut, NULL) : ImVec2(0.0f, 0.0f); + float w = window->MenuColumns.DeclColumns(label_size.x, shortcut_size.x, (float)(int)(g.FontSize * 1.20f)); // Feedback for next frame + float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w); + pressed = Selectable(label, false, flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2(w, 0.0f)); + if (shortcut_size.x > 0.0f) + { + PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]); + RenderText(pos + ImVec2(window->MenuColumns.Pos[1] + extra_w, 0.0f), shortcut, NULL, false); + PopStyleColor(); + } + if (selected) + RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * (0.20f+0.200f), g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); } - - if (selected) - RenderCheckMark(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * (0.20f+0.200f), g.FontSize * 0.134f * 0.5f), GetColorU32(enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled), g.FontSize * 0.866f); - return pressed; } From e03198bb0f636a4f997883b498125dee30f570db Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 09:08:12 +0200 Subject: [PATCH 07/12] Fixed compilation for #1375 + coding style fixes. --- examples/directx9_example/imgui_impl_dx9.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index d1062560b..1d122adfc 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -171,13 +171,13 @@ void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) d3d9_state_block->Release(); } -IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam) +IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: - SetCapture( hWnd ); + SetCapture(hwnd); io.MouseDown[0] = true; return true; case WM_LBUTTONUP: @@ -185,7 +185,7 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LP io.MouseDown[0] = false; return true; case WM_RBUTTONDOWN: - SetCapture( hWnd ); + SetCapture(hwnd); io.MouseDown[1] = true; return true; case WM_RBUTTONUP: @@ -193,7 +193,7 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LP io.MouseDown[1] = false; return true; case WM_MBUTTONDOWN: - SetCapture( hWnd ); + SetCapture(hwnd); io.MouseDown[2] = true; return true; case WM_MBUTTONUP: From 3e0765ee222a21bf801486f7a817d07569cada84 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 09:43:13 +0200 Subject: [PATCH 08/12] Examples: DirectX9: Using SetCapture/ReleaseCapture to get correct behavior (#1375) --- examples/directx9_example/imgui_impl_dx9.cpp | 34 +++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 1d122adfc..0e94d3b81 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -171,34 +171,44 @@ void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data) d3d9_state_block->Release(); } +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +// We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds. IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: - SetCapture(hwnd); + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; return true; - case WM_LBUTTONUP: - ReleaseCapture(); - io.MouseDown[0] = false; - return true; case WM_RBUTTONDOWN: - SetCapture(hwnd); + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[1] = true; return true; - case WM_RBUTTONUP: - ReleaseCapture(); - io.MouseDown[1] = false; - return true; case WM_MBUTTONDOWN: - SetCapture(hwnd); + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[2] = true; return true; + case WM_LBUTTONUP: + io.MouseDown[0] = false; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); + return true; + case WM_RBUTTONUP: + io.MouseDown[1] = false; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); + return true; case WM_MBUTTONUP: - ReleaseCapture(); io.MouseDown[2] = false; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; From a96f095deb83f001498157bf10eed3a44d3ee96a Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 09:46:49 +0200 Subject: [PATCH 09/12] Examples: DirectX10, DirectX11: Using SetCapture/ReleaseCapture to get correct behavior (#1375) ps: DirectX 12 example (#302) may want to adopt that as well. --- .../directx10_example/imgui_impl_dx10.cpp | 29 ++++++++++++++----- .../directx11_example/imgui_impl_dx11.cpp | 29 ++++++++++++++----- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index f85edf9b5..e0afa6f65 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -225,28 +225,43 @@ void ImGui_ImplDX10_RenderDrawLists(ImDrawData* draw_data) ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); } -IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam) +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; return true; + case WM_RBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); + io.MouseDown[1] = true; + return true; + case WM_MBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); + io.MouseDown[2] = true; + return true; case WM_LBUTTONUP: io.MouseDown[0] = false; - return true; - case WM_RBUTTONDOWN: - io.MouseDown[1] = true; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_RBUTTONUP: io.MouseDown[1] = false; - return true; - case WM_MBUTTONDOWN: - io.MouseDown[2] = true; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_MBUTTONUP: io.MouseDown[2] = false; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 49a4aa481..82c43f7e1 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -232,28 +232,43 @@ void ImGui_ImplDX11_RenderDrawLists(ImDrawData* draw_data) ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release(); } -IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, LPARAM lParam) +static bool IsAnyMouseButtonDown() +{ + ImGuiIO& io = ImGui::GetIO(); + for (int n = 0; n < ARRAYSIZE(io.MouseDown); n++) + if (io.MouseDown[n]) + return true; + return false; +} + +IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { case WM_LBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; return true; + case WM_RBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); + io.MouseDown[1] = true; + return true; + case WM_MBUTTONDOWN: + if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); + io.MouseDown[2] = true; + return true; case WM_LBUTTONUP: io.MouseDown[0] = false; - return true; - case WM_RBUTTONDOWN: - io.MouseDown[1] = true; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_RBUTTONUP: io.MouseDown[1] = false; - return true; - case WM_MBUTTONDOWN: - io.MouseDown[2] = true; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_MBUTTONUP: io.MouseDown[2] = false; + if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); return true; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; From c14a66970b71df8f11086f602df6dd316f5f749f Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 09:57:59 +0200 Subject: [PATCH 10/12] Examples: DirectX9/10/11: Renamed WndProc handler to use a generic Win32 name + returning 0 to all messages is more correct. --- .../directx10_example/imgui_impl_dx10.cpp | 24 +++++++++---------- examples/directx10_example/main.cpp | 4 ++-- .../directx11_example/imgui_impl_dx11.cpp | 24 +++++++++---------- examples/directx11_example/main.cpp | 4 ++-- examples/directx9_example/imgui_impl_dx9.cpp | 24 +++++++++---------- examples/directx9_example/main.cpp | 4 ++-- 6 files changed, 42 insertions(+), 42 deletions(-) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index e0afa6f65..13dc99c95 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -234,7 +234,7 @@ static bool IsAnyMouseButtonDown() return false; } -IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) @@ -242,47 +242,47 @@ IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPar case WM_LBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; - return true; + return 0; case WM_RBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[1] = true; - return true; + return 0; case WM_MBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[2] = true; - return true; + return 0; case WM_LBUTTONUP: io.MouseDown[0] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_RBUTTONUP: io.MouseDown[1] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MBUTTONUP: io.MouseDown[2] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; - return true; + return 0; case WM_MOUSEMOVE: io.MousePos.x = (signed short)(lParam); io.MousePos.y = (signed short)(lParam >> 16); - return true; + return 0; case WM_KEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; - return true; + return 0; case WM_KEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; - return true; + return 0; case WM_CHAR: // You can also use ToAscii()+GetKeyboardState() to retrieve characters. if (wParam > 0 && wParam < 0x10000) io.AddInputCharacter((unsigned short)wParam); - return true; + return 0; } return 0; } diff --git a/examples/directx10_example/main.cpp b/examples/directx10_example/main.cpp index 4675a21da..ea690742d 100644 --- a/examples/directx10_example/main.cpp +++ b/examples/directx10_example/main.cpp @@ -74,10 +74,10 @@ void CleanupDeviceD3D() if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } } -extern LRESULT ImGui_ImplDX10_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (ImGui_ImplDX10_WndProcHandler(hWnd, msg, wParam, lParam)) + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) return true; switch (msg) diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 82c43f7e1..6d057e07c 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -241,7 +241,7 @@ static bool IsAnyMouseButtonDown() return false; } -IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) @@ -249,47 +249,47 @@ IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPar case WM_LBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; - return true; + return 0; case WM_RBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[1] = true; - return true; + return 0; case WM_MBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[2] = true; - return true; + return 0; case WM_LBUTTONUP: io.MouseDown[0] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_RBUTTONUP: io.MouseDown[1] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MBUTTONUP: io.MouseDown[2] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; - return true; + return 0; case WM_MOUSEMOVE: io.MousePos.x = (signed short)(lParam); io.MousePos.y = (signed short)(lParam >> 16); - return true; + return 0; case WM_KEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; - return true; + return 0; case WM_KEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; - return true; + return 0; case WM_CHAR: // You can also use ToAscii()+GetKeyboardState() to retrieve characters. if (wParam > 0 && wParam < 0x10000) io.AddInputCharacter((unsigned short)wParam); - return true; + return 0; } return 0; } diff --git a/examples/directx11_example/main.cpp b/examples/directx11_example/main.cpp index 04321610e..794503e38 100644 --- a/examples/directx11_example/main.cpp +++ b/examples/directx11_example/main.cpp @@ -77,10 +77,10 @@ void CleanupDeviceD3D() if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } } -extern LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (ImGui_ImplDX11_WndProcHandler(hWnd, msg, wParam, lParam)) + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) return true; switch (msg) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 0e94d3b81..111ed8153 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -181,7 +181,7 @@ static bool IsAnyMouseButtonDown() } // We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds. -IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) @@ -189,47 +189,47 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPara case WM_LBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[0] = true; - return true; + return 0; case WM_RBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[1] = true; - return true; + return 0; case WM_MBUTTONDOWN: if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); io.MouseDown[2] = true; - return true; + return 0; case WM_LBUTTONUP: io.MouseDown[0] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_RBUTTONUP: io.MouseDown[1] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MBUTTONUP: io.MouseDown[2] = false; if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); - return true; + return 0; case WM_MOUSEWHEEL: io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; - return true; + return 0; case WM_MOUSEMOVE: io.MousePos.x = (signed short)(lParam); io.MousePos.y = (signed short)(lParam >> 16); - return true; + return 0; case WM_KEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; - return true; + return 0; case WM_KEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; - return true; + return 0; case WM_CHAR: // You can also use ToAscii()+GetKeyboardState() to retrieve characters. if (wParam > 0 && wParam < 0x10000) io.AddInputCharacter((unsigned short)wParam); - return true; + return 0; } return 0; } diff --git a/examples/directx9_example/main.cpp b/examples/directx9_example/main.cpp index b8e5907c8..6a359c62b 100644 --- a/examples/directx9_example/main.cpp +++ b/examples/directx9_example/main.cpp @@ -12,10 +12,10 @@ static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; static D3DPRESENT_PARAMETERS g_d3dpp; -extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); +extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { - if (ImGui_ImplDX9_WndProcHandler(hWnd, msg, wParam, lParam)) + if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) return true; switch (msg) From d6a99567812e3a20cf828fc4976942df233302a7 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 10:01:18 +0200 Subject: [PATCH 11/12] Examples: DirectX9/10/11: Added WM_SYSKEYDOWN / WM_SYSKEYUP handlers so e.g. VK_MENU can be read. --- examples/directx10_example/imgui_impl_dx10.cpp | 2 ++ examples/directx11_example/imgui_impl_dx11.cpp | 2 ++ examples/directx9_example/imgui_impl_dx9.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index 13dc99c95..816e56211 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -271,10 +271,12 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa io.MousePos.y = (signed short)(lParam >> 16); return 0; case WM_KEYDOWN: + case WM_SYSKEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; return 0; case WM_KEYUP: + case WM_SYSKEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; return 0; diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 6d057e07c..7b3a3ba83 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -278,10 +278,12 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa io.MousePos.y = (signed short)(lParam >> 16); return 0; case WM_KEYDOWN: + case WM_SYSKEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; return 0; case WM_KEYUP: + case WM_SYSKEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; return 0; diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 111ed8153..fc05c9ce5 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -218,10 +218,12 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa io.MousePos.y = (signed short)(lParam >> 16); return 0; case WM_KEYDOWN: + case WM_SYSKEYDOWN: if (wParam < 256) io.KeysDown[wParam] = 1; return 0; case WM_KEYUP: + case WM_SYSKEYUP: if (wParam < 256) io.KeysDown[wParam] = 0; return 0; From 50f5be9266ce21391597695dc80b15a4724447cc Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 23 Oct 2017 10:04:38 +0200 Subject: [PATCH 12/12] Examples: GLFW+GL2/GL3: Minor tweaks, comments. --- examples/opengl2_example/imgui_impl_glfw.cpp | 9 +++++---- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/opengl2_example/imgui_impl_glfw.cpp b/examples/opengl2_example/imgui_impl_glfw.cpp index 236a2d101..4aed20a6f 100644 --- a/examples/opengl2_example/imgui_impl_glfw.cpp +++ b/examples/opengl2_example/imgui_impl_glfw.cpp @@ -26,7 +26,7 @@ // Data static GLFWwindow* g_Window = NULL; static double g_Time = 0.0f; -static bool g_MousePressed[3] = { false, false, false }; +static bool g_MouseJustPressed[3] = { false, false, false }; static float g_MouseWheel = 0.0f; static GLuint g_FontTexture = 0; @@ -129,7 +129,7 @@ static void ImGui_ImplGlfwGL2_SetClipboardText(void* user_data, const char* text void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) { if (action == GLFW_PRESS && button >= 0 && button < 3) - g_MousePressed[button] = true; + g_MouseJustPressed[button] = true; } void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset) @@ -287,8 +287,9 @@ void ImGui_ImplGlfwGL2_NewFrame() for (int i = 0; i < 3; i++) { - io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. - g_MousePressed[i] = false; + // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; + g_MouseJustPressed[i] = false; } io.MouseWheel = g_MouseWheel; diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index ac711b91e..3611d6e6c 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -22,7 +22,7 @@ // Data static GLFWwindow* g_Window = NULL; static double g_Time = 0.0f; -static bool g_MousePressed[3] = { false, false, false }; +static bool g_MouseJustPressed[3] = { false, false, false }; static float g_MouseWheel = 0.0f; static GLuint g_FontTexture = 0; static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0; @@ -150,7 +150,7 @@ static void ImGui_ImplGlfwGL3_SetClipboardText(void* user_data, const char* text void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/) { if (action == GLFW_PRESS && button >= 0 && button < 3) - g_MousePressed[button] = true; + g_MouseJustPressed[button] = true; } void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset) @@ -401,8 +401,9 @@ void ImGui_ImplGlfwGL3_NewFrame() for (int i = 0; i < 3; i++) { - io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. - g_MousePressed[i] = false; + // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame. + io.MouseDown[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 0; + g_MouseJustPressed[i] = false; } io.MouseWheel = g_MouseWheel;