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 <vector>
#include "IEventButton.h"
namespace Oyster
{
namespace Event
{
template <class T>
class EventButton
template <class owner>
class EventButton : public IEventButton
{
private:
enum ButtonState
{
Button_Clicked,
Button_Hover,
Button_Hold,
Button_Smashed,
};
struct ButtonEvent
{
ButtonState state;
EventButton &sender;
T owner;
};
struct PrivData
{
static unsigned int currID;
unsigned int ID;
T owner;
owner owner;
void (*EventFunc)( ButtonEvent e );
};
@ -41,9 +28,9 @@ namespace Oyster
public:
EventButton();
EventButton(T owner);
EventButton(owner owner);
EventButton(void (*EventFunc)( ButtonEvent e));
EventButton(void (*EventFunc)( ButtonEvent e), T owner);
EventButton(void (*EventFunc)( ButtonEvent e), owner owner);
~EventButton();
@ -52,13 +39,13 @@ namespace Oyster
void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //?
unsigned int GetID();
T& GetOwner();
owner& GetOwner();
};
template <class T>
EventButton<T>::EventButton()
template <class owner>
EventButton<owner>::EventButton()
{
this->privData.ID = privData.currID;
this->privData.currID += 1;
@ -66,8 +53,8 @@ namespace Oyster
this->privData.EventFunc = NULL;
}
template <class T>
EventButton<T>::EventButton(T owner)
template <class owner>
EventButton<owner>::EventButton(owner owner)
{
this->privData.ID = privData.currID;
this->privData.currID += 1;
@ -75,8 +62,8 @@ namespace Oyster
this->privData.EventFunc = NULL;
}
template <class T>
EventButton<T>::EventButton(void (*EventFunc)( ButtonEvent e))
template <class owner>
EventButton<owner>::EventButton(void (*EventFunc)( ButtonEvent e))
{
this->privData.ID = privData.currID;
this->privData.currID += 1;
@ -84,8 +71,8 @@ namespace Oyster
this->privData.EventFunc = EventFunc;
}
template <class T>
EventButton<T>::EventButton(void (*EventFunc)( ButtonEvent e), T owner)
template <class owner>
EventButton<owner>::EventButton(void (*EventFunc)( ButtonEvent e), owner owner)
{
this->privData.ID = privData.currID;
this->privData.currID += 1;
@ -93,32 +80,32 @@ namespace Oyster
this->privData.EventFunc = EventFunc;
}
template <class T>
EventButton<T>~EventButton()
template <class owner>
EventButton<owner>~EventButton()
{
}
template <class T>
void EventButton<T>::checkCollision(InputClass *input)
template <class owner>
void EventButton<owner>::checkCollision(InputClass *input)
{
//??????????????? TODO: everything
}
template <class T>
void EventButton<T>::SetEventFunc(void (*EventFunc)( ButtonEvent e ))
template <class owner>
void EventButton<owner>::SetEventFunc(void (*EventFunc)( ButtonEvent e ))
{
this->privData.EventFunc = EventFunc;
}
template <class T>
unsigned int EventButton<T>::GetID()
template <class owner>
unsigned int EventButton<owner>::GetID()
{
return this->privData.ID;
}
template <class T>
T& EventButton<T>::GetOwner()
template <class owner>
owner& EventButton<owner>::GetOwner()
{
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="EventHandler\EventButton.h" />
<ClInclude Include="EventHandler\EventButtonCollection.h" />
<ClInclude Include="EventHandler\IEventButton.h" />
<ClInclude Include="GID.h" />
<ClInclude Include="IQueue.h" />
<ClInclude Include="EventHandler\EventHandler.h" />

View File

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