Input - Added toggle for input

This commit is contained in:
dean11 2014-02-24 16:01:06 +01:00
parent dee6c5f8d1
commit cc17f80fd7
15 changed files with 370 additions and 172 deletions

View File

@ -26,6 +26,11 @@ namespace Input
SAIType_futureExample2, SAIType_futureExample2,
SAIType_futureExample3, SAIType_futureExample3,
}; };
enum InputOptionType
{
InputOptionType_RawInput,
InputOptionType_PlatformDefault,
};
enum ButtonState enum ButtonState
{ {
ButtonState_Press, // When button is pressed (once) ButtonState_Press, // When button is pressed (once)
@ -37,15 +42,24 @@ namespace Input
/*********************************************************************/ /*********************************************************************/
namespace Struct namespace Struct
{ {
struct SAIPoint2D struct SAIPointInt2D
{ {
int x; int x;
int y; int y;
SAIPoint2D() :x(0), y(0) { } SAIPointInt2D() :x(0), y(0) { }
SAIPoint2D(int _x, int _y) :x(_x), y(_y) { } SAIPointInt2D(int _x, int _y) :x(_x), y(_y) { }
int Length() { return (abs(x) + abs(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; struct InputData;
} }
/*********************************************************************/ /*********************************************************************/

View File

@ -7,7 +7,6 @@
#include "InputManager.h" #include "InputManager.h"
#include "InputObject.h" #include "InputObject.h"
#include "Keyboard.h" #include "Keyboard.h"
#include "ApplicationKeyboard.h"
#include "Mouse.h" #include "Mouse.h"
#endif // !INPUT_INPUT_H #endif // !INPUT_INPUT_H

View File

@ -37,9 +37,9 @@ namespace Input
* @see InputDescription * @see InputDescription
* @return Returns a handle to a device that can be rethrown to a specific device. * @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 InputObject* CreateDevice ( const Enum::SAIType inputType, Typedefs::WindowHandle targetApplication ) = 0;
virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); } virtual Keyboard* CreateKeyboardDevice ( Typedefs::WindowHandle targetApplication ) { return (Keyboard*)CreateDevice(Enum::SAIType_Keyboard, targetApplication); }
virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication = 0 ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); } virtual Mouse* CreateMouseDevice ( Typedefs::WindowHandle targetApplication ) { return (Mouse*)CreateDevice(Enum::SAIType_Mouse, targetApplication); }
/** Enables or Disables the Input proccessing. /** Enables or Disables the Input proccessing.
* @param The toggler. * @param The toggler.

View File

@ -49,6 +49,10 @@ namespace Input
SAKI_7 , SAKI_7 ,
SAKI_8 , SAKI_8 ,
SAKI_9 , SAKI_9 ,
SAKI_Add ,
SAKI_Comma ,
SAKI_Minus ,
SAKI_Period ,
SAKI_A , SAKI_A ,
SAKI_B , SAKI_B ,
SAKI_C , SAKI_C ,
@ -133,9 +137,9 @@ namespace Input
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
namespace Typedefs namespace Typedefs
{ {
typedef void(*OnKeyPressCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); typedef void(*OnKeyPressCallback)(Enum::SAKI key, Keyboard* sender);
typedef void(*OnKeyDownCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); typedef void(*OnKeyDownCallback)(Enum::SAKI key, Keyboard* sender);
typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, const wchar_t[16], Keyboard* sender); typedef void(*OnKeyReleaseCallback)(Enum::SAKI key, Keyboard* sender);
} }
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
@ -145,9 +149,9 @@ namespace Input
class KeyboardEvent class KeyboardEvent
{ {
public: public:
virtual void OnKeyPress(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } virtual void OnKeyPress(Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyDown(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } virtual void OnKeyDown(Enum::SAKI key, Keyboard* sender) { }
virtual void OnKeyRelease(Enum::SAKI key, const wchar_t[40], Keyboard* sender) { } virtual void OnKeyRelease(Enum::SAKI key, Keyboard* sender) { }
}; };
public: /* Manual check functions */ public: /* Manual check functions */
@ -157,6 +161,11 @@ namespace Input
virtual bool IsKeyDown (Enum::SAKI key) = 0; virtual bool IsKeyDown (Enum::SAKI key) = 0;
virtual wchar_t* GetAsText(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 */ public: /* global subscribe callback functions */
void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func); void AddOnKeyPressCallback (Typedefs::OnKeyPressCallback func);
void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func); void AddOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
@ -166,11 +175,6 @@ namespace Input
void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func); void RemoveOnKeyDownCallback (Typedefs::OnKeyDownCallback func);
void RemoveOnKeyReleaseCallback (Typedefs::OnKeyReleaseCallback 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: public:
void operator+= (KeyboardEvent* object); void operator+= (KeyboardEvent* object);
void operator-= (KeyboardEvent* object); void operator-= (KeyboardEvent* object);
@ -185,9 +189,9 @@ namespace Input
Keyboard(); Keyboard();
protected: /* Internal event proc */ protected: /* Internal event proc */
void InternalOnKeyPress(Enum::SAKI key, wchar_t text[16]); void InternalOnKeyPress(Enum::SAKI key);
void InternalOnKeyDown(Enum::SAKI key, wchar_t text[16]); void InternalOnKeyDown(Enum::SAKI key);
void InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16]); void InternalOnKeyRelease(Enum::SAKI key);
protected: protected:
std::vector<KeyboardEvent*> keyEventSubscrivers; std::vector<KeyboardEvent*> keyEventSubscrivers;
@ -195,6 +199,7 @@ namespace Input
::std::wstring* textTarget; ::std::wstring* textTarget;
::std::wstring::size_type writePos; ::std::wstring::size_type writePos;
bool active; bool active;
Enum::InputOptionType inputMode;
}; };
} }

