From ecbfdd3143e60802c15d5341f664723ffb273d90 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 4 Jan 2018 11:06:12 +0100 Subject: [PATCH 01/12] Added extraneous initialization to NULL. (#1527). --- imgui_draw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index c7232af8..0cb7cd82 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1439,7 +1439,7 @@ void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_wid // Although it is likely to be the most commonly used format, our font rendering is 1 channel / 8 bpp if (!TexPixelsRGBA32) { - unsigned char* pixels; + unsigned char* pixels = NULL; GetTexDataAsAlpha8(&pixels, NULL, NULL); if (pixels) { From 4c90529c62ecb765a8b4315d91f69af157ee12df Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 4 Jan 2018 11:42:05 +0100 Subject: [PATCH 02/12] Examples: Visual Studio projects: Disabled extraneous function-level check in Release build. --- examples/directx10_example/directx10_example.vcxproj | 2 ++ examples/directx11_example/directx11_example.vcxproj | 2 ++ examples/directx9_example/directx9_example.vcxproj | 2 ++ examples/opengl2_example/opengl2_example.vcxproj | 2 ++ examples/opengl3_example/opengl3_example.vcxproj | 2 ++ 5 files changed, 10 insertions(+) diff --git a/examples/directx10_example/directx10_example.vcxproj b/examples/directx10_example/directx10_example.vcxproj index c4f15c56..8583e1de 100644 --- a/examples/directx10_example/directx10_example.vcxproj +++ b/examples/directx10_example/directx10_example.vcxproj @@ -110,6 +110,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true @@ -127,6 +128,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true diff --git a/examples/directx11_example/directx11_example.vcxproj b/examples/directx11_example/directx11_example.vcxproj index 944c8e86..7099a7bd 100644 --- a/examples/directx11_example/directx11_example.vcxproj +++ b/examples/directx11_example/directx11_example.vcxproj @@ -110,6 +110,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true @@ -127,6 +128,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true diff --git a/examples/directx9_example/directx9_example.vcxproj b/examples/directx9_example/directx9_example.vcxproj index c10731de..6fe7c9ce 100644 --- a/examples/directx9_example/directx9_example.vcxproj +++ b/examples/directx9_example/directx9_example.vcxproj @@ -110,6 +110,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true @@ -127,6 +128,7 @@ true true ..\..;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + false true diff --git a/examples/opengl2_example/opengl2_example.vcxproj b/examples/opengl2_example/opengl2_example.vcxproj index bea2104d..a6cbebd6 100644 --- a/examples/opengl2_example/opengl2_example.vcxproj +++ b/examples/opengl2_example/opengl2_example.vcxproj @@ -116,6 +116,7 @@ true true $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + false true @@ -135,6 +136,7 @@ true true $(SolutionDir)\libs\glfw\include;..\..;%(AdditionalIncludeDirectories) + false true diff --git a/examples/opengl3_example/opengl3_example.vcxproj b/examples/opengl3_example/opengl3_example.vcxproj index 8d8bec90..d481c943 100644 --- a/examples/opengl3_example/opengl3_example.vcxproj +++ b/examples/opengl3_example/opengl3_example.vcxproj @@ -116,6 +116,7 @@ true true $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + false true @@ -135,6 +136,7 @@ true true $(SolutionDir)\libs\glfw\include;$(SolutionDir)\libs\gl3w;..\..;%(AdditionalIncludeDirectories) + false true From 007f4034c907defdf781a1d34ad1f769b0374436 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 5 Jan 2018 15:33:24 +0100 Subject: [PATCH 03/12] Internals: Added LastActiveId, LastActiveIdTimer. (#1537) --- imgui.cpp | 8 ++++++++ imgui_internal.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index 3728a890..82dc2d6e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1929,7 +1929,14 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; g.ActiveIdIsJustActivated = (g.ActiveId != id); if (g.ActiveIdIsJustActivated) + { g.ActiveIdTimer = 0.0f; + if (id != 0) + { + g.LastActiveId = id; + g.LastActiveIdTimer = 0.0f; + } + } g.ActiveId = id; g.ActiveIdAllowOverlap = false; g.ActiveIdIsAlive |= (id != 0); @@ -2308,6 +2315,7 @@ void ImGui::NewFrame() ClearActiveID(); if (g.ActiveId) g.ActiveIdTimer += g.IO.DeltaTime; + g.LastActiveIdTimer += g.IO.DeltaTime; g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; g.ActiveIdIsJustActivated = false; diff --git a/imgui_internal.h b/imgui_internal.h index c8097025..cfc84437 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -533,6 +533,8 @@ struct ImGuiContext bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; + ImGuiID LastActiveId; // Store the last non-zero ActiveID, useful for animation. + float LastActiveIdTimer; ImGuiWindow* MovingWindow; // Track the child window we clicked on to move a window. ImGuiID MovingWindowMoveId; // == MovingWindow->MoveId ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() @@ -629,6 +631,8 @@ struct ImGuiContext ActiveIdAllowOverlap = false; ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = NULL; + LastActiveId = 0; + LastActiveIdTimer = 0.0f; MovingWindow = NULL; MovingWindowMoveId = 0; From 95b773370fceeaa5cbfadd6353b08a05381edcbc Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 5 Jan 2018 17:39:53 +0100 Subject: [PATCH 04/12] Revert "Internals: Added LastActiveId, LastActiveIdTimer. (#1537)" Will come up with a better design later. This reverts commit 007f4034c907defdf781a1d34ad1f769b0374436. --- imgui.cpp | 8 -------- imgui_internal.h | 4 ---- 2 files changed, 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 82dc2d6e..3728a890 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1929,14 +1929,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) ImGuiContext& g = *GImGui; g.ActiveIdIsJustActivated = (g.ActiveId != id); if (g.ActiveIdIsJustActivated) - { g.ActiveIdTimer = 0.0f; - if (id != 0) - { - g.LastActiveId = id; - g.LastActiveIdTimer = 0.0f; - } - } g.ActiveId = id; g.ActiveIdAllowOverlap = false; g.ActiveIdIsAlive |= (id != 0); @@ -2315,7 +2308,6 @@ void ImGui::NewFrame() ClearActiveID(); if (g.ActiveId) g.ActiveIdTimer += g.IO.DeltaTime; - g.LastActiveIdTimer += g.IO.DeltaTime; g.ActiveIdPreviousFrame = g.ActiveId; g.ActiveIdIsAlive = false; g.ActiveIdIsJustActivated = false; diff --git a/imgui_internal.h b/imgui_internal.h index cfc84437..c8097025 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -533,8 +533,6 @@ struct ImGuiContext bool ActiveIdAllowOverlap; // Active widget allows another widget to steal active id (generally for overlapping widgets, but not always) ImVec2 ActiveIdClickOffset; // Clicked offset from upper-left corner, if applicable (currently only set by ButtonBehavior) ImGuiWindow* ActiveIdWindow; - ImGuiID LastActiveId; // Store the last non-zero ActiveID, useful for animation. - float LastActiveIdTimer; ImGuiWindow* MovingWindow; // Track the child window we clicked on to move a window. ImGuiID MovingWindowMoveId; // == MovingWindow->MoveId ImVector ColorModifiers; // Stack for PushStyleColor()/PopStyleColor() @@ -631,8 +629,6 @@ struct ImGuiContext ActiveIdAllowOverlap = false; ActiveIdClickOffset = ImVec2(-1,-1); ActiveIdWindow = NULL; - LastActiveId = 0; - LastActiveIdTimer = 0.0f; MovingWindow = NULL; MovingWindowMoveId = 0; From 20ae6439eaf7bee14872fedd07b0188cc0a9afee Mon Sep 17 00:00:00 2001 From: Nick Dandoulakis Date: Fri, 5 Jan 2018 22:16:35 +0200 Subject: [PATCH 05/12] CS_DBLCLKS support for Directx9 --- examples/directx9_example/imgui_impl_dx9.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index 484e84cd..de00f88d 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -192,13 +192,16 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa switch (msg) { case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: { int button = 0; - if (msg == WM_LBUTTONDOWN) button = 0; - if (msg == WM_RBUTTONDOWN) button = 1; - if (msg == WM_MBUTTONDOWN) button = 2; + if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; + if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) button = 1; + if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) button = 2; if (!IsAnyMouseButtonDown() && GetCapture() == NULL) SetCapture(hwnd); io.MouseDown[button] = true; From 583e97b2975989dbe1762ee61a4fd4eb84541f0b Mon Sep 17 00:00:00 2001 From: Nick Dandoulakis Date: Fri, 5 Jan 2018 22:25:30 +0200 Subject: [PATCH 06/12] CS_DBLCLKS support for DirectX 10 --- examples/directx10_example/imgui_impl_dx10.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index 59152673..6338be72 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -246,13 +246,16 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa switch (msg) { case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: { int button = 0; - if (msg == WM_LBUTTONDOWN) button = 0; - if (msg == WM_RBUTTONDOWN) button = 1; - if (msg == WM_MBUTTONDOWN) button = 2; + if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; + if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) button = 1; + if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) button = 2; if (!IsAnyMouseButtonDown() && GetCapture() == NULL) SetCapture(hwnd); io.MouseDown[button] = true; From bfc25bc8a3c017084c7fc23c955e0c33e13e0226 Mon Sep 17 00:00:00 2001 From: Nick Dandoulakis Date: Fri, 5 Jan 2018 22:28:27 +0200 Subject: [PATCH 07/12] CS_DBLCLKS support for DirectX 11 --- examples/directx11_example/imgui_impl_dx11.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index af6e54f4..7016301b 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -253,13 +253,16 @@ IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPa switch (msg) { case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: { int button = 0; - if (msg == WM_LBUTTONDOWN) button = 0; - if (msg == WM_RBUTTONDOWN) button = 1; - if (msg == WM_MBUTTONDOWN) button = 2; + if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; + if (msg == WM_RBUTTONDOWN || msg == WM_RBUTTONDBLCLK) button = 1; + if (msg == WM_MBUTTONDOWN || msg == WM_MBUTTONDBLCLK) button = 2; if (!IsAnyMouseButtonDown() && GetCapture() == NULL) SetCapture(hwnd); io.MouseDown[button] = true; From 407955d9fbcfe5391e5f28790f21c15f85d06c90 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 5 Jan 2018 22:05:02 +0100 Subject: [PATCH 08/12] Examples: Using IM_OFFSETOF macro. + Comments --- examples/allegro5_example/imgui_impl_a5.cpp | 8 +++----- examples/apple_example/imguiex-ios/imgui_impl_ios.mm | 9 ++++----- examples/opengl2_example/imgui_impl_glfw.cpp | 8 +++----- examples/opengl3_example/imgui_impl_glfw_gl3.cpp | 8 +++----- examples/sdl_opengl2_example/imgui_impl_sdl.cpp | 8 +++----- examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp | 8 +++----- imgui.h | 2 +- 7 files changed, 20 insertions(+), 31 deletions(-) diff --git a/examples/allegro5_example/imgui_impl_a5.cpp b/examples/allegro5_example/imgui_impl_a5.cpp index 0d385923..7a7d4cc1 100644 --- a/examples/allegro5_example/imgui_impl_a5.cpp +++ b/examples/allegro5_example/imgui_impl_a5.cpp @@ -28,8 +28,6 @@ static double g_Time = 0.0; static ALLEGRO_MOUSE_CURSOR* g_MouseCursorInvisible = NULL; static ALLEGRO_VERTEX_DECL* g_VertexDecl = NULL; -#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) - struct ImDrawVertAllegro { ImVec2 pos; @@ -162,9 +160,9 @@ bool ImGui_ImplA5_Init(ALLEGRO_DISPLAY* display) // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion. ALLEGRO_VERTEX_ELEMENT elems[] = { - { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, pos) }, - { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, OFFSETOF(ImDrawVertAllegro, uv) }, - { ALLEGRO_PRIM_COLOR_ATTR, 0, OFFSETOF(ImDrawVertAllegro, col) }, + { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, pos) }, + { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, uv) }, + { ALLEGRO_PRIM_COLOR_ATTR, 0, IM_OFFSETOF(ImDrawVertAllegro, col) }, { 0, 0, 0 } }; g_VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro)); diff --git a/examples/apple_example/imguiex-ios/imgui_impl_ios.mm b/examples/apple_example/imguiex-ios/imgui_impl_ios.mm index bfcae7cd..7fd7466c 100644 --- a/examples/apple_example/imguiex-ios/imgui_impl_ios.mm +++ b/examples/apple_example/imguiex-ios/imgui_impl_ios.mm @@ -793,11 +793,10 @@ bool ImGui_ImplIOS_CreateDeviceObjects() glEnableVertexAttribArray(g_AttribLocationUV); glEnableVertexAttribArray(g_AttribLocationColor); -#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) - glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); - glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); - glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); -#undef OFFSETOF + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); + glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/examples/opengl2_example/imgui_impl_glfw.cpp b/examples/opengl2_example/imgui_impl_glfw.cpp index 33df611e..a635cc9a 100644 --- a/examples/opengl2_example/imgui_impl_glfw.cpp +++ b/examples/opengl2_example/imgui_impl_glfw.cpp @@ -77,15 +77,14 @@ void ImGui_ImplGlfwGL2_RenderDrawLists(ImDrawData* draw_data) glLoadIdentity(); // Render command lists - #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; - glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, pos))); - glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, uv))); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, col))); + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos))); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv))); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col))); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { @@ -103,7 +102,6 @@ void ImGui_ImplGlfwGL2_RenderDrawLists(ImDrawData* draw_data) idx_buffer += pcmd->ElemCount; } } - #undef OFFSETOF // Restore modified state glDisableClientState(GL_COLOR_ARRAY); diff --git a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp index 6c439fa1..a608e370 100644 --- a/examples/opengl3_example/imgui_impl_glfw_gl3.cpp +++ b/examples/opengl3_example/imgui_impl_glfw_gl3.cpp @@ -269,11 +269,9 @@ bool ImGui_ImplGlfwGL3_CreateDeviceObjects() glEnableVertexAttribArray(g_AttribLocationUV); glEnableVertexAttribArray(g_AttribLocationColor); -#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) - glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); - glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); - glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); -#undef OFFSETOF + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); ImGui_ImplGlfwGL3_CreateFontsTexture(); diff --git a/examples/sdl_opengl2_example/imgui_impl_sdl.cpp b/examples/sdl_opengl2_example/imgui_impl_sdl.cpp index baf5c017..c997d36d 100644 --- a/examples/sdl_opengl2_example/imgui_impl_sdl.cpp +++ b/examples/sdl_opengl2_example/imgui_impl_sdl.cpp @@ -70,15 +70,14 @@ void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) glLoadIdentity(); // Render command lists - #define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; - glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, pos))); - glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, uv))); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + OFFSETOF(ImDrawVert, col))); + glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos))); + glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv))); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col))); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { @@ -96,7 +95,6 @@ void ImGui_ImplSdl_RenderDrawLists(ImDrawData* draw_data) idx_buffer += pcmd->ElemCount; } } - #undef OFFSETOF // Restore modified state glDisableClientState(GL_COLOR_ARRAY); diff --git a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp index 93849cf8..4cdbe0f1 100644 --- a/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp +++ b/examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp @@ -273,11 +273,9 @@ bool ImGui_ImplSdlGL3_CreateDeviceObjects() glEnableVertexAttribArray(g_AttribLocationUV); glEnableVertexAttribArray(g_AttribLocationColor); -#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) - glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, pos)); - glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, uv)); - glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)OFFSETOF(ImDrawVert, col)); -#undef OFFSETOF + glVertexAttribPointer(g_AttribLocationPosition, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); + glVertexAttribPointer(g_AttribLocationUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); + glVertexAttribPointer(g_AttribLocationColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); ImGui_ImplSdlGL3_CreateFontsTexture(); diff --git a/imgui.h b/imgui.h index fc9791a7..bb717eb4 100644 --- a/imgui.h +++ b/imgui.h @@ -39,7 +39,7 @@ #define IM_FMTLIST(FMT) #endif #define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR)/sizeof(*_ARR))) -#define IM_OFFSETOF(_TYPE,_ELM) ((size_t)&(((_TYPE*)0)->_ELM)) +#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Standardized as offsetof() in modern C++. #if defined(__clang__) #pragma clang diagnostic push From 3d24a9eb405f024dd0be17608e9a912b0862efa7 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 5 Jan 2018 22:32:27 +0100 Subject: [PATCH 09/12] Examples: DirectX9/10/11: Comments about CS_DBLCLKS + formatting tweaks. (#1538) --- examples/directx10_example/imgui_impl_dx10.cpp | 10 ++++------ examples/directx11_example/imgui_impl_dx11.cpp | 10 ++++------ examples/directx9_example/imgui_impl_dx9.cpp | 10 ++++------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/examples/directx10_example/imgui_impl_dx10.cpp b/examples/directx10_example/imgui_impl_dx10.cpp index 6338be72..d181f7a5 100644 --- a/examples/directx10_example/imgui_impl_dx10.cpp +++ b/examples/directx10_example/imgui_impl_dx10.cpp @@ -240,17 +240,15 @@ static bool IsAnyMouseButtonDown() // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: + case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: { int button = 0; if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; diff --git a/examples/directx11_example/imgui_impl_dx11.cpp b/examples/directx11_example/imgui_impl_dx11.cpp index 7016301b..833a0bb0 100644 --- a/examples/directx11_example/imgui_impl_dx11.cpp +++ b/examples/directx11_example/imgui_impl_dx11.cpp @@ -247,17 +247,15 @@ static bool IsAnyMouseButtonDown() // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: + case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: { int button = 0; if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; diff --git a/examples/directx9_example/imgui_impl_dx9.cpp b/examples/directx9_example/imgui_impl_dx9.cpp index de00f88d..40f675af 100644 --- a/examples/directx9_example/imgui_impl_dx9.cpp +++ b/examples/directx9_example/imgui_impl_dx9.cpp @@ -186,17 +186,15 @@ static bool IsAnyMouseButtonDown() // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. // PS: In this Win32 handler, we use the capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds. +// PS: We treat DBLCLK messages as regular mouse down messages, so this code will work on windows classes that have the CS_DBLCLKS flag set. Our own example app code doesn't set this flag. IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { ImGuiIO& io = ImGui::GetIO(); switch (msg) { - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONDBLCLK: + case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: { int button = 0; if (msg == WM_LBUTTONDOWN || msg == WM_LBUTTONDBLCLK) button = 0; From 2874aabb9305645ff2e2de0615ce067573d80527 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 7 Jan 2018 12:29:54 +0100 Subject: [PATCH 10/12] Internals: BringWindowToFront() iterate front to back, faster in majority of use cases. --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 3728a890..fef9e11c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5123,10 +5123,10 @@ void ImGui::BringWindowToFront(ImGuiWindow* window) ImGuiContext& g = *GImGui; if (g.Windows.back() == window) return; - for (int i = 0; i < g.Windows.Size; i++) + for (int i = g.Windows.Size - 2; i >= 0; i--) // We can ignore the front most window if (g.Windows[i] == window) { - g.Windows.erase(g.Windows.begin() + i); + g.Windows.erase(g.Windows.Data + i); g.Windows.push_back(window); break; } From 5fd19f037fdb4d2054002e787055b910278832fd Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 7 Jan 2018 12:34:52 +0100 Subject: [PATCH 11/12] Internals: renamed FocusPreviousWindow() to FocusfrontMostActiveWindow() --- imgui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index fef9e11c..bf40902b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -675,7 +675,7 @@ static bool DataTypeApplyOpFromText(const char* buf, const char* ini namespace ImGui { -static void FocusPreviousWindow(); +static void FocusFrontMostActiveWindow(); } //----------------------------------------------------------------------------- @@ -2511,7 +2511,7 @@ void ImGui::NewFrame() // Closing the focused window restore focus to the first active root window in descending z-order if (g.NavWindow && !g.NavWindow->WasActive) - FocusPreviousWindow(); + FocusFrontMostActiveWindow(); // No window should be open at the beginning of the frame. // But in order to allow the user to call NewFrame() multiple times without calling Render(), we are doing an explicit clear. @@ -5172,7 +5172,7 @@ void ImGui::FocusWindow(ImGuiWindow* window) BringWindowToFront(window); } -void ImGui::FocusPreviousWindow() +void ImGui::FocusFrontMostActiveWindow() { ImGuiContext& g = *GImGui; for (int i = g.Windows.Size - 1; i >= 0; i--) From a34490239c5f58ddbf47c6c07b95441a9f6db982 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 7 Jan 2018 13:51:36 +0100 Subject: [PATCH 12/12] Internals: Popup: Separating MousePosOnOpen and PopupPosOnOpen. They are equal in the master branch but different in the navigation branch. --- imgui.cpp | 6 ++++-- imgui_internal.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index bf40902b..2f2443a2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3725,7 +3725,9 @@ void ImGui::OpenPopupEx(ImGuiID id, bool reopen_existing) ImGuiContext& g = *GImGui; ImGuiWindow* parent_window = g.CurrentWindow; int current_stack_size = g.CurrentPopupStack.Size; - ImGuiPopupRef popup_ref = ImGuiPopupRef(id, parent_window, parent_window->GetID("##Menus"), g.IO.MousePos); // Tagged as new ref because constructor sets Window to NULL. + ImVec2 mouse_pos = g.IO.MousePos; + ImVec2 popup_pos = mouse_pos; // NB: In the Navigation branch popup_pos may not use mouse_pos. + ImGuiPopupRef popup_ref = ImGuiPopupRef(id, parent_window, parent_window->GetID("##Menus"), popup_pos, mouse_pos); // Tagged as new ref because constructor sets Window to NULL. if (g.OpenPopupStack.Size < current_stack_size + 1) g.OpenPopupStack.push_back(popup_ref); else if (reopen_existing || g.OpenPopupStack[current_stack_size].PopupId != id) @@ -4479,7 +4481,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // Popup first latch mouse position, will position itself when it appears next frame window->AutoPosLastDirection = ImGuiDir_None; if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api) - window->PosFloat = g.IO.MousePos; + window->PosFloat = g.CurrentPopupStack.back().PopupPosOnOpen; } // Collapse window by double-clicking on title bar diff --git a/imgui_internal.h b/imgui_internal.h index c8097025..bdadc464 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -401,9 +401,10 @@ struct ImGuiPopupRef ImGuiWindow* Window; // Resolved on BeginPopup() - may stay unresolved if user never calls OpenPopup() ImGuiWindow* ParentWindow; // Set on OpenPopup() ImGuiID ParentMenuSet; // Set on OpenPopup() + ImVec2 PopupPosOnOpen; // Preferred popup position (typically == MousePosOnOpen when using mouse) ImVec2 MousePosOnOpen; // Copy of mouse position at the time of opening popup - ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; MousePosOnOpen = mouse_pos; } + ImGuiPopupRef(ImGuiID id, ImGuiWindow* parent_window, ImGuiID parent_menu_set, const ImVec2& popup_pos, const ImVec2& mouse_pos) { PopupId = id; Window = NULL; ParentWindow = parent_window; ParentMenuSet = parent_menu_set; PopupPosOnOpen = popup_pos; MousePosOnOpen = mouse_pos; } }; struct ImGuiColumnData