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

enable / disable raw input

parent 704f5322
...@@ -32,15 +32,15 @@ void App::DoFrame() ...@@ -32,15 +32,15 @@ void App::DoFrame()
{ {
if( e->IsPress() && e->GetCode() == VK_INSERT ) if( e->IsPress() && e->GetCode() == VK_INSERT )
{ {
if( cursorEnabled ) if( wnd.CursorEnabled() )
{ {
wnd.DisableCursor(); wnd.DisableCursor();
cursorEnabled = false; wnd.mouse.EnableRaw();
} }
else else
{ {
wnd.EnableCursor(); wnd.EnableCursor();
cursorEnabled = true; wnd.mouse.DisableRaw();
} }
} }
} }
...@@ -75,7 +75,7 @@ void App::ShowRawInputWindow() ...@@ -75,7 +75,7 @@ void App::ShowRawInputWindow()
if( ImGui::Begin( "Raw Input" ) ) if( ImGui::Begin( "Raw Input" ) )
{ {
ImGui::Text( "Tally: (%d,%d)",x,y ); ImGui::Text( "Tally: (%d,%d)",x,y );
ImGui::Text( "Cursor: %s",cursorEnabled?"enabled":"disabled" ); ImGui::Text( "Cursor: %s",wnd.CursorEnabled()?"enabled":"disabled" );
} }
ImGui::End(); ImGui::End();
} }
......
...@@ -19,7 +19,6 @@ private: ...@@ -19,7 +19,6 @@ private:
void ShowImguiDemoWindow(); void ShowImguiDemoWindow();
void ShowRawInputWindow(); void ShowRawInputWindow();
private: private:
bool cursorEnabled = true;
int x = 0,y = 0; int x = 0,y = 0;
ImguiManager imgui; ImguiManager imgui;
Window wnd; Window wnd;
......
...@@ -79,6 +79,21 @@ void Mouse::Flush() noexcept ...@@ -79,6 +79,21 @@ void Mouse::Flush() noexcept
buffer = std::queue<Event>(); buffer = std::queue<Event>();
} }
void Mouse::EnableRaw() noexcept
{
rawEnabled = true;
}
void Mouse::DisableRaw() noexcept
{
rawEnabled = false;
}
bool Mouse::RawEnabled() const noexcept
{
return rawEnabled;
}
void Mouse::OnMouseMove( int newx,int newy ) noexcept void Mouse::OnMouseMove( int newx,int newy ) noexcept
{ {
x = newx; x = newx;
......
...@@ -102,6 +102,9 @@ public: ...@@ -102,6 +102,9 @@ public:
return buffer.empty(); return buffer.empty();
} }
void Flush() noexcept; void Flush() noexcept;
void EnableRaw() noexcept;
void DisableRaw() noexcept;
bool RawEnabled() const noexcept;
private: private:
void OnMouseMove( int x,int y ) noexcept; void OnMouseMove( int x,int y ) noexcept;
void OnMouseLeave() noexcept; void OnMouseLeave() noexcept;
...@@ -124,6 +127,7 @@ private: ...@@ -124,6 +127,7 @@ private:
bool rightIsPressed = false; bool rightIsPressed = false;
bool isInWindow = false; bool isInWindow = false;
int wheelDeltaCarry = 0; int wheelDeltaCarry = 0;
bool rawEnabled = false;
std::queue<Event> buffer; std::queue<Event> buffer;
std::queue<RawDelta> rawDeltaBuffer; std::queue<RawDelta> rawDeltaBuffer;
}; };
\ No newline at end of file
...@@ -145,6 +145,11 @@ void Window::DisableCursor() noexcept ...@@ -145,6 +145,11 @@ void Window::DisableCursor() noexcept
ConfineCursor(); ConfineCursor();
} }
bool Window::CursorEnabled() const noexcept
{
return cursorEnabled;
}
std::optional<int> Window::ProcessMessages() noexcept std::optional<int> Window::ProcessMessages() noexcept
{ {
MSG msg; MSG msg;
...@@ -430,6 +435,10 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex ...@@ -430,6 +435,10 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
/************** RAW MOUSE MESSAGES **************/ /************** RAW MOUSE MESSAGES **************/
case WM_INPUT: case WM_INPUT:
{ {
if( !mouse.RawEnabled() )
{
break;
}
UINT size; UINT size;
// first get the size of the input data // first get the size of the input data
if( GetRawInputData( if( GetRawInputData(
......
...@@ -77,6 +77,7 @@ public: ...@@ -77,6 +77,7 @@ public:
void SetTitle( const std::string& title ); void SetTitle( const std::string& title );
void EnableCursor() noexcept; void EnableCursor() noexcept;
void DisableCursor() noexcept; void DisableCursor() noexcept;
bool CursorEnabled() const noexcept;
static std::optional<int> ProcessMessages() noexcept; static std::optional<int> ProcessMessages() noexcept;
Graphics& Gfx(); Graphics& Gfx();
private: private:
......
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