View File

@ -47,7 +47,8 @@ namespace Input
typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender); typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender);
typedef void(*OnMouseReleaseCallback)(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); typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender);
} }
//----------------------------------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------------------------------
@ -62,38 +63,39 @@ namespace Input
virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMousePress ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseDown ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { } virtual void OnMouseRelease ( Enum::SAMI key, Mouse* sender ) { }
virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, 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 ) { } virtual void OnMouseScroll ( int delta, Mouse* sender ) { }
}; };
public: /* Manual check functions */ 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;
virtual bool IsBtnUp(Enum::SAMI key) = 0; public: /* From InputObject */
virtual bool IsBtnDown(Enum::SAMI key) = 0; virtual void Activate () override = 0;
virtual void Deactivate () override = 0;
virtual bool IsActive() override = 0;
public: /* global subscribe callback functions */ 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 AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback 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 AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func); void RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func);
void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func ); void RemoveOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
void RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback 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 ); 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: public:
void operator+= (MouseEvent* object); void operator+= (MouseEvent* object);
void operator-= (MouseEvent* object); void operator-= (MouseEvent* object);
@ -106,21 +108,26 @@ namespace Input
protected: protected:
Mouse(); Mouse();
virtual ~Mouse();
protected: protected:
void InternalOnBtnPress(Enum::SAMI key); void InternalOnBtnPress(Enum::SAMI key);
void InternalOnBtnDown(Enum::SAMI key); void InternalOnBtnDown(Enum::SAMI key);
void InternalOnBtnRelease(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); void InternalOnScroll(int delta);
protected: protected:
std::vector<MouseEvent*> mouseSubscribers; std::vector<MouseEvent*> mouseSubscribers;
MouseCallbackList* callbackList; MouseCallbackList* callbackList;
Struct::SAIPoint2D pixelPos, deltaPos; Struct::SAIPointInt2D pixelPos;
Struct::SAIPointInt2D velocity;
Struct::SAIPointFloat2D normalPos;
Struct::SAIPointFloat2D deltaPos;
bool isCurorLocked; bool isCurorLocked;
int wheelDelta; int wheelDelta;
bool active; Enum::InputOptionType inputMode;
}; };
} }

View File

@ -8,7 +8,6 @@
#include "..\InputManager.h" #include "..\InputManager.h"
#include "Win32Keyboard.h" #include "Win32Keyboard.h"
#include "Win32Mouse.h" #include "Win32Mouse.h"
#include "Win32ApplicationKeyboard.h"
#include <vector> #include <vector>
#define NOMINMAX #define NOMINMAX
#include <Windows.h> #include <Windows.h>
@ -57,7 +56,6 @@ namespace Input
std::vector<Win32Mouse*> mouse; std::vector<Win32Mouse*> mouse;
bool enabled; bool enabled;
bool exclusive;
HWND targetHwin; HWND targetHwin;
private: private:

