From 9671eb8ee9ce1945c508974874bdd44dded432bf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 3 Feb 2014 10:41:54 +0100 Subject: [PATCH] Misc - Having problems with template with events. --- Code/Misc/EventHandler/EventButton.h | 29 ++++++++++++------- .../EventHandler/EventButtonCollection.cpp | 6 ++-- .../Misc/EventHandler/EventButtonCollection.h | 2 +- Code/Misc/EventHandler/IEventButton.h | 2 ++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 547cdb47..6a0a2cfb 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -13,7 +13,7 @@ namespace Oyster template class EventButton { - private: + public: struct ButtonEvent { IEventButton::ButtonState state; @@ -42,13 +42,16 @@ namespace Oyster void CheckCollision(InputClass *input); + void SendEvent(IEventButton::ButtonState state); + void SetEventFunc(void (*EventFunc)( ButtonEvent e )); //? unsigned int GetID(); - owner& GetOwner(); }; - + + template + unsigned int EventButton::PrivData::currID = 0; template EventButton::EventButton() @@ -73,7 +76,7 @@ namespace Oyster { this->privData.ID = privData.currID; this->privData.currID += 1; - this->privData.owner = NULL; + //this->privData.owner = NULL; this->privData.EventFunc = EventFunc; } @@ -96,6 +99,17 @@ namespace Oyster void EventButton::CheckCollision(InputClass *input) { //??????????????? TODO: everything + SendEvent(Button_Smashed); + } + + template + void EventButton::SendEvent(IEventButton::ButtonState state) + { + ButtonEvent event; + event.state = state; + event.sender = this; + event.owner = privData.owner; + privData.EventFunc(event); } template @@ -109,13 +123,8 @@ namespace Oyster { return this->privData.ID; } - - template - owner& EventButton::GetOwner() - { - return this->privData.owner; - } } } + #endif \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 859abc4d..a6e4ed40 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -23,16 +23,16 @@ void EventButtonCollection::Update(InputClass* inputObject) } template -void EventButtonCollection::AddButton(EventButton& button) +void EventButtonCollection::AddButton(Owner a) { - buttons.push_back(button); + //buttons.push_back(button); } template EventButton& EventButtonCollection::CreateButton() { EventButton temp; - buttons.push_back(&temp); + buttons.push_back((IEventButton)&temp); return temp; } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 9065ffc5..2a3faf35 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -30,7 +30,7 @@ namespace Oyster void Update(InputClass* inputObject); template - void AddButton(EventButton& button); + void AddButton(Owner a); template EventButton& CreateButton(); diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 4b2467c6..236ab73c 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -21,6 +21,8 @@ namespace Oyster virtual void CheckCollision(InputClass *input) = 0; + virtual void SendEvent(IEventButton::ButtonState state) = 0; + struct ButtonEvent; virtual void SetEventFunc(void (*EventFunc)( ButtonEvent e )) = 0;