2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libwiigui
|
|
|
|
*
|
|
|
|
* gui_customoptionbrowser.cpp
|
|
|
|
*
|
|
|
|
* GUI class definitions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
#include "../wpad.h"
|
|
|
|
#include "../main.h"
|
2010-09-19 01:04:39 +02:00
|
|
|
#include "../gecko.h"
|
2010-09-19 22:25:12 +02:00
|
|
|
#include "../settings/CSettings.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "gui_customoptionbrowser.h"
|
2010-09-24 19:58:56 +02:00
|
|
|
#include "themes/CTheme.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define GAMESELECTSIZE 30
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the GuiCustomOptionBrowser class.
|
|
|
|
*/
|
2010-10-31 10:30:53 +01:00
|
|
|
GuiCustomOptionBrowser::GuiCustomOptionBrowser(int w, int h, OptionList * l, const char * custombg, int scrollon, int col2)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
width = w;
|
|
|
|
height = h;
|
|
|
|
options = l;
|
|
|
|
size = PAGESIZE;
|
|
|
|
scrollbaron = scrollon;
|
|
|
|
selectable = true;
|
2010-09-24 02:48:03 +02:00
|
|
|
listOffset = this->FindMenuItem(-1, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
selectedItem = 0;
|
|
|
|
focus = 1; // allow focus
|
|
|
|
coL2 = col2;
|
|
|
|
|
|
|
|
trigA = new GuiTrigger;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
2010-09-19 01:16:05 +02:00
|
|
|
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);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
bgOptions = Resources::GetImageData(custombg);
|
2010-09-24 02:48:03 +02:00
|
|
|
|
|
|
|
bgOptionsImg = new GuiImage(bgOptions);
|
|
|
|
bgOptionsImg->SetParent(this);
|
|
|
|
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
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);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
arrowDown = Resources::GetImageData("scrollbar_arrowdown.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
arrowDownImg = new GuiImage(arrowDown);
|
2010-09-26 10:33:43 +02:00
|
|
|
arrowDownOver = Resources::GetImageData("scrollbar_arrowdown.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
arrowDownOverImg = new GuiImage(arrowDownOver);
|
2010-09-26 10:33:43 +02:00
|
|
|
arrowUp = Resources::GetImageData("scrollbar_arrowup.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
arrowUpImg = new GuiImage(arrowUp);
|
2010-09-26 10:33:43 +02:00
|
|
|
arrowUpOver = Resources::GetImageData("scrollbar_arrowup.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
arrowUpOverImg = new GuiImage(arrowUpOver);
|
2010-09-26 10:33:43 +02:00
|
|
|
scrollbarBox = Resources::GetImageData("scrollbar_box.png");
|
2010-09-24 02:48:03 +02:00
|
|
|
scrollbarBoxImg = new GuiImage(scrollbarBox);
|
2010-09-26 10:33:43 +02:00
|
|
|
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-19 01:16:05 +02:00
|
|
|
|
|
|
|
optionIndex = new int[size];
|
2010-09-24 02:48:03 +02:00
|
|
|
optionVal = new GuiText *[size];
|
|
|
|
optionValOver = new GuiText *[size];
|
|
|
|
optionBtn = new GuiButton *[size];
|
|
|
|
optionTxt = new GuiText *[size];
|
|
|
|
optionBg = new GuiImage *[size];
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 19:58:56 +02:00
|
|
|
optionTxt[i] = new GuiText(options->GetName(i), 20, Theme.settingstext);
|
2010-09-24 02:48:03 +02:00
|
|
|
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
optionTxt[i]->SetPosition(24, 0);
|
|
|
|
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), DOTTED);
|
|
|
|
|
|
|
|
optionBg[i] = new GuiImage(bgOptionsEntry);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
optionVal[i] = new GuiText((char *) NULL, 20, Theme.settingstext);
|
2010-09-24 02:48:03 +02:00
|
|
|
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
|
2010-09-24 19:58:56 +02:00
|
|
|
optionValOver[i] = new GuiText((char *) NULL, 20, Theme.settingstext);
|
2010-09-24 02:48:03 +02:00
|
|
|
optionValOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
|
|
|
|
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]->SetLabelOver(optionValOver[i], 1);
|
|
|
|
optionBtn[i]->SetImageOver(optionBg[i]);
|
|
|
|
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
|
|
|
optionBtn[i]->SetRumble(false);
|
|
|
|
optionBtn[i]->SetTrigger(trigA);
|
|
|
|
optionBtn[i]->SetSoundClick(btnSoundClick);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
UpdateListEntries();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiCustomOptionBrowser class.
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
GuiCustomOptionBrowser::~GuiCustomOptionBrowser()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
delete trigA;
|
|
|
|
delete trigHeldA;
|
|
|
|
delete btnSoundClick;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
delete optionTxt[i];
|
|
|
|
delete optionVal[i];
|
|
|
|
delete optionValOver[i];
|
|
|
|
delete optionBg[i];
|
|
|
|
delete optionBtn[i];
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
delete[] optionIndex;
|
|
|
|
delete[] optionVal;
|
|
|
|
delete[] optionValOver;
|
|
|
|
delete[] optionBtn;
|
|
|
|
delete[] optionTxt;
|
|
|
|
delete[] optionBg;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiCustomOptionBrowser::SetFocus(int f)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
focus = f;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
optionBtn[i]->ResetState();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (f == 1) optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiCustomOptionBrowser::ResetState()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (state != STATE_DISABLED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
state = STATE_DEFAULT;
|
|
|
|
stateChan = -1;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
optionBtn[i]->ResetState();
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
int GuiCustomOptionBrowser::GetClickedOption()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
int found = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[i]->SetState(STATE_SELECTED);
|
2010-09-19 01:16:05 +02:00
|
|
|
found = optionIndex[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
int GuiCustomOptionBrowser::GetSelectedOption()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
int found = -1;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
found = optionIndex[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiCustomOptionBrowser::SetClickable(bool enable)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[i]->SetClickable(enable);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiCustomOptionBrowser::SetScrollbar(int enable)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
scrollbaron = enable;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiCustomOptionBrowser::SetOffset(int optionnumber)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
listOffset = optionnumber;
|
|
|
|
selectedItem = optionnumber;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* FindMenuItem
|
|
|
|
*
|
|
|
|
* Help function to find the next visible menu item on the list
|
|
|
|
***************************************************************************/
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int GuiCustomOptionBrowser::FindMenuItem(int currentItem, int direction)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
int nextItem = currentItem + direction;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (nextItem < 0 || nextItem >= options->GetLength()) return -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (strlen(options->GetName(nextItem)) > 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
return nextItem;
|
2010-09-24 02:48:03 +02:00
|
|
|
else return FindMenuItem(nextItem, direction);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the button on screen
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiCustomOptionBrowser::Draw()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!this->IsVisible()) return;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
bgOptionsImg->Draw();
|
|
|
|
|
|
|
|
int next = listOffset;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (next >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
optionBtn[i]->Draw();
|
2010-09-24 02:48:03 +02:00
|
|
|
next = this->FindMenuItem(next, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (scrollbaron == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
scrollbarImg->Draw();
|
|
|
|
arrowUpBtn->Draw();
|
|
|
|
arrowDownBtn->Draw();
|
|
|
|
scrollbarBoxBtn->Draw();
|
|
|
|
}
|
|
|
|
this->UpdateEffects();
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
void GuiCustomOptionBrowser::UpdateListEntries()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
scrollbaron = options->GetLength() > size;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset < 0) listOffset = this->FindMenuItem(-1, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
int next = listOffset;
|
|
|
|
|
|
|
|
int maxNameWidth = 0;
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (next >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[i]->SetVisible(true);
|
|
|
|
optionBtn[i]->SetState(STATE_DEFAULT);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
optionTxt[i]->SetText(options->GetName(next));
|
|
|
|
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
|
|
|
optionVal[i]->SetText(options->GetValue(next));
|
|
|
|
optionValOver[i]->SetText(options->GetValue(next));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
optionIndex[i] = next;
|
2010-09-24 02:48:03 +02:00
|
|
|
next = this->FindMenuItem(next, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[i]->SetVisible(false);
|
|
|
|
optionBtn[i]->SetState(STATE_DISABLED);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (coL2 < (24 + maxNameWidth + 16)) coL2 = 24 + maxNameWidth + 16;
|
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionVal[i]->SetPosition(coL2, 0);
|
|
|
|
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), DOTTED);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
optionValOver[i]->SetPosition(coL2, 0);
|
|
|
|
optionValOver[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + 24), SCROLL_HORIZONTAL);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiCustomOptionBrowser::Update(GuiTrigger * t)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
LOCK( this );
|
|
|
|
int next, prev, lang = options->GetLength();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (state == STATE_DISABLED || !t) return;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (options->IsChanged())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
coL2 = 0;
|
|
|
|
UpdateListEntries();
|
|
|
|
}
|
|
|
|
int old_listOffset = listOffset;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (scrollbaron == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// 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);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
next = listOffset;
|
|
|
|
|
|
|
|
u32 buttonshold = ButtonsHold();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (buttonshold != WPAD_BUTTON_UP && buttonshold != WPAD_BUTTON_DOWN)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < size; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (next >= 0) next = this->FindMenuItem(next, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (focus)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
optionBtn[i]->ResetState();
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[i]->Update(t);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
selectedItem = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// pad/joystick navigation
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!focus) return; // skip navigation
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (t->Down())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
next = this->FindMenuItem(optionIndex[selectedItem], 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (next >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selectedItem == size - 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// move list down by 1
|
2010-09-24 02:48:03 +02:00
|
|
|
listOffset = this->FindMenuItem(listOffset, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (optionBtn[selectedItem + 1]->IsVisible())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
optionBtn[selectedItem]->ResetState();
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan);
|
2010-09-19 01:16:05 +02:00
|
|
|
selectedItem++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (t->Up())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (prev >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selectedItem == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// 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);
|
2010-09-19 01:16:05 +02:00
|
|
|
selectedItem--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (scrollbaron == 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (arrowDownBtn->GetState() == STATE_CLICKED || arrowDownBtn->GetState() == STATE_HELD)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
next = this->FindMenuItem(optionIndex[selectedItem], 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (next >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selectedItem == size - 1)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// move list down by 1
|
2010-09-24 02:48:03 +02:00
|
|
|
listOffset = this->FindMenuItem(listOffset, 1);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (optionBtn[selectedItem + 1]->IsVisible())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
optionBtn[selectedItem]->ResetState();
|
2010-09-24 02:48:03 +02:00
|
|
|
optionBtn[selectedItem + 1]->SetState(STATE_SELECTED, t->chan);
|
2010-09-19 01:16:05 +02:00
|
|
|
selectedItem++;
|
|
|
|
}
|
|
|
|
scrollbarBoxBtn->Draw();
|
2010-09-24 02:48:03 +02:00
|
|
|
usleep(35000);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (buttonshold != WPAD_BUTTON_A)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
arrowDownBtn->ResetState();
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (arrowUpBtn->GetState() == STATE_CLICKED || arrowUpBtn->GetState() == STATE_HELD)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
prev = this->FindMenuItem(optionIndex[selectedItem], -1);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (prev >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (selectedItem == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
// 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);
|
2010-09-19 01:16:05 +02:00
|
|
|
selectedItem--;
|
|
|
|
}
|
|
|
|
scrollbarBoxBtn->Draw();
|
2010-09-24 02:48:03 +02:00
|
|
|
usleep(35000);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
if (buttonshold != WPAD_BUTTON_A)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
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() > size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, 0);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
listOffset = (position * lang) / 180 - selectedItem;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset <= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
listOffset = 0;
|
|
|
|
selectedItem = 0;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (listOffset + size >= lang)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
listOffset = lang - size;
|
|
|
|
selectedItem = size - 1;
|
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
int positionbar = 237 * (listOffset + selectedItem) / lang;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (positionbar > 216) positionbar = 216;
|
|
|
|
scrollbarBoxBtn->SetPosition(width / 2 - 18 + 7, positionbar + 8);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (t->Right())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset < lang && lang > size)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
listOffset = listOffset + size;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset + size >= lang) listOffset = lang - size;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (t->Left())
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset > 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
listOffset = listOffset - size;
|
2010-09-24 02:48:03 +02:00
|
|
|
if (listOffset < 0) listOffset = 0;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (old_listOffset != listOffset) UpdateListEntries();
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (updateCB) updateCB(this);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|