View File

@ -13,14 +13,20 @@ namespace Input
class Win32Keyboard :public Keyboard class Win32Keyboard :public Keyboard
{ {
public: public:
Win32Keyboard(); Win32Keyboard(HWND target);
~Win32Keyboard(); ~Win32Keyboard();
bool IsKeyUp (Enum::SAKI key) override; bool IsKeyUp (Enum::SAKI key) override;
bool IsKeyDown (Enum::SAKI key) override; bool IsKeyDown (Enum::SAKI key) override;
wchar_t* GetAsText(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); void ProccessKeyboardData (RAWKEYBOARD keyboard);
bool Create( );
private: private:
void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0); void MapKey(RAWKEYBOARD& rawKB, Enum::SAKI& out_key, bool& isE0);
@ -31,9 +37,10 @@ namespace Input
bool isDown; bool isDown;
unsigned int makecode; unsigned int makecode;
}; };
RAWINPUTDEVICE device;
static const int MAXKEYS = 256; static const int MAXKEYS = 256;
Keys keys[MAXKEYS]; Keys keys[MAXKEYS];
bool isActive;
}; };
} }

View File

@ -12,13 +12,22 @@ namespace Input
class Win32Mouse :public Mouse class Win32Mouse :public Mouse
{ {
public: public:
Win32Mouse(); Win32Mouse(HWND target);
~Win32Mouse(); ~Win32Mouse();
bool IsBtnUp(Enum::SAMI key) override; bool IsBtnUp(Enum::SAMI key) const override;
bool IsBtnDown(Enum::SAMI key) 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); void ProccessMouseData (RAWMOUSE mouse);
bool Create( );
private: private:
struct Buttons struct Buttons
@ -26,8 +35,11 @@ namespace Input
unsigned int makeCode; unsigned int makeCode;
bool isDown; bool isDown;
}; };
static const int MAXBUTTONS = 25; static const int MAXBUTTONS =Enum::SAMI_Unknown;
Buttons buttons[25]; Buttons buttons[MAXBUTTONS];
RAWINPUTDEVICE device;
Struct::SAIPointInt2D windowSize;
bool isActive;
}; };
} }

View File

@ -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++) for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{ {
if(this->keyEventSubscrivers[i]) if(this->keyEventSubscrivers[i])
{ {
this->keyEventSubscrivers[i]->OnKeyPress(key, GetAsText(key), this); this->keyEventSubscrivers[i]->OnKeyPress(key, this);
} }
} }
KeyboardCallbackList *w = this->callbackList; KeyboardCallbackList *w = this->callbackList;
@ -126,17 +126,17 @@ void Keyboard::InternalOnKeyPress(Enum::SAKI key, wchar_t text[16])
{ {
if(w->function) if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnPress) if (w->type == KeyboardCallbackList::CallbackDataType_OnPress)
w->function.keyPressCallback(key, GetAsText(key), this); w->function.keyPressCallback(key, this);
w = w->next; 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++) for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{ {
if(this->keyEventSubscrivers[i]) if(this->keyEventSubscrivers[i])
{ {
this->keyEventSubscrivers[i]->OnKeyDown(key, GetAsText(key), this); this->keyEventSubscrivers[i]->OnKeyDown(key, this);
} }
} }
KeyboardCallbackList *w = this->callbackList; KeyboardCallbackList *w = this->callbackList;
@ -144,17 +144,17 @@ void Keyboard::InternalOnKeyDown(Enum::SAKI key, wchar_t text[16])
{ {
if(w->function) if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnDown) if (w->type == KeyboardCallbackList::CallbackDataType_OnDown)
w->function.keyDownCallback(key, GetAsText(key), this); w->function.keyDownCallback(key, this);
w = w->next; 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++) for (unsigned int i = 0; i < this->keyEventSubscrivers.size(); i++)
{ {
if(this->keyEventSubscrivers[i]) if(this->keyEventSubscrivers[i])
{ {
this->keyEventSubscrivers[i]->OnKeyRelease(key, GetAsText(key), this); this->keyEventSubscrivers[i]->OnKeyRelease(key, this);
} }
} }
KeyboardCallbackList *w = this->callbackList; KeyboardCallbackList *w = this->callbackList;
@ -162,7 +162,7 @@ void Keyboard::InternalOnKeyRelease(Enum::SAKI key, wchar_t text[16])
{ {
if(w->function) if(w->function)
if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease) if (w->type == KeyboardCallbackList::CallbackDataType_OnRelease)
w->function.keyReleaseCallback(key, GetAsText(key), this); w->function.keyReleaseCallback(key, this);
w = w->next; w = w->next;
} }
} }

