From 7013aa745e6fb44dd54239709bc37c120e6889f1 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 17 Mar 2024 14:22:39 +0200 Subject: [PATCH 1/3] factored out method to get clicked buttons --- abstractGuiManager.cpp | 28 +++++++++++++++++++--------- abstractGuiManager.h | 3 ++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/abstractGuiManager.cpp b/abstractGuiManager.cpp index f30f2c8..d8c61cd 100644 --- a/abstractGuiManager.cpp +++ b/abstractGuiManager.cpp @@ -94,22 +94,32 @@ namespace vb01Gui{ } } - void AbstractGuiManager::findClickedButton(){ - bool textboxClicked = false, listboxClicked = false; - + vector AbstractGuiManager::findClickedButtons(){ + vector 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 clickedButtons = findClickedButtons(); + + for (Button *b : clickedButtons) + if (b->isActive()){ b->onClick(); updateCurrentListbox(b, listboxClicked); updateCurrentSlider(b); updateCurrentTextbox(b, textboxClicked); } - } if(!textboxClicked && currentTextbox){ currentTextbox->disable(); diff --git a/abstractGuiManager.h b/abstractGuiManager.h index efcf824..762721a 100644 --- a/abstractGuiManager.h +++ b/abstractGuiManager.h @@ -19,7 +19,8 @@ namespace vb01Gui{ class AbstractGuiManager{ public: void update(); - void findClickedButton(); + std::vector findClickedButtons(); + void updateGui(); void addButton(Button *b){buttons.push_back(b);} void removeButton(Button*); void removeButton(std::string); From f6280cee6ab04752a22f5ea1e85958de8310105e Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 23 Mar 2024 08:37:19 +0200 Subject: [PATCH 2/3] utility method --- abstractGuiManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/abstractGuiManager.h b/abstractGuiManager.h index 762721a..db33c59 100644 --- a/abstractGuiManager.h +++ b/abstractGuiManager.h @@ -54,6 +54,7 @@ namespace vb01Gui{ std::vector = std::vector{} ); inline std::vector getButtons(){return buttons;} + inline std::vector getGuiRectangles(){return guiRectangles;} inline std::vector getListboxes(){return listboxes;} inline std::vector getTextboxes(){return textboxes;} private: From f4191ccd860beb41ba96ca00338307639e17aa21 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Wed, 15 May 2024 19:11:43 +0300 Subject: [PATCH 3/3] utility method changes --- abstractGuiManager.h | 5 ++++- button.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/abstractGuiManager.h b/abstractGuiManager.h index db33c59..63efe19 100644 --- a/abstractGuiManager.h +++ b/abstractGuiManager.h @@ -54,9 +54,12 @@ namespace vb01Gui{ std::vector = std::vector{} ); inline std::vector getButtons(){return buttons;} - inline std::vector getGuiRectangles(){return guiRectangles;} inline std::vector getListboxes(){return listboxes;} + inline std::vector getCheckboxes(){return checkboxes;} + inline std::vector getSliders(){return sliders;} inline std::vector getTextboxes(){return textboxes;} + inline std::vector getGuiRectangles(){return guiRectangles;} + inline std::vector getTexts(){return texts;} private: void updateCurrentListbox(Button*, bool&); void updateCurrentSlider(Button*); diff --git a/button.h b/button.h index 6a99bfd..224307a 100644 --- a/button.h +++ b/button.h @@ -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(){}