diff --git a/abstractGuiManager.cpp b/abstractGuiManager.cpp index 4058615..f30f2c8 100644 --- a/abstractGuiManager.cpp +++ b/abstractGuiManager.cpp @@ -5,6 +5,8 @@ #include "slider.h" #include "checkbox.h" #include "listbox.h" +#include "node.h" +#include "text.h" #include "util.h" namespace vb01Gui{ @@ -120,10 +122,6 @@ namespace vb01Gui{ } } - void AbstractGuiManager::addButton(Button* b) { - buttons.push_back(b); - } - void AbstractGuiManager::addListbox(Listbox* l) { listboxes.push_back(l); buttons.push_back(l->getListboxButton()); @@ -205,6 +203,41 @@ namespace vb01Gui{ } } + void AbstractGuiManager::removeGuiRectangle(Node* r) { + for (int i = 0; i < guiRectangles.size(); i++) { + if (r == guiRectangles[i]) { + guiRectangles.erase(guiRectangles.begin() + i); + Root::getSingleton()->getGuiNode()->dettachChild(r); + delete r; + break; + } + } + } + + void AbstractGuiManager::removeText(Text* t) { + for (int i = 0; i < texts.size(); i++) { + if (t == texts[i]) { + texts.erase(texts.begin() + i); + Node *textNode = t->getNode(); + Root::getSingleton()->getGuiNode()->dettachChild(textNode); + delete textNode; + break; + } + } + } + + Text* AbstractGuiManager::getText(string name){ + Text *text = nullptr; + + for(Text *t : texts) + if(t->getNode()->getName() == name){ + text = t; + break; + } + + return text; + } + void AbstractGuiManager::removeAllButtons(vector exceptions){ int targetId = 0; @@ -275,16 +308,50 @@ namespace vb01Gui{ } } + void AbstractGuiManager::removeAllGuiRectangles(vector exceptions) { + int targetId = 0; + + while(targetId != guiRectangles.size()) { + if(find(exceptions.begin(), exceptions.end(), guiRectangles[targetId]) == exceptions.end()){ + Node *guiRect = guiRectangles[guiRectangles.size() - 1]; + guiRectangles.pop_back(); + Root::getSingleton()->getGuiNode()->dettachChild(guiRect); + delete guiRect; + } + else + targetId++; + } + } + + void AbstractGuiManager::removeAllTexts(vector exceptions) { + int targetId = 0; + + while(targetId != texts.size()) { + if(find(exceptions.begin(), exceptions.end(), texts[targetId]) == exceptions.end()){ + Node *textNode = texts[texts.size() - 1]->getNode(); + texts.pop_back(); + Root::getSingleton()->getGuiNode()->dettachChild(textNode); + delete textNode; + } + else + targetId++; + } + } + void AbstractGuiManager::removeAllGuiElements( vector buttonExceptions, vector listboxExceptions, vector checkboxExceptions, vector sliderExceptions, - vector textboxExceptions){ + vector textboxExceptions, + vector guiRectExceptions, + vector textExceptions){ removeAllButtons(buttonExceptions); removeAllListboxes(listboxExceptions); removeAllCheckboxes(checkboxExceptions); removeAllSliders(sliderExceptions); removeAllTextboxes(textboxExceptions); + removeAllGuiRectangles(guiRectExceptions); + removeAllTexts(textExceptions); } } diff --git a/abstractGuiManager.h b/abstractGuiManager.h index 089f0e4..efcf824 100644 --- a/abstractGuiManager.h +++ b/abstractGuiManager.h @@ -4,6 +4,11 @@ #include #include +namespace vb01{ + class Node; + class Text; +} + namespace vb01Gui{ class Button; class Listbox; @@ -15,45 +20,56 @@ namespace vb01Gui{ public: void update(); void findClickedButton(); - void addButton(vb01Gui::Button*); - void removeButton(vb01Gui::Button*); + void addButton(Button *b){buttons.push_back(b);} + void removeButton(Button*); void removeButton(std::string); - void addListbox(vb01Gui::Listbox*); - void removeListbox(vb01Gui::Listbox*); - void addCheckbox(vb01Gui::Checkbox*); - void removeCheckbox(vb01Gui::Checkbox*); - void addTextbox(vb01Gui::Textbox*); - void removeTextbox(vb01Gui::Textbox*); - void addSlider(vb01Gui::Slider*); - void removeSlider(vb01Gui::Slider*); - void removeAllButtons(std::vector = std::vector{}); - void removeAllListboxes(std::vector = std::vector{}); - void removeAllCheckboxes(std::vector = std::vector{}); - void removeAllSliders(std::vector = std::vector{}); - void removeAllTextboxes(std::vector = std::vector{}); + void addListbox(Listbox*); + void removeListbox(Listbox*); + void addCheckbox(Checkbox*); + void removeCheckbox(Checkbox*); + void addTextbox(Textbox*); + void removeTextbox(Textbox*); + void addSlider(Slider*); + void addGuiRectangle(vb01::Node *r){guiRectangles.push_back(r);} + void removeGuiRectangle(vb01::Node*); + void addText(vb01::Text *t){texts.push_back(t);} + void removeText(vb01::Text*); + vb01::Text* getText(std::string); + void removeSlider(Slider*); + void removeAllButtons(std::vector = std::vector{}); + void removeAllListboxes(std::vector = std::vector{}); + void removeAllCheckboxes(std::vector = std::vector{}); + void removeAllSliders(std::vector = std::vector{}); + void removeAllTextboxes(std::vector = std::vector{}); + void removeAllGuiRectangles(std::vector = std::vector{}); + void removeAllTexts(std::vector = std::vector{}); void removeAllGuiElements( std::vector = std::vector{}, std::vector = std::vector{}, std::vector = std::vector{}, std::vector = std::vector{}, - std::vector = std::vector{} + std::vector = std::vector{}, + std::vector = std::vector{}, + std::vector = std::vector{} ); inline std::vector getButtons(){return buttons;} inline std::vector getListboxes(){return listboxes;} inline std::vector getTextboxes(){return textboxes;} private: - void updateCurrentListbox(vb01Gui::Button*, bool&); - void updateCurrentSlider(vb01Gui::Button*); - void updateCurrentTextbox(vb01Gui::Button*, bool&); + void updateCurrentListbox(Button*, bool&); + void updateCurrentSlider(Button*); + void updateCurrentTextbox(Button*, bool&); std::vector buttons; std::vector listboxes; std::vector checkboxes; std::vector sliders; std::vector textboxes; - vb01Gui::Slider *currentSlider = nullptr; - vb01Gui::Textbox *currentTextbox = nullptr; - vb01Gui::Listbox *currentListbox = nullptr; + std::vector guiRectangles; + std::vector texts; + Slider *currentSlider = nullptr; + Textbox *currentTextbox = nullptr; + Listbox *currentListbox = nullptr; protected: AbstractGuiManager(){} }; diff --git a/text.h b/text.h index 0177af9..c48cc22 100755 --- a/text.h +++ b/text.h @@ -28,6 +28,7 @@ namespace vb01{ void update(); void setText(std::wstring); inline void setScale(float s){this->scale = s;} + inline float getScale(){return scale;} inline int getLength(){return entry.length();} inline std::wstring getText(){return entry;} inline bool isHorizontal(){return horizontal;}