View File

@ -16,7 +16,8 @@ struct Mouse::MouseCallbackList
CallbackDataType_OnPress, CallbackDataType_OnPress,
CallbackDataType_OnDown, CallbackDataType_OnDown,
CallbackDataType_OnRelease, CallbackDataType_OnRelease,
CallbackDataType_OnMove, CallbackDataType_OnMovePixelPos,
CallbackDataType_OnMoveVelocity,
CallbackDataType_OnScroll, CallbackDataType_OnScroll,
} type; } type;
union CallbackData union CallbackData
@ -24,7 +25,8 @@ struct Mouse::MouseCallbackList
Typedefs::OnMousePressCallback mousePressCallback; Typedefs::OnMousePressCallback mousePressCallback;
Typedefs::OnMouseDownCallback mouseDownCallback; Typedefs::OnMouseDownCallback mouseDownCallback;
Typedefs::OnMouseReleaseCallback mouseReleaseCallback; Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
Typedefs::OnMouseMoveCallback mouseMoveCallback; Typedefs::OnMouseMovePixelPosCallback mouseMovePixelPosCallback;
Typedefs::OnMouseMoveVelocityCallback mouseMoveVelocityCallback;
Typedefs::OnMouseScrollCallback mouseScrollCallback; Typedefs::OnMouseScrollCallback mouseScrollCallback;
void* dummy; void* dummy;
@ -165,19 +167,24 @@ void Mouse::InternalOnBtnRelease(Enum::SAMI btn)
w = w->next; 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++) for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
{ {
if(this->mouseSubscribers[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; MouseCallbackList *w = this->callbackList;
while (w) while (w)
{ {
if(w->function) if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnMove) if (w->type == MouseCallbackList::CallbackDataType_OnMovePixelPos)
w->function.mouseMoveCallback(this->pixelPos, this); w->function.mouseMovePixelPosCallback(pixelPos, this);
else if (w->type == MouseCallbackList::CallbackDataType_OnMoveVelocity)
w->function.mouseMoveVelocityCallback(velocity, this);
w = w->next; w = w->next;
} }
} }
@ -192,7 +199,7 @@ void Mouse::InternalOnScroll(int delta)
while (w) while (w)
{ {
if(w->function) if(w->function)
if (w->type == MouseCallbackList::CallbackDataType_OnMove) if (w->type == MouseCallbackList::CallbackDataType_OnScroll)
w->function.mouseScrollCallback(delta, this); w->function.mouseScrollCallback(delta, this);
w = w->next; 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) void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func)
{ {
MouseCallbackList::CallbackData d; MouseCallbackList::CallbackData d;
d.mousePressCallback = func; d.mousePressCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress);
} }
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func ) void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
{ {
MouseCallbackList::CallbackData d; MouseCallbackList::CallbackData d;
d.mouseDownCallback = func; d.mouseDownCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown);
} }
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func ) 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); if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
else AddToList(this->callbackList, 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; MouseCallbackList::CallbackData d;
d.mouseMoveCallback = func; d.mouseMovePixelPosCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); 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 ) void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
{ {
MouseCallbackList::CallbackData d; MouseCallbackList::CallbackData d;
d.mouseScrollCallback = func; d.mouseScrollCallback = func;
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease); if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll);
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease); else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll);
} }
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func) void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
@ -265,7 +262,11 @@ void Mouse::RemoveOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func
{ {
RemoveFromList(this->callbackList, 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); RemoveFromList(this->callbackList, func);
} }

View File

