Removed hardcoded values from the GuiSrollbar class

This commit is contained in:
Maschell 2017-10-31 19:48:27 +01:00
parent 2db871522d
commit b783255b2d
2 changed files with 61 additions and 52 deletions

View File

@ -32,57 +32,33 @@ GuiScrollbar::GuiScrollbar(s32 h)
SelInd = 0;
PageSize = 0;
EntrieCount = 0;
ScrollSpeed = 15;
SetScrollSpeed(15);
ScrollState = 0;
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
btnSoundClick = Resources::GetSound("button_click.mp3");
scrollbarLine = Resources::GetImageData("scrollbarLine.png");
arrowDown = Resources::GetImageData("scrollbarArrowDown.png");
arrowUp = Resources::GetImageData("scrollbarArrowUp.png");
scrollbarBox = Resources::GetImageData("scrollbarButton.png");
height = h;
width = scrollbarBox->getWidth();
MaxHeight = height * 0.5f - (scrollbarBox ? (scrollbarBox->getHeight() * 0.5f) : 0) - (arrowUp ? arrowUp->getHeight() : 0);
MinHeight = -height * 0.5f + (scrollbarBox ? (scrollbarBox->getHeight() * 0.5f) : 0) + (arrowDown ? arrowDown->getHeight() : 0);
scrollbarLineImg = new GuiImage(scrollbarLine);
scrollbarLineImg->setParent(this);
scrollbarLineImg->setAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
scrollbarLineImg->setPosition(0, 0);
arrowDownImg = new GuiImage(arrowDown);
arrowUpImg = new GuiImage(arrowUp);
scrollbarBoxImg = new GuiImage(scrollbarBox);
arrowUpBtn = new GuiButton(arrowUpImg->getWidth(), arrowUpImg->getHeight());
arrowUpBtn = new GuiButton(50, 50);
arrowUpBtn->setParent(this);
arrowUpBtn->setImage(arrowUpImg);
arrowUpBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
arrowUpBtn->setPosition(0, 0);
arrowUpBtn->setTrigger(&touchTrigger, 0);
arrowUpBtn->setTrigger(&wpadTouchTrigger, 1);
arrowUpBtn->setSoundClick(btnSoundClick);
arrowUpBtn->setEffectGrow();
arrowUpBtn->clicked.connect(this, &GuiScrollbar::OnUpButtonClick);
arrowDownBtn = new GuiButton(arrowDownImg->getWidth(), arrowDownImg->getHeight());
arrowDownBtn = new GuiButton(50, 50);
arrowDownBtn->setParent(this);
arrowDownBtn->setImage(arrowDownImg);
arrowDownBtn->setAlignment(ALIGN_CENTER | ALIGN_BOTTOM);
arrowDownBtn->setPosition(0, 0);
arrowDownBtn->setTrigger(&touchTrigger, 0);
arrowDownBtn->setTrigger(&wpadTouchTrigger, 1);
arrowDownBtn->setSoundClick(btnSoundClick);
arrowDownBtn->setEffectGrow();
arrowDownBtn->clicked.connect(this, &GuiScrollbar::OnDownButtonClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->getWidth(), height);
scrollbarBoxBtn = new GuiButton(50, height);
scrollbarBoxBtn->setParent(this);
scrollbarBoxBtn->setImage(scrollbarBoxImg);
scrollbarBoxBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
scrollbarBoxBtn->setPosition(0, MaxHeight);
scrollbarBoxBtn->setHoldable(true);
@ -94,21 +70,9 @@ GuiScrollbar::GuiScrollbar(s32 h)
GuiScrollbar::~GuiScrollbar()
{
Resources::RemoveSound(btnSoundClick);
Resources::RemoveImageData(scrollbarLine);
Resources::RemoveImageData(arrowDown);
Resources::RemoveImageData(arrowUp);
Resources::RemoveImageData(scrollbarBox);
delete arrowUpBtn;
delete arrowDownBtn;
delete scrollbarBoxBtn;
delete scrollbarLineImg;
delete arrowDownImg;
delete arrowUpImg;
delete scrollbarBoxImg;
}
void GuiScrollbar::ScrollOneUp()
@ -257,7 +221,7 @@ void GuiScrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd)
void GuiScrollbar::draw(CVideo * video)
{
scrollbarLineImg->draw(video);
if(scrollbarLineImage){ scrollbarLineImage->draw(video); }
arrowUpBtn->draw(video);
arrowDownBtn->draw(video);
scrollbarBoxBtn->draw(video);

View File

@ -21,8 +21,8 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#ifndef SCROLLBAR_HPP_
#define SCROLLBAR_HPP_
#ifndef GUI_SCROLLBAR_HPP_
#define GUI_SCROLLBAR_HPP_
#include "gui/GuiElement.h"
#include "gui/GuiButton.h"
@ -42,11 +42,58 @@ class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
//! Signals
sigslot::signal2<s32, s32> listChanged;
//! Slots
void SetScrollSpeed(s32 speed){ScrollSpeed = speed;};
void SetPageSize(s32 size);
void SetRowSize(s32 size);
void SetSelectedItem(s32 pos);
void SetSelectedIndex(s32 pos);
void SetEntrieCount(s32 cnt);
void setSoundClick(GuiSound * snd){
clickSound = snd;
arrowUpBtn->setSoundClick(snd);
arrowDownBtn->setSoundClick(snd);
}
void setImageScrollbarLine(GuiImage * img){
if(img){
scrollbarLineImage = img;
scrollbarLineImage->setParent(this);
scrollbarLineImage->setParent(this);
scrollbarLineImage->setAlignment(ALIGN_CENTER | ALIGN_MIDDLE);
scrollbarLineImage->setPosition(0, 0);
}
}
void setImageArrowDown(GuiImage * img){
if(img){
arrowDownImage = img;
arrowDownBtn->setSize(img->getWidth(), img->getHeight());
arrowDownBtn->setImage(img);
}
}
void setImageArrowUp(GuiImage * img){
if(img){
arrowUpImage = img;
arrowUpBtn->setSize(img->getWidth(), img->getHeight());
arrowUpBtn->setImage(img);
}
}
void setImageScrollbarBox(GuiImage * img){
if(img){
scrollbarBoxImage = img;
scrollbarBoxBtn->setSize(img->getWidth(), height);
scrollbarBoxBtn->setImage(img);
width = img->getWidth();
MaxHeight = height * 0.5f - (img ? (img->getHeight() * 0.5f) : 0) - (arrowUpImage ? arrowUpImage->getHeight() : 0);
MinHeight = -height * 0.5f + (img ? (img->getHeight() * 0.5f) : 0) + (arrowDownImage ? arrowDownImage->getHeight() : 0);
}
}
protected:
void setScrollboxPosition(s32 SelItem, s32 SelInd);
void OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
@ -67,15 +114,13 @@ class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn;
GuiButton * scrollbarBoxBtn;
GuiImage * scrollbarLineImg;
GuiImage * arrowDownImg;
GuiImage * arrowUpImg;
GuiImage * scrollbarBoxImg;
GuiImageData * scrollbarLine;
GuiImageData * arrowDown;
GuiImageData * arrowUp;
GuiImageData * scrollbarBox;
GuiSound * btnSoundClick;
GuiSound * clickSound = NULL;
GuiImage * scrollbarLineImage = NULL;
GuiImage * arrowDownImage = NULL;
GuiImage * arrowUpImage = NULL;
GuiImage * scrollbarBoxImage = NULL;
GuiTrigger touchTrigger;
GuiTrigger wpadTouchTrigger;