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

ability to disable cursor


dissing
parent 88ecc24b
...@@ -16,6 +16,7 @@ App::App() ...@@ -16,6 +16,7 @@ App::App()
light( wnd.Gfx() ) light( wnd.Gfx() )
{ {
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) ); wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) );
wnd.DisableCursor();
} }
void App::DoFrame() void App::DoFrame()
......
...@@ -119,6 +119,18 @@ void Window::SetTitle( const std::string& title ) ...@@ -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 std::optional<int> Window::ProcessMessages() noexcept
{ {
MSG msg; MSG msg;
...@@ -150,6 +162,16 @@ Graphics& Window::Gfx() ...@@ -150,6 +162,16 @@ Graphics& Window::Gfx()
return *pGfx; 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 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 // 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 ...@@ -233,6 +255,17 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
/************* MOUSE MESSAGES ****************/ /************* MOUSE MESSAGES ****************/
case WM_MOUSEMOVE: 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 // stifle this mouse message if imgui wants to capture
if( imio.WantCaptureMouse ) if( imio.WantCaptureMouse )
{ {
......
...@@ -75,9 +75,13 @@ public: ...@@ -75,9 +75,13 @@ public:
Window( const Window& ) = delete; Window( const Window& ) = delete;
Window& operator=( const Window& ) = delete; Window& operator=( const Window& ) = delete;
void SetTitle( const std::string& title ); void SetTitle( const std::string& title );
void EnableCursor();
void DisableCursor();
static std::optional<int> ProcessMessages() noexcept; static std::optional<int> ProcessMessages() noexcept;
Graphics& Gfx(); Graphics& Gfx();
private: private:
void HideCursor();
void ShowCursor();
static LRESULT CALLBACK HandleMsgSetup( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) 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; static LRESULT CALLBACK HandleMsgThunk( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noexcept;
LRESULT HandleMsg( 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: ...@@ -85,6 +89,7 @@ public:
Keyboard kbd; Keyboard kbd;
Mouse mouse; Mouse mouse;
private: private:
bool cursorEnabled = false;
int width; int width;
int height; int height;
HWND hWnd; 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