Commit 7a461c18 authored by chili's avatar chili
Browse files

mousetrap

parent 12914fe9
......@@ -119,18 +119,20 @@ void Window::SetTitle( const std::string& title )
}
}
void Window::EnableCursor()
void Window::EnableCursor() noexcept
{
cursorEnabled = true;
ShowCursor();
EnableImGuiMouse();
FreeCursor();
}
void Window::DisableCursor()
void Window::DisableCursor() noexcept
{
cursorEnabled = false;
HideCursor();
DisableImGuiMouse();
ConfineCursor();
}
std::optional<int> Window::ProcessMessages() noexcept
......@@ -164,22 +166,35 @@ Graphics& Window::Gfx()
return *pGfx;
}
void Window::HideCursor()
void Window::ConfineCursor() noexcept
{
RECT rect;
GetClientRect( hWnd,&rect );
MapWindowPoints( hWnd,nullptr,reinterpret_cast<POINT*>(&rect),2 );
ClipCursor( &rect );
}
void Window::FreeCursor() noexcept
{
ClipCursor( nullptr );
}
void Window::HideCursor() noexcept
{
while( ::ShowCursor( FALSE ) >= 0 );
}
void Window::ShowCursor()
void Window::ShowCursor() noexcept
{
while( ::ShowCursor( TRUE ) < 0 );
}
void Window::EnableImGuiMouse()
void Window::EnableImGuiMouse() noexcept
{
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NoMouse;
}
void Window::DisableImGuiMouse()
void Window::DisableImGuiMouse() noexcept
{
ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NoMouse;
}
......@@ -267,6 +282,7 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
/************* MOUSE MESSAGES ****************/
case WM_MOUSEMOVE:
{
const POINTS pt = MAKEPOINTS( lParam );
// cursorless exclusive gets first dibs
if( !cursorEnabled )
{
......@@ -283,7 +299,6 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
{
break;
}
const POINTS pt = MAKEPOINTS( lParam );
// in client region -> log move, and log enter + capture mouse (if not previously in window)
if( pt.x >= 0 && pt.x < width && pt.y >= 0 && pt.y < height )
{
......
......@@ -75,15 +75,17 @@ public:
Window( const Window& ) = delete;
Window& operator=( const Window& ) = delete;
void SetTitle( const std::string& title );
void EnableCursor();
void DisableCursor();
void EnableCursor() noexcept;
void DisableCursor() noexcept;
static std::optional<int> ProcessMessages() noexcept;
Graphics& Gfx();
private:
void HideCursor();
void ShowCursor();
void EnableImGuiMouse();
void DisableImGuiMouse();
void ConfineCursor() noexcept;
void FreeCursor() noexcept;
void ShowCursor() noexcept;
void HideCursor() noexcept;
void EnableImGuiMouse() noexcept;
void DisableImGuiMouse() noexcept;
static LRESULT CALLBACK HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
static LRESULT CALLBACK HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
LRESULT HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment