mirror of
https://github.com/wiiu-env/libgui.git
synced 2024-12-26 16:21:49 +01:00
Removed hardcoded values from the GuiSrollbar class
This commit is contained in:
parent
2db871522d
commit
b783255b2d
@ -32,57 +32,33 @@ GuiScrollbar::GuiScrollbar(s32 h)
|
|||||||
SelInd = 0;
|
SelInd = 0;
|
||||||
PageSize = 0;
|
PageSize = 0;
|
||||||
EntrieCount = 0;
|
EntrieCount = 0;
|
||||||
ScrollSpeed = 15;
|
SetScrollSpeed(15);
|
||||||
ScrollState = 0;
|
ScrollState = 0;
|
||||||
|
|
||||||
listChanged.connect(this, &GuiScrollbar::setScrollboxPosition);
|
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;
|
height = h;
|
||||||
width = scrollbarBox->getWidth();
|
|
||||||
|
|
||||||
MaxHeight = height * 0.5f - (scrollbarBox ? (scrollbarBox->getHeight() * 0.5f) : 0) - (arrowUp ? arrowUp->getHeight() : 0);
|
arrowUpBtn = new GuiButton(50, 50);
|
||||||
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->setParent(this);
|
arrowUpBtn->setParent(this);
|
||||||
arrowUpBtn->setImage(arrowUpImg);
|
|
||||||
arrowUpBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
|
arrowUpBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
|
||||||
arrowUpBtn->setPosition(0, 0);
|
arrowUpBtn->setPosition(0, 0);
|
||||||
arrowUpBtn->setTrigger(&touchTrigger, 0);
|
arrowUpBtn->setTrigger(&touchTrigger, 0);
|
||||||
arrowUpBtn->setTrigger(&wpadTouchTrigger, 1);
|
arrowUpBtn->setTrigger(&wpadTouchTrigger, 1);
|
||||||
arrowUpBtn->setSoundClick(btnSoundClick);
|
|
||||||
arrowUpBtn->setEffectGrow();
|
arrowUpBtn->setEffectGrow();
|
||||||
arrowUpBtn->clicked.connect(this, &GuiScrollbar::OnUpButtonClick);
|
arrowUpBtn->clicked.connect(this, &GuiScrollbar::OnUpButtonClick);
|
||||||
|
|
||||||
arrowDownBtn = new GuiButton(arrowDownImg->getWidth(), arrowDownImg->getHeight());
|
arrowDownBtn = new GuiButton(50, 50);
|
||||||
arrowDownBtn->setParent(this);
|
arrowDownBtn->setParent(this);
|
||||||
arrowDownBtn->setImage(arrowDownImg);
|
|
||||||
arrowDownBtn->setAlignment(ALIGN_CENTER | ALIGN_BOTTOM);
|
arrowDownBtn->setAlignment(ALIGN_CENTER | ALIGN_BOTTOM);
|
||||||
arrowDownBtn->setPosition(0, 0);
|
arrowDownBtn->setPosition(0, 0);
|
||||||
arrowDownBtn->setTrigger(&touchTrigger, 0);
|
arrowDownBtn->setTrigger(&touchTrigger, 0);
|
||||||
arrowDownBtn->setTrigger(&wpadTouchTrigger, 1);
|
arrowDownBtn->setTrigger(&wpadTouchTrigger, 1);
|
||||||
arrowDownBtn->setSoundClick(btnSoundClick);
|
|
||||||
arrowDownBtn->setEffectGrow();
|
arrowDownBtn->setEffectGrow();
|
||||||
arrowDownBtn->clicked.connect(this, &GuiScrollbar::OnDownButtonClick);
|
arrowDownBtn->clicked.connect(this, &GuiScrollbar::OnDownButtonClick);
|
||||||
|
|
||||||
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->getWidth(), height);
|
scrollbarBoxBtn = new GuiButton(50, height);
|
||||||
scrollbarBoxBtn->setParent(this);
|
scrollbarBoxBtn->setParent(this);
|
||||||
scrollbarBoxBtn->setImage(scrollbarBoxImg);
|
|
||||||
scrollbarBoxBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
|
scrollbarBoxBtn->setAlignment(ALIGN_CENTER | ALIGN_TOP);
|
||||||
scrollbarBoxBtn->setPosition(0, MaxHeight);
|
scrollbarBoxBtn->setPosition(0, MaxHeight);
|
||||||
scrollbarBoxBtn->setHoldable(true);
|
scrollbarBoxBtn->setHoldable(true);
|
||||||
@ -94,21 +70,9 @@ GuiScrollbar::GuiScrollbar(s32 h)
|
|||||||
|
|
||||||
GuiScrollbar::~GuiScrollbar()
|
GuiScrollbar::~GuiScrollbar()
|
||||||
{
|
{
|
||||||
Resources::RemoveSound(btnSoundClick);
|
|
||||||
Resources::RemoveImageData(scrollbarLine);
|
|
||||||
Resources::RemoveImageData(arrowDown);
|
|
||||||
Resources::RemoveImageData(arrowUp);
|
|
||||||
Resources::RemoveImageData(scrollbarBox);
|
|
||||||
|
|
||||||
delete arrowUpBtn;
|
delete arrowUpBtn;
|
||||||
delete arrowDownBtn;
|
delete arrowDownBtn;
|
||||||
delete scrollbarBoxBtn;
|
delete scrollbarBoxBtn;
|
||||||
|
|
||||||
delete scrollbarLineImg;
|
|
||||||
|
|
||||||
delete arrowDownImg;
|
|
||||||
delete arrowUpImg;
|
|
||||||
delete scrollbarBoxImg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiScrollbar::ScrollOneUp()
|
void GuiScrollbar::ScrollOneUp()
|
||||||
@ -257,7 +221,7 @@ void GuiScrollbar::setScrollboxPosition(s32 SelItem, s32 SelInd)
|
|||||||
|
|
||||||
void GuiScrollbar::draw(CVideo * video)
|
void GuiScrollbar::draw(CVideo * video)
|
||||||
{
|
{
|
||||||
scrollbarLineImg->draw(video);
|
if(scrollbarLineImage){ scrollbarLineImage->draw(video); }
|
||||||
arrowUpBtn->draw(video);
|
arrowUpBtn->draw(video);
|
||||||
arrowDownBtn->draw(video);
|
arrowDownBtn->draw(video);
|
||||||
scrollbarBoxBtn->draw(video);
|
scrollbarBoxBtn->draw(video);
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#ifndef SCROLLBAR_HPP_
|
#ifndef GUI_SCROLLBAR_HPP_
|
||||||
#define SCROLLBAR_HPP_
|
#define GUI_SCROLLBAR_HPP_
|
||||||
|
|
||||||
#include "gui/GuiElement.h"
|
#include "gui/GuiElement.h"
|
||||||
#include "gui/GuiButton.h"
|
#include "gui/GuiButton.h"
|
||||||
@ -42,11 +42,58 @@ class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
|
|||||||
//! Signals
|
//! Signals
|
||||||
sigslot::signal2<s32, s32> listChanged;
|
sigslot::signal2<s32, s32> listChanged;
|
||||||
//! Slots
|
//! Slots
|
||||||
|
void SetScrollSpeed(s32 speed){ScrollSpeed = speed;};
|
||||||
void SetPageSize(s32 size);
|
void SetPageSize(s32 size);
|
||||||
void SetRowSize(s32 size);
|
void SetRowSize(s32 size);
|
||||||
void SetSelectedItem(s32 pos);
|
void SetSelectedItem(s32 pos);
|
||||||
void SetSelectedIndex(s32 pos);
|
void SetSelectedIndex(s32 pos);
|
||||||
void SetEntrieCount(s32 cnt);
|
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:
|
protected:
|
||||||
void setScrollboxPosition(s32 SelItem, s32 SelInd);
|
void setScrollboxPosition(s32 SelItem, s32 SelInd);
|
||||||
void OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
void OnUpButtonClick(GuiButton *button, const GuiController *controller, GuiTrigger *trigger);
|
||||||
@ -67,15 +114,13 @@ class GuiScrollbar : public GuiElement, public sigslot::has_slots<>
|
|||||||
GuiButton * arrowUpBtn;
|
GuiButton * arrowUpBtn;
|
||||||
GuiButton * arrowDownBtn;
|
GuiButton * arrowDownBtn;
|
||||||
GuiButton * scrollbarBoxBtn;
|
GuiButton * scrollbarBoxBtn;
|
||||||
GuiImage * scrollbarLineImg;
|
|
||||||
GuiImage * arrowDownImg;
|
GuiSound * clickSound = NULL;
|
||||||
GuiImage * arrowUpImg;
|
|
||||||
GuiImage * scrollbarBoxImg;
|
GuiImage * scrollbarLineImage = NULL;
|
||||||
GuiImageData * scrollbarLine;
|
GuiImage * arrowDownImage = NULL;
|
||||||
GuiImageData * arrowDown;
|
GuiImage * arrowUpImage = NULL;
|
||||||
GuiImageData * arrowUp;
|
GuiImage * scrollbarBoxImage = NULL;
|
||||||
GuiImageData * scrollbarBox;
|
|
||||||
GuiSound * btnSoundClick;
|
|
||||||
|
|
||||||
GuiTrigger touchTrigger;
|
GuiTrigger touchTrigger;
|
||||||
GuiTrigger wpadTouchTrigger;
|
GuiTrigger wpadTouchTrigger;
|
||||||
|
Loading…
Reference in New Issue
Block a user