Input - Added normalized cordinates
This commit is contained in:
parent
263eba782b
commit
53dc42ffc4
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>false</ShowAllFiles>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>
|
||||
|
|
|
@ -36,14 +36,22 @@ namespace Input
|
|||
/*********************************************************************/
|
||||
namespace Struct
|
||||
{
|
||||
struct SAIPoint2D
|
||||
struct SAIPointInt2D
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
SAIPoint2D() :x(0), y(0) { }
|
||||
SAIPoint2D(int _x, int _y) :x(_x), y(_y) { }
|
||||
SAIPointInt2D() :x(0), y(0) { }
|
||||
SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { }
|
||||
int Length() { return (abs(x) + abs(y)); }
|
||||
};
|
||||
struct SAIPointFloat2D
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
SAIPointFloat2D() :x(0.0f), y(0.0f) { }
|
||||
SAIPointFloat2D(float _x, float _y) :x(_x), y(_y) { }
|
||||
float Length() { return (fabs(x) + fabs(y)); }
|
||||
};
|
||||
|
||||
struct InputData;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Input
|
|||
typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender);
|
||||
typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender);
|
||||
typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender);
|
||||
typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D, Mouse* sender);
|
||||
typedef void(*OnMouseMoveCallback)(Struct::SAIPointInt2D, Mouse* sender);
|
||||
typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -61,7 +61,7 @@ namespace Input
|
|||
virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { }
|
||||
virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { }
|
||||
virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { }
|
||||
virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { }
|
||||
virtual void OnMouseMove ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { }
|
||||
virtual void OnMouseScroll ( int delta, Mouse* sender ) { }
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,8 @@ namespace Input
|
|||
virtual bool IsBtnUp(Enum::SAMI key) = 0;
|
||||
virtual bool IsBtnDown(Enum::SAMI key) = 0;
|
||||
virtual int GetWheelDelta() = 0;
|
||||
virtual Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) = 0;
|
||||
virtual Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) = 0;
|
||||
virtual Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) = 0;
|
||||
|
||||
public:
|
||||
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
|
||||
|
@ -135,7 +136,8 @@ namespace Input
|
|||
protected:
|
||||
std::vector<MouseEvent*> mouseSubscribers;
|
||||
MouseCallbackList* callbackList;
|
||||
Struct::SAIPoint2D pixelPos;
|
||||
Struct::SAIPointInt2D pixelPos;
|
||||
Struct::SAIPointFloat2D normalPos;
|
||||
bool isCurorLocked;
|
||||
int wheelDelta;
|
||||
};
|
||||
|
|
|
@ -18,9 +18,12 @@ namespace Input
|
|||
bool IsBtnUp(Enum::SAMI key) override;
|
||||
bool IsBtnDown(Enum::SAMI key) override;
|
||||
int GetWheelDelta() override;
|
||||
Struct::SAIPoint2D GetPixelPosition(Struct::SAIPoint2D targetMem = Struct::SAIPoint2D()) override;
|
||||
Struct::SAIPointInt2D GetPixelPosition(Struct::SAIPointInt2D targetMem = Struct::SAIPointInt2D()) override;
|
||||
Struct::SAIPointFloat2D GetNormalizedPosition(Struct::SAIPointFloat2D targetMem = Struct::SAIPointFloat2D()) override;
|
||||
|
||||
void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode);
|
||||
void ProccessMouseData (bool isDown, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode);
|
||||
|
||||
bool Create(HWND target);
|
||||
|
||||
private:
|
||||
struct Buttons
|
||||
|
@ -30,6 +33,7 @@ namespace Input
|
|||
};
|
||||
static const int MAXBUTTONS = 25;
|
||||
Buttons buttons[25];
|
||||
RAWINPUTDEVICE device;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ Mouse::Mouse()
|
|||
, wheelDelta(0)
|
||||
, isCurorLocked(0)
|
||||
, pixelPos()
|
||||
, normalPos()
|
||||
{
|
||||
}
|
||||
Mouse::~Mouse()
|
||||
|
@ -149,6 +150,8 @@ void Mouse::SetPixelPos(int x, int y)
|
|||
{
|
||||
this->pixelPos.x = x;
|
||||
this->pixelPos.y = y;
|
||||
|
||||
// TODO: Update normalized position
|
||||
}
|
||||
void Mouse::ToggleCursor(bool toggler)
|
||||
{
|
||||
|
|
|
@ -556,7 +556,7 @@ void MapKey(RAWKEYBOARD& rawKB, bool& out_isUp, SAKI& out_key, unsigned int& sCo
|
|||
rawKB.MakeCode = scanCode;
|
||||
sCode = scanCode;
|
||||
}
|
||||
void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPoint2D& vel, unsigned int& mcode)
|
||||
void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Struct::SAIPointInt2D& vel, unsigned int& mcode)
|
||||
{
|
||||
if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0)
|
||||
{
|
||||
|
@ -647,7 +647,7 @@ void Win32Input::RawInputParser(HWND h, LPARAM l)
|
|||
bool isUp = true;
|
||||
Enum::SAMI btn = Enum::SAMI_Unknown;
|
||||
int delta = 0;
|
||||
Struct::SAIPoint2D vel;
|
||||
Struct::SAIPointInt2D vel;
|
||||
unsigned int mcode = 0;
|
||||
MapButton(raw->data.mouse, isUp, btn, delta, vel, mcode);
|
||||
|
||||
|
@ -759,20 +759,15 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH
|
|||
|
||||
case SAIType_Mouse:
|
||||
{
|
||||
rid.usUsage = RawInput_Usage_mouse;
|
||||
rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE;
|
||||
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
|
||||
{
|
||||
int i = 0;
|
||||
val = (InputObject*)1;
|
||||
Win32Mouse* obj = new Win32Mouse();
|
||||
this->mouse.push_back(obj);
|
||||
val = obj;
|
||||
}
|
||||
else
|
||||
if(!obj->Create(this->targetHwin))
|
||||
{
|
||||
delete obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->mouse.push_back(obj);
|
||||
val = obj;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#include "..\..\Include\Win32\Win32Mouse.h"
|
||||
#include "..\..\Include\Win32\Win32Input.h"
|
||||
|
||||
using namespace Input;
|
||||
using namespace Input::Enum;
|
||||
|
@ -11,6 +11,7 @@ using namespace Input::Typedefs;
|
|||
|
||||
Win32Mouse::Win32Mouse()
|
||||
{
|
||||
memset(&this->device, 0, sizeof(RAWINPUTDEVICE));
|
||||
memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS);
|
||||
}
|
||||
Win32Mouse::~Win32Mouse()
|
||||
|
@ -34,13 +35,29 @@ int Win32Mouse::GetWheelDelta()
|
|||
{
|
||||
return this->wheelDelta;
|
||||
}
|
||||
Struct::SAIPoint2D Win32Mouse::GetPixelPosition(Struct::SAIPoint2D targetMem)
|
||||
Struct::SAIPointInt2D Win32Mouse::GetPixelPosition(Struct::SAIPointInt2D targetMem)
|
||||
{
|
||||
targetMem = this->pixelPos;
|
||||
return targetMem;
|
||||
}
|
||||
Struct::SAIPointFloat2D Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D targetMem)
|
||||
{
|
||||
POINT mousePos;
|
||||
GetCursorPos( &mousePos );
|
||||
|
||||
void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPoint2D velocity, unsigned int makeCode)
|
||||
RECT windowVertex;
|
||||
GetWindowRect( this->device.hwndTarget, &windowVertex );
|
||||
|
||||
this->normalPos.x = (float)(mousePos.x - windowVertex.left);
|
||||
this->normalPos.x /= (float)(windowVertex.right - windowVertex.left);
|
||||
|
||||
this->normalPos.y = (float)(mousePos.y - windowVertex.top);
|
||||
this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top);
|
||||
|
||||
return targetMem;
|
||||
}
|
||||
|
||||
void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct::SAIPointInt2D velocity, unsigned int makeCode)
|
||||
{
|
||||
if(velocity.Length() != 0)
|
||||
{
|
||||
|
@ -138,4 +155,30 @@ void Win32Mouse::ProccessMouseData (bool isUp, Enum::SAMI btn, int delta, Struct
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Win32Mouse::Create(HWND target)
|
||||
{
|
||||
this->device.usUsagePage = 0x01;
|
||||
this->device.hwndTarget = target;
|
||||
this->device.usUsage = Input::RawInput_Usage_mouse;
|
||||
this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE;
|
||||
|
||||
if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
memset(&this->device, 0, sizeof(RAWINPUTDEVICE));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue