Input - Added toggle for input
This commit is contained in:
parent
dee6c5f8d1
commit
cc17f80fd7
|
@ -26,6 +26,11 @@ namespace Input
|
|||
SAIType_futureExample2,
|
||||
SAIType_futureExample3,
|
||||
};
|
||||
enum InputOptionType
|
||||
{
|
||||
InputOptionType_RawInput,
|
||||
InputOptionType_PlatformDefault,
|
||||
};
|
||||
enum ButtonState
|
||||
{
|
||||
ButtonState_Press, // When button is pressed (once)
|
||||
|
@ -37,15 +42,24 @@ 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;
|
||||
}
|
||||
/*********************************************************************/
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "InputManager.h"
|
||||
#include "InputObject.h"
|
||||
#include "Keyboard.h"
|
||||
#include "ApplicationKeyboard.h"
|
||||
#include "Mouse.h"
|
||||
|
||||
#endif // !INPUT_INPUT_H
|
||||
|
|
|
@ -37,9 +37,9 @@ namespace Input
|
|||
* @see InputDescription
|
||||
* @return Returns a handle to a device that can be rethrown to a specific device.
|
||||
*/
|
||||
virtual InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication = 0 ) = 0;
|
||||
virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); }
|
||||
virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); }
|
||||
virtual InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication ) = 0;
|
||||
virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); }
|
||||
virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); }
|
||||
|
||||
/** Enables or Disables the Input proccessing.
|
||||
* @param The toggler.
|
||||
|
|
|
@ -49,6 +49,10 @@ namespace Input
|
|||
SAKI_7 ,
|
||||
SAKI_8 ,
|
||||
SAKI_9 ,
|
||||
SAKI_Add ,
|
||||
SAKI_Comma ,
|
||||
SAKI_Minus ,
|
||||
SAKI_Period ,
|
||||
SAKI_A ,
|
||||
SAKI_B ,
|
||||
SAKI_C ,
|
||||
|
@ -133,9 +137,9 @@ namespace Input
|
|||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
namespace Typedefs
|
||||
{
|
||||
typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender);
|
||||
typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender);
|
||||
typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender);
|
||||
typedef void(*OnKeyPressCallback)(Enum::SAKI key, Keyboard* sender);
|
||||
typedef void(*OnKeyDownCallback)(Enum::SAKI key, Keyboard* sender);
|
||||
typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, Keyboard* sender);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -145,9 +149,9 @@ namespace Input
|
|||
class KeyboardEvent
|
||||
{
|
||||
public:
|
||||
virtual void OnKeyPress(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
|
||||
virtual void OnKeyDown(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
|
||||
virtual void OnKeyRelease(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { }
|
||||
virtual void OnKeyPress(Enum::SAKI key, Keyboard* sender) { }
|
||||
virtual void OnKeyDown(Enum::SAKI key, Keyboard* sender) { }
|
||||
virtual void OnKeyRelease(Enum::SAKI key, Keyboard* sender) { }
|
||||
};
|
||||
|
||||
public: /* Manual check functions */
|
||||
|
@ -157,6 +161,11 @@ namespace Input
|
|||
virtual bool IsKeyDown (Enum::SAKI key) = 0;
|
||||
virtual wchar_t* GetAsText(Enum::SAKI key) = 0;
|
||||
|
||||
public: /* From InputObject */
|
||||
virtual void Activate () override = 0;
|
||||
virtual void Deactivate () override = 0;
|
||||
virtual bool IsActive() override = 0;
|
||||
|
||||
public: /* global subscribe callback functions */
|
||||
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
|
||||
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
|
||||
|
@ -166,11 +175,6 @@ namespace Input
|
|||
void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
|
||||
void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback func);
|
||||
|
||||
public: /* From InputObject */
|
||||
virtual void Activate () override { this->active = true; }
|
||||
virtual void Deactivate () override { this->active = false; }
|
||||
virtual bool IsActive() override { return this->active; }
|
||||
|
||||
public:
|
||||
void operator+= (KeyboardEvent* object);
|
||||
void operator-= (KeyboardEvent* object);
|
||||
|
@ -185,9 +189,9 @@ namespace Input
|
|||
Keyboard();
|
||||
|
||||
protected: /* Internal event proc */
|
||||
void InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]);
|
||||
void InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]);
|
||||
void InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]);
|
||||
void InternalOnKeyPress(Enum::SAKI key);
|
||||
void InternalOnKeyDown(Enum::SAKI key);
|
||||
void InternalOnKeyRelease(Enum::SAKI key);
|
||||
|
||||
protected:
|
||||
std::vector<KeyboardEvent*> keyEventSubscrivers;
|
||||
|
@ -195,6 +199,7 @@ namespace Input
|
|||
::std::wstring* textTarget;
|
||||
::std::wstring::size_type writePos;
|
||||
bool active;
|
||||
Enum::InputOptionType inputMode;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,8 @@ 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 cord, Mouse* sender);
|
||||
typedef void(*OnMouseMovePixelPosCallback)(Struct::SAIPointInt2D cord, Mouse* sender);
|
||||
typedef void(*OnMouseMoveVelocityCallback)(Struct::SAIPointInt2D cord, Mouse* sender);
|
||||
typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -59,41 +60,42 @@ namespace Input
|
|||
class MouseEvent
|
||||
{
|
||||
public:
|
||||
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 OnMouseScroll ( int delta, Mouse* sender ) { }
|
||||
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 OnMouseMovePixelPos ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { }
|
||||
virtual void OnMouseMoveVelocity ( Struct::SAIPointInt2D coordinate, Mouse* sender ) { }
|
||||
virtual void OnMouseScroll ( int delta, Mouse* sender ) { }
|
||||
};
|
||||
|
||||
public: /* Manual check functions */
|
||||
virtual ~Mouse();
|
||||
virtual bool IsBtnUp(Enum::SAMI key) const = 0;
|
||||
virtual bool IsBtnDown(Enum::SAMI key) const = 0;
|
||||
virtual int GetWheelDelta() const = 0;
|
||||
virtual Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D& targetMem = Struct::SAIPointInt2D()) const = 0;
|
||||
virtual Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) = 0;
|
||||
virtual Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const = 0;
|
||||
|
||||
public: /* From InputObject */
|
||||
virtual void Activate () override = 0;
|
||||
virtual void Deactivate () override = 0;
|
||||
virtual bool IsActive() override = 0;
|
||||
|
||||
virtual bool IsBtnUp(Enum::SAMI key) = 0;
|
||||
virtual bool IsBtnDown(Enum::SAMI key) = 0;
|
||||
|
||||
public: /* global subscribe callback functions */
|
||||
int GetWheelDelta() const;
|
||||
Struct::SAIPoint2D & GetPixelPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const;
|
||||
Struct::SAIPoint2D & GetDeltaPosition( Struct::SAIPoint2D &targetMem = Struct::SAIPoint2D() ) const;
|
||||
|
||||
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
|
||||
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
|
||||
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
|
||||
void AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func );
|
||||
void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func );
|
||||
void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
|
||||
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
||||
|
||||
void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func);
|
||||
void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
|
||||
void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
|
||||
void RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func );
|
||||
void RemoveOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func );
|
||||
void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
|
||||
void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
||||
|
||||
public: /* From InputObject */
|
||||
virtual void Activate () override { this->active = true; }
|
||||
virtual void Deactivate () override { this->active = false; }
|
||||
virtual bool IsActive() override { return this->active; }
|
||||
|
||||
public:
|
||||
void operator+= (MouseEvent* object);
|
||||
void operator-= (MouseEvent* object);
|
||||
|
@ -106,21 +108,26 @@ namespace Input
|
|||
|
||||
protected:
|
||||
Mouse();
|
||||
virtual ~Mouse();
|
||||
|
||||
protected:
|
||||
void InternalOnBtnPress(Enum::SAMI key);
|
||||
void InternalOnBtnDown(Enum::SAMI key);
|
||||
void InternalOnBtnRelease(Enum::SAMI key);
|
||||
void InternalOnMove(Struct::SAIPoint2D cord);
|
||||
void InternalOnMove(Struct::SAIPointInt2D pixelPos, Struct::SAIPointInt2D velocity);
|
||||
void InternalOnScroll(int delta);
|
||||
|
||||
protected:
|
||||
std::vector<MouseEvent*> mouseSubscribers;
|
||||
MouseCallbackList* callbackList;
|
||||
Struct::SAIPoint2D pixelPos, deltaPos;
|
||||
Struct::SAIPointInt2D pixelPos;
|
||||
Struct::SAIPointInt2D velocity;
|
||||
Struct::SAIPointFloat2D normalPos;
|
||||
Struct::SAIPointFloat2D deltaPos;
|
||||
|
||||
bool isCurorLocked;
|
||||
int wheelDelta;
|
||||
bool active;
|
||||
Enum::InputOptionType inputMode;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "..\InputManager.h"
|
||||
#include "Win32Keyboard.h"
|
||||
#include "Win32Mouse.h"
|
||||
#include "Win32ApplicationKeyboard.h"
|
||||
#include <vector>
|
||||
#define NOMINMAX
|
||||
#include <Windows.h>
|
||||
|
@ -57,7 +56,6 @@ namespace Input
|
|||
std::vector<Win32Mouse*> mouse;
|
||||
|
||||
bool enabled;
|
||||
bool exclusive;
|
||||
HWND targetHwin;
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,14 +13,20 @@ namespace Input
|
|||
class Win32Keyboard :public Keyboard
|
||||
{
|
||||
public:
|
||||
Win32Keyboard();
|
||||
Win32Keyboard(HWND target);
|
||||
~Win32Keyboard();
|
||||
|
||||
bool IsKeyUp (Enum::SAKI key) override;
|
||||
bool IsKeyDown (Enum::SAKI key) override;
|
||||
wchar_t* GetAsText(Enum::SAKI key) override;
|
||||
|
||||
public: /* From InputObject */
|
||||
void Activate () override;
|
||||
void Deactivate () override;
|
||||
inline bool IsActive() override { return this->isActive; }
|
||||
|
||||
void ProccessKeyboardData (RAWKEYBOARD keyboard);
|
||||
bool Create( );
|
||||
|
||||
private:
|
||||
void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0);
|
||||
|
@ -31,9 +37,10 @@ namespace Input
|
|||
bool isDown;
|
||||
unsigned int makecode;
|
||||
};
|
||||
|
||||
RAWINPUTDEVICE device;
|
||||
static const int MAXKEYS = 256;
|
||||
Keys keys[MAXKEYS];
|
||||
bool isActive;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,22 @@ namespace Input
|
|||
class Win32Mouse :public Mouse
|
||||
{
|
||||
public:
|
||||
Win32Mouse();
|
||||
Win32Mouse(HWND target);
|
||||
~Win32Mouse();
|
||||
|
||||
bool IsBtnUp(Enum::SAMI key) override;
|
||||
bool IsBtnDown(Enum::SAMI key) override;
|
||||
bool IsBtnUp(Enum::SAMI key) const override;
|
||||
bool IsBtnDown(Enum::SAMI key) const override;
|
||||
int GetWheelDelta() const override;
|
||||
Struct::SAIPointInt2D& GetPixelPosition(Struct::SAIPointInt2D &targetMem = Struct::SAIPointInt2D()) const override;
|
||||
Struct::SAIPointFloat2D& GetNormalizedPosition(Struct::SAIPointFloat2D &targetMem = Struct::SAIPointFloat2D()) override;
|
||||
Struct::SAIPointFloat2D& GetDeltaPosition(Struct::SAIPointFloat2D& targetMem = Struct::SAIPointFloat2D()) const override;
|
||||
|
||||
void Activate () override;
|
||||
void Deactivate () override;
|
||||
inline bool IsActive() override { return this->isActive; }
|
||||
|
||||
void ProccessMouseData (RAWMOUSE mouse);
|
||||
bool Create( );
|
||||
|
||||
private:
|
||||
struct Buttons
|
||||
|
@ -26,8 +35,11 @@ namespace Input
|
|||
unsigned int makeCode;
|
||||
bool isDown;
|
||||
};
|
||||
static const int MAXBUTTONS = 25;
|
||||
Buttons buttons[25];
|
||||
static const int MAXBUTTONS =Enum::SAMI_Unknown;
|
||||
Buttons buttons[MAXBUTTONS];
|
||||
RAWINPUTDEVICE device;
|
||||
Struct::SAIPointInt2D windowSize;
|
||||
bool isActive;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -112,13 +112,13 @@ Keyboard::~Keyboard()
|
|||
|
||||
}
|
||||
|
||||
void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16])
|
||||
void Keyboard::InternalOnKeyPress(Enum::SAKI key)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
|
||||
{
|
||||
if(this->keyEventSubscrivers[i])
|
||||
{
|
||||
this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this);
|
||||
this->keyEventSubscrivers[i]->OnKeyPress(key, this);
|
||||
}
|
||||
}
|
||||
KeyboardCallbackList *w = this->callbackList;
|
||||
|
@ -126,17 +126,17 @@ void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16])
|
|||
{
|
||||
if(w->function)
|
||||
if (w->type == KeyboardCallbackList::CallbackDataType_OnPress)
|
||||
w->function.keyPressCallback(key, GetAsText(key), this);
|
||||
w->function.keyPressCallback(key, this);
|
||||
w = w->next;
|
||||
}
|
||||
}
|
||||
void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16])
|
||||
void Keyboard::InternalOnKeyDown(Enum::SAKI key)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
|
||||
{
|
||||
if(this->keyEventSubscrivers[i])
|
||||
{
|
||||
this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this);
|
||||
this->keyEventSubscrivers[i]->OnKeyDown(key, this);
|
||||
}
|
||||
}
|
||||
KeyboardCallbackList *w = this->callbackList;
|
||||
|
@ -144,17 +144,17 @@ void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16])
|
|||
{
|
||||
if(w->function)
|
||||
if (w->type == KeyboardCallbackList::CallbackDataType_OnDown)
|
||||
w->function.keyDownCallback(key, GetAsText(key), this);
|
||||
w->function.keyDownCallback(key, this);
|
||||
w = w->next;
|
||||
}
|
||||
}
|
||||
void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16])
|
||||
void Keyboard::InternalOnKeyRelease(Enum::SAKI key)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
|
||||
{
|
||||
if(this->keyEventSubscrivers[i])
|
||||
{
|
||||
this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this);
|
||||
this->keyEventSubscrivers[i]->OnKeyRelease(key, this);
|
||||
}
|
||||
}
|
||||
KeyboardCallbackList *w = this->callbackList;
|
||||
|
@ -162,7 +162,7 @@ void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16])
|
|||
{
|
||||
if(w->function)
|
||||
if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease)
|
||||
w->function.keyReleaseCallback(key, GetAsText(key), this);
|
||||
w->function.keyReleaseCallback(key, this);
|
||||
w = w->next;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@ struct Mouse::MouseCallbackList
|
|||
CallbackDataType_OnPress,
|
||||
CallbackDataType_OnDown,
|
||||
CallbackDataType_OnRelease,
|
||||
CallbackDataType_OnMove,
|
||||
CallbackDataType_OnMovePixelPos,
|
||||
CallbackDataType_OnMoveVelocity,
|
||||
CallbackDataType_OnScroll,
|
||||
} type;
|
||||
union CallbackData
|
||||
|
@ -24,7 +25,8 @@ struct Mouse::MouseCallbackList
|
|||
Typedefs::OnMousePressCallback mousePressCallback;
|
||||
Typedefs::OnMouseDownCallback mouseDownCallback;
|
||||
Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
|
||||
Typedefs::OnMouseMoveCallback mouseMoveCallback;
|
||||
Typedefs::OnMouseMovePixelPosCallback mouseMovePixelPosCallback;
|
||||
Typedefs::OnMouseMoveVelocityCallback mouseMoveVelocityCallback;
|
||||
Typedefs::OnMouseScrollCallback mouseScrollCallback;
|
||||
void* dummy;
|
||||
|
||||
|
@ -165,19 +167,24 @@ void Mouse::InternalOnBtnRelease(Enum::SAMI btn)
|
|||
w = w->next;
|
||||
}
|
||||
}
|
||||
void Mouse::InternalOnMove(Struct::SAIPoint2D cord)
|
||||
void Mouse::InternalOnMove(Struct::SAIPointInt2D pixelPos, Struct::SAIPointInt2D velocity)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
|
||||
{
|
||||
if(this->mouseSubscribers[i])
|
||||
this->mouseSubscribers[i]->OnMouseMove(this->pixelPos, this);
|
||||
{
|
||||
this->mouseSubscribers[i]->OnMouseMovePixelPos(pixelPos, this);
|
||||
this->mouseSubscribers[i]->OnMouseMoveVelocity(velocity, this);
|
||||
}
|
||||
}
|
||||
MouseCallbackList *w = this->callbackList;
|
||||
while (w)
|
||||
{
|
||||
if(w->function)
|
||||
if (w->type == MouseCallbackList::CallbackDataType_OnMove)
|
||||
w->function.mouseMoveCallback(this->pixelPos, this);
|
||||
if (w->type == MouseCallbackList::CallbackDataType_OnMovePixelPos)
|
||||
w->function.mouseMovePixelPosCallback(pixelPos, this);
|
||||
else if (w->type == MouseCallbackList::CallbackDataType_OnMoveVelocity)
|
||||
w->function.mouseMoveVelocityCallback(velocity, this);
|
||||
w = w->next;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +199,7 @@ void Mouse::InternalOnScroll(int delta)
|
|||
while (w)
|
||||
{
|
||||
if(w->function)
|
||||
if (w->type == MouseCallbackList::CallbackDataType_OnMove)
|
||||
if (w->type == MouseCallbackList::CallbackDataType_OnScroll)
|
||||
w->function.mouseScrollCallback(delta, this);
|
||||
w = w->next;
|
||||
}
|
||||
|
@ -200,36 +207,19 @@ void Mouse::InternalOnScroll(int delta)
|
|||
|
||||
|
||||
|
||||
int Mouse::GetWheelDelta() const
|
||||
{
|
||||
return this->wheelDelta;
|
||||
}
|
||||
SAIPoint2D & Mouse::GetPixelPosition( Struct::SAIPoint2D &targetMem ) const
|
||||
{
|
||||
targetMem.x = this->pixelPos.x;
|
||||
targetMem.y = this->pixelPos.y;
|
||||
return targetMem;
|
||||
}
|
||||
SAIPoint2D & Mouse::GetDeltaPosition( Struct::SAIPoint2D &targetMem ) const
|
||||
{
|
||||
targetMem.x = this->deltaPos.x;
|
||||
targetMem.y = this->deltaPos.y;
|
||||
return targetMem;
|
||||
}
|
||||
|
||||
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func)
|
||||
{
|
||||
MouseCallbackList::CallbackData d;
|
||||
d.mousePressCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress);
|
||||
}
|
||||
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
|
||||
{
|
||||
MouseCallbackList::CallbackData d;
|
||||
d.mouseDownCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown);
|
||||
}
|
||||
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
|
||||
{
|
||||
|
@ -238,19 +228,26 @@ void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
|
|||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
}
|
||||
void Mouse::AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func )
|
||||
void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func )
|
||||
{
|
||||
MouseCallbackList::CallbackData d;
|
||||
d.mouseMoveCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
d.mouseMovePixelPosCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
|
||||
}
|
||||
void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func )
|
||||
{
|
||||
MouseCallbackList::CallbackData d;
|
||||
d.mouseMoveVelocityCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
|
||||
}
|
||||
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
|
||||
{
|
||||
MouseCallbackList::CallbackData d;
|
||||
d.mouseScrollCallback = func;
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll);
|
||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll);
|
||||
}
|
||||
|
||||
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
|
||||
|
@ -265,7 +262,11 @@ void Mouse::RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func
|
|||
{
|
||||
RemoveFromList(this->callbackList, func);
|
||||
}
|
||||
void Mouse::RemoveOnMouseMoveCallback( Typedefs::OnMouseMoveCallback func )
|
||||
void Mouse::RemoveOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func )
|
||||
{
|
||||
RemoveFromList(this->callbackList, func);
|
||||
}
|
||||
void Mouse::RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func )
|
||||
{
|
||||
RemoveFromList(this->callbackList, func);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ using namespace Input::Enum;
|
|||
using namespace Input::Struct;
|
||||
using namespace Input::Typedefs;
|
||||
|
||||
|
||||
Win32Input *Win32Input::instance = 0;
|
||||
|
||||
LRESULT Win32Input::RawInputParser(HWND h, LPARAM l)
|
||||
|
@ -88,14 +87,6 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM
|
|||
case WM_INPUT:
|
||||
return Win32Input::instance->RawInputParser(h, l);
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
val = 0;
|
||||
break;
|
||||
|
||||
case WM_CHAR:
|
||||
val = 0;
|
||||
break;
|
||||
|
||||
case WM_ACTIVATE:
|
||||
Win32Input::instance->WindowActivate((w == TRUE));
|
||||
|
@ -115,7 +106,7 @@ void Win32Input::WindowActivate(bool activate)
|
|||
}
|
||||
else
|
||||
{
|
||||
ShowCursor(0);
|
||||
ShowCursor(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,55 +142,49 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH
|
|||
{
|
||||
if(!this->instance->targetHwin)
|
||||
{
|
||||
this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL );
|
||||
RECT rc;
|
||||
GetClientRect((HWND)targetApplication, &rc);
|
||||
|
||||
AdjustWindowRect(&rc, GetWindowStyle((HWND)targetApplication), FALSE);
|
||||
|
||||
rc.right = rc.right - rc.left;
|
||||
rc.bottom = rc.bottom - rc.top;
|
||||
|
||||
this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, rc.left, rc.top, rc.right, rc.bottom,
|
||||
(HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL );
|
||||
}
|
||||
|
||||
InputObject* val = 0;
|
||||
RAWINPUTDEVICE rid;
|
||||
rid.usUsagePage = 0x01;
|
||||
rid.hwndTarget = this->instance->targetHwin;
|
||||
|
||||
switch (inputType)
|
||||
{
|
||||
case SAIType_Keyboard:
|
||||
{
|
||||
rid.usUsage = RawInput_Usage_keyboard;
|
||||
rid.dwFlags = RIDEV_NOLEGACY;
|
||||
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
|
||||
{
|
||||
Win32Keyboard* obj = new Win32Keyboard();
|
||||
this->keyboard.push_back(obj);
|
||||
val = obj;
|
||||
}
|
||||
else
|
||||
Win32Keyboard* obj = new Win32Keyboard(this->targetHwin);
|
||||
if(!obj->Create())
|
||||
{
|
||||
delete obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->keyboard.push_back(obj);
|
||||
val = obj;
|
||||
}
|
||||
break;
|
||||
|
||||
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
|
||||
Win32Mouse* obj = new Win32Mouse(this->targetHwin);
|
||||
if(!obj->Create())
|
||||
{
|
||||
delete obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
this->mouse.push_back(obj);
|
||||
val = obj;
|
||||
}
|
||||
break;
|
||||
|
||||
//case SAIType_ApplicationKeyboard:
|
||||
// //val = new Win32ApplicationKeyboard();
|
||||
// break;
|
||||
}
|
||||
|
||||
return val;
|
||||
|
@ -208,6 +193,21 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH
|
|||
void Win32Input::ToggleInputSystem(bool enable)
|
||||
{
|
||||
this->enabled = enable;
|
||||
|
||||
if(this->enabled)
|
||||
{
|
||||
for (unsigned int i = 0; i < this->mouse.size(); i++)
|
||||
{ this->mouse[i]->Deactivate(); }
|
||||
for (unsigned int i = 0; i < this->keyboard.size(); i++)
|
||||
{ this->keyboard[i]->Deactivate(); }
|
||||
}
|
||||
else
|
||||
{
|
||||
for (unsigned int i = 0; i < this->mouse.size(); i++)
|
||||
{ this->mouse[i]->Activate(); }
|
||||
for (unsigned int i = 0; i < this->keyboard.size(); i++)
|
||||
{ this->keyboard[i]->Activate(); }
|
||||
}
|
||||
}
|
||||
void Win32Input::Destroy ()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#include "..\..\Include\Win32\Win32Keyboard.h"
|
||||
#include "..\..\Include\Win32\Win32Input.h"
|
||||
#include <algorithm>
|
||||
|
||||
#pragma warning ( disable : 4172 )
|
||||
|
@ -10,8 +10,13 @@ using namespace Input::Enum;
|
|||
using namespace std;
|
||||
|
||||
|
||||
Win32Keyboard::Win32Keyboard()
|
||||
Win32Keyboard::Win32Keyboard(HWND target)
|
||||
{
|
||||
this->isActive = false;
|
||||
this->device.usUsagePage = 0x01;
|
||||
this->device.hwndTarget = target;
|
||||
this->device.usUsage = RawInput_Usage_keyboard;
|
||||
this->device.dwFlags = RIDEV_NOLEGACY;
|
||||
memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS);
|
||||
}
|
||||
Win32Keyboard::~Win32Keyboard()
|
||||
|
@ -37,6 +42,28 @@ wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key)
|
|||
GetKeyNameTextW((LONG)temp, buff, 16);
|
||||
return buff;
|
||||
}
|
||||
|
||||
void Win32Keyboard::Activate ()
|
||||
{
|
||||
if(this->isActive) return;
|
||||
|
||||
this->Create();
|
||||
}
|
||||
void Win32Keyboard::Deactivate ()
|
||||
{
|
||||
if(!this->isActive) return;
|
||||
|
||||
RAWINPUTDEVICE d;
|
||||
d.dwFlags = RIDEV_REMOVE;
|
||||
d.hwndTarget = 0;
|
||||
d.usUsage = RawInput_Usage_keyboard;
|
||||
d.usUsagePage = 0x01;
|
||||
if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE)))
|
||||
{
|
||||
this->isActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
|
||||
{
|
||||
if(!this->active)
|
||||
|
@ -55,7 +82,7 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
|
|||
//The key is released.
|
||||
if(isUp)/*(k.Flags == RI_KEY_BREAK || k.Flags == (RI_KEY_BREAK | RI_KEY_E0) || k.Flags == (RI_KEY_BREAK | RI_KEY_E1))*/
|
||||
{
|
||||
InternalOnKeyRelease(key, L"");
|
||||
InternalOnKeyRelease(key);
|
||||
this->keys[key].isDown = false;
|
||||
this->keys[key].isE0 = isE0;
|
||||
this->keys[key].makecode = keyboard.MakeCode;
|
||||
|
@ -65,11 +92,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
|
|||
{
|
||||
if(this->keys[key].isDown)
|
||||
{
|
||||
this->InternalOnKeyDown(key, L"");
|
||||
this->InternalOnKeyDown(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->InternalOnKeyPress(key, L"");
|
||||
this->InternalOnKeyPress(key);
|
||||
this->keys[key].isDown = true;
|
||||
this->keys[key].isE0 = isE0;
|
||||
this->keys[key].makecode = keyboard.MakeCode;
|
||||
|
@ -108,8 +135,32 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
|
|||
{
|
||||
wchar_t test = towlower((wchar_t)virtualKey);
|
||||
if( this->keys[SAKI_LeftShift].isDown || this->keys[SAKI_RightShift].isDown )
|
||||
{
|
||||
if(key == SAKI_0) test = L'=';
|
||||
else if(key == SAKI_1) test = L'!';
|
||||
else if(key == SAKI_2) test = L'"';
|
||||
else if(key == SAKI_3) test = L'#';
|
||||
else if(key == SAKI_4) test = L'¤';
|
||||
else if(key == SAKI_5) test = L'%';
|
||||
else if(key == SAKI_6) test = L'&';
|
||||
else if(key == SAKI_7) test = L'/';
|
||||
else if(key == SAKI_8) test = L'(';
|
||||
else if(key == SAKI_9) test = L')';
|
||||
else if(key == SAKI_Add) test = L'?';
|
||||
test = towupper(test);
|
||||
|
||||
}
|
||||
else if( this->keys[SAKI_LeftAlt].isDown || this->keys[SAKI_RightAlt].isDown )
|
||||
{
|
||||
if(key == SAKI_2) test = L'@';
|
||||
else if(key == SAKI_3) test = L'£';
|
||||
else if(key == SAKI_4) test = L'$';
|
||||
else if(key == SAKI_5) test = L'€';
|
||||
else if(key == SAKI_7) test = L'{';
|
||||
else if(key == SAKI_8) test = L'[';
|
||||
else if(key == SAKI_9) test = L']';
|
||||
else if(key == SAKI_0) test = L'}';
|
||||
else if(key == SAKI_Add) test = L'\\';
|
||||
}
|
||||
this->textTarget->insert( this->writePos, 1, test);
|
||||
++this->writePos;
|
||||
}
|
||||
|
@ -247,7 +298,7 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0)
|
|||
out_key = SAKI_LeftShift;
|
||||
out_key = SAKI_RightShift;
|
||||
break;
|
||||
case 0x13 : //VK_PAUSE
|
||||
case 0x13 : //VK_PAUSE
|
||||
out_key = SAKI_Pause;
|
||||
break;
|
||||
case 0x14 : //VK_CAPITAL
|
||||
|
@ -614,12 +665,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0)
|
|||
break;
|
||||
|
||||
case 0xBB://VK_OEM_PLUS
|
||||
out_key = SAKI_Add;
|
||||
break;
|
||||
case 0xBC://VK_OEM_COMMA
|
||||
out_key = SAKI_Comma;
|
||||
break;
|
||||
case 0xBD://VK_OEM_MINUS
|
||||
out_key = SAKI_Minus;
|
||||
break;
|
||||
case 0xBE://VK_OEM_PERIOD
|
||||
out_key = SAKI_Period;
|
||||
break;
|
||||
case 0xBA://VK_OEM_1
|
||||
break;
|
||||
|
@ -639,6 +694,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0)
|
|||
break;
|
||||
}
|
||||
}
|
||||
bool Win32Keyboard::Create()
|
||||
{
|
||||
if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
|
||||
{
|
||||
this->isActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
#include "..\..\Include\Win32\Win32Mouse.h"
|
||||
#include "..\..\Include\Win32\Win32Input.h"
|
||||
|
||||
using namespace Input;
|
||||
using namespace Input::Enum;
|
||||
using namespace Input::Struct;
|
||||
using namespace Input::Typedefs;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -62,43 +62,109 @@ void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Stru
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Win32Mouse::Win32Mouse()
|
||||
void ContainPoint(Struct::SAIPointInt2D& pixelPos, Struct::SAIPointInt2D& windowSize)
|
||||
{
|
||||
if(pixelPos.x < 0) { pixelPos.x = 0; }
|
||||
else if(pixelPos.x > windowSize.x) { pixelPos.x = windowSize.x; }
|
||||
if(pixelPos.y < 0) { pixelPos.y = 0; }
|
||||
else if(pixelPos.y > windowSize.y) { pixelPos.y = windowSize.y; }
|
||||
}
|
||||
|
||||
Win32Mouse::Win32Mouse(HWND target)
|
||||
{
|
||||
this->isActive = false;
|
||||
this->device.usUsagePage = 0x01;
|
||||
this->device.hwndTarget = target;
|
||||
this->device.usUsage = RawInput_Usage_mouse;
|
||||
this->device.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE;
|
||||
memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS);
|
||||
}
|
||||
Win32Mouse::~Win32Mouse()
|
||||
{
|
||||
}
|
||||
{ }
|
||||
|
||||
|
||||
bool Win32Mouse::IsBtnUp(Enum::SAMI btn)
|
||||
bool Win32Mouse::IsBtnUp(Enum::SAMI btn) const
|
||||
{
|
||||
if(btn == SAMI_Unknown) return false;
|
||||
|
||||
return !this->buttons[btn].isDown;
|
||||
}
|
||||
bool Win32Mouse::IsBtnDown(Enum::SAMI btn)
|
||||
bool Win32Mouse::IsBtnDown(Enum::SAMI btn) const
|
||||
{
|
||||
if(btn == SAMI_Unknown) return false;
|
||||
|
||||
return this->buttons[btn].isDown;
|
||||
}
|
||||
int Win32Mouse::GetWheelDelta() const
|
||||
{
|
||||
return this->wheelDelta;
|
||||
}
|
||||
SAIPointInt2D& Win32Mouse::GetPixelPosition( Struct::SAIPointInt2D &targetMem ) const
|
||||
{
|
||||
memcpy(&targetMem, &this->pixelPos, sizeof(SAIPointFloat2D));
|
||||
|
||||
return targetMem;
|
||||
}
|
||||
SAIPointFloat2D& Win32Mouse::GetNormalizedPosition(Struct::SAIPointFloat2D& targetMem)
|
||||
{
|
||||
RECT windowVertex;
|
||||
GetWindowRect( this->device.hwndTarget, &windowVertex );
|
||||
|
||||
this->normalPos.x = (float)(pixelPos.x - windowVertex.left);
|
||||
this->normalPos.x /= (float)(windowVertex.right - windowVertex.left);
|
||||
|
||||
this->normalPos.y = (float)(pixelPos.y - windowVertex.top);
|
||||
this->normalPos.y /= (float)(windowVertex.bottom - windowVertex.top);
|
||||
|
||||
memcpy(&targetMem, &this->normalPos, sizeof(SAIPointFloat2D));
|
||||
|
||||
return targetMem;
|
||||
}
|
||||
SAIPointFloat2D& Win32Mouse::GetDeltaPosition(Struct::SAIPointFloat2D& targetMem) const
|
||||
{
|
||||
memcpy(&targetMem, &this->deltaPos, sizeof(SAIPointFloat2D));
|
||||
|
||||
return targetMem;
|
||||
}
|
||||
|
||||
void Win32Mouse::Activate ()
|
||||
{
|
||||
if(this->isActive) return;
|
||||
|
||||
this->Create();
|
||||
}
|
||||
void Win32Mouse::Deactivate ()
|
||||
{
|
||||
if(!this->isActive) return;
|
||||
|
||||
RAWINPUTDEVICE d;
|
||||
d.dwFlags = RIDEV_REMOVE;
|
||||
d.hwndTarget = 0;
|
||||
d.usUsage = RawInput_Usage_mouse;
|
||||
d.usUsagePage = 0x01;
|
||||
if(RegisterRawInputDevices(&d, 1, sizeof(RAWINPUTDEVICE)))
|
||||
{
|
||||
this->isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
||||
{
|
||||
bool isUp = true;
|
||||
Enum::SAMI btn = Enum::SAMI_Unknown;
|
||||
int delta = 0;
|
||||
Struct::SAIPoint2D velocity;
|
||||
Struct::SAIPointInt2D velocity;
|
||||
unsigned int makeCode = 0;
|
||||
MapButton(mouse, isUp, btn, delta, velocity, makeCode);
|
||||
|
||||
if(velocity.Length() != 0)
|
||||
{
|
||||
this->pixelPos.x += this->deltaPos.x = velocity.x;
|
||||
this->pixelPos.y += this->deltaPos.y = velocity.y;
|
||||
InternalOnMove(this->pixelPos);
|
||||
this->pixelPos.x += velocity.x;
|
||||
this->pixelPos.y += velocity.y;
|
||||
|
||||
ContainPoint(this->pixelPos, this->windowSize);
|
||||
|
||||
InternalOnMove(this->pixelPos, velocity);
|
||||
}
|
||||
|
||||
if(delta != 0)
|
||||
|
@ -130,4 +196,33 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
|||
InternalOnBtnPress(btn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool Win32Mouse::Create()
|
||||
{
|
||||
if(!this->device.hwndTarget)
|
||||
{
|
||||
RECT desktop;
|
||||
const HWND hDesktop = GetDesktopWindow();
|
||||
GetClientRect(hDesktop, &desktop);
|
||||
windowSize.x = desktop.right;
|
||||
windowSize.y = desktop.bottom;
|
||||
this->device.dwFlags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RECT re;
|
||||
GetClientRect(this->device.hwndTarget, &re);
|
||||
windowSize.x = re.right - re.left;
|
||||
windowSize.y = re.bottom - re.top;
|
||||
}
|
||||
|
||||
if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
|
||||
{
|
||||
this->isActive = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -77,7 +77,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
|
|||
if(!desc.hInstance) desc.hInstance = GetModuleHandle(0);
|
||||
if(desc.windowSize.x <= 0) desc.windowSize.x = 50;
|
||||
if(desc.windowSize.y <= 0) desc.windowSize.y = 50;
|
||||
|
||||
|
||||
__windowShellData.parent = desc.parent;
|
||||
__windowShellData.hIns = desc.hInstance;
|
||||
|
@ -111,20 +110,14 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
|
|||
|
||||
|
||||
RECT rectW;
|
||||
int width;
|
||||
int height;
|
||||
DWORD style = desc.windowStyle;
|
||||
bool windowed = false;
|
||||
|
||||
width = desc.windowSize.x + GetSystemMetrics(SM_CXFIXEDFRAME)*2;
|
||||
height = desc.windowSize.y + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
|
||||
rectW.left = 0;
|
||||
rectW.top = 0;
|
||||
rectW.right = desc.windowSize.x;
|
||||
rectW.bottom = desc.windowSize.y;
|
||||
|
||||
rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2;
|
||||
rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2;
|
||||
rectW.right=rectW.left+width;
|
||||
rectW.bottom=rectW.top+height;
|
||||
|
||||
|
||||
if(__windowShellData.parent)
|
||||
{
|
||||
rectW.left = 0;
|
||||
|
@ -135,6 +128,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
|
|||
windowed = true;
|
||||
}
|
||||
|
||||
AdjustWindowRect(& rectW, style, FALSE);
|
||||
|
||||
if(windowed)
|
||||
{
|
||||
__windowShellData.hWnd = CreateWindowExW(
|
||||
|
@ -161,8 +156,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
|
|||
style,
|
||||
desc.windowPosition.x,
|
||||
desc.windowPosition.y,
|
||||
desc.windowSize.x,
|
||||
desc.windowSize.y,
|
||||
rectW.right - rectW.left,
|
||||
rectW.bottom - rectW.top,
|
||||
0,
|
||||
0,
|
||||
__windowShellData.hIns,
|
||||
|
@ -173,7 +168,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
|
|||
if( !__windowShellData.hWnd )
|
||||
{
|
||||
printf("Failed to create window handle : Code ( %ul )", GetLastError());
|
||||
//MessageBox(0, L"Failed to create window", L"Error!", 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -258,3 +252,4 @@ bool WindowShell::Frame()
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
POINT _windowSize = cPOINT(800, 600),
|
||||
POINT _windowPosition = cPOINT(0,0),
|
||||
UINT _windowClassStyle = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC),
|
||||
UINT _windowStyle = (WS_POPUPWINDOW|WS_SYSMENU|WS_CAPTION),
|
||||
UINT _windowStyle = (WS_POPUPWINDOW|WS_CAPTION),
|
||||
HICON _icon = LoadIcon(0, IDI_APPLICATION),
|
||||
HCURSOR _cursor = LoadCursor(NULL, IDC_ARROW),
|
||||
HBRUSH _background = (HBRUSH)GetStockObject(BLACK_BRUSH)
|
||||
|
|
Loading…
Reference in New Issue