* added two new wrapmodes for gui_text "DOTTED" & "SCROLL"

- DOTTED: cuts the text and appends "..."
  - SCROLL: scrolls the text
* added dotted/scrolled text for gamebrowser, gamepromt and so on (more will come later)
* remove CFG.maxcharacters and THEME.maxcharacters (no more needed)
This commit is contained in:
ardi@ist-einmalig.de 2009-05-22 22:36:55 +00:00
parent ccc2b7215a
commit 5cf5cd6ae7
9 changed files with 438 additions and 306 deletions

View File

@ -246,7 +246,7 @@ void CFG_Default(int widescreen) // -1 = non forced Mode
sprintf(CFG.ogg_path, "notset"); sprintf(CFG.ogg_path, "notset");
CFG.parentalcontrol = 0; CFG.parentalcontrol = 0;
CFG.maxcharacters = 38; // CFG.maxcharacters = 38;
CFG.godmode = 0; CFG.godmode = 0;
CFG.xflip = 0; CFG.xflip = 0;
CFG.wsprompt = 0; CFG.wsprompt = 0;
@ -260,7 +260,7 @@ void CFG_Default(int widescreen) // -1 = non forced Mode
THEME.cover_x = 26; THEME.cover_x = 26;
THEME.cover_y = 55; THEME.cover_y = 55;
THEME.showID = 1; THEME.showID = 1;
THEME.maxcharacters = 36; // THEME.maxcharacters = 36;
THEME.id_x = 68; THEME.id_x = 68;
THEME.id_y = 305; THEME.id_y = 305;
THEME.region_x = 68; THEME.region_x = 68;
@ -689,13 +689,14 @@ void theme_set(char *name, char *val)
} }
} }
/*
else if (strcmp(cfg_name, "maxcharacters") == 0) { else if (strcmp(cfg_name, "maxcharacters") == 0) {
short x; short x;
if (sscanf(val, "%hd", &x) == 1) { if (sscanf(val, "%hd", &x) == 1) {
THEME.maxcharacters = x; THEME.maxcharacters = x;
} }
} }
*/

View File

@ -60,7 +60,7 @@ struct CFG
// short savesettings; // short savesettings;
short widescreen; short widescreen;
short parentalcontrol; short parentalcontrol;
short maxcharacters; // short maxcharacters;
short godmode; short godmode;
short xflip; short xflip;
short wsprompt; short wsprompt;
@ -85,7 +85,7 @@ struct THEME
short cover_x; short cover_x;
short cover_y; short cover_y;
short showID; short showID;
short maxcharacters; // short maxcharacters;
short batteryUnused; short batteryUnused;
short id_x; short id_x;
short id_y; short id_y;

View File

@ -641,7 +641,7 @@ class GuiText : public GuiElement
//!Sets the maximum width of the drawn texture image //!Sets the maximum width of the drawn texture image
//!If the text exceeds this, it is wrapped to the next line //!If the text exceeds this, it is wrapped to the next line
//!\param w Maximum width //!\param w Maximum width
void SetMaxWidth(int w); void SetMaxWidth(int w, short m=GuiText::WRAP);
//!Sets the font color //!Sets the font color
//!\param c Font color //!\param c Font color
void SetColor(GXColor c); void SetColor(GXColor c);
@ -661,10 +661,19 @@ class GuiText : public GuiElement
void SetWidescreen(bool w); void SetWidescreen(bool w);
//!Constantly called to draw the text //!Constantly called to draw the text
void Draw(); void Draw();
enum {
WRAP,
DOTTED,
SCROLL
};
protected: protected:
wchar_t* text; //!< Unicode text value wchar_t* text; //!< Unicode text value
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)
short wrapMode;
short scrollPos1;
short scrollPos2;
u32 scrollDelay;
u16 style; //!< FreeTypeGX style attributes u16 style; //!< FreeTypeGX style attributes
GXColor color; //!< Font color GXColor color; //!< Font color
FreeTypeGX *font; FreeTypeGX *font;

View File

@ -49,6 +49,8 @@ GuiGameBrowser::GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, co
bgGameImg->SetParent(this); bgGameImg->SetParent(this);
bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); bgGameImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
maxTextWidth = bgGameImg->GetWidth() - 24 - 4;
snprintf(imgPath, sizeof(imgPath), "%sbg_options_entry.png", themePath); snprintf(imgPath, sizeof(imgPath), "%sbg_options_entry.png", themePath);
bgGamesEntry = new GuiImageData(imgPath, bg_options_entry_png); bgGamesEntry = new GuiImageData(imgPath, bg_options_entry_png);
@ -59,6 +61,8 @@ GuiGameBrowser::GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, co
scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP); scrollbarImg->SetAlignment(ALIGN_RIGHT, ALIGN_TOP);
scrollbarImg->SetPosition(0, 4); scrollbarImg->SetPosition(0, 4);
maxTextWidth -= scrollbarImg->GetWidth() + 4;
snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowdown.png", themePath); snprintf(imgPath, sizeof(imgPath), "%sscrollbar_arrowdown.png", themePath);
arrowDown = new GuiImageData(imgPath, scrollbar_arrowdown_png); arrowDown = new GuiImageData(imgPath, scrollbar_arrowdown_png);
arrowDownImg = new GuiImage(arrowDown); arrowDownImg = new GuiImage(arrowDown);
@ -115,37 +119,35 @@ GuiGameBrowser::GuiGameBrowser(int w, int h, struct discHdr * l, int gameCnt, co
gameIndex = new int[pagesize]; gameIndex = new int[pagesize];
game = new GuiButton * [pagesize]; game = new GuiButton * [pagesize];
gameTxt = new GuiText * [pagesize]; gameTxt = new GuiText * [pagesize];
gameTxtOver = new GuiText * [pagesize];
gameBg = new GuiImage * [pagesize]; gameBg = new GuiImage * [pagesize];
char buffer[THEME.maxcharacters + 4];
for(int i=0; i < pagesize; i++) for(int i=0; i < pagesize; i++)
{ {
if (strlen(get_title(&gameList[i])) < (u32)(THEME.maxcharacters + 3)) gameTxt[i] = new GuiText(get_title(&gameList[i]), 20, (GXColor){THEME.gameText_r, THEME.gameText_g, THEME.gameText_b, 0xff});
{
sprintf(buffer, "%s", get_title(&gameList[i]));
}
else
{
sprintf(buffer, get_title(&gameList[i]), THEME.maxcharacters);
buffer[THEME.maxcharacters] = '\0';
strncat(buffer, "...", 3);
}
gameTxt[i] = new GuiText(buffer, 20, (GXColor){THEME.gameText_r, THEME.gameText_g, THEME.gameText_b, 0xff});
gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); gameTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
gameTxt[i]->SetPosition(24,0); gameTxt[i]->SetPosition(24,0);
gameTxt[i]->SetMaxWidth(maxTextWidth, GuiText::DOTTED);
gameTxtOver[i] = new GuiText(get_title(&gameList[i]), 20, (GXColor){THEME.gameText_r, THEME.gameText_g, THEME.gameText_b, 0xff});
gameTxtOver[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
gameTxtOver[i]->SetPosition(24,0);
gameTxtOver[i]->SetMaxWidth(maxTextWidth, GuiText::SCROLL);
gameBg[i] = new GuiImage(bgGamesEntry); gameBg[i] = new GuiImage(bgGamesEntry);
game[i] = new GuiButton(width-28,GAMESELECTSIZE); game[i] = new GuiButton(width-28,GAMESELECTSIZE);
game[i]->SetParent(this); game[i]->SetParent(this);
game[i]->SetLabel(gameTxt[i]); game[i]->SetLabel(gameTxt[i]);
game[i]->SetLabelOver(gameTxtOver[i]);
game[i]->SetImageOver(gameBg[i]); game[i]->SetImageOver(gameBg[i]);
game[i]->SetPosition(5,GAMESELECTSIZE*i+4); game[i]->SetPosition(5,GAMESELECTSIZE*i+4);
game[i]->SetRumble(false); game[i]->SetRumble(false);
game[i]->SetTrigger(trigA); game[i]->SetTrigger(trigA);
game[i]->SetSoundClick(btnSoundClick); game[i]->SetSoundClick(btnSoundClick);
gameIndex[i] = i;
} }
} }
@ -182,12 +184,14 @@ GuiGameBrowser::~GuiGameBrowser()
for(int i=0; i<pagesize; i++) for(int i=0; i<pagesize; i++)
{ {
delete gameTxt[i]; delete gameTxt[i];
delete gameTxtOver[i];
delete gameBg[i]; delete gameBg[i];
delete game[i]; delete game[i];
} }
delete [] gameIndex; delete [] gameIndex;
delete [] game; delete [] game;
delete [] gameTxt; delete [] gameTxt;
delete [] gameTxtOver;
delete [] gameBg; delete [] gameBg;
} }
@ -303,6 +307,34 @@ void GuiGameBrowser::Draw()
} }
this->UpdateEffects(); this->UpdateEffects();
} }
void GuiGameBrowser::UpdateListEntries()
{
int next = listOffset;
for(int i=0; i<pagesize; i++)
{
if(next >= 0)
{
if(game[i]->GetState() == STATE_DISABLED)
{
game[i]->SetVisible(true);
game[i]->SetState(STATE_DEFAULT);
}
gameTxt[i]->SetText(get_title(&gameList[next]));
gameTxt[i]->SetPosition(24, 0);
gameTxtOver[i]->SetText(get_title(&gameList[next]));
gameTxtOver[i]->SetPosition(24, 0);
gameIndex[i] = next;
next = this->FindMenuItem(next, 1);
}
else
{
game[i]->SetVisible(false);
game[i]->SetState(STATE_DISABLED);
}
// }
}
}
void GuiGameBrowser::Update(GuiTrigger * t) void GuiGameBrowser::Update(GuiTrigger * t)
{ {
@ -311,6 +343,7 @@ void GuiGameBrowser::Update(GuiTrigger * t)
return; return;
int next, prev; int next, prev;
int old_listOffset = listOffset;
static int position2; static int position2;
// scrolldelay affects how fast the list scrolls // scrolldelay affects how fast the list scrolls
// when the arrows are clicked // when the arrows are clicked
@ -324,40 +357,11 @@ void GuiGameBrowser::Update(GuiTrigger * t)
} }
next = listOffset; next = listOffset;
char buffer[THEME.maxcharacters + 4];
for(int i=0; i<pagesize; i++) for(int i=0; i<pagesize; i++)
{ {
if(next >= 0) if(next >= 0)
{
if(game[i]->GetState() == STATE_DISABLED)
{
game[i]->SetVisible(true);
game[i]->SetState(STATE_DEFAULT);
}
if (strlen(get_title(&gameList[next])) < (u32)(THEME.maxcharacters + 3))
{
sprintf(buffer, "%s", get_title(&gameList[next]));
}
else
{
sprintf(buffer, get_title(&gameList[next]), THEME.maxcharacters);
buffer[THEME.maxcharacters] = '\0';
strncat(buffer, "...", 3);
}
gameTxt[i]->SetText(buffer);
gameTxt[i]->SetPosition(24, 0);
gameIndex[i] = next;
next = this->FindMenuItem(next, 1); next = this->FindMenuItem(next, 1);
}
else
{
game[i]->SetVisible(false);
game[i]->SetState(STATE_DISABLED);
}
if(focus) if(focus)
{ {
@ -379,245 +383,258 @@ void GuiGameBrowser::Update(GuiTrigger * t)
if(!focus) if(!focus)
return; // skip navigation return; // skip navigation
if (scrollbaron == 1) { if (scrollbaron == 1)
if (t->Down() ||
arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down
arrowDownBtn->GetState() == STATE_HELD)
{ {
if (t->Down() ||
next = this->FindMenuItem(gameIndex[selectedItem], 1); arrowDownBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////down
arrowDownBtn->GetState() == STATE_HELD)
if(next >= 0)
{ {
if(selectedItem == pagesize-1)
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{ {
// move list down by 1 if(selectedItem == pagesize-1)
listOffset = this->FindMenuItem(listOffset, 1); {
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
// UpdateEntries();
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
} }
else if(game[selectedItem+1]->IsVisible()) WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A)
{ {
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowDownBtn->ResetState();
}
}
else if(t->Up() ||
arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
} }
else else
{ {
game[selectedItem]->ResetState(); arrowDownBtn->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
} }
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
} }
else if(t->Up() ||
arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
// UpdateEntries();
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
WPAD_ScanPads();
u8 cnt, buttons = NULL;
/* Get pressed buttons */
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A)
{
}
else
{
arrowUpBtn->ResetState();
}
}
WPAD_ScanPads(); WPAD_ScanPads();
u8 cnt, buttons = NULL; u8 cnt, buttons = NULL;/////////////////////////////////////////////////////scroll by holding B and tilt wiimote
/* Get pressed buttons */ int position1 = 0;
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_A) {
} else {
arrowUpBtn->ResetState();
}
}
WPAD_ScanPads();
u8 cnt, buttons = NULL;/////////////////////////////////////////////////////scroll by holding B and tilt wiimote
int position1 = 0;
position1 = t->wpad.ir.y; position1 = t->wpad.ir.y;
if (position2 == 0 && position1 > 0) { if (position2 == 0 && position1 > 0)
position2 = position1;
}
for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_B && position1 > 0) {
scrollbarBoxBtn->ScrollIsOn(1);
if (position2 > position1) {
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{ {
if(selectedItem == 0) position2 = position1;
{
// move list up by 1
listOffset = prev;
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
} }
} else if (position2 < position1) { for (cnt = 0; cnt < 4; cnt++)
buttons |= WPAD_ButtonsHeld(cnt);
if (buttons == WPAD_BUTTON_B && position1 > 0)
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{ {
if(selectedItem == pagesize-1) scrollbarBoxBtn->ScrollIsOn(1);
if (position2 > position1)
{ {
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1); prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
// UpdateEntries();
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
} }
else if(game[selectedItem+1]->IsVisible()) else if (position2 < position1)
{ {
game[selectedItem]->ResetState(); next = this->FindMenuItem(gameIndex[selectedItem], 1);
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++; if(next >= 0)
{
if(selectedItem == pagesize-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
// UpdateEntries();
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
}
} }
scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay);
} }
} else if (!buttons)
} else if (!buttons) {
scrollbarBoxBtn->ScrollIsOn(0);
position2 = 0;
}
if(scrollbarBoxBtn->GetState() == STATE_HELD &&/////////////////////allow dragging of scrollbar box
scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && gameCnt > pagesize)
{
scrollbarBoxBtn->SetPosition(width/2-18+7,0);
//int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
int position = t->wpad.ir.y - 32 - scrollbarBoxBtn->GetTop();
//listOffset = (position * gameCnt)/237 - selectedItem;
listOffset = (position * gameCnt)/(25.2 * pagesize) - selectedItem;
if(listOffset <= 0)
{ {
listOffset = 0; scrollbarBoxBtn->ScrollIsOn(0);
selectedItem = 0; position2 = 0;
}
else if(listOffset+pagesize >= gameCnt)
{
listOffset = gameCnt - pagesize;
selectedItem = pagesize-1;
} }
} if(scrollbarBoxBtn->GetState() == STATE_HELD &&/////////////////////allow dragging of scrollbar box
//int positionbar = 237*(listOffset + selectedItem) / gameCnt; scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && gameCnt > pagesize)
{
scrollbarBoxBtn->SetPosition(width/2-18+7,0);
//int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
int position = t->wpad.ir.y - 32 - scrollbarBoxBtn->GetTop();
//listOffset = (position * gameCnt)/237 - selectedItem;
listOffset = (position * gameCnt)/(25.2 * pagesize) - selectedItem;
// UpdateEntries();
if(listOffset <= 0)
{
listOffset = 0;
// UpdateEntries();
selectedItem = 0;
}
else if(listOffset+pagesize >= gameCnt)
{
listOffset = gameCnt - pagesize;
// UpdateEntries();
selectedItem = pagesize-1;
}
}
//int positionbar = 237*(listOffset + selectedItem) / gameCnt;
int positionbar = (25.2 * pagesize)*(listOffset + selectedItem) / gameCnt; int positionbar = (25.2 * pagesize)*(listOffset + selectedItem) / gameCnt;
if(positionbar > (24 * pagesize))//if(positionbar > 216) if(positionbar > (24 * pagesize))//if(positionbar > 216)
positionbar = (24 * pagesize);//positionbar = 216; positionbar = (24 * pagesize);//positionbar = 216;
scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8); scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8);
if(t->Right())/////////////////////////////////////////////////////skip pagesize # of games if right is pressed if(t->Right())/////////////////////////////////////////////////////skip pagesize # of games if right is pressed
{
if(listOffset < gameCnt && gameCnt > pagesize)
{ {
listOffset =listOffset+ pagesize; if(listOffset < gameCnt && gameCnt > pagesize)
if(listOffset+pagesize >= gameCnt)
listOffset = gameCnt-pagesize;
}
}
else if(t->Left())
{
if(listOffset > 0)
{
listOffset =listOffset- pagesize;
if(listOffset < 0)
listOffset = 0;
}
}
} else {
if(t->Down())/////////////////////////////////////////////////////if there isn't a scrollbar and down is pressed
{
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == pagesize-1)
{ {
// move list down by 1 listOffset =listOffset+ pagesize;
listOffset = this->FindMenuItem(listOffset, 1); if(listOffset+pagesize >= gameCnt)
} listOffset = gameCnt-pagesize;
else if(game[selectedItem+1]->IsVisible()) // UpdateEntries();
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
} }
} }
} else if(t->Left())
else if(t->Up())///////////////////////////////////////////////////up
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{ {
if(selectedItem == 0) if(listOffset > 0)
{ {
// move list up by 1 listOffset =listOffset- pagesize;
listOffset = prev; if(listOffset < 0)
} listOffset = 0;
else // UpdateEntries();
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
} }
} }
} }
else
{
if(t->Down())/////////////////////////////////////////////////////if there isn't a scrollbar and down is pressed
{
next = this->FindMenuItem(gameIndex[selectedItem], 1);
if(next >= 0)
{
if(selectedItem == pagesize-1)
{
// move list down by 1
listOffset = this->FindMenuItem(listOffset, 1);
// UpdateEntries();
}
else if(game[selectedItem+1]->IsVisible())
{
game[selectedItem]->ResetState();
game[selectedItem+1]->SetState(STATE_SELECTED, t->chan);
selectedItem++;
}
}
}
else if(t->Up())///////////////////////////////////////////////////up
{
prev = this->FindMenuItem(gameIndex[selectedItem], -1);
if(prev >= 0)
{
if(selectedItem == 0)
{
// move list up by 1
listOffset = prev;
// UpdateEntries();
}
else
{
game[selectedItem]->ResetState();
game[selectedItem-1]->SetState(STATE_SELECTED, t->chan);
selectedItem--;
}
}
}
} }
if(old_listOffset != listOffset)
UpdateListEntries();
if(updateCB) if(updateCB)
updateCB(this); updateCB(this);
@ -631,6 +648,7 @@ void GuiGameBrowser::Reload(struct discHdr * l, int count)
scrollbaron = (gameCnt > pagesize) ? 1 : 0; scrollbaron = (gameCnt > pagesize) ? 1 : 0;
selectedItem = 0; selectedItem = 0;
listOffset = 0; listOffset = 0;
UpdateListEntries();
for(int i=0; i<pagesize; i++) for(int i=0; i<pagesize; i++)
game[i]->ResetState(); game[i]->ResetState();

View File

@ -45,10 +45,12 @@ class GuiGameBrowser : public GuiElement
void Reload(struct discHdr * l, int count); void Reload(struct discHdr * l, int count);
//GuiText * optionVal[PAGESIZE]; //GuiText * optionVal[PAGESIZE];
protected: protected:
void UpdateListEntries();
int selectedItem; int selectedItem;
int listOffset; int listOffset;
int scrollbaron; int scrollbaron;
int pagesize; int pagesize;
int maxTextWidth;
struct discHdr * gameList; struct discHdr * gameList;
int gameCnt; int gameCnt;
@ -56,6 +58,7 @@ class GuiGameBrowser : public GuiElement
int * gameIndex; int * gameIndex;
GuiButton ** game; GuiButton ** game;
GuiText ** gameTxt; GuiText ** gameTxt;
GuiText ** gameTxtOver;
GuiImage ** gameBg; GuiImage ** gameBg;
GuiButton * arrowUpBtn; GuiButton * arrowUpBtn;

View File

@ -14,6 +14,7 @@ static int currentSize = 0;
static int currentWidescreen = 0; static int currentWidescreen = 0;
static int presetSize = 0; static int presetSize = 0;
static int presetMaxWidth = 0; static int presetMaxWidth = 0;
static int presetWrapMode = GuiText::WRAP;
static int presetAlignmentHor = 0; static int presetAlignmentHor = 0;
static int presetAlignmentVert = 0; static int presetAlignmentVert = 0;
static u16 presetStyle = 0; static u16 presetStyle = 0;
@ -30,6 +31,10 @@ GuiText::GuiText(const char * t, int s, GXColor c)
alpha = c.a; alpha = c.a;
style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE; style = FTGX_JUSTIFY_CENTER | FTGX_ALIGN_MIDDLE;
maxWidth = 0; maxWidth = 0;
wrapMode = GuiText::WRAP;
scrollPos1 = 0;
scrollPos2 = 0;
scrollDelay = 0;
font = NULL; font = NULL;
widescreen = 0; //added widescreen = 0; //added
@ -51,6 +56,10 @@ GuiText::GuiText(const char * t)
alpha = presetColor.a; alpha = presetColor.a;
style = presetStyle; style = presetStyle;
maxWidth = presetMaxWidth; maxWidth = presetMaxWidth;
wrapMode = presetWrapMode;
scrollPos1 = 0;
scrollPos2 = 0;
scrollDelay = 0;
font = NULL; font = NULL;
widescreen = 0; //added widescreen = 0; //added
@ -82,6 +91,8 @@ void GuiText::SetText(const char * t)
if(t) if(t)
text = fontSystem->charToWideChar((char *)t); text = fontSystem->charToWideChar((char *)t);
scrollPos2 = 0;
scrollDelay = 0;
} }
void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v) void GuiText::SetPresets(int sz, GXColor c, int w, u16 s, int h, int v)
@ -100,10 +111,11 @@ void GuiText::SetFontSize(int s)
size = s; size = s;
} }
void GuiText::SetMaxWidth(int w) void GuiText::SetMaxWidth(int w, short m/*=GuiText::WRAP*/)
{ {
LOCK(this); LOCK(this);
maxWidth = w; maxWidth = w;
wrapMode = m;
} }
void GuiText::SetColor(GXColor c) void GuiText::SetColor(GXColor c)
@ -211,68 +223,164 @@ void GuiText::Draw()
if(alignmentVert == ALIGN_MIDDLE) if(alignmentVert == ALIGN_MIDDLE)
voffset = -newSize/2 + 2; voffset = -newSize/2 + 2;
if(maxWidth > 0) // text wrapping if(maxWidth > 0 && (font ? font : fontSystem)->getWidth(text) > maxWidth)
{ {
int lineheight = newSize + 6; if(wrapMode == GuiText::WRAP) // text wrapping
int strlen = wcslen(text);
int i = 0;
int ch = 0;
int linenum = 0;
int lastSpace = -1;
int lastSpaceIndex = -1;
wchar_t * tmptext[20];
while(ch < strlen)
{ {
if(i == 0) int lineheight = newSize + 6;
tmptext[linenum] = new wchar_t[strlen + 1]; int strlen = wcslen(text);
int i = 0;
int ch = 0;
int linenum = 0;
int lastSpace = -1;
int lastSpaceIndex = -1;
wchar_t * tmptext[20];
tmptext[linenum][i] = text[ch]; while(ch < strlen)
tmptext[linenum][i+1] = 0;
if(text[ch] == ' ' || ch == strlen-1)
{ {
if((font ? font : fontSystem)->getWidth(tmptext[linenum]) >= maxWidth) if(i == 0)
//if(fontSystem->getWidth(tmptext[linenum]) >= maxWidth) tmptext[linenum] = new wchar_t[strlen + 1];
tmptext[linenum][i] = text[ch];
tmptext[linenum][i+1] = 0;
if(text[ch] == ' ' || ch == strlen-1)
{ {
if(lastSpace >= 0) if((font ? font : fontSystem)->getWidth(tmptext[linenum]) >= maxWidth)
//if(fontSystem->getWidth(tmptext[linenum]) >= maxWidth)
{ {
tmptext[linenum][lastSpaceIndex] = 0; // discard space, and everything after if(lastSpace >= 0)
ch = lastSpace; // go backwards to the last space {
lastSpace = -1; // we have used this space tmptext[linenum][lastSpaceIndex] = 0; // discard space, and everything after
lastSpaceIndex = -1; ch = lastSpace; // go backwards to the last space
lastSpace = -1; // we have used this space
lastSpaceIndex = -1;
}
linenum++;
i = -1;
}
else if(ch == strlen-1)
{
linenum++;
} }
linenum++;
i = -1;
} }
else if(ch == strlen-1) if(text[ch] == ' ' && i >= 0)
{ {
linenum++; lastSpace = ch;
lastSpaceIndex = i;
} }
ch++;
i++;
} }
if(text[ch] == ' ' && i >= 0)
if(alignmentVert == ALIGN_MIDDLE)
voffset = voffset - (lineheight*linenum)/2 + lineheight/2;
for(i=0; i < linenum; i++)
{ {
lastSpace = ch; (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style);
lastSpaceIndex = i; delete tmptext[i];
} }
ch++;
i++;
} }
else if(wrapMode == GuiText::DOTTED) // text dotted
if(alignmentVert == ALIGN_MIDDLE)
voffset = voffset - (lineheight*linenum)/2 + lineheight/2;
for(i=0; i < linenum; i++)
{ {
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style); wchar_t save[4];
//fontSystem->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style); int strlen = wcslen(text);
delete tmptext[i]; int dotPos=strlen-3;
int i;
bool drawed = false;
while(dotPos > 0 && drawed == false)
{
for(i=0; i<4; i++) // save Text for "..."
{
save[i] = text[dotPos+i];
text[dotPos+i] = (i != 3 ? _TEXT('.') : 0);
}
if(((font ? font : fontSystem)->getWidth(text)) <= maxWidth)
{
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
drawed = true;
}
for(i=0; i<4; i++) // write saved Text back
text[dotPos+i] = save[i];
dotPos--;
}
if(!drawed)
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
}
else if(wrapMode == GuiText::SCROLL) // text scroller
{
wchar_t save;
if(scrollPos2 == 0 || frameCount > scrollDelay+5)
{
scrollPos1 = 0;
for(scrollPos2 = wcslen(text); scrollPos2 > 1; scrollPos2--)
{
save = text[scrollPos2]; // save Pos2
text[scrollPos2] = 0;
int textWidth = (font ? font : fontSystem)->getWidth(text);
text[scrollPos2] = save; // restore Pos2
if(textWidth <= maxWidth)
break;
}
scrollDelay = frameCount+50; // wait 50 Frames before beginning with scrolling
}
else if(scrollPos2 > 0 && frameCount >= scrollDelay)
{
scrollPos1++;
int strlen = wcslen(text);
for(; scrollPos2 < strlen; scrollPos2++)
{
save = text[scrollPos2+1]; // save Pos2
text[scrollPos2+1] = 0;
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
text[scrollPos2+1] = save; // restore Pos2
if(textWidth > maxWidth)
break;
}
if(scrollPos2 == strlen)
{
scrollPos2 = -scrollPos2;
scrollDelay = frameCount+25; // when dir-change wait 25 Frames
}
else
scrollDelay = frameCount+10; // wait 10 Frames
}
else if(frameCount >= scrollDelay)
{
scrollPos2 = -scrollPos2;
scrollPos1--;
for(; scrollPos2 > scrollPos1; scrollPos2--)
{
save = text[scrollPos2]; // save Pos2
text[scrollPos2] = 0;
int textWidth = (font ? font : fontSystem)->getWidth(&text[scrollPos1]);
text[scrollPos2] = save; // restore Pos2
if(textWidth <= maxWidth)
break;
}
if(scrollPos1 == 0)
{
scrollPos2 = -scrollPos2;
scrollDelay = frameCount+25; // when dir-change wait 25 Frames
}
else
scrollDelay = frameCount+10; // wait 10 Frames
scrollPos2 = -scrollPos2;
}
save = text[abs(scrollPos2)]; // save Pos2
text[abs(scrollPos2)] = 0;
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, &text[scrollPos1], c, style);
text[abs(scrollPos2)] = save; // restore Pos2
} }
} }
else else
{ {
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style); (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
//fontSystem->drawText(this->GetLeft(), this->GetTop()+voffset, text, c, style);
} }
this->UpdateEffects(); this->UpdateEffects();
} }

