mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-01 02:37:24 +01:00
Examples: DirectX9/10/11: Tweak usage of SetCapture/ReleaseCapture. (#1375)
ps: DirectX 12 example (#302) may want to adopt that as well.
This commit is contained in:
parent
0260fdd1c6
commit
d2c65aa3e8
@ -234,35 +234,38 @@ static bool IsAnyMouseButtonDown()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
|
||||||
IMGUI_API LRESULT ImGui_ImplWin32_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();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[0] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[1] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
{
|
||||||
io.MouseDown[2] = true;
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONDOWN) button = 0;
|
||||||
|
if (msg == WM_RBUTTONDOWN) button = 1;
|
||||||
|
if (msg == WM_MBUTTONDOWN) button = 2;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == NULL)
|
||||||
|
SetCapture(hwnd);
|
||||||
|
io.MouseDown[button] = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
io.MouseDown[0] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
io.MouseDown[1] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
io.MouseDown[2] = false;
|
{
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONUP) button = 0;
|
||||||
|
if (msg == WM_RBUTTONUP) button = 1;
|
||||||
|
if (msg == WM_MBUTTONUP) button = 2;
|
||||||
|
io.MouseDown[button] = false;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == hwnd)
|
||||||
|
ReleaseCapture();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -241,35 +241,38 @@ static bool IsAnyMouseButtonDown()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
|
||||||
IMGUI_API LRESULT ImGui_ImplWin32_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();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[0] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[1] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
{
|
||||||
io.MouseDown[2] = true;
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONDOWN) button = 0;
|
||||||
|
if (msg == WM_RBUTTONDOWN) button = 1;
|
||||||
|
if (msg == WM_MBUTTONDOWN) button = 2;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == NULL)
|
||||||
|
SetCapture(hwnd);
|
||||||
|
io.MouseDown[button] = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
io.MouseDown[0] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
io.MouseDown[1] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
io.MouseDown[2] = false;
|
{
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONUP) button = 0;
|
||||||
|
if (msg == WM_RBUTTONUP) button = 1;
|
||||||
|
if (msg == WM_MBUTTONUP) button = 2;
|
||||||
|
io.MouseDown[button] = false;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == hwnd)
|
||||||
|
ReleaseCapture();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -180,36 +180,38 @@ static bool IsAnyMouseButtonDown()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds.
|
// We use the Win32 capture API (GetCapture/SetCapture/ReleaseCapture) to be able to read mouse coordinations when dragging mouse outside of our window bounds.
|
||||||
IMGUI_API LRESULT ImGui_ImplWin32_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();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[0] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
|
||||||
io.MouseDown[1] = true;
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
|
{
|
||||||
io.MouseDown[2] = true;
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONDOWN) button = 0;
|
||||||
|
if (msg == WM_RBUTTONDOWN) button = 1;
|
||||||
|
if (msg == WM_MBUTTONDOWN) button = 2;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == NULL)
|
||||||
|
SetCapture(hwnd);
|
||||||
|
io.MouseDown[button] = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
io.MouseDown[0] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
io.MouseDown[1] = false;
|
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
|
||||||
return 0;
|
|
||||||
case WM_MBUTTONUP:
|
case WM_MBUTTONUP:
|
||||||
io.MouseDown[2] = false;
|
{
|
||||||
if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
|
int button = 0;
|
||||||
|
if (msg == WM_LBUTTONUP) button = 0;
|
||||||
|
if (msg == WM_RBUTTONUP) button = 1;
|
||||||
|
if (msg == WM_MBUTTONUP) button = 2;
|
||||||
|
io.MouseDown[button] = false;
|
||||||
|
if (!IsAnyMouseButtonDown() && GetCapture() == hwnd)
|
||||||
|
ReleaseCapture();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user