2014-02-14 15:50:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2014-02-21 11:43:05 +01:00
|
|
|
#include "..\..\Include\Win32\Win32Mouse.h"
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
using namespace Input;
|
|
|
|
using namespace Input::Enum;
|
|
|
|
using namespace Input::Struct;
|
|
|
|
using namespace Input::Typedefs;
|
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode)
|
|
|
|
{
|
|
|
|
if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0)
|
|
|
|
{
|
|
|
|
vel.x = rawMouse.lLastX;
|
|
|
|
vel.y = rawMouse.lLastY;
|
|
|
|
}
|
|
|
|
if( rawMouse.usButtonFlags > 0 )
|
|
|
|
{
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
//Mouse button pressed
|
|
|
|
if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_DOWN)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseLeftBtn;
|
|
|
|
isUp = false;
|
|
|
|
}
|
|
|
|
else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_DOWN)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseMiddleBtn;
|
|
|
|
isUp = false;
|
|
|
|
}
|
|
|
|
else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_DOWN)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseRightBtn;
|
|
|
|
isUp = false;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
//Mouse button Released
|
|
|
|
else if(rawMouse.usButtonFlags == RI_MOUSE_LEFT_BUTTON_UP)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseLeftBtn;
|
|
|
|
isUp = true;
|
|
|
|
}
|
|
|
|
else if(rawMouse.usButtonFlags == RI_MOUSE_MIDDLE_BUTTON_UP)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseMiddleBtn;
|
|
|
|
isUp = true;
|
|
|
|
}
|
|
|
|
else if(rawMouse.usButtonFlags == RI_MOUSE_RIGHT_BUTTON_UP)
|
|
|
|
{
|
|
|
|
btn = SAMI_MouseRightBtn;
|
|
|
|
isUp = true;
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
else if (rawMouse.usButtonFlags == RI_MOUSE_WHEEL)
|
|
|
|
{
|
|
|
|
delta = ((int)rawMouse.usButtonData);
|
|
|
|
|
|
|
|
if(delta > 120) delta = -1;
|
|
|
|
else delta = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
Win32Mouse::Win32Mouse()
|
|
|
|
{
|
|
|
|
memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS);
|
|
|
|
}
|
|
|
|
Win32Mouse::~Win32Mouse()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Win32Mouse::IsBtnUp(Enum::SAMI btn)
|
|
|
|
{
|
|
|
|
if(btn == SAMI_Unknown) return false;
|
|
|
|
|
|
|
|
return !this->buttons[btn].isDown;
|
|
|
|
}
|
|
|
|
bool Win32Mouse::IsBtnDown(Enum::SAMI btn)
|
|
|
|
{
|
|
|
|
if(btn == SAMI_Unknown) return false;
|
|
|
|
|
|
|
|
return this->buttons[btn].isDown;
|
|
|
|
}
|
2014-02-20 11:27:43 +01:00
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
2014-02-14 15:50:00 +01:00
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
bool isUp = true;
|
|
|
|
Enum::SAMI btn = Enum::SAMI_Unknown;
|
|
|
|
int delta = 0;
|
|
|
|
Struct::SAIPoint2D velocity;
|
|
|
|
unsigned int makeCode = 0;
|
|
|
|
MapButton(mouse, isUp, btn, delta, velocity, makeCode);
|
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
if(velocity.Length() != 0)
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
this->pixelPos.x += this->deltaPos.x = velocity.x;
|
|
|
|
this->pixelPos.y += this->deltaPos.y = velocity.y;
|
|
|
|
InternalOnMove(this->pixelPos);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(delta != 0)
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
InternalOnScroll(delta);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(btn == SAMI_Unknown) return;
|
|
|
|
|
|
|
|
this->buttons[btn].isDown = !isUp;
|
|
|
|
this->buttons[btn].makeCode = makeCode;
|
|
|
|
|
|
|
|
//The btn is released.
|
|
|
|
if(isUp)
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
InternalOnBtnRelease(btn);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
//The btn is pressed.
|
|
|
|
else
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
//The btn is down since last frame
|
2014-02-14 15:50:00 +01:00
|
|
|
if(this->buttons[btn].isDown)
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
InternalOnBtnDown(btn);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-21 11:43:05 +01:00
|
|
|
InternalOnBtnPress(btn);
|
2014-02-14 15:50:00 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-21 11:43:05 +01:00
|
|
|
}
|