usbloadergx/source/libwiigui/gui_optionbrowser.cpp

671 lines
21 KiB
C++
Raw Normal View History

/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_optionbrowser.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
#include "../wpad.h"
#include "settings/CSettings.h"
#include "themes/CTheme.h"
#include <unistd.h>
#define GAMESELECTSIZE 30
static int scrollbaron = 0, startat = 0, loaded = 0;
/**
* Constructor for the GuiOptionBrowser class.
*/
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollon)
{
width = w;
height = h;
options = l;
scrollbaron = scrollon;
selectable = true;
2010-09-24 02:48:03 +02:00
listOffset = this->FindMenuItem(-1, 1);
listChanged = true; // trigger an initial list update
selectedItem = 0;
focus = 1; // allow focus
trigA = new GuiTrigger;
2010-09-24 02:48:03 +02:00
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
trigHeldA = new GuiTrigger;
2010-09-24 02:48:03 +02:00
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A);
2010-09-24 02:48:03 +02:00
btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, Settings.sfxvolume);
bgOptions = Resources::GetImageData(imagebg);
2010-09-24 02:48:03 +02:00
bgOptionsImg = new GuiImage(bgOptions);
bgOptionsImg->SetParent(this);
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
scrollbar = Resources::GetImageData("scrollbar.png");
2010-09-24 02:48:03 +02:00
scrollbarImg = new GuiImage(scrollbar);
scrollbarImg->SetParent(this);
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarImg->SetPosition(0, 4);
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
2010-09-24 02:48:03 +02:00
arrowDownImg = new GuiImage(arrowDown);
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
2010-09-24 02:48:03 +02:00
arrowDownOverImg = new GuiImage(arrowDownOver);
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
2010-09-24 02:48:03 +02:00
arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png");
2010-09-24 02:48:03 +02:00
arrowUpOverImg = new GuiImage(arrowUpOver);
scrollbarBox = Resources::GetImageData("scrollbar_box.png");
2010-09-24 02:48:03 +02:00
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png");
2010-09-24 02:48:03 +02:00
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this);
arrowUpBtn->SetImage(arrowUpImg);
arrowUpBtn->SetImageOver(arrowUpOverImg);
arrowUpBtn->SetImageHold(arrowUpOverImg);
arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18);
arrowUpBtn->SetSelectable(false);
arrowUpBtn->SetTrigger(trigA);
arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowUpBtn->SetSoundClick(btnSoundClick);
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
arrowDownBtn->SetParent(this);
arrowDownBtn->SetImage(arrowDownImg);
arrowDownBtn->SetImageOver(arrowDownOverImg);
arrowDownBtn->SetImageHold(arrowDownOverImg);
arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18);
arrowDownBtn->SetSelectable(false);
arrowDownBtn->SetTrigger(trigA);
arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120);
scrollbarBoxBtn->SetMinY(0);
scrollbarBoxBtn->SetMaxY(height);
scrollbarBoxBtn->SetHoldable(true);
scrollbarBoxBtn->SetTrigger(trigHeldA);
}
2010-09-24 02:48:03 +02:00
// optionBg = new GuiImage(bgOptionsEntry);
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
optionTxt[i] = new GuiText((char *) NULL, 20, ( GXColor )
{ 0, 0, 0, 0xff});
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionTxt[i]->SetPosition(24, 0);
optionBg[i] = new GuiImage(bgOptionsEntry);
optionVal[i] = new GuiText((char *) NULL, 20, ( GXColor )
{ 0, 0, 0, 0xff});
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionVal[i]->SetPosition(250, 0);
optionBtn[i] = new GuiButton(width - 28, GAMESELECTSIZE);
optionBtn[i]->SetParent(this);
optionBtn[i]->SetLabel(optionTxt[i], 0);
optionBtn[i]->SetLabel(optionVal[i], 1);
optionBtn[i]->SetImageOver(optionBg[i]);
optionBtn[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
optionBtn[i]->SetRumble(false);
optionBtn[i]->SetTrigger(trigA);
optionBtn[i]->SetSoundClick(btnSoundClick);
}
}
/**
* Constructor for the GuiOptionBrowser class.
*/
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char *imagebg, int scrollon, int start)
{
width = w;
height = h;
options = l;
2010-09-24 02:48:03 +02:00
startat = start;
loaded = 0;
scrollbaron = scrollon;
selectable = true;
2010-09-24 02:48:03 +02:00
listOffset = this->FindMenuItem(-1, 1);
selectedItem = 0;
focus = 1; // allow focus
trigA = new GuiTrigger;
2010-09-24 02:48:03 +02:00
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
trigHeldA = new GuiTrigger;
2010-09-24 02:48:03 +02:00
trigHeldA->SetHeldTrigger(-1, WPAD_BUTTON_A, PAD_BUTTON_A);
btnSoundClick = new GuiSound(button_click_pcm, button_click_pcm_size, Settings.sfxvolume);
bgOptions = Resources::GetImageData(imagebg);
2010-09-24 02:48:03 +02:00
bgOptionsImg = new GuiImage(bgOptions);
bgOptionsImg->SetParent(this);
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
scrollbar = Resources::GetImageData("scrollbar.png");
2010-09-24 02:48:03 +02:00
scrollbarImg = new GuiImage(scrollbar);
scrollbarImg->SetParent(this);
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarImg->SetPosition(0, 4);
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
2010-09-24 02:48:03 +02:00
arrowDownImg = new GuiImage(arrowDown);
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
2010-09-24 02:48:03 +02:00
arrowDownOverImg = new GuiImage(arrowDownOver);
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
2010-09-24 02:48:03 +02:00
arrowUpImg = new GuiImage(arrowUp);
arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png");
2010-09-24 02:48:03 +02:00
arrowUpOverImg = new GuiImage(arrowUpOver);
scrollbarBox = Resources::GetImageData("scrollbar_box.png");
2010-09-24 02:48:03 +02:00
scrollbarBoxImg = new GuiImage(scrollbarBox);
scrollbarBoxOver = Resources::GetImageData("scrollbar_box.png");
2010-09-24 02:48:03 +02:00
scrollbarBoxOverImg = new GuiImage(scrollbarBoxOver);
arrowUpBtn = new GuiButton(arrowUpImg->GetWidth(), arrowUpImg->GetHeight());
arrowUpBtn->SetParent(this);
arrowUpBtn->SetImage(arrowUpImg);
arrowUpBtn->SetImageOver(arrowUpOverImg);
arrowUpBtn->SetImageHold(arrowUpOverImg);
arrowUpBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
arrowUpBtn->SetPosition(width / 2 - 18 + 7, -18);
arrowUpBtn->SetSelectable(false);
arrowUpBtn->SetTrigger(trigA);
arrowUpBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowUpBtn->SetSoundClick(btnSoundClick);
arrowDownBtn = new GuiButton(arrowDownImg->GetWidth(), arrowDownImg->GetHeight());
arrowDownBtn->SetParent(this);
arrowDownBtn->SetImage(arrowDownImg);
arrowDownBtn->SetImageOver(arrowDownOverImg);
arrowDownBtn->SetImageHold(arrowDownOverImg);
arrowDownBtn->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
arrowDownBtn->SetPosition(width / 2 - 18 + 7, 18);
arrowDownBtn->SetSelectable(false);
arrowDownBtn->SetTrigger(trigA);
arrowDownBtn->SetEffectOnOver(EFFECT_SCALE, 50, 130);
arrowDownBtn->SetSoundClick(btnSoundClick);
scrollbarBoxBtn = new GuiButton(scrollbarBoxImg->GetWidth(), scrollbarBoxImg->GetHeight());
scrollbarBoxBtn->SetParent(this);
scrollbarBoxBtn->SetImage(scrollbarBoxImg);
scrollbarBoxBtn->SetImageOver(scrollbarBoxOverImg);
scrollbarBoxBtn->SetImageHold(scrollbarBoxOverImg);
scrollbarBoxBtn->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
scrollbarBoxBtn->SetSelectable(false);
scrollbarBoxBtn->SetEffectOnOver(EFFECT_SCALE, 50, 120);
scrollbarBoxBtn->SetMinY(0);
scrollbarBoxBtn->SetMaxY(height - 30);
scrollbarBoxBtn->SetHoldable(true);
scrollbarBoxBtn->SetTrigger(trigHeldA);
}
2010-09-24 02:48:03 +02:00
// optionBg = new GuiImage(bgOptionsEntry);
for (int i = 0; i < PAGESIZE; i++)
{
optionTxt[i] = new GuiText(options->GetName(i), 20, ( GXColor ) {0, 0, 0, 0xff});
2010-09-24 02:48:03 +02:00
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionTxt[i]->SetPosition(24, 0);
optionBg[i] = new GuiImage(bgOptionsEntry);
optionVal[i] = new GuiText((char *) NULL, 20, ( GXColor )
{ 0, 0, 0, 0xff});
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
optionVal[i]->SetPosition(250, 0);
optionBtn[i] = new GuiButton(width - 28, GAMESELECTSIZE);
optionBtn[i]->SetParent(this);
optionBtn[i]->SetLabel(optionTxt[i], 0);
optionBtn[i]->SetLabel(optionVal[i], 1);
optionBtn[i]->SetImageOver(optionBg[i]);
optionBtn[i]->SetPosition(5, GAMESELECTSIZE * i + 4);
optionBtn[i]->SetTrigger(trigA);
optionBtn[i]->SetSoundClick(btnSoundClick);
}
}
/**
* Destructor for the GuiOptionBrowser class.
*/
GuiOptionBrowser::~GuiOptionBrowser()
{
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
delete arrowUpBtn;
delete arrowDownBtn;
delete scrollbarBoxBtn;
delete scrollbarImg;
delete arrowDownImg;
delete arrowDownOverImg;
delete arrowUpImg;
delete arrowUpOverImg;
delete scrollbarBoxImg;
delete scrollbarBoxOverImg;
delete scrollbar;
delete arrowDown;
delete arrowDownOver;
delete arrowUp;
delete arrowUpOver;
delete scrollbarBox;
delete scrollbarBoxOver;
}
delete bgOptionsImg;
delete bgOptions;
delete bgOptionsEntry;
loaded = 0;
delete trigA;
delete btnSoundClick;
2010-09-24 02:48:03 +02:00
// delete optionBg;
for (int i = 0; i < PAGESIZE; i++)
{
delete optionTxt[i];
delete optionVal[i];
delete optionBg[i];
delete optionBtn[i];
}
}
2010-09-24 02:48:03 +02:00
void GuiOptionBrowser::SetCol2Position(int x)
{
LOCK( this );
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
optionVal[i]->SetPosition(x, 0);
}
2010-09-24 02:48:03 +02:00
void GuiOptionBrowser::SetFocus(int f)
{
LOCK( this );
focus = f;
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
optionBtn[i]->ResetState();
2010-09-24 02:48:03 +02:00
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
}
void GuiOptionBrowser::ResetState()
{
LOCK( this );
2010-09-24 02:48:03 +02:00
if (state != STATE_DISABLED)
{
state = STATE_DEFAULT;
stateChan = -1;
}
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
optionBtn[i]->ResetState();
}
}
int GuiOptionBrowser::GetClickedOption()
{
int found = -1;
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
if (optionBtn[i]->GetState() == STATE_CLICKED)
{
2010-09-24 02:48:03 +02:00
optionBtn[i]->SetState(STATE_SELECTED);
found = optionIndex[i];
break;
}
}
return found;
}
int GuiOptionBrowser::GetSelectedOption()
{
int found = -1;
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
if (optionBtn[i]->GetState() == STATE_SELECTED)
{
2010-09-24 02:48:03 +02:00
optionBtn[i]->SetState(STATE_SELECTED);
found = optionIndex[i];
break;
}
}
return found;
}
/****************************************************************************
* FindMenuItem
*
* Help function to find the next visible menu item on the list
***************************************************************************/
2010-09-24 02:48:03 +02:00
int GuiOptionBrowser::FindMenuItem(int currentItem, int direction)
{
int nextItem = currentItem + direction;
if (nextItem < 0 || nextItem >= options->GetLength()) return -1;
if (options->GetName(nextItem) && strlen(options->GetName(nextItem)) > 0)
return nextItem;
else
return FindMenuItem(nextItem, direction);
}
/**
* Draw the button on screen
*/
void GuiOptionBrowser::Draw()
{
LOCK( this );
2010-09-24 02:48:03 +02:00
if (!this->IsVisible()) return;
bgOptionsImg->Draw();
int next = listOffset;
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
if (next >= 0)
{
optionBtn[i]->Draw();
2010-09-24 02:48:03 +02:00
next = this->FindMenuItem(next, 1);
}
2010-09-24 02:48:03 +02:00
else break;
}
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
scrollbarImg->Draw();
arrowUpBtn->Draw();
arrowDownBtn->Draw();
scrollbarBoxBtn->Draw();
}
this->UpdateEffects();
}
void GuiOptionBrowser::TriggerUpdate()
{
listChanged = true;
}
2010-09-24 02:48:03 +02:00
void GuiOptionBrowser::Update(GuiTrigger * t)
{
LOCK( this );
int next, prev, lang = options->GetLength();
//go to the last game selected
2010-09-24 02:48:03 +02:00
if ((loaded == 0) && (startat > 0))
{
2010-09-24 02:48:03 +02:00
if (startat > (lang - 9))
{
2010-09-24 02:48:03 +02:00
listOffset = (lang - 9);
selectedItem = startat;
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan);
}
2010-09-24 02:48:03 +02:00
else if (startat < 9)
{
selectedItem = startat;
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan);
}
else if(startat < PAGESIZE)
{
2010-09-24 02:48:03 +02:00
listOffset = (startat - 4);
selectedItem = startat;
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem]->SetState(STATE_SELECTED, t->chan);
}
2010-09-24 02:48:03 +02:00
this->SetFocus(1);
loaded = 1;
}
2010-09-24 02:48:03 +02:00
if (state == STATE_DISABLED || !t) return;
// scrolldelay affects how fast the list scrolls
// when the arrows are clicked
float scrolldelay = 3.5;
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
// update the location of the scroll box based on the position in the option list
2010-09-24 02:48:03 +02:00
arrowUpBtn->Update(t);
arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t);
}
next = listOffset;
2010-09-24 02:48:03 +02:00
if (listChanged)
{
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
if (next >= 0)
{
2010-09-24 02:48:03 +02:00
if (optionBtn[i]->GetState() == STATE_DISABLED)
{
2010-09-24 02:48:03 +02:00
optionBtn[i]->SetVisible(true);
optionBtn[i]->SetState(STATE_DEFAULT);
}
optionTxt[i]->SetText(options->GetName(next));
optionVal[i]->SetText(options->GetValue(next));
optionIndex[i] = next;
2010-09-24 02:48:03 +02:00
next = this->FindMenuItem(next, 1);
}
else
{
2010-09-24 02:48:03 +02:00
optionBtn[i]->SetVisible(false);
optionBtn[i]->SetState(STATE_DISABLED);
}
}
}
2010-09-24 02:48:03 +02:00
for (int i = 0; i < PAGESIZE; i++)
{
2010-09-24 02:48:03 +02:00
if (focus)
{
2010-09-24 02:48:03 +02:00
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
optionBtn[i]->ResetState();
2010-09-24 02:48:03 +02:00
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT) optionBtn[selectedItem]->SetState(
STATE_SELECTED, t->chan);
}
2010-09-24 02:48:03 +02:00
optionBtn[i]->Update(t);
2010-09-24 02:48:03 +02:00
if (optionBtn[i]->GetState() == STATE_SELECTED)
{
selectedItem = i;
}
}
// pad/joystick navigation
2010-09-24 02:48:03 +02:00
if (!focus) return; // skip navigation
2010-09-24 02:48:03 +02:00
if (scrollbaron == 1)
{
2010-09-24 02:48:03 +02:00
if (t->Down() || arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down
arrowDownBtn->GetState() == STATE_HELD)
{
2010-09-24 02:48:03 +02:00
next = this->FindMenuItem(optionIndex[selectedItem], 1);
2010-09-24 02:48:03 +02:00
if (next >= 0)
{
2010-09-24 02:48:03 +02:00
if (selectedItem == PAGESIZE - 1)
{
// move list down by 1
2010-09-24 02:48:03 +02:00
listOffset = this->FindMenuItem(listOffset, 1);
}
2010-09-24 02:48:03 +02:00
else if (optionBtn[selectedItem + 1]->IsVisible())
{
optionBtn[selectedItem]->ResetState();
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
2010-09-24 02:48:03 +02:00
usleep(10000 * scrolldelay);
2010-09-24 02:48:03 +02:00
}
WPAD_ScanPads();
u8 cnt, buttons = 0;
/* Get pressed buttons */
2010-09-24 02:48:03 +02:00
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A)
{
}
else
{
arrowDownBtn->ResetState();
}
}
2010-09-24 02:48:03 +02:00
else if (t->Up() || arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{
2010-09-24 02:48:03 +02:00
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
2010-09-24 02:48:03 +02:00
if (prev >= 0)
{
2010-09-24 02:48:03 +02:00
if (selectedItem == 0)
{
// move list up by 1
listOffset = prev;
}
else
{
optionBtn[selectedItem]->ResetState();
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
2010-09-24 02:48:03 +02:00
usleep(10000 * scrolldelay);
2010-09-24 02:48:03 +02:00
}
WPAD_ScanPads();
u8 cnt, buttons = 0;
/* Get pressed buttons */
2010-09-24 02:48:03 +02:00
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A)
{
}
else
{
arrowUpBtn->ResetState();
}
}
2010-09-24 02:48:03 +02:00
if (scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid
&& options->GetLength() > PAGESIZE)
{
2010-09-24 02:48:03 +02:00
scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, 0);
int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
2010-09-24 02:48:03 +02:00
listOffset = (position * lang) / 180 - selectedItem;
2010-09-24 02:48:03 +02:00
if (listOffset <= 0)
{
listOffset = 0;
selectedItem = 0;
}
2010-09-24 02:48:03 +02:00
else if (listOffset + PAGESIZE >= lang)
{
listOffset = lang - PAGESIZE;
selectedItem = PAGESIZE - 1;
}
}
2010-09-24 02:48:03 +02:00
int positionbar = 237 * (listOffset + selectedItem) / lang;
2010-09-24 02:48:03 +02:00
if (positionbar > 216) positionbar = 216;
scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, positionbar + 8);
2010-09-24 02:48:03 +02:00
if (t->Right())
{
2010-09-24 02:48:03 +02:00
if (listOffset < lang && lang > PAGESIZE)
{
listOffset = listOffset + PAGESIZE;
2010-09-24 02:48:03 +02:00
if (listOffset + PAGESIZE >= lang) listOffset = lang - PAGESIZE;
}
}
2010-09-24 02:48:03 +02:00
else if (t->Left())
{
2010-09-24 02:48:03 +02:00
if (listOffset > 0)
{
listOffset = listOffset - PAGESIZE;
2010-09-24 02:48:03 +02:00
if (listOffset < 0) listOffset = 0;
}
}
}
else
{
2010-09-24 02:48:03 +02:00
if (t->Down())
{
2010-09-24 02:48:03 +02:00
next = this->FindMenuItem(optionIndex[selectedItem], 1);
2010-09-24 02:48:03 +02:00
if (next >= 0)
{
2010-09-24 02:48:03 +02:00
if (selectedItem == PAGESIZE - 1)
{
// move list down by 1
2010-09-24 02:48:03 +02:00
listOffset = this->FindMenuItem(listOffset, 1);
listChanged = true;
}
2010-09-24 02:48:03 +02:00
else if (optionBtn[selectedItem + 1]->IsVisible())
{
optionBtn[selectedItem]->ResetState();
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
}
}
2010-09-24 02:48:03 +02:00
else if (t->Up())
{
2010-09-24 02:48:03 +02:00
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
2010-09-24 02:48:03 +02:00
if (prev >= 0)
{
2010-09-24 02:48:03 +02:00
if (selectedItem == 0)
{
// move list up by 1
listOffset = prev;
listChanged = true;
}
else
{
optionBtn[selectedItem]->ResetState();
2010-09-24 02:48:03 +02:00
optionBtn[selectedItem - 1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
}
}
}
2010-09-24 02:48:03 +02:00
if (updateCB) updateCB(this);
}