Input - Added mouse features, custom tags and all-in-one callback
This commit is contained in:
parent
df2572a95e
commit
13167064cb
|
@ -1,36 +0,0 @@
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
// Created by [Dan Andersson] [2014]
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
#ifndef INPUT_APPLICATION_KEBOARD_H
|
|
||||||
#define INPUT_APPLICATION_KEBOARD_H
|
|
||||||
|
|
||||||
#include "InputObject.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Input
|
|
||||||
{
|
|
||||||
class ApplicationKeyboard : public InputObject
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~ApplicationKeyboard();
|
|
||||||
|
|
||||||
bool IsActive() const;
|
|
||||||
|
|
||||||
void Activate();
|
|
||||||
void Deactivate();
|
|
||||||
|
|
||||||
void BindTextTarget( ::std::wstring *field );
|
|
||||||
void ReleaseTextTarget();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
::std::wstring *textTarget;
|
|
||||||
::std::wstring::size_type writePos;
|
|
||||||
|
|
||||||
ApplicationKeyboard();
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool active;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !INPUT_KEBOARD_H
|
|
|
@ -21,22 +21,17 @@ namespace Input
|
||||||
{
|
{
|
||||||
SAIType_Keyboard,
|
SAIType_Keyboard,
|
||||||
SAIType_Mouse,
|
SAIType_Mouse,
|
||||||
//SAIType_ApplicationKeyboard,
|
|
||||||
SAIType_futureExample1,
|
SAIType_futureExample1,
|
||||||
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)
|
||||||
ButtonState_Down, // When the button is held down
|
ButtonState_Down, // When the button is held down
|
||||||
ButtonState_Release, // When button is released (once)
|
ButtonState_Release, // When button is released (once)
|
||||||
ButtonState_Up, // Default state, will not be proccesed as a callback!
|
ButtonState_Up, // Default state, will not be proccesed as a callback!
|
||||||
|
ButtonState_Unknown,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
|
@ -25,11 +25,6 @@ namespace Input
|
||||||
*/
|
*/
|
||||||
static InputManager* CreateInputManager ();
|
static InputManager* CreateInputManager ();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Destroy default input manager.
|
|
||||||
*/
|
|
||||||
static void DestroyInputManager ();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Destroys a input manager.
|
* @return Destroys a input manager.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -199,7 +199,6 @@ 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;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,30 @@ namespace Input
|
||||||
SAMI_MouseBtnX18,
|
SAMI_MouseBtnX18,
|
||||||
SAMI_MouseBtnX19,
|
SAMI_MouseBtnX19,
|
||||||
SAMI_MouseBtnX20,
|
SAMI_MouseBtnX20,
|
||||||
|
SAMI_MouseMove,
|
||||||
|
SAMI_MouseScroll,
|
||||||
SAMI_Unknown,
|
SAMI_Unknown,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
namespace Struct
|
||||||
|
{
|
||||||
|
struct MouseEventData
|
||||||
|
{
|
||||||
|
Enum::SAMI type;
|
||||||
|
Enum::ButtonState buttonState;
|
||||||
|
Struct::SAIPointInt2D pixelPos;
|
||||||
|
Struct::SAIPointFloat2D normalizedPos;
|
||||||
|
Struct::SAIPointInt2D velocity;
|
||||||
|
Mouse* sender;
|
||||||
|
int scrollDelta;
|
||||||
|
void* tag;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------------------
|
||||||
namespace Typedefs
|
namespace Typedefs
|
||||||
{
|
{
|
||||||
|
typedef void(*OnMouseCallback)( const Struct::MouseEventData& eventData );
|
||||||
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);
|
||||||
|
@ -60,6 +78,7 @@ namespace Input
|
||||||
class MouseEvent
|
class MouseEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual void OnMouse ( const Struct::MouseEventData& eventData ) { }
|
||||||
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 ) { }
|
||||||
|
@ -82,13 +101,21 @@ namespace Input
|
||||||
virtual bool IsActive() override = 0;
|
virtual bool IsActive() override = 0;
|
||||||
|
|
||||||
public: /* global subscribe callback functions */
|
public: /* global subscribe callback functions */
|
||||||
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
|
void AddMouseEvent(MouseEvent* object);
|
||||||
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
|
void RemoveMouseEvent(MouseEvent* object);
|
||||||
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
|
void operator+= (MouseEvent* object);
|
||||||
void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func );
|
void operator-= (MouseEvent* object);
|
||||||
void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
|
|
||||||
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
|
||||||
|
|
||||||
|
public: /* global subscribe callback functions */
|
||||||
|
void AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag);
|
||||||
|
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag);
|
||||||
|
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag );
|
||||||
|
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag );
|
||||||
|
void AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag );
|
||||||
|
void AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag );
|
||||||
|
void AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag );
|
||||||
|
|
||||||
|
void RemoveOnMouseCallback( Typedefs::OnMouseCallback 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 );
|
||||||
|
@ -96,10 +123,6 @@ namespace Input
|
||||||
void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
|
void RemoveOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func );
|
||||||
void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
void RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
||||||
|
|
||||||
public:
|
|
||||||
void operator+= (MouseEvent* object);
|
|
||||||
void operator-= (MouseEvent* object);
|
|
||||||
|
|
||||||
void SetPixelPos(int x, int y);
|
void SetPixelPos(int x, int y);
|
||||||
void ToggleCursor(bool toggler);
|
void ToggleCursor(bool toggler);
|
||||||
|
|
||||||
|
@ -111,6 +134,7 @@ namespace Input
|
||||||
virtual ~Mouse();
|
virtual ~Mouse();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void InternalOnEvent(Struct::MouseEventData & data);
|
||||||
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);
|
||||||
|
@ -127,7 +151,6 @@ namespace Input
|
||||||
|
|
||||||
bool isCurorLocked;
|
bool isCurorLocked;
|
||||||
int wheelDelta;
|
int wheelDelta;
|
||||||
Enum::InputOptionType inputMode;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
// Created by [Dan Andersson] [2014]
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
|
||||||
#ifndef INPUT_WIN32_APPLICATION_KEBOARD_H
|
|
||||||
#define INPUT_WIN32_APPLICATION_KEBOARD_H
|
|
||||||
|
|
||||||
#define NOMINMAX
|
|
||||||
#include <Windows.h>
|
|
||||||
#include "..\ApplicationKeyboard.h"
|
|
||||||
|
|
||||||
namespace Input
|
|
||||||
{
|
|
||||||
class Win32ApplicationKeyboard : public ApplicationKeyboard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Win32ApplicationKeyboard();
|
|
||||||
~Win32ApplicationKeyboard();
|
|
||||||
|
|
||||||
void CaptureText( UINT msg, WPARAM param );
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !INPUT_WIN32_APPLICATION_KEBOARD_H
|
|
|
@ -1,44 +0,0 @@
|
||||||
#include "../Include/ApplicationKeyboard.h"
|
|
||||||
|
|
||||||
using namespace ::Input;
|
|
||||||
|
|
||||||
ApplicationKeyboard::ApplicationKeyboard() :
|
|
||||||
InputObject( Enum::SAIType_ApplicationKeyboard )
|
|
||||||
{
|
|
||||||
this->textTarget = nullptr;
|
|
||||||
this->writePos = 0;
|
|
||||||
this->isEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplicationKeyboard::~ApplicationKeyboard()
|
|
||||||
{ /* DO nothing */ }
|
|
||||||
|
|
||||||
bool ApplicationKeyboard::IsActive() const
|
|
||||||
{
|
|
||||||
return this->isEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationKeyboard::Activate()
|
|
||||||
{
|
|
||||||
this->isEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationKeyboard::Deactivate()
|
|
||||||
{
|
|
||||||
this->isEnabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationKeyboard::BindTextTarget( ::std::wstring *field )
|
|
||||||
{
|
|
||||||
this->textTarget = field;
|
|
||||||
|
|
||||||
if( field )
|
|
||||||
{
|
|
||||||
this->writePos = field->size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationKeyboard::ReleaseTextTarget( )
|
|
||||||
{
|
|
||||||
this->BindTextTarget( nullptr );
|
|
||||||
}
|
|
|
@ -57,11 +57,6 @@ InputManager* InputManager::CreateInputManager()
|
||||||
{
|
{
|
||||||
return CreateManager();
|
return CreateManager();
|
||||||
}
|
}
|
||||||
void InputManager::DestroyInputManager()
|
|
||||||
{
|
|
||||||
delete defaultInstance;
|
|
||||||
defaultInstance = 0;
|
|
||||||
}
|
|
||||||
void InputManager::DestroyInputManager(InputManager* inputSystem)
|
void InputManager::DestroyInputManager(InputManager* inputSystem)
|
||||||
{
|
{
|
||||||
if(!inputSystem) return;
|
if(!inputSystem) return;
|
||||||
|
@ -82,4 +77,3 @@ InputManager::~InputManager()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -226,10 +226,6 @@ void Keyboard::BindTextTarget( ::std::wstring *field )
|
||||||
{
|
{
|
||||||
this->writePos = field->size();
|
this->writePos = field->size();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
this->writePos = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void Keyboard::ReleaseTextTarget( )
|
void Keyboard::ReleaseTextTarget( )
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct Mouse::MouseCallbackList
|
||||||
{
|
{
|
||||||
enum CallbackDataType
|
enum CallbackDataType
|
||||||
{
|
{
|
||||||
|
CallbackDataType_OnEvent,
|
||||||
CallbackDataType_OnPress,
|
CallbackDataType_OnPress,
|
||||||
CallbackDataType_OnDown,
|
CallbackDataType_OnDown,
|
||||||
CallbackDataType_OnRelease,
|
CallbackDataType_OnRelease,
|
||||||
|
@ -22,6 +23,7 @@ struct Mouse::MouseCallbackList
|
||||||
} type;
|
} type;
|
||||||
union CallbackData
|
union CallbackData
|
||||||
{
|
{
|
||||||
|
Typedefs::OnMouseCallback mouseCallback;
|
||||||
Typedefs::OnMousePressCallback mousePressCallback;
|
Typedefs::OnMousePressCallback mousePressCallback;
|
||||||
Typedefs::OnMouseDownCallback mouseDownCallback;
|
Typedefs::OnMouseDownCallback mouseDownCallback;
|
||||||
Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
|
Typedefs::OnMouseReleaseCallback mouseReleaseCallback;
|
||||||
|
@ -37,7 +39,8 @@ struct Mouse::MouseCallbackList
|
||||||
operator bool(){ return this->dummy != 0; }
|
operator bool(){ return this->dummy != 0; }
|
||||||
} function;
|
} function;
|
||||||
MouseCallbackList *next;
|
MouseCallbackList *next;
|
||||||
MouseCallbackList(CallbackData func, CallbackDataType t) :function(func), next(0), type(t) { }
|
void* tag;
|
||||||
|
MouseCallbackList(CallbackData func, CallbackDataType t, void* ct) :function(func), next(0), type(t), tag(ct) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
void ClearList(Mouse::MouseCallbackList* first)
|
void ClearList(Mouse::MouseCallbackList* first)
|
||||||
|
@ -52,7 +55,7 @@ void ClearList(Mouse::MouseCallbackList* first)
|
||||||
delete removee;
|
delete removee;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type)
|
void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data, Mouse::MouseCallbackList::CallbackDataType type, void* tag)
|
||||||
{
|
{
|
||||||
Mouse::MouseCallbackList *w = first;
|
Mouse::MouseCallbackList *w = first;
|
||||||
Mouse::MouseCallbackList *prev = first;
|
Mouse::MouseCallbackList *prev = first;
|
||||||
|
@ -62,7 +65,7 @@ void AddToList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::Callba
|
||||||
Mouse::MouseCallbackList::CallbackData f;
|
Mouse::MouseCallbackList::CallbackData f;
|
||||||
f = data;
|
f = data;
|
||||||
|
|
||||||
prev->next = new Mouse::MouseCallbackList(f, type);
|
prev->next = new Mouse::MouseCallbackList(f, type, tag);
|
||||||
}
|
}
|
||||||
void RemoveFromList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data)
|
void RemoveFromList(Mouse::MouseCallbackList* first, Mouse::MouseCallbackList::CallbackData data)
|
||||||
{
|
{
|
||||||
|
@ -119,6 +122,25 @@ Mouse::~Mouse()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mouse::InternalOnEvent(MouseEventData & data)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
|
||||||
|
{
|
||||||
|
if(this->mouseSubscribers[i])
|
||||||
|
this->mouseSubscribers[i]->OnMouse(data);
|
||||||
|
}
|
||||||
|
MouseCallbackList *w = this->callbackList;
|
||||||
|
while (w)
|
||||||
|
{
|
||||||
|
if(w->function)
|
||||||
|
if (w->type == MouseCallbackList::CallbackDataType_OnEvent)
|
||||||
|
{
|
||||||
|
data.tag = w->tag;
|
||||||
|
w->function.mouseCallback(data);
|
||||||
|
}
|
||||||
|
w = w->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
void Mouse::InternalOnBtnPress(Enum::SAMI btn)
|
void Mouse::InternalOnBtnPress(Enum::SAMI btn)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
|
for (unsigned int i = 0; i < this->mouseSubscribers.size(); i++)
|
||||||
|
@ -205,49 +227,85 @@ void Mouse::InternalOnScroll(int delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mouse::AddMouseEvent(MouseEvent* object)
|
||||||
|
{
|
||||||
|
if(ExistsInList(this->mouseSubscribers, object)) return;
|
||||||
|
|
||||||
|
this->mouseSubscribers.push_back(object);
|
||||||
|
}
|
||||||
|
void Mouse::RemoveMouseEvent(MouseEvent* object)
|
||||||
|
{
|
||||||
|
int i = -1;
|
||||||
|
if((i = ExistsInList(this->mouseSubscribers, object)))
|
||||||
|
{
|
||||||
|
std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]);
|
||||||
|
this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Mouse::operator+= (MouseEvent* object)
|
||||||
|
{
|
||||||
|
if(ExistsInList(this->mouseSubscribers, object)) return;
|
||||||
|
|
||||||
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func)
|
this->mouseSubscribers.push_back(object);
|
||||||
|
}
|
||||||
|
void Mouse::operator-= (MouseEvent* object)
|
||||||
|
{
|
||||||
|
int i = -1;
|
||||||
|
if((i = ExistsInList(this->mouseSubscribers, object)))
|
||||||
|
{
|
||||||
|
std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]);
|
||||||
|
this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mouse::AddOnMouseCallback( Typedefs::OnMouseCallback func, void* tag)
|
||||||
|
{
|
||||||
|
MouseCallbackList::CallbackData d;
|
||||||
|
d.mouseCallback = func;
|
||||||
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnEvent, tag);
|
||||||
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnEvent, tag);
|
||||||
|
}
|
||||||
|
void Mouse::AddOnMousePressCallback( Typedefs::OnMousePressCallback func, void* tag)
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mousePressCallback = func;
|
d.mousePressCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnPress, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnPress, tag);
|
||||||
}
|
}
|
||||||
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func )
|
void Mouse::AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func, void* tag )
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mouseDownCallback = func;
|
d.mouseDownCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnDown, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnDown, tag);
|
||||||
}
|
}
|
||||||
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func )
|
void Mouse::AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func, void* tag )
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mouseReleaseCallback = func;
|
d.mouseReleaseCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnRelease, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnRelease, tag);
|
||||||
}
|
}
|
||||||
void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func )
|
void Mouse::AddOnMouseMovePixelPosCallback( Typedefs::OnMouseMovePixelPosCallback func, void* tag )
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mouseMovePixelPosCallback = func;
|
d.mouseMovePixelPosCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMovePixelPos, tag);
|
||||||
}
|
}
|
||||||
void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func )
|
void Mouse::AddOnMouseMoveVelocityCallback( Typedefs::OnMouseMoveVelocityCallback func, void* tag )
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mouseMoveVelocityCallback = func;
|
d.mouseMoveVelocityCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnMoveVelocity, tag);
|
||||||
}
|
}
|
||||||
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func )
|
void Mouse::AddOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func, void* tag )
|
||||||
{
|
{
|
||||||
MouseCallbackList::CallbackData d;
|
MouseCallbackList::CallbackData d;
|
||||||
d.mouseScrollCallback = func;
|
d.mouseScrollCallback = func;
|
||||||
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll);
|
if(!this->callbackList) this->callbackList = new MouseCallbackList(d, MouseCallbackList::CallbackDataType_OnScroll, tag);
|
||||||
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll);
|
else AddToList(this->callbackList, d, MouseCallbackList::CallbackDataType_OnScroll, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
|
void Mouse::RemoveOnMousePressCallback( Typedefs::OnMousePressCallback func)
|
||||||
|
@ -285,21 +343,6 @@ void Mouse::ToggleCursor(bool toggler)
|
||||||
this->isCurorLocked = toggler;
|
this->isCurorLocked = toggler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::operator+= (MouseEvent* object)
|
|
||||||
{
|
|
||||||
if(ExistsInList(this->mouseSubscribers, object)) return;
|
|
||||||
|
|
||||||
this->mouseSubscribers.push_back(object);
|
|
||||||
}
|
|
||||||
void Mouse::operator-= (MouseEvent* object)
|
|
||||||
{
|
|
||||||
int i = -1;
|
|
||||||
if((i = ExistsInList(this->mouseSubscribers, object)))
|
|
||||||
{
|
|
||||||
std::swap(this->mouseSubscribers[i], this->mouseSubscribers[this->mouseSubscribers.size() - 1]);
|
|
||||||
this->mouseSubscribers.resize(this->mouseSubscribers.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#include "../../Include/Win32/Win32ApplicationKeyboard.h"
|
|
||||||
#include "Utilities.h"
|
|
||||||
|
|
||||||
using namespace ::Input;
|
|
||||||
using namespace ::Utility::Value;
|
|
||||||
using ::std::wstring;
|
|
||||||
|
|
||||||
Win32ApplicationKeyboard::Win32ApplicationKeyboard() : ApplicationKeyboard() { /* DO nothing */ }
|
|
||||||
|
|
||||||
Win32ApplicationKeyboard::~Win32ApplicationKeyboard() { /* DO nothing */ }
|
|
||||||
|
|
||||||
void Win32ApplicationKeyboard::CaptureText( UINT msg, WPARAM param )
|
|
||||||
{
|
|
||||||
if( !this->textTarget | !this->isEnabled )
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch( msg )
|
|
||||||
{
|
|
||||||
case WM_CHAR:
|
|
||||||
this->textTarget->insert( this->writePos, 1, (wchar_t)param );
|
|
||||||
++this->writePos;
|
|
||||||
break;
|
|
||||||
case WM_KEYDOWN:
|
|
||||||
{
|
|
||||||
switch( param )
|
|
||||||
{
|
|
||||||
case VK_BACK:
|
|
||||||
if( this->writePos > 0 )
|
|
||||||
{
|
|
||||||
--this->writePos;
|
|
||||||
this->textTarget->erase( this->writePos, 1 );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_DELETE:
|
|
||||||
if( this->writePos < this->textTarget->size() )
|
|
||||||
{
|
|
||||||
this->textTarget->erase( this->writePos, 1 );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case VK_LEFT:
|
|
||||||
this->writePos = Max( this->writePos - 1, (wstring::size_type)0 );
|
|
||||||
break;
|
|
||||||
case VK_RIGHT:
|
|
||||||
this->writePos = Min( this->writePos + 1, this->textTarget->size() );
|
|
||||||
break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -150,7 +150,7 @@ Win32Input::Win32Input()
|
||||||
{ /*wrong*/ }
|
{ /*wrong*/ }
|
||||||
}
|
}
|
||||||
Win32Input::~Win32Input()
|
Win32Input::~Win32Input()
|
||||||
{ Destroy(); }
|
{}
|
||||||
InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication)
|
InputObject* Win32Input::CreateDevice(const SAIType inputType, Typedefs::WindowHandle targetApplication)
|
||||||
{
|
{
|
||||||
if(!this->instance->targetHwin)
|
if(!this->instance->targetHwin)
|
||||||
|
@ -225,7 +225,9 @@ void Win32Input::ToggleInputSystem(bool enable)
|
||||||
void Win32Input::Destroy ()
|
void Win32Input::Destroy ()
|
||||||
{
|
{
|
||||||
ShowCursor(true);
|
ShowCursor(true);
|
||||||
ClipCursor(0);
|
RECT r;
|
||||||
|
GetWindowRect(GetDesktopWindow(), &r);
|
||||||
|
ClipCursor(&r);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < this->keyboard.size(); i++)
|
for (unsigned int i = 0; i < this->keyboard.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -152,6 +152,10 @@ void Win32Mouse::Deactivate ()
|
||||||
|
|
||||||
void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
||||||
{
|
{
|
||||||
|
static MouseEventData mouseEventData;
|
||||||
|
memset(&mouseEventData, 0, sizeof(MouseEventData));
|
||||||
|
|
||||||
|
|
||||||
bool isUp = true;
|
bool isUp = true;
|
||||||
Enum::SAMI btn = Enum::SAMI_Unknown;
|
Enum::SAMI btn = Enum::SAMI_Unknown;
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
|
@ -167,11 +171,30 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
||||||
ContainPoint(this->pixelPos, this->windowSize);
|
ContainPoint(this->pixelPos, this->windowSize);
|
||||||
|
|
||||||
InternalOnMove(this->pixelPos, velocity);
|
InternalOnMove(this->pixelPos, velocity);
|
||||||
|
|
||||||
|
GetNormalizedPosition( mouseEventData.normalizedPos );
|
||||||
|
mouseEventData.pixelPos = this->pixelPos;
|
||||||
|
mouseEventData.velocity = velocity;
|
||||||
|
mouseEventData.buttonState = Enum::ButtonState_Unknown;
|
||||||
|
mouseEventData.scrollDelta = 0;
|
||||||
|
mouseEventData.sender = this;
|
||||||
|
mouseEventData.type = SAMI::SAMI_MouseMove;
|
||||||
|
|
||||||
|
InternalOnEvent(mouseEventData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(delta != 0)
|
if(delta != 0)
|
||||||
{
|
{
|
||||||
InternalOnScroll(delta);
|
InternalOnScroll(delta);
|
||||||
|
|
||||||
|
GetNormalizedPosition( mouseEventData.normalizedPos );
|
||||||
|
mouseEventData.pixelPos = this->pixelPos;
|
||||||
|
mouseEventData.buttonState = Enum::ButtonState_Unknown;
|
||||||
|
mouseEventData.scrollDelta = delta;
|
||||||
|
mouseEventData.sender = this;
|
||||||
|
mouseEventData.type = SAMI::SAMI_MouseScroll;
|
||||||
|
|
||||||
|
InternalOnEvent(mouseEventData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,6 +207,14 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
||||||
if(isUp)
|
if(isUp)
|
||||||
{
|
{
|
||||||
InternalOnBtnRelease(btn);
|
InternalOnBtnRelease(btn);
|
||||||
|
|
||||||
|
GetNormalizedPosition( mouseEventData.normalizedPos );
|
||||||
|
mouseEventData.pixelPos = this->pixelPos;
|
||||||
|
mouseEventData.buttonState = Enum::ButtonState_Release;
|
||||||
|
mouseEventData.type = btn;
|
||||||
|
mouseEventData.sender = this;
|
||||||
|
|
||||||
|
InternalOnEvent(mouseEventData);
|
||||||
}
|
}
|
||||||
//The btn is pressed.
|
//The btn is pressed.
|
||||||
else
|
else
|
||||||
|
@ -192,10 +223,26 @@ void Win32Mouse::ProccessMouseData (RAWMOUSE mouse)
|
||||||
if(this->buttons[btn].isDown)
|
if(this->buttons[btn].isDown)
|
||||||
{
|
{
|
||||||
InternalOnBtnDown(btn);
|
InternalOnBtnDown(btn);
|
||||||
|
|
||||||
|
GetNormalizedPosition( mouseEventData.normalizedPos );
|
||||||
|
mouseEventData.pixelPos = this->pixelPos;
|
||||||
|
mouseEventData.buttonState = Enum::ButtonState_Down;
|
||||||
|
mouseEventData.type = btn;
|
||||||
|
mouseEventData.sender = this;
|
||||||
|
|
||||||
|
InternalOnEvent(mouseEventData);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InternalOnBtnPress(btn);
|
InternalOnBtnPress(btn);
|
||||||
|
|
||||||
|
GetNormalizedPosition( mouseEventData.normalizedPos );
|
||||||
|
mouseEventData.pixelPos = this->pixelPos;
|
||||||
|
mouseEventData.buttonState = Enum::ButtonState_Press;
|
||||||
|
mouseEventData.type = btn;
|
||||||
|
mouseEventData.sender = this;
|
||||||
|
|
||||||
|
InternalOnEvent(mouseEventData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue