optimizations

This commit is contained in:
dborth 2010-01-25 07:34:45 +00:00
parent 775ad14651
commit 8e5eb64a5c
12 changed files with 224 additions and 158 deletions

View File

@ -223,11 +223,11 @@ class GuiTrigger
//!\return true if selection should be moved down, false otherwise //!\return true if selection should be moved down, false otherwise
bool Down(); bool Down();
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
WPADData * wpad; //!< Wii controller trigger
WPADData wpaddata; //!< Wii controller trigger data WPADData wpaddata; //!< Wii controller trigger data
PADData pad; //!< GameCube controller trigger data PADData pad; //!< GameCube controller trigger data
WPADData * wpad; //!< Wii controller trigger
s32 chan; //!< Trigger controller channel (0-3, -1 for all)
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
}; };
extern GuiTrigger userInput[4]; extern GuiTrigger userInput[4];
@ -399,7 +399,9 @@ class GuiElement
//!Called constantly to redraw the element //!Called constantly to redraw the element
virtual void Draw(); virtual void Draw();
protected: protected:
bool visible; //!< Visibility of the element. If false, Draw() is skipped GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to
UpdateCallback updateCB; //!< Callback function to call when this element is updated
GuiElement * parentElement; //!< Parent element
int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused) int focus; //!< Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
int width; //!< Element width int width; //!< Element width
int height; //!< Element height int height; //!< Element height
@ -412,10 +414,9 @@ class GuiElement
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects) int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects) int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
int alpha; //!< Element alpha value (0-255) int alpha; //!< Element alpha value (0-255)
f32 scale; //!< Element scale (1 = 100%)
int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects) int alphaDyn; //!< Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
f32 scale; //!< Element scale (1 = 100%)
f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects) f32 scaleDyn; //!< Element scale, dynamic (multiplied by alpha value for blending/fading effects)
bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
int effects; //!< Currently enabled effect(s). 0 when no effects are enabled int effects; //!< Currently enabled effect(s). 0 when no effects are enabled
int effectAmount; //!< Effect amount. Used by different effects for different purposes int effectAmount; //!< Effect amount. Used by different effects for different purposes
int effectTarget; //!< Effect target amount. Used by different effects for different purposes int effectTarget; //!< Effect target amount. Used by different effects for different purposes
@ -429,9 +430,8 @@ class GuiElement
bool selectable; //!< Whether or not this element selectable (can change to SELECTED state) bool selectable; //!< Whether or not this element selectable (can change to SELECTED state)
bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state) bool clickable; //!< Whether or not this element is clickable (can change to CLICKED state)
bool holdable; //!< Whether or not this element is holdable (can change to HELD state) bool holdable; //!< Whether or not this element is holdable (can change to HELD state)
GuiTrigger * trigger[2]; //!< GuiTriggers (input actions) that this element responds to bool visible; //!< Visibility of the element. If false, Draw() is skipped
GuiElement * parentElement; //!< Parent element bool rumble; //!< Wiimote rumble (on/off) - set to on when this element requests a rumble event
UpdateCallback updateCB; //!< Callback function to call when this element is updated
}; };
//!Allows GuiElements to be grouped together into a "window" //!Allows GuiElements to be grouped together into a "window"
@ -650,18 +650,18 @@ class GuiText : public GuiElement
//!Constantly called to draw the text //!Constantly called to draw the text
void Draw(); void Draw();
protected: protected:
char * origText; //!< Original text data GXColor color; //!< Font color
wchar_t* text; //!< Unicode text value wchar_t* text; //!< Unicode text value
wchar_t* textDyn; //!< Wrapped text value
char * origText; //!< Original text data
int size; //!< Font size int size; //!< Font size
int maxWidth; //!< Maximum width of the generated text object (for text wrapping) int maxWidth; //!< Maximum width of the generated text object (for text wrapping)
bool wrap; //!< Wrapping toggle
wchar_t* textDyn; //!< Wrapped text value
int textScroll; //!< Scrolling toggle int textScroll; //!< Scrolling toggle
int textScrollPos; //!< Current starting index of text string for scrolling int textScrollPos; //!< Current starting index of text string for scrolling
int textScrollInitialDelay; //!< Delay to wait before starting to scroll int textScrollInitialDelay; //!< Delay to wait before starting to scroll
int textScrollDelay; //!< Scrolling speed int textScrollDelay; //!< Scrolling speed
u16 style; //!< FreeTypeGX style attributes u16 style; //!< FreeTypeGX style attributes
GXColor color; //!< Font color bool wrap; //!< Wrapping toggle
}; };
//!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional) //!Display, manage, and manipulate buttons in the GUI. Buttons can have images, icons, text, and sound set (all of which are optional)
@ -760,7 +760,6 @@ class GuiKeyboard : public GuiWindow
char kbtextstr[256]; char kbtextstr[256];
protected: protected:
u32 kbtextmaxlen; u32 kbtextmaxlen;
Key keys[4][11];
int shift; int shift;
int caps; int caps;
GuiText * kbText; GuiText * kbText;
@ -794,6 +793,7 @@ class GuiKeyboard : public GuiWindow
GuiSound * keySoundOver; GuiSound * keySoundOver;
GuiSound * keySoundClick; GuiSound * keySoundClick;
GuiTrigger * trigA; GuiTrigger * trigA;
Key keys[4][11]; // two chars = less space than one pointer
}; };
typedef struct _optionlist { typedef struct _optionlist {
@ -818,16 +818,15 @@ class GuiOptionBrowser : public GuiElement
void Update(GuiTrigger * t); void Update(GuiTrigger * t);
GuiText * optionVal[PAGESIZE]; GuiText * optionVal[PAGESIZE];
protected: protected:
int selectedItem;
int listOffset;
bool listChanged;
OptionList * options;
int optionIndex[PAGESIZE]; int optionIndex[PAGESIZE];
GuiButton * optionBtn[PAGESIZE]; GuiButton * optionBtn[PAGESIZE];
GuiText * optionTxt[PAGESIZE]; GuiText * optionTxt[PAGESIZE];
GuiImage * optionBg[PAGESIZE]; GuiImage * optionBg[PAGESIZE];
int selectedItem;
int listOffset;
OptionList * options;
GuiButton * arrowUpBtn; GuiButton * arrowUpBtn;
GuiButton * arrowDownBtn; GuiButton * arrowDownBtn;
@ -849,6 +848,8 @@ class GuiOptionBrowser : public GuiElement
GuiSound * btnSoundOver; GuiSound * btnSoundOver;
GuiSound * btnSoundClick; GuiSound * btnSoundClick;
GuiTrigger * trigA; GuiTrigger * trigA;
bool listChanged;
}; };
typedef struct _savelist { typedef struct _savelist {
@ -874,10 +875,8 @@ class GuiSaveBrowser : public GuiElement
void Update(GuiTrigger * t); void Update(GuiTrigger * t);
protected: protected:
int selectedItem; int selectedItem;
int listOffset;
int action; int action;
bool saveBtnLastOver[SAVELISTSIZE]; int listOffset;
SaveList * saves; SaveList * saves;
GuiButton * saveBtn[SAVELISTSIZE]; GuiButton * saveBtn[SAVELISTSIZE];
GuiText * saveDate[SAVELISTSIZE]; GuiText * saveDate[SAVELISTSIZE];
@ -909,6 +908,8 @@ class GuiSaveBrowser : public GuiElement
GuiSound * btnSoundOver; GuiSound * btnSoundOver;
GuiSound * btnSoundClick; GuiSound * btnSoundClick;
GuiTrigger * trigA; GuiTrigger * trigA;
bool saveBtnLastOver[SAVELISTSIZE];
}; };
//!Display a list of files //!Display a list of files
@ -924,10 +925,6 @@ class GuiFileBrowser : public GuiElement
void Update(GuiTrigger * t); void Update(GuiTrigger * t);
GuiButton * fileList[FILE_PAGESIZE]; GuiButton * fileList[FILE_PAGESIZE];
protected: protected:
int selectedItem;
int numEntries;
bool listChanged;
GuiText * fileListText[FILE_PAGESIZE]; GuiText * fileListText[FILE_PAGESIZE];
GuiImage * fileListBg[FILE_PAGESIZE]; GuiImage * fileListBg[FILE_PAGESIZE];
GuiImage * fileListIcon[FILE_PAGESIZE]; GuiImage * fileListIcon[FILE_PAGESIZE];
@ -964,6 +961,10 @@ class GuiFileBrowser : public GuiElement
GuiSound * btnSoundClick; GuiSound * btnSoundClick;
GuiTrigger * trigA; GuiTrigger * trigA;
GuiTrigger * trigHeldA; GuiTrigger * trigHeldA;
int selectedItem;
int numEntries;
bool listChanged;
}; };
#endif #endif