View File

@ -979,7 +979,6 @@ int GameWindowPrompt()
f32 size = 0.0; f32 size = 0.0;
char ID[4]; char ID[4];
char IDFull[7]; char IDFull[7];
char gameName[CFG.maxcharacters + 4];
u8 faveChoice = 0; u8 faveChoice = 0;
u16 playCount = 0; u16 playCount = 0;
@ -1030,6 +1029,7 @@ int GameWindowPrompt()
GuiText nameTxt("", 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{50, 50, 50, 255}); GuiText nameTxt("", 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{50, 50, 50, 255});
if (Settings.wsprompt == yes) if (Settings.wsprompt == yes)
nameTxt.SetWidescreen(CFG.widescreen); nameTxt.SetWidescreen(CFG.widescreen);
nameTxt.SetMaxWidth(350, GuiText::SCROLL);
GuiButton nameBtn(120,50); GuiButton nameBtn(120,50);
nameBtn.SetLabel(&nameTxt); nameBtn.SetLabel(&nameTxt);
// nameBtn.SetLabelOver(&nameTxt); // nameBtn.SetLabelOver(&nameTxt);
@ -1193,7 +1193,6 @@ int GameWindowPrompt()
diskCover = NULL; diskCover = NULL;
} }
// changed = 0;
//load disc image based or what game is seleted //load disc image based or what game is seleted
struct discHdr * header = &gameList[gameSelected]; struct discHdr * header = &gameList[gameSelected];
WBFS_GameSize(header->id, &size); WBFS_GameSize(header->id, &size);
@ -1203,17 +1202,6 @@ int GameWindowPrompt()
snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]); snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]);
snprintf (IDFull,sizeof(IDFull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]); snprintf (IDFull,sizeof(IDFull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]);
//set name
if (strlen(get_title(header)) < (u32)(CFG.maxcharacters + 3)) {
sprintf(gameName, "%s", get_title(header));
}
else {
strncpy(gameName, get_title(header), CFG.maxcharacters);
gameName[CFG.maxcharacters] = '\0';
strncat(gameName, "...", 3);
}
if (diskCover) if (diskCover)
delete diskCover; delete diskCover;
@ -1282,7 +1270,7 @@ int GameWindowPrompt()
else else
diskImg.SetImage(diskCover); diskImg.SetImage(diskCover);
sizeTxt.SetText(sizeText); sizeTxt.SetText(sizeText);
nameTxt.SetText(gameName); nameTxt.SetText(get_title(header));
struct Game_NUM* game_num = CFG_get_game_num(header->id); struct Game_NUM* game_num = CFG_get_game_num(header->id);
if (game_num) { if (game_num) {
@ -2616,11 +2604,12 @@ static int MenuInstall()
Disc_ReadHeader(&headerdisc); Disc_ReadHeader(&headerdisc);
name = headerdisc.title; name = headerdisc.title;
if (strlen(name) < (34 + 3)) { if (strlen(name) < (MAX_CHARACTERS + 3)) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
sprintf(name, "%s", name); sprintf(name, "%s", name);
} else { } else {
strncpy(buffer, name, 34); strncpy(buffer, name, MAX_CHARACTERS);
buffer[MAX_CHARACTERS] = '\0';
strncat(buffer, "...", 3); strncat(buffer, "...", 3);
sprintf(name, "%s", buffer); sprintf(name, "%s", buffer);
} }
@ -4855,9 +4844,10 @@ int GameSettings(struct discHdr * header)
GuiTrigger trigB; GuiTrigger trigB;
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
GuiText titleTxt(gameName, 28, (GXColor){0, 0, 0, 255}); GuiText titleTxt(get_title(header), 28, (GXColor){0, 0, 0, 255});
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
titleTxt.SetPosition(0,40); titleTxt.SetPosition(12,40);
titleTxt.SetMaxWidth(356, GuiText::SCROLL);
GuiImage settingsbackground(&settingsbg); GuiImage settingsbackground(&settingsbg);
GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight()); GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight());

View File

@ -27,6 +27,7 @@ static unsigned char gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32);
static Mtx GXmodelView2D; static Mtx GXmodelView2D;
int screenheight; int screenheight;
int screenwidth; int screenwidth;
u32 frameCount = 0;
/**************************************************************************** /****************************************************************************
* UpdatePadsCB * UpdatePadsCB
@ -36,6 +37,7 @@ int screenwidth;
static void static void
UpdatePadsCB () UpdatePadsCB ()
{ {
frameCount++;
#ifdef HW_RVL #ifdef HW_RVL
WPAD_ScanPads(); WPAD_ScanPads();
#endif #endif

View File

@ -20,5 +20,6 @@ void Menu_DrawRectangle(f32 x, f32 y, f32 width, f32 height, GXColor color, u8 f
extern int screenheight; extern int screenheight;
extern int screenwidth; extern int screenwidth;
extern u32 frameCount;
#endif #endif