mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
+18
-8
@@ -94,22 +94,32 @@ namespace vb01Gui{
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractGuiManager::findClickedButton(){
|
||||
bool textboxClicked = false, listboxClicked = false;
|
||||
vector<Button*> AbstractGuiManager::findClickedButtons(){
|
||||
vector<Button*> clickedButtons;
|
||||
Vector2 mousePos = getCursorPos();
|
||||
|
||||
for (int i = 0; i < buttons.size(); i++) {
|
||||
Vector2 mousePos = getCursorPos();
|
||||
Button *b = buttons[i];
|
||||
bool withinX = mousePos.x > b->getPos().x && mousePos.x < b->getPos().x + b->getSize().x;
|
||||
bool withinY = mousePos.y > b->getPos().y && mousePos.y < b->getPos().y + b->getSize().y;
|
||||
bool withinX = mousePos.x > buttons[i]->getPos().x && mousePos.x < buttons[i]->getPos().x + buttons[i]->getSize().x;
|
||||
bool withinY = mousePos.y > buttons[i]->getPos().y && mousePos.y < buttons[i]->getPos().y + buttons[i]->getSize().y;
|
||||
|
||||
if (b->isActive() && withinX && withinY){
|
||||
if (withinX && withinY)
|
||||
clickedButtons.push_back(buttons[i]);
|
||||
}
|
||||
|
||||
return clickedButtons;
|
||||
}
|
||||
|
||||
void AbstractGuiManager::updateGui(){
|
||||
bool textboxClicked = false, listboxClicked = false;
|
||||
vector<Button*> clickedButtons = findClickedButtons();
|
||||
|
||||
for (Button *b : clickedButtons)
|
||||
if (b->isActive()){
|
||||
b->onClick();
|
||||
updateCurrentListbox(b, listboxClicked);
|
||||
updateCurrentSlider(b);
|
||||
updateCurrentTextbox(b, textboxClicked);
|
||||
}
|
||||
}
|
||||
|
||||
if(!textboxClicked && currentTextbox){
|
||||
currentTextbox->disable();
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace vb01Gui{
|
||||
class AbstractGuiManager{
|
||||
public:
|
||||
void update();
|
||||
void findClickedButton();
|
||||
std::vector<Button*> findClickedButtons();
|
||||
void updateGui();
|
||||
void addButton(Button *b){buttons.push_back(b);}
|
||||
void removeButton(Button*);
|
||||
void removeButton(std::string);
|
||||
@@ -54,7 +55,11 @@ namespace vb01Gui{
|
||||
);
|
||||
inline std::vector<Button*> getButtons(){return buttons;}
|
||||
inline std::vector<Listbox*> getListboxes(){return listboxes;}
|
||||
inline std::vector<Checkbox*> getCheckboxes(){return checkboxes;}
|
||||
inline std::vector<Slider*> getSliders(){return sliders;}
|
||||
inline std::vector<Textbox*> getTextboxes(){return textboxes;}
|
||||
inline std::vector<vb01::Node*> getGuiRectangles(){return guiRectangles;}
|
||||
inline std::vector<vb01::Text*> getTexts(){return texts;}
|
||||
private:
|
||||
void updateCurrentListbox(Button*, bool&);
|
||||
void updateCurrentSlider(Button*);
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace vb01Gui{
|
||||
public:
|
||||
Button(vb01::Vector2, vb01::Vector2, std::string, std::string, int = -1, bool = true, std::string = "");
|
||||
virtual ~Button();
|
||||
void update();
|
||||
virtual void update();
|
||||
virtual void onMouseOver();
|
||||
virtual void onMouseOff();
|
||||
virtual void onClick(){}
|
||||
|
||||
Reference in New Issue
Block a user