View File

@ -130,23 +130,48 @@ void GuiButton::Draw()
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
// draw image if(state == STATE_SELECTED || state == STATE_HELD)
if((state == STATE_SELECTED || state == STATE_HELD) && imageOver)
imageOver->Draw();
else if(image)
image->Draw();
// draw icon
if((state == STATE_SELECTED || state == STATE_HELD) && iconOver)
iconOver->Draw();
else if(icon)
icon->Draw();
// draw text
for(int i=0; i<3; i++)
{ {
if((state == STATE_SELECTED || state == STATE_HELD) && labelOver[i]) if(imageOver)
labelOver[i]->Draw(); imageOver->Draw();
else if(label[i]) else if(image) // draw image
label[i]->Draw(); image->Draw();
if(iconOver)
iconOver->Draw();
else if(icon) // draw icon
icon->Draw();
// draw text
if(labelOver[0])
labelOver[0]->Draw();
else if(label[0])
label[0]->Draw();
if(labelOver[1])
labelOver[1]->Draw();
else if(label[1])
label[1]->Draw();
if(labelOver[2])
labelOver[2]->Draw();
else if(label[2])
label[2]->Draw();
}
else
{
if(image) // draw image
image->Draw();
if(icon) // draw icon
icon->Draw();
// draw text
if(label[0])
label[0]->Draw();
if(label[1])
label[1]->Draw();
if(label[2])
label[2]->Draw();
} }
this->UpdateEffects(); this->UpdateEffects();

View File

@ -91,7 +91,7 @@ int GuiElement::GetLeft()
x = pLeft; x = pLeft;
break; break;
case ALIGN_CENTRE: case ALIGN_CENTRE:
x = pLeft + (pWidth/2) - (width/2); x = pLeft + (pWidth>>1) - (width>>1);
break; break;
case ALIGN_RIGHT: case ALIGN_RIGHT:
x = pLeft + pWidth - width; x = pLeft + pWidth - width;
@ -121,7 +121,7 @@ int GuiElement::GetTop()
y = pTop; y = pTop;
break; break;
case ALIGN_MIDDLE: case ALIGN_MIDDLE:
y = pTop + (pHeight/2) - (height/2); y = pTop + (pHeight>>1) - (height>>1);
break; break;
case ALIGN_BOTTOM: case ALIGN_BOTTOM:
y = pTop + pHeight - height; y = pTop + pHeight - height;
@ -204,15 +204,13 @@ void GuiElement::SetAlpha(int a)
int GuiElement::GetAlpha() int GuiElement::GetAlpha()
{ {
int a; int a = alpha;
if(alphaDyn >= 0) if(alphaDyn >= 0)
a = alphaDyn; a = alphaDyn;
else
a = alpha;
if(parentElement) if(parentElement)
a *= parentElement->GetAlpha()/255.0; a *= float(parentElement->GetAlpha())/255.0f;
return a; return a;
} }
@ -352,13 +350,12 @@ void GuiElement::SetEffect(int eff, int amount, int target)
else if(eff & EFFECT_SLIDE_RIGHT) else if(eff & EFFECT_SLIDE_RIGHT)
xoffsetDyn = screenwidth; xoffsetDyn = screenwidth;
} }
if(eff & EFFECT_FADE && amount > 0) if(eff & EFFECT_FADE)
{ {
alphaDyn = 0; if(amount > 0)
} alphaDyn = 0;
else if(eff & EFFECT_FADE && amount < 0) else if(amount < 0)
{ alphaDyn = alpha;
alphaDyn = alpha;
} }
effects |= eff; effects |= eff;
@ -474,12 +471,13 @@ void GuiElement::UpdateEffects()
} }
if(effects & EFFECT_SCALE) if(effects & EFFECT_SCALE)
{ {
scaleDyn += effectAmount/100.0; scaleDyn += f32(effectAmount)*0.01f;
f32 effTar100 = f32(effectTarget)*0.01f;
if((effectAmount < 0 && scaleDyn <= effectTarget/100.0) if((effectAmount < 0 && scaleDyn <= effTar100)
|| (effectAmount > 0 && scaleDyn >= effectTarget/100.0)) || (effectAmount > 0 && scaleDyn >= effTar100))
{ {
scaleDyn = effectTarget/100.0; scaleDyn = effTar100;
effects = 0; // shut off effect effects = 0; // shut off effect
} }
} }
@ -522,8 +520,8 @@ void GuiElement::Draw()
bool GuiElement::IsInside(int x, int y) bool GuiElement::IsInside(int x, int y)
{ {
if(x > this->GetLeft() && x < (this->GetLeft()+width) if(unsigned(x - this->GetLeft()) < unsigned(width)
&& y > this->GetTop() && y < (this->GetTop()+height)) && unsigned(y - this->GetTop()) < unsigned(height))
return true; return true;
return false; return false;
} }

View File

