Merge pull request #24 from devZoGok/imp-23-new-gui

Imp 23 new gui
This commit is contained in:
devZoGok
2023-12-30 12:44:12 +00:00
committed by GitHub
3 changed files with 111 additions and 27 deletions
+72 -5
View File
@@ -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<Button*> exceptions){
int targetId = 0;
@@ -275,16 +308,50 @@ namespace vb01Gui{
}
}
void AbstractGuiManager::removeAllGuiRectangles(vector<Node*> 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<Text*> 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<Button*> buttonExceptions,
vector<Listbox*> listboxExceptions,
vector<Checkbox*> checkboxExceptions,
vector<Slider*> sliderExceptions,
vector<Textbox*> textboxExceptions){
vector<Textbox*> textboxExceptions,
vector<Node*> guiRectExceptions,
vector<Text*> textExceptions){
removeAllButtons(buttonExceptions);
removeAllListboxes(listboxExceptions);
removeAllCheckboxes(checkboxExceptions);
removeAllSliders(sliderExceptions);
removeAllTextboxes(textboxExceptions);
removeAllGuiRectangles(guiRectExceptions);
removeAllTexts(textExceptions);
}
}
+38 -22
View File
@@ -4,6 +4,11 @@
#include <vector>
#include <string>
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<vb01Gui::Button*> = std::vector<vb01Gui::Button*>{});
void removeAllListboxes(std::vector<vb01Gui::Listbox*> = std::vector<vb01Gui::Listbox*>{});
void removeAllCheckboxes(std::vector<vb01Gui::Checkbox*> = std::vector<vb01Gui::Checkbox*>{});
void removeAllSliders(std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{});
void removeAllTextboxes(std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{});
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<Button*> = std::vector<Button*>{});
void removeAllListboxes(std::vector<Listbox*> = std::vector<Listbox*>{});
void removeAllCheckboxes(std::vector<Checkbox*> = std::vector<Checkbox*>{});
void removeAllSliders(std::vector<Slider*> = std::vector<Slider*>{});
void removeAllTextboxes(std::vector<Textbox*> = std::vector<Textbox*>{});
void removeAllGuiRectangles(std::vector<vb01::Node*> = std::vector<vb01::Node*>{});
void removeAllTexts(std::vector<vb01::Text*> = std::vector<vb01::Text*>{});
void removeAllGuiElements(
std::vector<Button*> = std::vector<Button*>{},
std::vector<Listbox*> = std::vector<Listbox*>{},
std::vector<Checkbox*> = std::vector<Checkbox*>{},
std::vector<Slider*> = std::vector<Slider*>{},
std::vector<Textbox*> = std::vector<Textbox*>{}
std::vector<Textbox*> = std::vector<Textbox*>{},
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
);
inline std::vector<Button*> getButtons(){return buttons;}
inline std::vector<Listbox*> getListboxes(){return listboxes;}
inline std::vector<Textbox*> 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<Button*> buttons;
std::vector<Listbox*> listboxes;
std::vector<Checkbox*> checkboxes;
std::vector<Slider*> sliders;
std::vector<Textbox*> textboxes;
vb01Gui::Slider *currentSlider = nullptr;
vb01Gui::Textbox *currentTextbox = nullptr;
vb01Gui::Listbox *currentListbox = nullptr;
std::vector<vb01::Node*> guiRectangles;
std::vector<vb01::Text*> texts;
Slider *currentSlider = nullptr;
Textbox *currentTextbox = nullptr;
Listbox *currentListbox = nullptr;
protected:
AbstractGuiManager(){}
};
+1
View File
@@ -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;}