Some small tweaks

This commit is contained in:
Maschell 2017-10-31 17:18:42 +01:00
parent 9c4efe8b71
commit 2db871522d
10 changed files with 60 additions and 54 deletions

View File

@ -19,6 +19,7 @@
#include "FreeTypeGX.h" #include "FreeTypeGX.h"
#include "GameBgImage.h" #include "GameBgImage.h"
#include "GridBackground.h"
#include "GuiButton.h" #include "GuiButton.h"
#include "GuiCheckBox.h" #include "GuiCheckBox.h"
#include "GuiController.h" #include "GuiController.h"

View File

@ -21,9 +21,9 @@
* Constructor for the GuiCheckBox class. * 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){ : GuiToggle(checked,width,height){
setImageBackground(background);
} }
/** /**
@ -36,7 +36,6 @@ GuiCheckBox::~GuiCheckBox(){
void GuiCheckBox::setImageBackground(GuiImage* img){ void GuiCheckBox::setImageBackground(GuiImage* img){
backgroundImg = img; backgroundImg = img;
if(img){ img->setParent(this); } if(img){ img->setParent(this); }
setImage(img);
} }
void GuiCheckBox::setImageSelected(GuiImage* img){ void GuiCheckBox::setImageSelected(GuiImage* img){

View File

@ -26,7 +26,7 @@ class GuiCheckBox : public GuiToggle{
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\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 //!Destructor
virtual ~GuiCheckBox(); virtual ~GuiCheckBox();

View File

@ -24,7 +24,7 @@
#include "GuiScrollbar.h" #include "GuiScrollbar.h"
#include "resources/Resources.h" #include "resources/Resources.h"
Scrollbar::Scrollbar(s32 h) GuiScrollbar::GuiScrollbar(s32 h)
: touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH) : touchTrigger(GuiTrigger::CHANNEL_1, GuiTrigger::VPAD_TOUCH)
, wpadTouchTrigger(GuiTrigger::CHANNEL_2 | GuiTrigger::CHANNEL_3 | GuiTrigger::CHANNEL_4 | GuiTrigger::CHANNEL_5, GuiTrigger::BUTTON_A) , 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; ScrollSpeed = 15;
ScrollState = 0; ScrollState = 0;
listChanged.connect(this, &Scrollbar::setScrollboxPosition); listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
btnSoundClick = Resources::GetSound("button_click.mp3"); btnSoundClick = Resources::GetSound("button_click.mp3");
scrollbarLine = Resources::GetImageData("scrollbarLine.png"); scrollbarLine = Resources::GetImageData("scrollbarLine.png");
@ -67,7 +67,7 @@ Scrollbar::Scrollbar(s32 h)
arrowUpBtn->setTrigger(&wpadTouchTrigger, 1); arrowUpBtn->setTrigger(&wpadTouchTrigger, 1);
arrowUpBtn->setSoundClick(btnSoundClick); arrowUpBtn->setSoundClick(btnSoundClick);
arrowUpBtn->setEffectGrow(); arrowUpBtn->setEffectGrow();
arrowUpBtn->clicked.connect(this, &Scrollbar::OnUpButtonClick); arrowUpBtn->clicked.connect(this, &GuiScrollbar::OnUpButtonClick);
arrowDownBtn = new GuiButton(arrowDownImg->getWidth(), arrowDownImg->getHeight()); arrowDownBtn = new GuiButton(arrowDownImg->getWidth(), arrowDownImg->getHeight());
arrowDownBtn->setParent(this); arrowDownBtn->setParent(this);
@ -78,7 +78,7 @@ Scrollbar::Scrollbar(s32 h)
arrowDownBtn->setTrigger(&wpadTouchTrigger, 1); arrowDownBtn->setTrigger(&wpadTouchTrigger, 1);
arrowDownBtn->setSoundClick(btnSoundClick); arrowDownBtn->setSoundClick(btnSoundClick);
arrowDownBtn->setEffectGrow(); arrowDownBtn->setEffectGrow();
arrowDownBtn->clicked.connect(this, &Scrollbar::OnDownButtonClick); arrowDownBtn->clicked.connect(this, &GuiScrollbar::OnDownButtonClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->getWidth(), height); scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->getWidth(), height);
scrollbarBoxBtn->setParent(this); scrollbarBoxBtn->setParent(this);
@ -89,10 +89,10 @@ Scrollbar::Scrollbar(s32 h)
scrollbarBoxBtn->setTrigger(&touchTrigger, 0); scrollbarBoxBtn->setTrigger(&touchTrigger, 0);
scrollbarBoxBtn->setTrigger(&wpadTouchTrigger, 1); scrollbarBoxBtn->setTrigger(&wpadTouchTrigger, 1);
scrollbarBoxBtn->setEffectGrow(); scrollbarBoxBtn->setEffectGrow();
scrollbarBoxBtn->held.connect(this, &Scrollbar::OnBoxButtonHold); scrollbarBoxBtn->held.connect(this, &GuiScrollbar::OnBoxButtonHold);
} }
Scrollbar::~Scrollbar() GuiScrollbar::~GuiScrollbar()
{ {
Resources::RemoveSound(btnSoundClick); Resources::RemoveSound(btnSoundClick);
Resources::RemoveImageData(scrollbarLine); Resources::RemoveImageData(scrollbarLine);
@ -111,7 +111,7 @@ Scrollbar::~Scrollbar()
delete scrollbarBoxImg; delete scrollbarBoxImg;
} }
void Scrollbar::ScrollOneUp() void GuiScrollbar::ScrollOneUp()
{ {
if(SelItem == 0 && SelInd > 0) if(SelItem == 0 && SelInd > 0)
{ {
@ -124,7 +124,7 @@ void Scrollbar::ScrollOneUp()
} }
} }
void Scrollbar::ScrollOneDown() void GuiScrollbar::ScrollOneDown()
{ {
if(SelInd+SelItem + 1 < EntrieCount) 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) if(ScrollState < ScrollSpeed)
return; return;
@ -151,7 +151,7 @@ void Scrollbar::OnUpButtonClick(GuiButton *button, const GuiController *controll
listChanged(SelItem, SelInd); 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) if(ScrollState < ScrollSpeed)
return; return;
@ -162,7 +162,7 @@ void Scrollbar::OnDownButtonClick(GuiButton *button, const GuiController *contro
listChanged(SelItem, SelInd); 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){ if(EntrieCount == 0){
return; return;
@ -207,7 +207,7 @@ void Scrollbar::OnBoxButtonHold(GuiButton *button, const GuiController *controll
listChanged(SelItem, SelInd); listChanged(SelItem, SelInd);
} }
void Scrollbar::SetPageSize(s32 size) void GuiScrollbar::SetPageSize(s32 size)
{ {
if(PageSize == size) if(PageSize == size)
return; return;
@ -216,7 +216,7 @@ void Scrollbar::SetPageSize(s32 size)
listChanged(SelItem, SelInd); listChanged(SelItem, SelInd);
} }
void Scrollbar::SetSelectedItem(s32 pos) void GuiScrollbar::SetSelectedItem(s32 pos)
{ {
if(SelItem == pos) if(SelItem == pos)
return; return;
@ -225,7 +225,7 @@ void Scrollbar::SetSelectedItem(s32 pos)
listChanged(SelItem, SelInd); listChanged(SelItem, SelInd);
} }
void Scrollbar::SetSelectedIndex(s32 pos) void GuiScrollbar::SetSelectedIndex(s32 pos)
{ {
if(SelInd == pos) if(SelInd == pos)
return; return;
@ -234,7 +234,7 @@ void Scrollbar::SetSelectedIndex(s32 pos)
listChanged(SelItem, SelInd); listChanged(SelItem, SelInd);
} }
void Scrollbar::SetEntrieCount(s32 cnt) void GuiScrollbar::SetEntrieCount(s32 cnt)
{ {
if(EntrieCount == cnt) if(EntrieCount == cnt)
return; return;
@ -243,7 +243,7 @@ void Scrollbar::SetEntrieCount(s32 cnt)
listChanged(SelItem, SelInd); 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); s32 position = MaxHeight-(MaxHeight-MinHeight)*(SelInd+SelItem)/(EntrieCount-1);
@ -255,7 +255,7 @@ void Scrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd)
scrollbarBoxBtn->setPosition(0, position); scrollbarBoxBtn->setPosition(0, position);
} }
void Scrollbar::draw(CVideo * video) void GuiScrollbar::draw(CVideo * video)
{ {
scrollbarLineImg->draw(video); scrollbarLineImg->draw(video);
arrowUpBtn->draw(video); arrowUpBtn->draw(video);
@ -265,7 +265,7 @@ void Scrollbar::draw(CVideo * video)
updateEffects(); updateEffects();
} }
void Scrollbar::update(GuiController * t) void GuiScrollbar::update(GuiController * t)
{ {
if(this->isStateSet(STATE_DISABLED)) if(this->isStateSet(STATE_DISABLED))
return; return;

View File

@ -27,11 +27,11 @@
#include "gui/GuiElement.h" #include "gui/GuiElement.h"
#include "gui/GuiButton.h" #include "gui/GuiButton.h"
class Scrollbar : public GuiElement, public sigslot::has_slots<> class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
{ {
public: public:
Scrollbar(s32 height); GuiScrollbar(s32 height);
virtual ~Scrollbar(); virtual ~GuiScrollbar();
void ScrollOneUp(); void ScrollOneUp();
void ScrollOneDown(); void ScrollOneDown();
s32 GetSelectedItem() { return SelItem; } s32 GetSelectedItem() { return SelItem; }

View File

@ -16,17 +16,20 @@
****************************************************************************/ ****************************************************************************/
#include <vector> #include <vector>
#include <string> #include <string>
#include <utils/StringTools.h>
#include <utils/logger.h>
#include "GuiSelectBox.h" #include "GuiSelectBox.h"
#include "GuiImage.h" #include "GuiImage.h"
#include "GuiTrigger.h" #include "GuiTrigger.h"
#include "GuiImageData.h" #include "GuiImageData.h"
#include "utils/StringTools.h"
/** /**
* Constructor for the GuiCheckBox class. * Constructor for the GuiCheckBox class.
*/ */
GuiSelectBox::GuiSelectBox(std::string caption,GuiFrame *parent) GuiSelectBox::GuiSelectBox(GuiImage * background,std::string caption,f32 width,f32 height,GuiFrame *parent)
: GuiFrame(0,0,parent) : GuiFrame(width,height,parent)
,selected(0) ,selected(0)
,captionText(caption) ,captionText(caption)
,topValueButton(0,0) ,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) ,buttonDownTrigger(GuiTrigger::CHANNEL_ALL, GuiTrigger::BUTTON_DOWN | GuiTrigger::STICK_L_DOWN, true)
,DPADButtons(0,0) ,DPADButtons(0,0)
{ {
setImageTopBackground(background);
showValues = false; showValues = false;
bChanged = false; bChanged = false;
bSelectedChanged = false; bSelectedChanged = false;
@ -67,6 +71,11 @@ GuiSelectBox::GuiSelectBox(std::string caption,GuiFrame *parent)
bChanged = true; 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){ void GuiSelectBox::OnValueClicked(GuiButton *button, const GuiController *controller, GuiTrigger *trigger){
for(u32 i = 0; i < valueButtons.size(); ++i){ for(u32 i = 0; i < valueButtons.size(); ++i){
if(valueButtons[i].valueButton == button){ if(valueButtons[i].valueButton == button){
@ -237,11 +246,17 @@ void GuiSelectBox::OnValueCloseEffectFinish(GuiElement *element)
} }
f32 GuiSelectBox::getTopValueHeight() { f32 GuiSelectBox::getTopValueHeight() {
return topBackgroundImg == NULL ? 0 : topBackgroundImg->getHeight(); if(topBackgroundImg == NULL){
return 0.0f;
}
return topBackgroundImg->getHeight();
} }
f32 GuiSelectBox::getTopValueWidth() { f32 GuiSelectBox::getTopValueWidth() {
return topBackgroundImg == NULL ? 0 : topBackgroundImg->getWidth(); if(topBackgroundImg == NULL){
return 0.0f;
}
return topBackgroundImg->getWidth();
} }
f32 GuiSelectBox::getHeight(){ f32 GuiSelectBox::getHeight(){

View File

@ -26,7 +26,7 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\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 //!Destructor
virtual ~GuiSelectBox(); virtual ~GuiSelectBox();
@ -35,10 +35,6 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{
void setImageTopBackground(GuiImage * img){ void setImageTopBackground(GuiImage * img){
topBackgroundImg = img; topBackgroundImg = img;
if(img != NULL){
setSize(img->getWidth(),img->getHeight());
topValueButton.setSize(img->getWidth(),img->getHeight());
}
topValueButton.setImage(img); topValueButton.setImage(img);
} }
@ -69,6 +65,7 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{
void setState(s32 s, s32 c = -1); void setState(s32 s, s32 c = -1);
virtual void setSize(f32 width, f32 height);
virtual f32 getTopValueHeight(); virtual f32 getTopValueHeight();
virtual f32 getTopValueWidth(); virtual f32 getTopValueWidth();
@ -94,13 +91,13 @@ class GuiSelectBox : public GuiFrame, public sigslot::has_slots<>{
bool opened; bool opened;
std::string captionText; std::string captionText;
GuiFrame valuesFrame; GuiFrame valuesFrame;
GuiImage* topBackgroundImg; GuiImage* topBackgroundImg = NULL;
GuiImage* topHighlightedImg; GuiImage* topHighlightedImg = NULL;
GuiButton topValueButton; GuiButton topValueButton;
GuiImageData * valueImageData; GuiImageData * valueImageData = NULL;
GuiImageData * valueSelectedImageData; GuiImageData * valueSelectedImageData = NULL;
GuiImageData * valueHighlightedImageData; GuiImageData * valueHighlightedImageData = NULL;
GuiText topValueText; GuiText topValueText;
GuiTrigger touchTrigger; GuiTrigger touchTrigger;

View File

@ -22,9 +22,9 @@
* Constructor for the GuiSwitch class. * 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){ : GuiToggle(checked,w,h){
setImageBackground(background);
} }
/** /**
* Destructor for the GuiSwitch class. * Destructor for the GuiSwitch class.
@ -35,10 +35,7 @@ GuiSwitch::~GuiSwitch(){
void GuiSwitch::setImageBackground(GuiImage* img){ void GuiSwitch::setImageBackground(GuiImage* img){
backgroundImg = img; backgroundImg = img;
if(img){ if(img){ img->setParent(this); }
img->setParent(this);
}
setImage(img); setImage(img);
} }

View File

@ -26,7 +26,7 @@ class GuiSwitch : public GuiToggle{
public: public:
//!Constructor //!Constructor
//!\param checked Checked //!\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 //!Destructor
virtual ~GuiSwitch(); virtual ~GuiSwitch();
@ -37,13 +37,12 @@ class GuiSwitch : public GuiToggle{
void setImageOff(GuiImage* img); void setImageOff(GuiImage* img);
void setImageHighlighted(GuiImage* img); void setImageHighlighted(GuiImage* img);
protected: protected:
GuiImage * backgroundImg; GuiImage * backgroundImg = NULL;
GuiImage * onImg; GuiImage * onImg = NULL;
GuiImage * offImg; GuiImage * offImg = NULL;
GuiImage * highlightedImg; GuiImage * highlightedImg = NULL;
void draw(CVideo * v); void draw(CVideo * v);
}; };

View File

@ -7,7 +7,6 @@
#include <fs/FSUtils.h> #include <fs/FSUtils.h>
#include "gui/GuiImageAsync.h" #include "gui/GuiImageAsync.h"
#include "gui/GuiSound.h" #include "gui/GuiSound.h"
#include "utils/logger.h"
Resources * Resources::instance = NULL; Resources * Resources::instance = NULL;
@ -65,7 +64,6 @@ bool Resources::LoadFiles(const char * path)
const u8 * Resources::GetFile(const char * filename) const u8 * Resources::GetFile(const char * filename)
{ {
DEBUG_FUNCTION_LINE(".\n");
ResourceFile * ResourceList = getResourceList(); ResourceFile * ResourceList = getResourceList();
if(ResourceList == NULL) return NULL; if(ResourceList == NULL) return NULL;