Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle situation when WM_*BUTTONDOWN and WM_*BUTTONUP received at the… #1320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions examples/directx10_example/imgui_impl_dx10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static ID3D10RasterizerState* g_pRasterizerState = NULL;
static ID3D10BlendState* g_pBlendState = NULL;
static ID3D10DepthStencilState* g_pDepthStencilState = NULL;
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
static bool g_PrevMouseDown[3] = { 0, 0, 0 };
static bool g_MouseNeedRelease[3] = { 0, 0, 0 };

struct VERTEX_CONSTANT_BUFFER
{
Expand Down Expand Up @@ -234,19 +236,28 @@ IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND, UINT msg, WPARAM wParam, L
io.MouseDown[0] = true;
return true;
case WM_LBUTTONUP:
io.MouseDown[0] = false;
if(g_PrevMouseDown[0])
io.MouseDown[0] = false;
else
g_MouseNeedRelease[0] = true;
return true;
case WM_RBUTTONDOWN:
io.MouseDown[1] = true;
return true;
case WM_RBUTTONUP:
io.MouseDown[1] = false;
if(g_PrevMouseDown[1])
io.MouseDown[1] = false;
else
g_MouseNeedRelease[1] = true;
return true;
case WM_MBUTTONDOWN:
io.MouseDown[2] = true;
return true;
case WM_MBUTTONUP:
io.MouseDown[2] = false;
if(g_PrevMouseDown[2])
io.MouseDown[2] = false;
else
g_MouseNeedRelease[2] = true;
return true;
case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
Expand Down Expand Up @@ -578,4 +589,9 @@ void ImGui_ImplDX10_NewFrame()

// Start the frame
ImGui::NewFrame();

g_PrevMouseDown[0] = io.MouseDown[0]; g_PrevMouseDown[1] = io.MouseDown[1]; g_PrevMouseDown[2] = io.MouseDown[2];
if(g_MouseNeedRelease[0]) { io.MouseDown[0] = g_MouseNeedRelease[0] = false; }
if(g_MouseNeedRelease[1]) { io.MouseDown[1] = g_MouseNeedRelease[1] = false; }
if(g_MouseNeedRelease[2]) { io.MouseDown[2] = g_MouseNeedRelease[2] = false; }
}
22 changes: 19 additions & 3 deletions examples/directx11_example/imgui_impl_dx11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static ID3D11RasterizerState* g_pRasterizerState = NULL;
static ID3D11BlendState* g_pBlendState = NULL;
static ID3D11DepthStencilState* g_pDepthStencilState = NULL;
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
static bool g_PrevMouseDown[3] = { 0, 0, 0 };
static bool g_MouseNeedRelease[3] = { 0, 0, 0 };

struct VERTEX_CONSTANT_BUFFER
{
Expand Down Expand Up @@ -241,19 +243,28 @@ IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND, UINT msg, WPARAM wParam, L
io.MouseDown[0] = true;
return true;
case WM_LBUTTONUP:
io.MouseDown[0] = false;
if(g_PrevMouseDown[0])
io.MouseDown[0] = false;
else
g_MouseNeedRelease[0] = true;
return true;
case WM_RBUTTONDOWN:
io.MouseDown[1] = true;
return true;
case WM_RBUTTONUP:
io.MouseDown[1] = false;
if(g_PrevMouseDown[1])
io.MouseDown[1] = false;
else
g_MouseNeedRelease[1] = true;
return true;
case WM_MBUTTONDOWN:
io.MouseDown[2] = true;
return true;
case WM_MBUTTONUP:
io.MouseDown[2] = false;
if(g_PrevMouseDown[2])
io.MouseDown[2] = false;
else
g_MouseNeedRelease[2] = true;
return true;
case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
Expand Down Expand Up @@ -581,4 +592,9 @@ void ImGui_ImplDX11_NewFrame()

// Start the frame
ImGui::NewFrame();

g_PrevMouseDown[0] = io.MouseDown[0]; g_PrevMouseDown[1] = io.MouseDown[1]; g_PrevMouseDown[2] = io.MouseDown[2];
if(g_MouseNeedRelease[0]) { io.MouseDown[0] = g_MouseNeedRelease[0] = false; }
if(g_MouseNeedRelease[1]) { io.MouseDown[1] = g_MouseNeedRelease[1] = false; }
if(g_MouseNeedRelease[2]) { io.MouseDown[2] = g_MouseNeedRelease[2] = false; }
}
22 changes: 19 additions & 3 deletions examples/directx9_example/imgui_impl_dx9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL;
static LPDIRECT3DINDEXBUFFER9 g_pIB = NULL;
static LPDIRECT3DTEXTURE9 g_FontTexture = NULL;
static int g_VertexBufferSize = 5000, g_IndexBufferSize = 10000;
static bool g_PrevMouseDown[3] = { 0, 0, 0 };
static bool g_MouseNeedRelease[3] = { 0, 0, 0 };

struct CUSTOMVERTEX
{
Expand Down Expand Up @@ -180,19 +182,28 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND, UINT msg, WPARAM wParam, LP
io.MouseDown[0] = true;
return true;
case WM_LBUTTONUP:
io.MouseDown[0] = false;
if(g_PrevMouseDown[0])
io.MouseDown[0] = false;
else
g_MouseNeedRelease[0] = true;
return true;
case WM_RBUTTONDOWN:
io.MouseDown[1] = true;
return true;
case WM_RBUTTONUP:
io.MouseDown[1] = false;
if(g_PrevMouseDown[1])
io.MouseDown[1] = false;
else
g_MouseNeedRelease[1] = true;
return true;
case WM_MBUTTONDOWN:
io.MouseDown[2] = true;
return true;
case WM_MBUTTONUP:
io.MouseDown[2] = false;
if(g_PrevMouseDown[2])
io.MouseDown[2] = false;
else
g_MouseNeedRelease[2] = true;
return true;
case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
Expand Down Expand Up @@ -355,4 +366,9 @@ void ImGui_ImplDX9_NewFrame()

// Start the frame
ImGui::NewFrame();

g_PrevMouseDown[0] = io.MouseDown[0]; g_PrevMouseDown[1] = io.MouseDown[1]; g_PrevMouseDown[2] = io.MouseDown[2];
if(g_MouseNeedRelease[0]) { io.MouseDown[0] = g_MouseNeedRelease[0] = false; }
if(g_MouseNeedRelease[1]) { io.MouseDown[1] = g_MouseNeedRelease[1] = false; }
if(g_MouseNeedRelease[2]) { io.MouseDown[2] = g_MouseNeedRelease[2] = false; }
}