Commit 9413bde0 authored by chili's avatar chili
Browse files

proper wheel delta

parent 524925dd
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* along with The Chili DirectX Framework. If not, see <http://www.gnu.org/licenses/>. * * along with The Chili DirectX Framework. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************************/ ******************************************************************************************/
#include "Mouse.h" #include "Mouse.h"
#include <Windows.h>
std::pair<int,int> Mouse::GetPos() const noexcept std::pair<int,int> Mouse::GetPos() const noexcept
{ {
...@@ -143,4 +143,20 @@ void Mouse::TrimBuffer() noexcept ...@@ -143,4 +143,20 @@ void Mouse::TrimBuffer() noexcept
{ {
buffer.pop(); buffer.pop();
} }
} }
\ No newline at end of file
void Mouse::OnWheelDelta( int x,int y,int delta ) noexcept
{
wheelDeltaCarry += delta;
// generate events for every 120
while( wheelDeltaCarry >= WHEEL_DELTA )
{
wheelDeltaCarry -= WHEEL_DELTA;
OnWheelUp( x,y );
}
while( wheelDeltaCarry <= -WHEEL_DELTA )
{
wheelDeltaCarry += WHEEL_DELTA;
OnWheelDown( x,y );
}
}
...@@ -120,6 +120,7 @@ private: ...@@ -120,6 +120,7 @@ private:
void OnWheelUp( int x,int y ) noexcept; void OnWheelUp( int x,int y ) noexcept;
void OnWheelDown( int x,int y ) noexcept; void OnWheelDown( int x,int y ) noexcept;
void TrimBuffer() noexcept; void TrimBuffer() noexcept;
void OnWheelDelta( int x,int y,int delta ) noexcept;
private: private:
static constexpr unsigned int bufferSize = 16u; static constexpr unsigned int bufferSize = 16u;
int x; int x;
...@@ -127,5 +128,6 @@ private: ...@@ -127,5 +128,6 @@ private:
bool leftIsPressed = false; bool leftIsPressed = false;
bool rightIsPressed = false; bool rightIsPressed = false;
bool isInWindow = false; bool isInWindow = false;
int wheelDeltaCarry = 0;
std::queue<Event> buffer; std::queue<Event> buffer;
}; };
\ No newline at end of file
...@@ -240,14 +240,8 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex ...@@ -240,14 +240,8 @@ LRESULT Window::HandleMsg( HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam ) noex
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
const POINTS pt = MAKEPOINTS( lParam ); const POINTS pt = MAKEPOINTS( lParam );
if( GET_WHEEL_DELTA_WPARAM( wParam ) > 0 ) const int delta = GET_WHEEL_DELTA_WPARAM( wParam );
{ mouse.OnWheelDelta( pt.x,pt.y,delta );
mouse.OnWheelUp( pt.x,pt.y );
}
else if( GET_WHEEL_DELTA_WPARAM( wParam ) < 0 )
{
mouse.OnWheelDown( pt.x,pt.y );
}
break; break;
} }
/************** END MOUSE MESSAGES **************/ /************** END MOUSE MESSAGES **************/
......
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