@ -104,7 +104,7 @@ GuiFileBrowser::GuiFileBrowser(int w, int h)
scrollbarBoxBtn->SetHoldable(true); scrollbarBoxBtn->SetHoldable(true);
scrollbarBoxBtn->SetTrigger(trigHeldA); scrollbarBoxBtn->SetTrigger(trigHeldA);
for(int i=0; i<FILE_PAGESIZE; i++) for(int i=0; i<FILE_PAGESIZE; ++i)
{ {
fileListText[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff}); fileListText[i] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff});
fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); fileListText[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
@ -211,7 +211,7 @@ void GuiFileBrowser::Draw()
bgFileSelectionImg->Draw(); bgFileSelectionImg->Draw();
for(int i=0; i<FILE_PAGESIZE; i++) for(u32 i=0; i<FILE_PAGESIZE; ++i)
{ {
fileList[i]->Draw(); fileList[i]->Draw();
} }
@ -251,7 +251,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
else if(positionWiimote > scrollbarBoxBtn->GetMaxY()) else if(positionWiimote > scrollbarBoxBtn->GetMaxY())
positionWiimote = scrollbarBoxBtn->GetMaxY(); positionWiimote = scrollbarBoxBtn->GetMaxY();
browser.pageIndex = (positionWiimote * browser.numEntries)/156.0 - selectedItem; browser.pageIndex = (positionWiimote * browser.numEntries)/156.0f - selectedItem;
if(browser.pageIndex <= 0) if(browser.pageIndex <= 0)
{ {
@ -312,7 +312,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(selectedItem == FILE_PAGESIZE-1) if(selectedItem == FILE_PAGESIZE-1)
{ {
// move list down by 1 // move list down by 1
browser.pageIndex++; ++browser.pageIndex;
listChanged = true; listChanged = true;
} }
else if(fileList[selectedItem+1]->IsVisible()) else if(fileList[selectedItem+1]->IsVisible())
@ -327,7 +327,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(selectedItem == 0 && browser.pageIndex + selectedItem > 0) if(selectedItem == 0 && browser.pageIndex + selectedItem > 0)
{ {
// move list up by 1 // move list up by 1
browser.pageIndex--; --browser.pageIndex;
listChanged = true; listChanged = true;
} }
else if(selectedItem > 0) else if(selectedItem > 0)
@ -339,7 +339,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
endNavigation: endNavigation:
for(int i=0; i<FILE_PAGESIZE; i++) for(int i=0; i<FILE_PAGESIZE; ++i)
{ {
if(listChanged || numEntries != browser.numEntries) if(listChanged || numEntries != browser.numEntries)
{ {
@ -414,20 +414,24 @@ void GuiFileBrowser::Update(GuiTrigger * t)
} }
// update the location of the scroll box based on the position in the file list // update the location of the scroll box based on the position in the file list
if(positionWiimote > 0 || listChanged || numEntries != browser.numEntries) if(positionWiimote > 0)
{ {
if(positionWiimote > 0) position = positionWiimote; // follow wiimote cursor
scrollbarBoxBtn->SetPosition(0,position+36);
}
else if(listChanged || numEntries != browser.numEntries)
{
if(float((browser.pageIndex<<1))/(float(FILE_PAGESIZE)) < 1.0)
{ {
position = positionWiimote; // follow wiimote cursor position = 0;
}
else if(browser.pageIndex+FILE_PAGESIZE >= browser.numEntries)
{
position = 156;
} }
else else
{ {
position = 156*(browser.pageIndex + FILE_PAGESIZE/2.0) / (browser.numEntries*1.0); position = 156* (int((float(browser.pageIndex) + float(FILE_PAGESIZE)*0.5f) / (float(browser.numEntries))));
if(browser.pageIndex/(FILE_PAGESIZE/2.0) < 1)
position = 0;
else if((browser.pageIndex+FILE_PAGESIZE)/(FILE_PAGESIZE*1.0) >= (browser.numEntries)/(FILE_PAGESIZE*1.0))
position = 156;
} }
scrollbarBoxBtn->SetPosition(0,position+36); scrollbarBoxBtn->SetPosition(0,position+36);
} }

View File

@ -53,7 +53,7 @@ GuiImage::GuiImage(u8 * img, int w, int h)
GuiImage::GuiImage(int w, int h, GXColor c) GuiImage::GuiImage(int w, int h, GXColor c)
{ {
image = (u8 *)memalign (32, w * h * 4); image = (u8 *)memalign (32, w * h << 2);
width = w; width = w;
height = h; height = h;
imageangle = 0; imageangle = 0;
@ -66,14 +66,14 @@ GuiImage::GuiImage(int w, int h, GXColor c)
int x, y; int x, y;
for(y=0; y < h; y++) for(y=0; y < h; ++y)
{ {
for(x=0; x < w; x++) for(x=0; x < w; ++x)
{ {
this->SetPixel(x, y, c); this->SetPixel(x, y, c);
} }
} }
int len = w*h*4; int len = w * h << 2;
if(len%32) len += (32-len%32); if(len%32) len += (32-len%32);
DCFlushRange(image, len); DCFlushRange(image, len);
} }
@ -157,21 +157,24 @@ void GuiImage::SetStripe(int s)
void GuiImage::ColorStripe(int shift) void GuiImage::ColorStripe(int shift)
{ {
int x, y;
GXColor color; GXColor color;
int x, y=0;
int alt = 0; int alt = 0;
int thisHeight = this->GetHeight();
int thisWidth = this->GetWidth();
for(y=0; y < this->GetHeight(); y++) for(; y < thisHeight; ++y)
{ {
if(y % 3 == 0) if(y % 3 == 0)
alt ^= 1; alt ^= 1;
for(x=0; x < this->GetWidth(); x++) if(alt)
{ {
color = GetPixel(x, y); for(x=0; x < thisWidth; ++x)
if(alt)
{ {
color = GetPixel(x, y);
if(color.r < 255-shift) if(color.r < 255-shift)
color.r += shift; color.r += shift;
else else
@ -186,9 +189,15 @@ void GuiImage::ColorStripe(int shift)
color.b = 255; color.b = 255;
color.a = 255; color.a = 255;
SetPixel(x, y, color);
} }
else }
else
{
for(x=0; x < thisWidth; ++x)
{ {
color = GetPixel(x, y);
if(color.r > shift) if(color.r > shift)
color.r -= shift; color.r -= shift;
else else
@ -203,8 +212,8 @@ void GuiImage::ColorStripe(int shift)
color.b = 0; color.b = 0;
color.a = 255; color.a = 255;
SetPixel(x, y, color);
} }
SetPixel(x, y, color);
} }
} }
} }
@ -219,24 +228,31 @@ void GuiImage::Draw()
float currScale = this->GetScale(); float currScale = this->GetScale();
int currLeft = this->GetLeft(); int currLeft = this->GetLeft();
int thisTop = this->GetTop();
if(tile > 0) if(tile > 0)
{ {
for(int i=0; i<tile; i++) int alpha = this->GetAlpha();
Menu_DrawImg(currLeft+width*i, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha()); for(int i=0; i<tile; ++i)
{
Menu_DrawImg(currLeft+width*i, thisTop, width, height, image, imageangle, currScale, currScale, alpha);
}
} }
else else
{ {
// temporary (maybe), used to correct offset for scaled images // temporary (maybe), used to correct offset for scaled images
if(scale != 1) if(scale != 1)
currLeft = currLeft - width/2 + (width*scale)/2; currLeft += (width*(scale - 1))/2;
Menu_DrawImg(currLeft, this->GetTop(), width, height, image, imageangle, currScale, currScale, this->GetAlpha()); Menu_DrawImg(currLeft, thisTop, width, height, image, imageangle, currScale, currScale, this->GetAlpha());
} }
if(stripe > 0) if(stripe > 0)
for(int y=0; y < this->GetHeight(); y+=6) {
Menu_DrawRectangle(currLeft,this->GetTop()+y,this->GetWidth(),3,(GXColor){0, 0, 0, stripe},1); int thisHeight = this->GetHeight();
int thisWidth = this->GetWidth();
for(int y=0; y < thisHeight; y+=6)
Menu_DrawRectangle(currLeft,thisTop+y,thisWidth,3,(GXColor){0, 0, 0, stripe},1);
}
this->UpdateEffects(); this->UpdateEffects();
} }

View File

@ -31,7 +31,7 @@ GuiImageData::GuiImageData(const u8 * i)
if(res == PNGU_OK) if(res == PNGU_OK)
{ {
int len = imgProp.imgWidth * imgProp.imgHeight * 4; int len = (imgProp.imgWidth * imgProp.imgHeight) <<2;
if(len%32) len += (32-len%32); if(len%32) len += (32-len%32);
data = (u8 *)memalign (32, len); data = (u8 *)memalign (32, len);

View File

@ -211,7 +211,7 @@ void GuiOptionBrowser::Draw()
int next = listOffset; int next = listOffset;
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; ++i)
{ {
if(next >= 0) if(next >= 0)
{ {
@ -249,7 +249,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
if(listChanged) if(listChanged)
{ {
listChanged = false; listChanged = false;
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; ++i)
{ {
if(next >= 0) if(next >= 0)
{ {
@ -272,7 +272,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
} }
} }
for(int i=0; i<PAGESIZE; i++) for(int i=0; i<PAGESIZE; ++i)
{ {
if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED) if(i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
optionBtn[i]->ResetState(); optionBtn[i]->ResetState();
@ -311,7 +311,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
{ {
optionBtn[selectedItem]->ResetState(); optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem+1]->SetState(STATE_SELECTED, t->chan); optionBtn[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++; ++selectedItem;
} }
} }
arrowDownBtn->ResetState(); arrowDownBtn->ResetState();
@ -332,7 +332,7 @@ void GuiOptionBrowser::Update(GuiTrigger * t)
{ {
optionBtn[selectedItem]->ResetState(); optionBtn[selectedItem]->ResetState();
optionBtn[selectedItem-1]->SetState(STATE_SELECTED, t->chan); optionBtn[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--; --selectedItem;
} }
} }
arrowUpBtn->ResetState(); arrowUpBtn->ResetState();

View File

@ -107,7 +107,7 @@ GuiSaveBrowser::GuiSaveBrowser(int w, int h, SaveList * s, int a)
saveBtn[i]->SetImageOver(saveBgOverImg[i]); saveBtn[i]->SetImageOver(saveBgOverImg[i]);
saveBtn[i]->SetIcon(savePreviewImg[i]); saveBtn[i]->SetIcon(savePreviewImg[i]);
saveBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP); saveBtn[i]->SetAlignment(ALIGN_LEFT, ALIGN_TOP);
saveBtn[i]->SetPosition(257*(i % 2),87*(i/2)); saveBtn[i]->SetPosition(257*(i % 2),87*(i>>1));
saveBtn[i]->SetTrigger(trigA); saveBtn[i]->SetTrigger(trigA);
saveBtn[i]->SetState(STATE_DISABLED); saveBtn[i]->SetState(STATE_DISABLED);
saveBtn[i]->SetEffectGrow(); saveBtn[i]->SetEffectGrow();
@ -257,7 +257,7 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
if(selectedItem == 0) if(selectedItem == 0)
{ {
if((listOffset - 2 >= 0 && action == 0) || if((listOffset - 2 >= 0 && action == 0) ||
(listOffset - 2 >= -2 && action == 1)) (listOffset >= 0 && action == 1))
{ {
// move list up by 1 // move list up by 1
listOffset -= 2; listOffset -= 2;
@ -295,7 +295,7 @@ void GuiSaveBrowser::Update(GuiTrigger * t)
if(selectedItem < 2) if(selectedItem < 2)
{ {
if((listOffset - 2 >= 0 && action == 0) || if((listOffset - 2 >= 0 && action == 0) ||
(listOffset - 2 >= -2 && action == 1)) (listOffset >= 0 && action == 1))
{ {
// move list up by 1 // move list up by 1
listOffset -= 2; listOffset -= 2;

View File

@ -42,7 +42,7 @@ void GuiSound::Play()
switch(type) switch(type)
{ {
case SOUND_PCM: case SOUND_PCM:
vol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0); vol = 2.55f*(volume*GCSettings.SFXVolume);
voice = ASND_GetFirstUnusedVoice(); voice = ASND_GetFirstUnusedVoice();
if(voice >= 0) if(voice >= 0)
ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0, ASND_SetVoice(voice, VOICE_STEREO_16BIT, 48000, 0,
@ -55,7 +55,7 @@ void GuiSound::Play()
PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME); PlayOgg((char *)sound, length, 0, OGG_INFINITE_TIME);
else else
PlayOgg((char *)sound, length, 0, OGG_ONE_TIME); PlayOgg((char *)sound, length, 0, OGG_ONE_TIME);
SetVolumeOgg(255*(volume/100.0)); SetVolumeOgg(2.55f*(volume));
break; break;
} }
#endif #endif
@ -134,7 +134,7 @@ void GuiSound::SetVolume(int vol)
if(voice < 0) if(voice < 0)
return; return;
int newvol = 255*(volume/100.0)*(GCSettings.SFXVolume/100.0); int newvol = 2.55f*(volume*GCSettings.SFXVolume);
switch(type) switch(type)
{ {
@ -143,7 +143,7 @@ void GuiSound::SetVolume(int vol)
break; break;
case SOUND_OGG: case SOUND_OGG:
SetVolumeOgg(255*(volume/100.0)); SetVolumeOgg(2.55f*(volume));
break; break;
} }
#endif #endif

View File

@ -10,13 +10,13 @@
#include "gui.h" #include "gui.h"
static GXColor presetColor = (GXColor){255, 255, 255, 255};
static int currentSize = 0; static int currentSize = 0;
static int presetSize = 0; static int presetSize = 0;
static int presetMaxWidth = 0; static int presetMaxWidth = 0;
static int presetAlignmentHor = 0; static int presetAlignmentHor = 0;
static int presetAlignmentVert = 0; static int presetAlignmentVert = 0;
static u16 presetStyle = 0; static u16 presetStyle = 0;
static GXColor presetColor = (GXColor){255, 255, 255, 255};
#define TEXT_SCROLL_DELAY 8 #define TEXT_SCROLL_DELAY 8
#define TEXT_SCROLL_INITIAL_DELAY 6 #define TEXT_SCROLL_INITIAL_DELAY 6
@ -230,7 +230,7 @@ void GuiText::Draw()
if(maxWidth > 0) if(maxWidth > 0)
{ {
char * tmpText = strdup(origText); char * tmpText = strdup(origText);
u8 maxChar = (maxWidth*2.0) / newSize; u8 maxChar = int((float((maxWidth<<1))) / (float(newSize)));
if(!textDyn) if(!textDyn)
{ {
@ -247,11 +247,11 @@ void GuiText::Draw()
{ {
if(textScrollInitialDelay) if(textScrollInitialDelay)
{ {
textScrollInitialDelay--; --textScrollInitialDelay;
} }
else else
{ {
textScrollPos++; ++textScrollPos;
if(textScrollPos > textlen-1) if(textScrollPos > textlen-1)
{ {
textScrollPos = 0; textScrollPos = 0;
@ -306,12 +306,12 @@ void GuiText::Draw()
lastSpace = -1; // we have used this space lastSpace = -1; // we have used this space
lastSpaceIndex = -1; lastSpaceIndex = -1;
} }
linenum++; ++linenum;
i = -1; i = -1;
} }
else if(ch == txtlen-1) else if(ch == txtlen-1)
{ {
linenum++; ++linenum;
} }
} }
if(text[ch] == ' ' && i >= 0) if(text[ch] == ' ' && i >= 0)
@ -319,18 +319,21 @@ void GuiText::Draw()
lastSpace = ch; lastSpace = ch;
lastSpaceIndex = i; lastSpaceIndex = i;
} }
ch++; ++ch;
i++; ++i;
} }
int voffset = 0; int voffset = 0;
if(alignmentVert == ALIGN_MIDDLE) if(alignmentVert == ALIGN_MIDDLE)
voffset = -(lineheight*linenum)/2 + lineheight/2; voffset = (lineheight >> 1) * (1-linenum);
for(i=0; i < linenum; i++) int left = this->GetLeft();
int top = this->GetTop() + voffset;
for(i=0; i < linenum; ++i)
{ {
fontSystem[currentSize]->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, textrow[i], c, style); fontSystem[currentSize]->drawText(left, top+i*lineheight, textrow[i], c, style);
delete[] textrow[i]; delete[] textrow[i];
} }
} }

View File

@ -53,7 +53,8 @@ void GuiWindow::Remove(GuiElement* e)
if (e == NULL) if (e == NULL)
return; return;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
if(e == _elements.at(i)) if(e == _elements.at(i))
{ {
@ -85,7 +86,8 @@ void GuiWindow::Draw()
if(_elements.size() == 0 || !this->IsVisible()) if(_elements.size() == 0 || !this->IsVisible())
return; return;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try { _elements.at(i)->Draw(); } try { _elements.at(i)->Draw(); }
catch (const std::exception& e) { } catch (const std::exception& e) { }
@ -102,7 +104,8 @@ void GuiWindow::ResetState()
if(state != STATE_DISABLED) if(state != STATE_DISABLED)
state = STATE_DEFAULT; state = STATE_DEFAULT;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try { _elements.at(i)->ResetState(); } try { _elements.at(i)->ResetState(); }
catch (const std::exception& e) { } catch (const std::exception& e) { }
@ -113,7 +116,8 @@ void GuiWindow::SetState(int s)
{ {
state = s; state = s;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try { _elements.at(i)->SetState(s); } try { _elements.at(i)->SetState(s); }
catch (const std::exception& e) { } catch (const std::exception& e) { }
@ -124,7 +128,8 @@ void GuiWindow::SetVisible(bool v)
{ {
visible = v; visible = v;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try { _elements.at(i)->SetVisible(v); } try { _elements.at(i)->SetVisible(v); }
catch (const std::exception& e) { } catch (const std::exception& e) { }
@ -146,7 +151,8 @@ void GuiWindow::ChangeFocus(GuiElement* e)
if(parentElement) if(parentElement)
return; // this is only intended for the main window return; // this is only intended for the main window
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
if(e == _elements.at(i)) if(e == _elements.at(i))
_elements.at(i)->SetFocus(1); _elements.at(i)->SetFocus(1);
@ -162,10 +168,12 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
int found = -1; int found = -1;
int newfocus = -1; int newfocus = -1;
u8 i; int i;
int elemSize = _elements.size();
// look for currently in focus element // look for currently in focus element
for (i = 0; i < _elements.size(); i++) for (i = 0; i < elemSize; ++i)
{ {
try try
{ {
@ -181,7 +189,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
// element with focus not found, try to give focus // element with focus not found, try to give focus
if(found == -1) if(found == -1)
{ {
for (i = 0; i < _elements.size(); i++) for (i = 0; i < elemSize; ++i)
{ {
try try
{ {
@ -198,7 +206,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
else if(t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) else if(t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
|| t->pad.btns_d & PAD_BUTTON_B) || t->pad.btns_d & PAD_BUTTON_B)
{ {
for (i = found; i < _elements.size(); i++) for (i = found; i < elemSize; ++i)
{ {
try try
{ {
@ -215,7 +223,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
if(newfocus == -1) if(newfocus == -1)
{ {
for (i = 0; i < found; i++) for (i = 0; i < found; ++i)
{ {
try try
{ {
@ -236,13 +244,14 @@ int GuiWindow::GetSelected()
{ {
// find selected element // find selected element
int found = -1; int found = -1;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try try
{ {
if(_elements.at(i)->GetState() == STATE_SELECTED) if(_elements.at(i)->GetState() == STATE_SELECTED)
{ {
found = i; found = int(i);
break; break;
} }
} }
@ -258,7 +267,8 @@ void GuiWindow::MoveSelectionHor(int dir)
int found = -1; int found = -1;
u16 left = 0; u16 left = 0;
u16 top = 0; u16 top = 0;
u8 i = 0; u32 i;
u32 elemSize = _elements.size();
int selected = this->GetSelected(); int selected = this->GetSelected();
@ -268,8 +278,9 @@ void GuiWindow::MoveSelectionHor(int dir)
top = _elements.at(selected)->GetTop(); top = _elements.at(selected)->GetTop();
} }
// look for a button on the same row, to the left/right // look for a button on the same row, to the left/right
for (i = 0; i < _elements.size(); i++) for (i = 0; i < elemSize; ++i)
{ {
try try
{ {
@ -278,9 +289,9 @@ void GuiWindow::MoveSelectionHor(int dir)
if(_elements.at(i)->GetLeft()*dir > left*dir && _elements.at(i)->GetTop() == top) if(_elements.at(i)->GetLeft()*dir > left*dir && _elements.at(i)->GetTop() == top)
{ {
if(found == -1) if(found == -1)
found = i; found = int(i);
else if(_elements.at(i)->GetLeft()*dir < _elements.at(found)->GetLeft()*dir) else if(_elements.at(i)->GetLeft()*dir < _elements.at(found)->GetLeft()*dir)
found = i; // this is a better match found = int(i); // this is a better match
} }
} }
} }
@ -290,7 +301,7 @@ void GuiWindow::MoveSelectionHor(int dir)
goto matchfound; goto matchfound;
// match still not found, let's try the first button in the next row // match still not found, let's try the first button in the next row
for (i = 0; i < _elements.size(); i++) for (i = 0; i < elemSize; ++i)
{ {
try try
{ {
@ -327,7 +338,6 @@ void GuiWindow::MoveSelectionVert(int dir)
int found = -1; int found = -1;
u16 left = 0; u16 left = 0;
u16 top = 0; u16 top = 0;
u8 i = 0;
int selected = this->GetSelected(); int selected = this->GetSelected();
@ -338,7 +348,8 @@ void GuiWindow::MoveSelectionVert(int dir)
} }
// look for a button above/below, with the least horizontal difference // look for a button above/below, with the least horizontal difference
for (i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try try
{ {
@ -378,7 +389,8 @@ void GuiWindow::Update(GuiTrigger * t)
if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement)) if(_elements.size() == 0 || (state == STATE_DISABLED && parentElement))
return; return;
for (u8 i = 0; i < _elements.size(); i++) u32 elemSize = _elements.size();
for (u32 i = 0; i < elemSize; ++i)
{ {
try { _elements.at(i)->Update(t); } try { _elements.at(i)->Update(t); }
catch (const std::exception& e) { } catch (const std::exception& e) { }

View File

@ -264,19 +264,23 @@ UpdateGUI (void *arg)
mainWindow->Draw(); mainWindow->Draw();
#ifdef HW_RVL #ifdef HW_RVL
for(i=3; i >= 0; i--) // so that player 1's cursor appears on top! i = 3;
do
{ {
if(userInput[i].wpad->ir.valid) if(userInput[i].wpad->ir.valid)
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48, Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255); 96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
DoRumble(i); DoRumble(i);
} --i;
} while(i>=0);
#endif #endif
Menu_Render(); Menu_Render();
for(i=3; i >= 0; i--) mainWindow->Update(&userInput[3]);
mainWindow->Update(&userInput[i]); mainWindow->Update(&userInput[2]);
mainWindow->Update(&userInput[1]);
mainWindow->Update(&userInput[0]);
#ifdef HW_RVL #ifdef HW_RVL
if(updateFound) if(updateFound)
@ -416,12 +420,12 @@ ProgressWindow(char *title, char *msg)
{ {
if(count % 5 == 0) if(count % 5 == 0)
{ {
angle+=45; angle+=45.0f;
if(angle >= 360) if(angle >= 360.0f)
angle = 0; angle = 0;
throbberImg.SetAngle(angle); throbberImg.SetAngle(angle);
} }
count++; ++count;
} }
} }
@ -844,22 +848,25 @@ static void WindowCredits(void * ptr)
bgTopImg->Draw(); bgTopImg->Draw();
creditsWindow.Draw(); creditsWindow.Draw();
for(i=3; i >= 0; i--) #ifdef HW_RVL
{ i = 3;
#ifdef HW_RVL do {
if(userInput[i].wpad->ir.valid) if(userInput[i].wpad->ir.valid)
Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48, Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255); 96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
DoRumble(i); DoRumble(i);
#endif --i;
} } while(i >= 0);
#endif
Menu_Render(); Menu_Render();
for(i=0; i < 4; i++) if((userInput[0].wpad->btns_d || userInput[0].pad.btns_d) ||
(userInput[1].wpad->btns_d || userInput[1].pad.btns_d) ||
(userInput[2].wpad->btns_d || userInput[2].pad.btns_d) ||
(userInput[3].wpad->btns_d || userInput[3].pad.btns_d))
{ {
if(userInput[i].wpad->btns_d || userInput[i].pad.btns_d) exit = true;
exit = true;
} }
usleep(THREAD_SLEEP); usleep(THREAD_SLEEP);
} }
@ -1362,7 +1369,7 @@ static int MenuGame()
if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE) if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE)
{ {
newStatus = true; newStatus = true;
newLevel = (userInput[i].wpad->battery_level / 100.0) * 4; newLevel = int(userInput[i].wpad->battery_level / 100.0) << 2;
if(newLevel > 4) newLevel = 4; if(newLevel > 4) newLevel = 4;
} }
else else