@ -16,7 +16,6 @@ using namespace Input::Enum;
using namespace Input::Struct; using namespace Input::Struct;
using namespace Input::Typedefs; using namespace Input::Typedefs;
Win32Input *Win32Input::instance = 0; Win32Input *Win32Input::instance = 0;
LRESULT Win32Input::RawInputParser(HWND h, LPARAM l) LRESULT Win32Input::RawInputParser(HWND h, LPARAM l)
@ -89,14 +88,6 @@ LRESULT CALLBACK Win32Input::RawWindowCallback(HWND h, UINT m, WPARAM w, LPARAM
return Win32Input::instance->RawInputParser(h, l); return Win32Input::instance->RawInputParser(h, l);
break; break;
case WM_KEYDOWN:
val = 0;
break;
case WM_CHAR:
val = 0;
break;
case WM_ACTIVATE: case WM_ACTIVATE:
Win32Input::instance->WindowActivate((w == TRUE)); Win32Input::instance->WindowActivate((w == TRUE));
break; break;
@ -115,7 +106,7 @@ void Win32Input::WindowActivate(bool activate)
} }
else else
{ {
ShowCursor(0); ShowCursor(1);
} }
} }
@ -151,55 +142,49 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH
{ {
if(!this->instance->targetHwin) if(!this->instance->targetHwin)
{ {
this->targetHwin = CreateWindowExW( 0, L"RawInputCallbackFunc" , NULL, NULL, NULL, NULL, NULL, RECT rc;
NULL, (HWND)targetApplication, NULL, (HINSTANCE)GetModuleHandle(0), NULL ); 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; InputObject* val = 0;
RAWINPUTDEVICE rid;
rid.usUsagePage = 0x01;
rid.hwndTarget = this->instance->targetHwin;
switch (inputType) switch (inputType)
{ {
case SAIType_Keyboard: case SAIType_Keyboard:
{ {
rid.usUsage = RawInput_Usage_keyboard; Win32Keyboard* obj = new Win32Keyboard(this->targetHwin);
rid.dwFlags = RIDEV_NOLEGACY; if(!obj->Create())
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{
Win32Keyboard* obj = new Win32Keyboard();
this->keyboard.push_back(obj);
val = obj;
}
else
{ {
delete obj;
return 0; return 0;
} }
this->keyboard.push_back(obj);
val = obj;
} }
break; break;
case SAIType_Mouse: case SAIType_Mouse:
{ {
rid.usUsage = RawInput_Usage_mouse; Win32Mouse* obj = new Win32Mouse(this->targetHwin);
rid.dwFlags = RIDEV_NOLEGACY | RIDEV_CAPTUREMOUSE; if(!obj->Create())
if(RegisterRawInputDevices(&rid, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{ {
int i = 0; delete obj;
val = (InputObject*)1; return 0;
Win32Mouse* obj = new Win32Mouse(); }
this->mouse.push_back(obj); this->mouse.push_back(obj);
val = obj; val = obj;
} }
else
{
return 0;
}
}
break; break;
//case SAIType_ApplicationKeyboard:
// //val = new Win32ApplicationKeyboard();
// break;
} }
return val; return val;
@ -208,6 +193,21 @@ InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowH
void Win32Input::ToggleInputSystem(bool enable) void Win32Input::ToggleInputSystem(bool enable)
{ {
this->enabled = 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 () void Win32Input::Destroy ()
{ {

View File

@ -1,7 +1,7 @@
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013] // Created by [Dennis Andersen] [2013]
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
#include "..\..\Include\Win32\Win32Keyboard.h" #include "..\..\Include\Win32\Win32Input.h"
#include <algorithm> #include <algorithm>
#pragma warning ( disable : 4172 ) #pragma warning ( disable : 4172 )
@ -10,8 +10,13 @@ using namespace Input::Enum;
using namespace std; 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); memset(&this->keys[0], 0, sizeof(Win32Keyboard::Keys) * MAXKEYS);
} }
Win32Keyboard::~Win32Keyboard() Win32Keyboard::~Win32Keyboard()
@ -37,6 +42,28 @@ wchar_t* Win32Keyboard::GetAsText(Enum::SAKI key)
GetKeyNameTextW((LONG)temp, buff, 16); GetKeyNameTextW((LONG)temp, buff, 16);
return buff; 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) void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
{ {
if(!this->active) if(!this->active)
@ -55,7 +82,7 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
//The key is released. //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))*/ 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].isDown = false;
this->keys[key].isE0 = isE0; this->keys[key].isE0 = isE0;
this->keys[key].makecode = keyboard.MakeCode; this->keys[key].makecode = keyboard.MakeCode;
@ -65,11 +92,11 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
{ {
if(this->keys[key].isDown) if(this->keys[key].isDown)
{ {
this->InternalOnKeyDown(key, L""); this->InternalOnKeyDown(key);
} }
else else
{ {
this->InternalOnKeyPress(key, L""); this->InternalOnKeyPress(key);
this->keys[key].isDown = true; this->keys[key].isDown = true;
this->keys[key].isE0 = isE0; this->keys[key].isE0 = isE0;
this->keys[key].makecode = keyboard.MakeCode; this->keys[key].makecode = keyboard.MakeCode;
@ -108,8 +135,32 @@ void Win32Keyboard::ProccessKeyboardData (RAWKEYBOARD keyboard)
{ {
wchar_t test = towlower((wchar_t)virtualKey); wchar_t test = towlower((wchar_t)virtualKey);
if( this->keys[SAKI_LeftShift].isDown || this->keys[SAKI_RightShift].isDown ) 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); 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->textTarget->insert( this->writePos, 1, test);
++this->writePos; ++this->writePos;
} }
@ -614,12 +665,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0)
break; break;
case 0xBB://VK_OEM_PLUS case 0xBB://VK_OEM_PLUS
out_key = SAKI_Add;
break; break;
case 0xBC://VK_OEM_COMMA case 0xBC://VK_OEM_COMMA
out_key = SAKI_Comma;
break; break;
case 0xBD://VK_OEM_MINUS case 0xBD://VK_OEM_MINUS
out_key = SAKI_Minus;
break; break;
case 0xBE://VK_OEM_PERIOD case 0xBE://VK_OEM_PERIOD
out_key = SAKI_Period;
break; break;
case 0xBA://VK_OEM_1 case 0xBA://VK_OEM_1
break; break;
@ -639,6 +694,16 @@ void Win32Keyboard::MapKey(RAWKEYBOARD& rawKB, SAKI& out_key, bool& isE0)
break; break;
} }
} }
bool Win32Keyboard::Create()
{
if(RegisterRawInputDevices(&this->device, 1, sizeof(RAWINPUTDEVICE)) == TRUE)
{
this->isActive = true;
return true;
}
return false;
}

View File

@ -1,14 +1,14 @@
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013] // Created by [Dennis Andersen] [2013]
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
#include "..\..\Include\Win32\Win32Mouse.h" #include "..\..\Include\Win32\Win32Input.h"
using namespace Input; using namespace Input;
using namespace Input::Enum; using namespace Input::Enum;
using namespace Input::Struct; using namespace Input::Struct;
using namespace Input::Typedefs; 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) if(rawMouse.lLastX != 0 || rawMouse.lLastY != 0)
{ {
@ -62,43 +62,109 @@ void MapButton(RAWMOUSE& rawMouse, bool &isUp, Enum::SAMI& btn, int& delta, Stru
} }
} }
void ContainPoint(Struct::SAIPointInt2D& pixelPos, Struct::SAIPointInt2D& windowSize)
Win32Mouse::Win32Mouse()
{ {
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); memset(&this->buttons[0], 0, sizeof(Buttons) * MAXBUTTONS);
} }
Win32Mouse::~Win32Mouse() Win32Mouse::~Win32Mouse()
{ { }
}
bool Win32Mouse::IsBtnUp(Enum::SAMI btn) bool Win32Mouse::IsBtnUp(Enum::SAMI btn) const
{ {
if(btn == SAMI_Unknown) return false; if(btn == SAMI_Unknown) return false;
return !this->buttons[btn].isDown; return !this->buttons[btn].isDown;
} }
bool Win32Mouse::IsBtnDown(Enum::SAMI btn) bool Win32Mouse::IsBtnDown(Enum::SAMI btn) const
{ {
if(btn == SAMI_Unknown) return false; if(btn == SAMI_Unknown) return false;
return this->buttons[btn].isDown; 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) void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
{ {
bool isUp = true; bool isUp = true;
Enum::SAMI btn = Enum::SAMI_Unknown; Enum::SAMI btn = Enum::SAMI_Unknown;
int delta = 0; int delta = 0;
Struct::SAIPoint2D velocity; Struct::SAIPointInt2D velocity;
unsigned int makeCode = 0; unsigned int makeCode = 0;
MapButton(mouse, isUp, btn, delta, velocity, makeCode); MapButton(mouse, isUp, btn, delta, velocity, makeCode);
if(velocity.Length() != 0) if(velocity.Length() != 0)
{ {
this->pixelPos.x += this->deltaPos.x = velocity.x; this->pixelPos.x += velocity.x;
this->pixelPos.y += this->deltaPos.y = velocity.y; this->pixelPos.y += velocity.y;
InternalOnMove(this->pixelPos);
ContainPoint(this->pixelPos, this->windowSize);
InternalOnMove(this->pixelPos, velocity);
} }
if(delta != 0) if(delta != 0)
@ -131,3 +197,32 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
} }
} }
} }
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;
}

