2014-02-14 15:50:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef INPUT_MOUSE_H
|
|
|
|
#define INPUT_MOUSE_H
|
|
|
|
|
|
|
|
#include "InputObject.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Input
|
|
|
|
{
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace Enum
|
|
|
|
{
|
|
|
|
//! Contains keycodes (SAMI -> Sam Awsome Mouse Input)
|
|
|
|
enum SAMI
|
|
|
|
{
|
|
|
|
SAMI_MouseLeftBtn,
|
|
|
|
SAMI_MouseMiddleBtn,
|
|
|
|
SAMI_MouseRightBtn,
|
|
|
|
SAMI_MouseBtnX01,
|
|
|
|
SAMI_MouseBtnX02,
|
|
|
|
SAMI_MouseBtnX03,
|
|
|
|
SAMI_MouseBtnX04,
|
|
|
|
SAMI_MouseBtnX05,
|
|
|
|
SAMI_MouseBtnX06,
|
|
|
|
SAMI_MouseBtnX07,
|
|
|
|
SAMI_MouseBtnX08,
|
|
|
|
SAMI_MouseBtnX09,
|
|
|
|
SAMI_MouseBtnX10,
|
|
|
|
SAMI_MouseBtnX11,
|
|
|
|
SAMI_MouseBtnX12,
|
|
|
|
SAMI_MouseBtnX13,
|
|
|
|
SAMI_MouseBtnX14,
|
|
|
|
SAMI_MouseBtnX15,
|
|
|
|
SAMI_MouseBtnX16,
|
|
|
|
SAMI_MouseBtnX17,
|
|
|
|
SAMI_MouseBtnX18,
|
|
|
|
SAMI_MouseBtnX19,
|
|
|
|
SAMI_MouseBtnX20,
|
|
|
|
SAMI_Unknown,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
namespace Typedefs
|
|
|
|
{
|
|
|
|
typedef void(*OnMousePressCallback)(Enum::SAMI btn, Mouse* sender);
|
|
|
|
typedef void(*OnMouseDownCallback)(Enum::SAMI btn, Mouse* sender);
|
|
|
|
typedef void(*OnMouseReleaseCallback)(Enum::SAMI btn, Mouse* sender);
|
2014-02-21 11:43:05 +01:00
|
|
|
typedef void(*OnMouseMoveCallback)(Struct::SAIPoint2D cord, Mouse* sender);
|
2014-02-14 15:50:00 +01:00
|
|
|
typedef void(*OnMouseScrollCallback)(int delta, Mouse* sender);
|
|
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Mouse :public InputObject
|
|
|
|
{
|
|
|
|
public:
|
2014-02-21 11:43:05 +01:00
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
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 ) { }
|
2014-02-21 11:43:05 +01:00
|
|
|
virtual void OnMouseMove ( Struct::SAIPoint2D coordinate, Mouse* sender ) { }
|
2014-02-14 15:50:00 +01:00
|
|
|
virtual void OnMouseScroll ( int delta, Mouse* sender ) { }
|
|
|
|
};
|
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
public: /* Manual check functions */
|
|
|
|
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;
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
void AddOnMousePressCallback( Typedefs::OnMousePressCallback func);
|
|
|
|
void AddOnMouseDownCallback( Typedefs::OnMouseDownCallback func );
|
|
|
|
void AddOnMouseReleaseCallback( Typedefs::OnMouseReleaseCallback func );
|
|
|
|
void AddOnMouseMoveCallback( Typedefs::OnMouseMoveCallback 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 RemoveOnMouseScrollCallback( Typedefs::OnMouseScrollCallback func );
|
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
public: /* From InputObject */
|
|
|
|
virtual void Activate () override { this->active = true; }
|
|
|
|
virtual void Deactivate () override { this->active = false; }
|
|
|
|
virtual bool IsActive() override { return this->active; }
|
2014-02-14 15:50:00 +01:00
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
public:
|
2014-02-14 15:50:00 +01:00
|
|
|
void operator+= (MouseEvent* object);
|
|
|
|
void operator-= (MouseEvent* object);
|
|
|
|
|
2014-02-21 11:43:05 +01:00
|
|
|
void SetPixelPos(int x, int y);
|
|
|
|
void ToggleCursor(bool toggler);
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct MouseCallbackList;
|
|
|
|
|
2014-02-14 15:50:00 +01:00
|
|
|
protected:
|
|
|
|
Mouse();
|
|
|
|
~Mouse();
|
|
|
|
|
|
|
|
protected:
|
2014-02-21 11:43:05 +01:00
|
|
|
void InternalOnBtnPress(Enum::SAMI key);
|
|
|
|
void InternalOnBtnDown(Enum::SAMI key);
|
|
|
|
void InternalOnBtnRelease(Enum::SAMI key);
|
|
|
|
void InternalOnMove(Struct::SAIPoint2D cord);
|
|
|
|
void InternalOnScroll(int delta);
|
2014-02-14 15:50:00 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<MouseEvent*> mouseSubscribers;
|
|
|
|
MouseCallbackList* callbackList;
|
2014-02-21 11:43:05 +01:00
|
|
|
Struct::SAIPoint2D pixelPos, deltaPos;
|
2014-02-14 15:50:00 +01:00
|
|
|
bool isCurorLocked;
|
|
|
|
int wheelDelta;
|
2014-02-21 11:43:05 +01:00
|
|
|
bool active;
|
2014-02-14 15:50:00 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // !INPUT_MOUSE_H
|