From 2db871522da84b63bc8027bd864d4cc902bbbd90 Mon Sep 17 00:00:00 2001 From: Maschell Date: Tue, 31 Oct 2017 17:18:42 +0100 Subject: [PATCH] Some small tweaks --- source/gui/Gui.h | 1 + source/gui/GuiCheckBox.cpp | 5 ++--- source/gui/GuiCheckBox.h | 2 +- source/gui/GuiScrollbar.cpp | 36 +++++++++++++++++----------------- source/gui/GuiScrollbar.h | 6 +++--- source/gui/GuiSelectBox.cpp | 25 ++++++++++++++++++----- source/gui/GuiSelectBox.h | 17 +++++++--------- source/gui/GuiSwitch.cpp | 9 +++------ source/gui/GuiSwitch.h | 11 +++++------ source/resources/Resources.cpp | 2 -- 10 files changed, 60 insertions(+), 54 deletions(-) diff --git a/source/gui/Gui.h b/source/gui/Gui.h index 43087ef..e0d01a0 100644 --- a/source/gui/Gui.h +++ b/source/gui/Gui.h @@ -19,6 +19,7 @@ #include "FreeTypeGX.h" #include "GameBgImage.h" +#include "GridBackground.h" #include "GuiButton.h" #include "GuiCheckBox.h" #include "GuiController.h" diff --git a/source/gui/GuiCheckBox.cpp b/source/gui/GuiCheckBox.cpp index 4131a09..55ef02b 100644 --- a/source/gui/GuiCheckBox.cpp +++ b/source/gui/GuiCheckBox.cpp @@ -21,9 +21,9 @@ * Constructor for the GuiCheckBox class. */ -GuiCheckBox::GuiCheckBox(bool checked, f32 width,f32 height) +GuiCheckBox::GuiCheckBox(GuiImage * background, bool checked, f32 width,f32 height) : GuiToggle(checked,width,height){ - + setImageBackground(background); } /** @@ -36,7 +36,6 @@ GuiCheckBox::~GuiCheckBox(){ void GuiCheckBox::setImageBackground(GuiImage* img){ backgroundImg = img; if(img){ img->setParent(this); } - setImage(img); } void GuiCheckBox::setImageSelected(GuiImage* img){ diff --git a/source/gui/GuiCheckBox.h b/source/gui/GuiCheckBox.h index 005543c..d0cb204 100644 --- a/source/gui/GuiCheckBox.h +++ b/source/gui/GuiCheckBox.h @@ -26,7 +26,7 @@ class GuiCheckBox : public GuiToggle{ public: //!Constructor //!\param checked Checked - GuiCheckBox(bool checked, f32 width = 0.0f,f32 height= 0.0f); + GuiCheckBox(GuiImage * background, bool checked, f32 width = 0.0f,f32 height= 0.0f); //!Destructor virtual ~GuiCheckBox(); diff --git a/source/gui/GuiScrollbar.cpp b/source/gui/GuiScrollbar.cpp index 490b68f..1c1a22c 100644 --- a/source/gui/GuiScrollbar.cpp +++ b/source/gui/GuiScrollbar.cpp @@ -24,7 +24,7 @@ #include "GuiScrollbar.h" #include "resources/Resources.h" -Scrollbar::Scrollbar(s32 h) +GuiScrollbar::GuiScrollbar(s32 h) : touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH) , wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) { @@ -35,7 +35,7 @@ Scrollbar::Scrollbar(s32 h) ScrollSpeed = 15; ScrollState = 0; - listChanged.connect(this, &Scrollbar::setScrollboxPosition); + listChanged.connect(this, &GuiScrollbar::setScrollboxPosition); btnSoundClick = Resources::GetSound("button_click.mp3"); scrollbarLine = Resources::GetImageData("scrollbarLine.png"); @@ -67,7 +67,7 @@ Scrollbar::Scrollbar(s32 h) arrowUpBtn->setTrigger(&wpadTouchTrigger, 1); arrowUpBtn->setSoundClick(btnSoundClick); arrowUpBtn->setEffectGrow(); - arrowUpBtn->clicked.connect(this, &Scrollbar::OnUpButtonClick); + arrowUpBtn->clicked.connect(this, &GuiScrollbar::OnUpButtonClick); arrowDownBtn = new GuiButton(arrowDownImg->getWidth(), arrowDownImg->getHeight()); arrowDownBtn->setParent(this); @@ -78,7 +78,7 @@ Scrollbar::Scrollbar(s32 h) arrowDownBtn->setTrigger(&wpadTouchTrigger, 1); arrowDownBtn->setSoundClick(btnSoundClick); arrowDownBtn->setEffectGrow(); - arrowDownBtn->clicked.connect(this, &Scrollbar::OnDownButtonClick); + arrowDownBtn->clicked.connect(this, &GuiScrollbar::OnDownButtonClick); scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->getWidth(), height); scrollbarBoxBtn->setParent(this); @@ -89,10 +89,10 @@ Scrollbar::Scrollbar(s32 h) scrollbarBoxBtn->setTrigger(&touchTrigger, 0); scrollbarBoxBtn->setTrigger(&wpadTouchTrigger, 1); scrollbarBoxBtn->setEffectGrow(); - scrollbarBoxBtn->held.connect(this, &Scrollbar::OnBoxButtonHold); + scrollbarBoxBtn->held.connect(this, &GuiScrollbar::OnBoxButtonHold); } -Scrollbar::~Scrollbar() +GuiScrollbar::~GuiScrollbar() { Resources::RemoveSound(btnSoundClick); Resources::RemoveImageData(scrollbarLine); @@ -111,7 +111,7 @@ Scrollbar::~Scrollbar() delete scrollbarBoxImg; } -void Scrollbar::ScrollOneUp() +void GuiScrollbar::ScrollOneUp() { if(SelItem == 0 && SelInd > 0) { @@ -124,7 +124,7 @@ void Scrollbar::ScrollOneUp() } } -void Scrollbar::ScrollOneDown() +void GuiScrollbar::ScrollOneDown() { if(SelInd+SelItem + 1 < EntrieCount) { @@ -140,7 +140,7 @@ void Scrollbar::ScrollOneDown() } } -void Scrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) +void GuiScrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { if(ScrollState < ScrollSpeed) return; @@ -151,7 +151,7 @@ void Scrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controll listChanged(SelItem, SelInd); } -void Scrollbar::OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) +void GuiScrollbar::OnDownButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { if(ScrollState < ScrollSpeed) return; @@ -162,7 +162,7 @@ void Scrollbar::OnDownButtonClick(GuiButton *button, const GuiController *contro listChanged(SelItem, SelInd); } -void Scrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) +void GuiScrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controller, GuiTrigger *trigger) { if(EntrieCount == 0){ return; @@ -207,7 +207,7 @@ void Scrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controll listChanged(SelItem, SelInd); } -void Scrollbar::SetPageSize(s32 size) +void GuiScrollbar::SetPageSize(s32 size) { if(PageSize == size) return; @@ -216,7 +216,7 @@ void Scrollbar::SetPageSize(s32 size) listChanged(SelItem, SelInd); } -void Scrollbar::SetSelectedItem(s32 pos) +void GuiScrollbar::SetSelectedItem(s32 pos) { if(SelItem == pos) return; @@ -225,7 +225,7 @@ void Scrollbar::SetSelectedItem(s32 pos) listChanged(SelItem, SelInd); } -void Scrollbar::SetSelectedIndex(s32 pos) +void GuiScrollbar::SetSelectedIndex(s32 pos) { if(SelInd == pos) return; @@ -234,7 +234,7 @@ void Scrollbar::SetSelectedIndex(s32 pos) listChanged(SelItem, SelInd); } -void Scrollbar::SetEntrieCount(s32 cnt) +void GuiScrollbar::SetEntrieCount(s32 cnt) { if(EntrieCount == cnt) return; @@ -243,7 +243,7 @@ void Scrollbar::SetEntrieCount(s32 cnt) listChanged(SelItem, SelInd); } -void Scrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd) +void GuiScrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd) { s32 position = MaxHeight-(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1); @@ -255,7 +255,7 @@ void Scrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd) scrollbarBoxBtn->setPosition(0, position); } -void Scrollbar::draw(CVideo * video) +void GuiScrollbar::draw(CVideo * video) { scrollbarLineImg->draw(video); arrowUpBtn->draw(video); @@ -265,7 +265,7 @@ void Scrollbar::draw(CVideo * video) updateEffects(); } -void Scrollbar::update(GuiController * t) +void GuiScrollbar::update(GuiController * t) { if(this->isStateSet(STATE_DISABLED)) return; diff --git a/source/gui/GuiScrollbar.h b/source/gui/GuiScrollbar.h index 1900a03..668ed43 100644 --- a/source/gui/GuiScrollbar.h +++ b/source/gui/GuiScrollbar.h @@ -27,11 +27,11 @@ #include "gui/GuiElement.h" #include "gui/GuiButton.h" -class Scrollbar : public GuiElement, public sigslot::has_slots<> +class GuiScrollbar : public GuiElement, public sigslot::has_slots<> { public: - Scrollbar(s32 height); - virtual ~Scrollbar(); + GuiScrollbar(s32 height); + virtual ~GuiScrollbar(); void ScrollOneUp(); void ScrollOneDown(); s32 GetSelectedItem() { return SelItem; } diff --git a/source/gui/GuiSelectBox.cpp b/source/gui/GuiSelectBox.cpp index c62b313..429a8cc 100644 --- a/source/gui/GuiSelectBox.cpp +++ b/source/gui/GuiSelectBox.cpp @@ -16,17 +16,20 @@ ****************************************************************************/ #include #include +#include +#include + #include "GuiSelectBox.h" #include "GuiImage.h" #include "GuiTrigger.h" #include "GuiImageData.h" -#include "utils/StringTools.h" + /** * Constructor for the GuiCheckBox class. */ -GuiSelectBox::GuiSelectBox(std::string caption,GuiFrame *parent) - : GuiFrame(0,0,parent) +GuiSelectBox::GuiSelectBox(GuiImage * background,std::string caption,f32 width,f32 height,GuiFrame *parent) + : GuiFrame(width,height,parent) ,selected(0) ,captionText(caption) ,topValueButton(0,0) @@ -38,6 +41,7 @@ GuiSelectBox::GuiSelectBox(std::string caption,GuiFrame *parent) ,buttonDownTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true) ,DPADButtons(0,0) { + setImageTopBackground(background); showValues = false; bChanged = false; bSelectedChanged = false; @@ -67,6 +71,11 @@ GuiSelectBox::GuiSelectBox(std::string caption,GuiFrame *parent) bChanged = true; } +void GuiSelectBox::setSize(f32 width,f32 height){ + GuiFrame::setSize(width,height); + topValueButton.setSize(width,height); +} + void GuiSelectBox::OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger){ for(u32 i = 0; i < valueButtons.size(); ++i){ if(valueButtons[i].valueButton == button){ @@ -237,11 +246,17 @@ void GuiSelectBox::OnValueCloseEffectFinish(GuiElement *element) } f32 GuiSelectBox::getTopValueHeight() { - return topBackgroundImg == NULL ? 0 : topBackgroundImg->getHeight(); + if(topBackgroundImg == NULL){ + return 0.0f; + } + return topBackgroundImg->getHeight(); } f32 GuiSelectBox::getTopValueWidth() { - return topBackgroundImg == NULL ? 0 : topBackgroundImg->getWidth(); + if(topBackgroundImg == NULL){ + return 0.0f; + } + return topBackgroundImg->getWidth(); } f32 GuiSelectBox::getHeight(){ diff --git a/source/gui/GuiSelectBox.h b/source/gui/GuiSelectBox.h index fa61650..4917c3b 100644 --- a/source/gui/GuiSelectBox.h +++ b/source/gui/GuiSelectBox.h @@ -26,7 +26,7 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{ public: //!Constructor //!\param checked Checked - GuiSelectBox(std::string caption,GuiFrame *parent = 0); + GuiSelectBox(GuiImage * background, std::string caption,f32 width = 0.0f, f32 height = 0.0f,GuiFrame *parent = 0); //!Destructor virtual ~GuiSelectBox(); @@ -35,10 +35,6 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{ void setImageTopBackground(GuiImage * img){ topBackgroundImg = img; - if(img != NULL){ - setSize(img->getWidth(),img->getHeight()); - topValueButton.setSize(img->getWidth(),img->getHeight()); - } topValueButton.setImage(img); } @@ -69,6 +65,7 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{ void setState(s32 s, s32 c = -1); + virtual void setSize(f32 width, f32 height); virtual f32 getTopValueHeight(); virtual f32 getTopValueWidth(); @@ -94,13 +91,13 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{ bool opened; std::string captionText; GuiFrame valuesFrame; - GuiImage* topBackgroundImg; - GuiImage* topHighlightedImg; + GuiImage* topBackgroundImg = NULL; + GuiImage* topHighlightedImg = NULL; GuiButton topValueButton; - GuiImageData * valueImageData; - GuiImageData * valueSelectedImageData; - GuiImageData * valueHighlightedImageData; + GuiImageData * valueImageData = NULL; + GuiImageData * valueSelectedImageData = NULL; + GuiImageData * valueHighlightedImageData = NULL; GuiText topValueText; GuiTrigger touchTrigger; diff --git a/source/gui/GuiSwitch.cpp b/source/gui/GuiSwitch.cpp index 64cf66a..3a7d87d 100644 --- a/source/gui/GuiSwitch.cpp +++ b/source/gui/GuiSwitch.cpp @@ -22,9 +22,9 @@ * Constructor for the GuiSwitch class. */ -GuiSwitch::GuiSwitch(bool checked,f32 w, f32 h) +GuiSwitch::GuiSwitch(GuiImage * background,bool checked,f32 w, f32 h) : GuiToggle(checked,w,h){ - + setImageBackground(background); } /** * Destructor for the GuiSwitch class. @@ -35,10 +35,7 @@ GuiSwitch::~GuiSwitch(){ void GuiSwitch::setImageBackground(GuiImage* img){ backgroundImg = img; - if(img){ - img->setParent(this); - - } + if(img){ img->setParent(this); } setImage(img); } diff --git a/source/gui/GuiSwitch.h b/source/gui/GuiSwitch.h index 054d22c..da20e77 100644 --- a/source/gui/GuiSwitch.h +++ b/source/gui/GuiSwitch.h @@ -26,7 +26,7 @@ class GuiSwitch : public GuiToggle{ public: //!Constructor //!\param checked Checked - GuiSwitch(bool checked,f32 w = 0.0f, f32 h = 0.0f); + GuiSwitch(GuiImage * background, bool checked, f32 w = 0.0f, f32 h = 0.0f); //!Destructor virtual ~GuiSwitch(); @@ -37,13 +37,12 @@ class GuiSwitch : public GuiToggle{ void setImageOff(GuiImage* img); void setImageHighlighted(GuiImage* img); - protected: - GuiImage * backgroundImg; - GuiImage * onImg; - GuiImage * offImg; - GuiImage * highlightedImg; + GuiImage * backgroundImg = NULL; + GuiImage * onImg = NULL; + GuiImage * offImg = NULL; + GuiImage * highlightedImg = NULL; void draw(CVideo * v); }; diff --git a/source/resources/Resources.cpp b/source/resources/Resources.cpp index 13c9e0d..9208c66 100644 --- a/source/resources/Resources.cpp +++ b/source/resources/Resources.cpp @@ -7,7 +7,6 @@ #include #include "gui/GuiImageAsync.h" #include "gui/GuiSound.h" -#include "utils/logger.h" Resources * Resources::instance = NULL; @@ -65,7 +64,6 @@ bool Resources::LoadFiles(const char * path) const u8 * Resources::GetFile(const char * filename) { - DEBUG_FUNCTION_LINE(".\n"); ResourceFile * ResourceList = getResourceList(); if(ResourceList == NULL) return NULL;