From d0955b2f4ef31af65e07d82652f744a07bac6da1 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 12 Feb 2014 09:08:38 +0100 Subject: [PATCH] GL - Button delete update. --- Code/Game/DanBiasGame/DanBiasGame.vcxproj | 2 +- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 8 +- .../GameClientState/Buttons/ButtonCircle.h | 62 ---------------- .../GameClientState/Buttons/ButtonEllipse.h | 63 ++++++++++++++++ .../GameClientState/Buttons/ButtonRectangle.h | 43 +++++++---- .../GameClientState/Buttons/EventButtonGUI.h | 59 +++++++++++---- .../GameClientState/LoginState.cpp | 73 +++++++++++++++++-- Code/Misc/EventHandler/EventButton.h | 23 +++++- .../EventHandler/EventButtonCollection.cpp | 10 ++- Code/Misc/EventHandler/EventHandler.cpp | 23 ++++++ Code/Misc/EventHandler/EventHandler.h | 5 +- 11 files changed, 267 insertions(+), 104 deletions(-) delete mode 100644 Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h create mode 100644 Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 2a02099a..5049b6e7 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -215,7 +215,7 @@ - + diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 587a3df1..2a9bb5da 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -59,8 +59,8 @@ namespace DanBias { WindowShell::CreateConsoleWindow(); - //if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT()))) - if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC())) + if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1024, 768), cPOINT()))) + //if(! m_data->window->CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasClientReturn_Error; if( FAILED( InitDirect3D() ) ) @@ -132,7 +132,7 @@ namespace DanBias HRESULT DanBiasGame::InitInput() { m_data->inputObj = new InputClass; - if(!m_data->inputObj->Initialize(m_data->window->GetHINSTANCE(), m_data->window->GetHWND(), m_data->window->GetHeight(), m_data->window->GetWidth())) + if(!m_data->inputObj->Initialize(m_data->window->GetHINSTANCE(), m_data->window->GetHWND(), m_data->window->GetWidth(), m_data->window->GetHeight())) { MessageBox(0, L"Could not initialize the input object.", L"Error", MB_OK); return E_FAIL; @@ -207,6 +207,8 @@ namespace DanBias delete m_data->inputObj; delete m_data; + EventHandler::Instance().Clean(); + Oyster::Graphics::API::Clean(); GameServerAPI::ServerStop(); diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h deleted file mode 100644 index f399382d..00000000 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonCircle.h +++ /dev/null @@ -1,62 +0,0 @@ -////////////////////////////////////// -// Created by Pontus Fransson 2014 // -////////////////////////////////////// - -#ifndef DANBIAS_CLIENT_BUTTON_CIRCLE_H -#define DANBIAS_CLIENT_BUTTON_CIRCLE_H - -#include "EventButtonGUI.h" - -namespace DanBias -{ - namespace Client - { - template - class ButtonCircle : public EventButtonGUI - { - public: - ButtonCircle() - : EventButtonGUI(), radius(0) - {} - ButtonCircle(std::wstring textureName, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight) - : EventButtonGUI(textureName, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius) - {} - ButtonCircle(std::wstring textureName, EventFunc func, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight) - : EventButtonGUI(textureName, func, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius) - {} - ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight) - : EventButtonGUI(textureName, func, owner, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius) - {} - ButtonCircle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float radius, float textureHalfWidth, float textureHalfHeight) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureHalfWidth, textureHalfHeight), radius(radius) - {} - ~ButtonCircle() - {} - - //Circle vs point collision - bool Collision(InputClass* inputObject) - { - //Should come from the InputClass - float xMouse = 2, yMouse = 2; - - float xDiff = xMouse - xPos; - float yDiff = yMouse - yPos; - - float length = (xDiff * xDiff) + (yDiff * yDiff); - - if(length <= radius*radius) - { - return true; - } - - return false; - } - - protected: - float radius; - - }; - } -} - -#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h new file mode 100644 index 00000000..e74d4233 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -0,0 +1,63 @@ +////////////////////////////////////// +// Created by Pontus Fransson 2014 // +////////////////////////////////////// + +#ifndef DANBIAS_CLIENT_BUTTON_CIRCLE_H +#define DANBIAS_CLIENT_BUTTON_CIRCLE_H + +#include "EventButtonGUI.h" + +//Only for testing because we don't have any other input +#include "../WindowManager/WindowShell.h" + +namespace DanBias +{ + namespace Client + { + template + class ButtonEllipse : public EventButtonGUI + { + public: + ButtonEllipse() + : EventButtonGUI(), radius(0) + {} + ButtonEllipse(std::wstring textureName, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight) + : EventButtonGUI(textureName, owner, xPos, yPos, textureWidth, textureHeight) + {} + ButtonEllipse(std::wstring textureName, EventFunc func, float xPos, float yPos, float textureWidth, float textureHeight) + : EventButtonGUI(textureName, func, xPos, yPos, textureWidth, textureHeight) + {} + ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float textureWidth, float textureHeight) + : EventButtonGUI(textureName, func, owner, xPos, yPos, textureWidth, textureHeight) + {} + ButtonEllipse(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float textureWidth, float textureHeight) + : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, textureWidth, textureHeight) + {} + virtual ~ButtonEllipse() + {} + + //Circle vs point collision + bool Collision(InputClass* inputObject) + { + POINT p; + GetCursorPos(&p); + ScreenToClient(WindowShell::GetHWND(), &p); + RECT r; + GetClientRect(WindowShell::GetHWND(), &r); + + //Should come from the InputClass + float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + + double normx = (xMouse - xPos) / width; + double normy = (yMouse - yPos) / height; + + return (normx * normx + normy * normy) < 0.25; + } + + protected: + + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index a77f5346..1c725211 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -6,6 +6,9 @@ #define DANBIAS_CLIENT_BUTTON_RECTANGLE_H #include "EventButtonGUI.h" +#include +//Only for testing because we don't have any other input +#include "../WindowManager/WindowShell.h" namespace DanBias { @@ -16,31 +19,43 @@ namespace DanBias { public: ButtonRectangle() - : EventButtonGUI(), halfWidth(0), halfHeight(0) + : EventButtonGUI(), width(0), height(0) {} - ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButtonGUI(textureName, owner, xPos, yPos, halfWidth, halfHeight) + ButtonRectangle(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height) + : EventButtonGUI(textureName, owner, xPos, yPos, width, height) {} - ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButtonGUI(textureName, func, xPos, yPos, halfWidth, halfHeight) + ButtonRectangle(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height) + : EventButtonGUI(textureName, func, xPos, yPos, width, height) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButtonGUI(textureName, func, owner, xPos, yPos, halfWidth, halfHeight) + ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height) + : EventButtonGUI(textureName, func, owner, xPos, yPos, width, height) {} - ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, halfWidth, halfHeight) + ButtonRectangle(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height) + : EventButtonGUI(textureName, func, owner, userData, xPos, yPos, width, height) {} - ~ButtonRectangle() + virtual ~ButtonRectangle() {} //Circle vs point collision bool Collision(InputClass* inputObject) { - //Should come from the InputClass - float xMouse = 1, yMouse = 0; + POINT p; + RECT r; + GetCursorPos(&p); + ScreenToClient(WindowShell::GetHWND(), &p); + GetClientRect(WindowShell::GetHWND(), &r); - if(xMouse >= xPos - halfWidth && xMouse <= xPos + halfWidth - && yMouse >= yPos - halfHeight && yMouse <= yPos + halfHeight) + //Should come from the InputClass + float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + + float widthTemp = xPos - width * 0.5f; + float widthTemp2 = xPos + width * 0.5f; + float heightTemp = yPos - height * 0.5f; + float heightTemp2 = yPos + height * 0.5f; + //std::cout << p.x << ' ' << p.y << ' ' << widthTemp << ' ' << heightTemp << std::endl; + + if(xMouse >= widthTemp && xMouse <= widthTemp2 && + yMouse >= heightTemp && yMouse <= heightTemp2) { return true; } diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h index 9519a586..7e2de14f 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/EventButtonGUI.h @@ -6,6 +6,7 @@ #define DANBIAS_CLIENT_EVENT_BUTTON_GUI_H #include "../Misc/EventHandler/EventButton.h" +#include "../OysterGraphics/DllInterfaces/GFXAPI.h" namespace DanBias { @@ -16,49 +17,79 @@ namespace DanBias { public: EventButtonGUI() - : EventButton(), xPos(0), yPos(0), halfWidth(0), halfHeight(0), texture(NULL) + : EventButton(), xPos(0), yPos(0), width(0), height(0), texture(NULL) {} - EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButton(owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + EventButtonGUI(std::wstring textureName, Owner owner, float xPos, float yPos, float width, float height) + : EventButton(owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) { CreateTexture(textureName); } - EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButton(func), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + EventButtonGUI(std::wstring textureName, EventFunc func, float xPos, float yPos, float width, float height) + : EventButton(func), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) { CreateTexture(textureName); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButton(func, owner), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, float xPos, float yPos, float width, float height) + : EventButton(func, owner), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) { CreateTexture(textureName); } - EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float halfWidth, float halfHeight) - : EventButton(func, owner, userData), xPos(xPos), yPos(yPos), halfWidth(halfWidth), halfHeight(halfHeight) + EventButtonGUI(std::wstring textureName, EventFunc func, Owner owner, void* userData, float xPos, float yPos, float width, float height) + : EventButton(func, owner, userData), xPos(xPos), yPos(yPos), width(width), height(height), texture(NULL) { CreateTexture(textureName); } - ~EventButtonGUI() - {} + virtual ~EventButtonGUI() + { + Oyster::Graphics::API::DeleteTexture(texture); + Oyster::Graphics::API::DeleteTexture(texture2); + Oyster::Graphics::API::DeleteTexture(texture3); + texture = NULL; + texture2 = NULL; + texture3 = NULL; + } void CreateTexture(std::wstring textureName) { + std::wstring file = L".png"; + //Create texture + texture = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"none") + file); + texture2 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"highlight") + file); + texture3 = Oyster::Graphics::API::CreateTexture(textureName + std::wstring(L"down") + file); } virtual void Render() { + if(EventButton::Enabled()) { //Render att xPos and yPos - //With halfWidth and halfHeight + //With width and height + + if(EventButton::GetState() == ButtonState_None) + { + Oyster::Graphics::API::RenderGuiElement(texture, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + } + else if(EventButton::GetState() == ButtonState_Hover) + { + Oyster::Graphics::API::RenderGuiElement(texture2, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + } + else + { + Oyster::Graphics::API::RenderGuiElement(texture3, Oyster::Math::Float2(xPos, yPos), Oyster::Math::Float2(width, height)); + } + } } protected: float xPos, yPos; - float halfWidth, halfHeight; - void* texture; + float width, height; + Oyster::Graphics::API::Texture texture; + Oyster::Graphics::API::Texture texture2; + Oyster::Graphics::API::Texture texture3; + }; } diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index a2f5a197..4f148624 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -9,7 +9,7 @@ using namespace DanBias::Client; //Menu buttons -#include "Buttons/ButtonCircle.h" +#include "Buttons/ButtonEllipse.h" #include "Buttons/ButtonRectangle.h" #include "../Misc/EventHandler/EventHandler.h" using namespace Oyster::Event; @@ -27,6 +27,7 @@ struct LoginState::myData //Menu button collection EventButtonCollection* collection; + int testNumber; }privData; @@ -34,6 +35,8 @@ enum TestEnum { Create, Options, + Incr, + Decr, Exit, }; @@ -48,15 +51,46 @@ void LoginState::ButtonCallback(Oyster::Event::ButtonEvent& e) switch(type) { case Create: - if(e.state == ButtonState_Released) + /*if(e.state == ButtonState_None) + { + int a = 0; + std::cout << "None" << std::endl; + } + else if(e.state == ButtonState_Hover) + { + int a = 0; + std::cout << "Hover" << std::endl; + } + else if(e.state == ButtonState_Down) + { + int a = 0; + std::cout << "Down" << std::endl; + } + else if(e.state == ButtonState_Pressed) + { + int a = 0; + std::cout << "Pressed" << std::endl; + } + else if(e.state == ButtonState_Released) { //Change to create state or something similar - } + int a = 0; + std::cout << "Released" << std::endl; + }*/ break; case Options: break; case Exit: break; + + case Incr: + if(e.state == ButtonState_Released) + e.owner->privData->testNumber++; + break; + case Decr: + if(e.state == ButtonState_Released) + e.owner->privData->testNumber--; + break; } } @@ -68,7 +102,7 @@ LoginState::~LoginState(void) bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) { privData = new myData(); - this->nwClient = nwClient; + this->nwClient = nwClient; // load models //LoadModels(L"UImodels.txt"); InitCamera(Oyster::Math::Float3(0,0,5.4f)); @@ -76,7 +110,23 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) //Create menu buttons privData->collection = new EventButtonCollection; EventHandler::Instance().AddCollection(privData->collection); - privData->collection->AddButton(new ButtonRectangle(L"textureName.jpg", &LoginState::ButtonCallback, this, (void*)Options, 0.0f, 0.0f, 0.0f, 0.0f)); + privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.2f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.3f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.4f, 0.1f, 0.2f)); + privData->collection->AddButton(new ButtonEllipse(L"circle_", &LoginState::ButtonCallback, this, (void*)Create, 0.2f, 0.5f, 0.1f, 0.2f)); + + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.15f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.25f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.35f, 0.05f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.45f, 0.05f, 0.1f, 0.1f)); + + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Create, 0.5f, 0.5f, 0.3f, 0.3f)); + + //Incr/decr buttons + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Incr, 0.85f, 0.2f, 0.1f, 0.1f)); + privData->collection->AddButton(new ButtonRectangle(L"button_", &LoginState::ButtonCallback, this, (void*)Decr, 0.55f, 0.2f, 0.1f, 0.1f)); + + privData->testNumber = 0; return true; } @@ -146,6 +196,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } + privData->collection->SetState(EventCollectionState_Disabled); return ClientState_LobbyCreated; } // join game @@ -159,6 +210,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key // failed to connect return ClientState_Same; } + privData->collection->SetState(EventCollectionState_Disabled); return ClientState_Lobby; } return ClientState_Same; @@ -181,8 +233,16 @@ bool LoginState::Render(float dt) // render lights //Render buttons + Oyster::Graphics::API::StartGuiRender(); EventHandler::Instance().Render(); + std::wstring number; + wchar_t temp[10]; + _itow_s(privData->testNumber, temp, 10); + number = temp; + Oyster::Graphics::API::StartTextRender(); + Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7, 0.2), Oyster::Math::Float2(0.1, 0.1)); + Oyster::Graphics::API::EndFrame(); return true; } @@ -196,6 +256,9 @@ bool LoginState::Release() privData->object[i] = NULL; } + delete privData->collection; + //EventHandler::Instance().DeleteCollection(privData->collection); + delete privData; privData = NULL; return true; diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index 636552cc..6a220845 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -54,7 +54,7 @@ namespace Oyster EventButton(EventFunc func); EventButton(EventFunc func, Owner owner); EventButton(EventFunc func, Owner owner, void* userData); - ~EventButton(); + virtual ~EventButton(); void Update(InputClass *input); @@ -72,6 +72,7 @@ namespace Oyster unsigned int GetID(); //EventFunc GetFunctionPointer(); Owner GetOwner(); + ButtonState GetState(); bool operator ==(const EventButton& obj); @@ -139,7 +140,8 @@ namespace Oyster if(this->privData.enabled) { ButtonState currentState = ButtonState_None; - + static bool outside = false; + static bool clicked = false; if(Collision(input)) { if(input->IsMousePressed()) @@ -148,12 +150,19 @@ namespace Oyster switch(this->privData.previousState) { case ButtonState_None: + outside = true; currentState = ButtonState_Hover; break; case ButtonState_Hover: case ButtonState_Released: - currentState = ButtonState_Pressed; + if(outside == false) + { + clicked = true; + currentState = ButtonState_Pressed; + } + else + currentState = ButtonState_Hover; break; case ButtonState_Pressed: @@ -166,6 +175,7 @@ namespace Oyster } else { + outside = false; //Change state when the mouse button is NOT pressed switch(this->privData.previousState) { @@ -173,6 +183,7 @@ namespace Oyster case ButtonState_Hover: case ButtonState_Released: currentState = ButtonState_Hover; + clicked = false; break; case ButtonState_Pressed: @@ -256,6 +267,12 @@ namespace Oyster { return this->privData.owner; } + + template + ButtonState EventButton::GetState() + { + return this->privData.previousState; + } template bool EventButton::operator ==(const EventButton& obj) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 4096bd44..cc769b5c 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -3,7 +3,7 @@ ////////////////////////////////////// #include "EventButtonCollection.h" - +#include "EventHandler.h" #include "../../Input/L_inputClass.h" using namespace Oyster::Event; @@ -15,6 +15,14 @@ EventButtonCollection::EventButtonCollection() EventButtonCollection::~EventButtonCollection() { + for(int i = 0; i < EventHandler::Instance().collections.size(); i++) + { + if(EventHandler::Instance().collections.at(i) == this) + { + EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i); + } + } + int size = buttons.size(); for(int i = 0; i < size; i++) { diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 7c7f7722..139e0cac 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -26,6 +26,16 @@ EventHandler::~EventHandler() } } +void EventHandler::Clean() +{ + int size = collections.size(); + for(int i = 0; i < size; i++) + { + delete collections[i]; + } + collections.clear(); +} + void EventHandler::Update(InputClass* inputObject) { for(int i = 0; i < (int)collections.size(); i++) @@ -45,4 +55,17 @@ void EventHandler::Render() void EventHandler::AddCollection(EventButtonCollection* collection) { collections.push_back(collection); +} + +void EventHandler::DeleteCollection(EventButtonCollection* collection) +{ + for(int i = 0; i < collections.size(); i++) + { + if(collections.at(i) == collection) + { + delete collection; + collections.erase(collections.begin() + i); + break; + } + } } \ No newline at end of file diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index c58d628d..8459a77a 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -24,14 +24,17 @@ namespace Oyster static EventHandler& Instance(); + void Clean(); + void Update(InputClass* inputObject); void Render(); void AddCollection(EventButtonCollection* collection); + void DeleteCollection(EventButtonCollection* collection); private: std::vector collections; - + friend class EventButtonCollection; }; } }