Merge branch 'GameLogic-MessageHandler' of https://github.com/dean11/Danbias into GameLogic-MessageHandler

Conflicts:
	Code/Misc/EventHandler/EventButton.h
This commit is contained in:
Pontus Fransson 2014-01-31 15:07:55 +01:00
commit e7d592e71a
4 changed files with 71 additions and 42 deletions

View File

@ -4,39 +4,23 @@
#include "../../Input/L_inputClass.h" #include "../../Input/L_inputClass.h"
#include <vector> #include <vector>
#include "IEventButton.h"
namespace Oyster namespace Oyster
{ {
namespace Event namespace Event
{ {
struct IButton
{ template <class owner>
enum ButtonState class EventButton : public IEventButton
{
Button_Clicked,
Button_Hover,
Button_Hold,
Button_Smashed,
};
};
template <class T>
class EventButton :public IButton
{ {
private: private:
struct ButtonEvent
{
ButtonState state;
EventButton &sender;
T owner;
};
struct PrivData struct PrivData
{ {
static unsigned int currID; static unsigned int currID;
unsigned int ID; unsigned int ID;
T owner; owner owner;
void (*EventFunc)( ButtonEvent e ); void (*EventFunc)( ButtonEvent e );
}; };
@ -44,9 +28,9 @@ namespace Oyster
public: public:
EventButton(); EventButton();
EventButton(T owner); EventButton(owner owner);
EventButton(void (*EventFunc)( ButtonEvent e)); EventButton(void (*EventFunc)( ButtonEvent e));
EventButton(void (*EventFunc)( ButtonEvent e), T owner); EventButton(void (*EventFunc)( ButtonEvent e), owner owner);
~EventButton(); ~EventButton();
@ -55,13 +39,13 @@ namespace Oyster
void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //?
unsigned int GetID(); unsigned int GetID();
T& GetOwner(); owner& GetOwner();
}; };
template <class T> template <class owner>
EventButton<T>::EventButton() EventButton<owner>::EventButton()
{ {
this->privData.ID = privData.currID; this->privData.ID = privData.currID;
this->privData.currID += 1; this->privData.currID += 1;
@ -69,8 +53,8 @@ namespace Oyster
this->privData.EventFunc = NULL; this->privData.EventFunc = NULL;
} }
template <class T> template <class owner>
EventButton<T>::EventButton(T owner) EventButton<owner>::EventButton(owner owner)
{ {
this->privData.ID = privData.currID; this->privData.ID = privData.currID;
this->privData.currID += 1; this->privData.currID += 1;
@ -78,8 +62,8 @@ namespace Oyster
this->privData.EventFunc = NULL; this->privData.EventFunc = NULL;
} }
template <class T> template <class owner>
EventButton<T>::EventButton(void (*EventFunc)( ButtonEvent e)) EventButton<owner>::EventButton(void (*EventFunc)( ButtonEvent e))
{ {
this->privData.ID = privData.currID; this->privData.ID = privData.currID;
this->privData.currID += 1; this->privData.currID += 1;
@ -87,8 +71,8 @@ namespace Oyster
this->privData.EventFunc = EventFunc; this->privData.EventFunc = EventFunc;
} }
template <class T> template <class owner>
EventButton<T>::EventButton(void (*EventFunc)( ButtonEvent e), T owner) EventButton<owner>::EventButton(void (*EventFunc)( ButtonEvent e), owner owner)
{ {
this->privData.ID = privData.currID; this->privData.ID = privData.currID;
this->privData.currID += 1; this->privData.currID += 1;
@ -96,32 +80,32 @@ namespace Oyster
this->privData.EventFunc = EventFunc; this->privData.EventFunc = EventFunc;
} }
template <class T> template <class owner>
EventButton<T>~EventButton() EventButton<owner>~EventButton()
{ {
} }
template <class T> template <class owner>
void EventButton<T>::checkCollision(InputClass *input) void EventButton<owner>::checkCollision(InputClass *input)
{ {
//??????????????? TODO: everything //??????????????? TODO: everything
} }
template <class T> template <class owner>
void EventButton<T>::SetEventFunc(void (*EventFunc)( ButtonEvent e )) void EventButton<owner>::SetEventFunc(void (*EventFunc)( ButtonEvent e ))
{ {
this->privData.EventFunc = EventFunc; this->privData.EventFunc = EventFunc;
} }
template <class T> template <class owner>
unsigned int EventButton<T>::GetID() unsigned int EventButton<owner>::GetID()
{ {
return this->privData.ID; return this->privData.ID;
} }
template <class T> template <class owner>
T& EventButton<T>::GetOwner() owner& EventButton<owner>::GetOwner()
{ {
return this->privData.owner; return this->privData.owner;
} }

View File

@ -0,0 +1,41 @@
#include "../../Input/L_inputClass.h"
namespace Oyster
{
namespace Event
{
class IEventButton
{
private:
enum ButtonState
{
Button_Clicked,
Button_Hover,
Button_Hold,
Button_Smashed,
};
struct ButtonEvent
{
ButtonState state;
IEventButton &sender;
template<class owner>
owner owner;
};
public:
virtual void checkCollision(InputClass *input) = 0;
virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0;
virtual unsigned int GetID() = 0;
template<class owner>
virtual owner& GetOwner() = 0;
};
}
}

View File

@ -166,6 +166,7 @@
<ClInclude Include="DynamicArray.h" /> <ClInclude Include="DynamicArray.h" />
<ClInclude Include="EventHandler\EventButton.h" /> <ClInclude Include="EventHandler\EventButton.h" />
<ClInclude Include="EventHandler\EventButtonCollection.h" /> <ClInclude Include="EventHandler\EventButtonCollection.h" />
<ClInclude Include="EventHandler\IEventButton.h" />
<ClInclude Include="GID.h" /> <ClInclude Include="GID.h" />
<ClInclude Include="IQueue.h" /> <ClInclude Include="IQueue.h" />
<ClInclude Include="EventHandler\EventHandler.h" /> <ClInclude Include="EventHandler\EventHandler.h" />

View File

@ -131,5 +131,8 @@
<ClInclude Include="EventHandler\EventButtonCollection.h"> <ClInclude Include="EventHandler\EventButtonCollection.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="EventHandler\IEventButton.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>