Misc - EventButton changed to inheritance

This commit is contained in:
Sam Mario Svensson 2014-01-31 15:06:25 +01:00
parent 8f83dcd413
commit e76dfc73f2
4 changed files with 71 additions and 39 deletions

View File

@ -4,36 +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
{ {
template <class owner>
template <class T> class EventButton : public IEventButton
class EventButton
{ {
private: private:
enum ButtonState
{
Button_Clicked,
Button_Hover,
Button_Hold,
Button_Smashed,
};
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 );
}; };
@ -41,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();
@ -52,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;
@ -66,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;
@ -75,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;
@ -84,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;
@ -93,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

@ -167,6 +167,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

@ -134,5 +134,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>