View File

@ -78,7 +78,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
if(desc.windowSize.x <= 0) desc.windowSize.x = 50; if(desc.windowSize.x <= 0) desc.windowSize.x = 50;
if(desc.windowSize.y <= 0) desc.windowSize.y = 50; if(desc.windowSize.y <= 0) desc.windowSize.y = 50;
__windowShellData.parent = desc.parent; __windowShellData.parent = desc.parent;
__windowShellData.hIns = desc.hInstance; __windowShellData.hIns = desc.hInstance;
__windowShellData.windowClassName = WINDOW_SHELL_CLASS_NAME; __windowShellData.windowClassName = WINDOW_SHELL_CLASS_NAME;
@ -111,19 +110,13 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
RECT rectW; RECT rectW;
int width;
int height;
DWORD style = desc.windowStyle; DWORD style = desc.windowStyle;
bool windowed = false; bool windowed = false;
width = desc.windowSize.x + GetSystemMetrics(SM_CXFIXEDFRAME)*2; rectW.left = 0;
height = desc.windowSize.y + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION); rectW.top = 0;
rectW.right = desc.windowSize.x;
rectW.left=(GetSystemMetrics(SM_CXSCREEN)-width)/2; rectW.bottom = desc.windowSize.y;
rectW.top=(GetSystemMetrics(SM_CYSCREEN)-height)/2;
rectW.right=rectW.left+width;
rectW.bottom=rectW.top+height;
if(__windowShellData.parent) if(__windowShellData.parent)
{ {
@ -135,6 +128,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
windowed = true; windowed = true;
} }
AdjustWindowRect(& rectW, style, FALSE);
if(windowed) if(windowed)
{ {
__windowShellData.hWnd = CreateWindowExW( __windowShellData.hWnd = CreateWindowExW(
@ -161,8 +156,8 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
style, style,
desc.windowPosition.x, desc.windowPosition.x,
desc.windowPosition.y, desc.windowPosition.y,
desc.windowSize.x, rectW.right - rectW.left,
desc.windowSize.y, rectW.bottom - rectW.top,
0, 0,
0, 0,
__windowShellData.hIns, __windowShellData.hIns,
@ -173,7 +168,6 @@ bool WindowShell::CreateWin(WINDOW_INIT_DESC &desc)
if( !__windowShellData.hWnd ) if( !__windowShellData.hWnd )
{ {
printf("Failed to create window handle : Code ( %ul )", GetLastError()); printf("Failed to create window handle : Code ( %ul )", GetLastError());
//MessageBox(0, L"Failed to create window", L"Error!", 0);
return false; return false;
} }
@ -258,3 +252,4 @@ bool WindowShell::Frame()
return true; return true;
} }

View File

@ -40,7 +40,7 @@ public:
POINT _windowSize = cPOINT(800, 600), POINT _windowSize = cPOINT(800, 600),
POINT _windowPosition = cPOINT(0,0), POINT _windowPosition = cPOINT(0,0),
UINT _windowClassStyle = (CS_HREDRAW | CS_VREDRAW | CS_OWNDC), 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), HICON _icon = LoadIcon(0, IDI_APPLICATION),
HCURSOR _cursor = LoadCursor(NULL, IDC_ARROW), HCURSOR _cursor = LoadCursor(NULL, IDC_ARROW),
HBRUSH _background = (HBRUSH)GetStockObject(BLACK_BRUSH) HBRUSH _background = (HBRUSH)GetStockObject(BLACK_BRUSH)