Commit 2f5bddb5 authored by chili's avatar chili
Browse files

ability to disable cursor


dissing
parent 88ecc24b
......@@ -16,6 +16,7 @@ App::App()
light( wnd.Gfx() )
{
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) );
wnd.DisableCursor();
}
void App::DoFrame()
......
......@@ -119,6 +119,18 @@ void Window::SetTitle( const std::string& title )
}
}
void Window::EnableCursor()
{
cursorEnabled = true;
ShowCursor();
}
void Window::DisableCursor()
{
cursorEnabled = false;
HideCursor();
}
std::optional<int> Window::ProcessMessages() noexcept
{
MSG msg;
......@@ -150,6 +162,16 @@ Graphics& Window::Gfx()
return *pGfx;
}
void Window::HideCursor()
{
while( ::ShowCursor( FALSE ) >= 0 );
}
void Window::ShowCursor()
{
while( ::ShowCursor( TRUE ) < 0 );
}
LRESULT CALLBACK Window::HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept
{
// use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side
......@@ -233,6 +255,17 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
/************* MOUSE MESSAGES ****************/
case WM_MOUSEMOVE:
{
// cursorless exclusive gets first dibs
if( !cursorEnabled )
{
if( !mouse.IsInWindow() )
{
SetCapture( hWnd );
mouse.OnMouseEnter();
HideCursor();
}
break;
}
// stifle this mouse message if imgui wants to capture
if( imio.WantCaptureMouse )
{
......
......@@ -75,9 +75,13 @@ public:
Window( const Window& ) = delete;
Window& operator=( const Window& ) = delete;
void SetTitle( const std::string& title );
void EnableCursor();
void DisableCursor();
static std::optional<int> ProcessMessages() noexcept;
Graphics& Gfx();
private:
void HideCursor();
void ShowCursor();
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;
......@@ -85,6 +89,7 @@ public:
Keyboard kbd;
Mouse mouse;
private:
bool cursorEnabled = false;
int width;
int height;
HWND hWnd;
......
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