Added functions/vars to GuiText to allow showing & hiding rows when it is wrapped.

new vars are
firstLine = 1;
numLines = -1;
totalLines = 1;
totalLines is not changed until the text is set to wrap and Draw() is called 1 time.
The other 2 are set with functions.
new functions are
void GuiText::SetNumLines(int n)
void GuiText::SetFirstLine(int n)
int GuiText::GetNumLines()
int GuiText::GetFirstLine()
int GuiText::GetTotalLines()
int GuiText::GetLineHeight(int n) 
These should be self explanatory. GetLineHeight relies on total lines so it needs to be called after the first Draw();
Raised the chars[] to 3000 for the synopsis because people are writing books in there.
Used those new fancy functions make the synopsis fit in the info window.  Press up/down to scroll the text.  Arrows may come later for the buttons.  Also put a home buttononlytrigger on the game prompt.  moved disable mainWindow to the beginning of the infoprompt to keep from loading images and stuff from the sd at the same time we are reading the xml file.
This commit is contained in:
giantpune 2009-07-13 11:19:31 +00:00
parent 3906d0fe32
commit 57f0ce0ed4
8 changed files with 190 additions and 25 deletions

View File

@ -34,7 +34,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project # any extra libraries we wish to link with the project
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -ldb -lfat -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -ltremor -lmxml LIBS := -lfat -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -ltremor -lmxml
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
# include and lib # include and lib

File diff suppressed because one or more lines are too long

View File

@ -730,6 +730,12 @@ class GuiText : public GuiElement
int GetTextWidth(); int GetTextWidth();
// not NULL set horizontal scale to 0.75 //added // not NULL set horizontal scale to 0.75 //added
void SetWidescreen(bool w); void SetWidescreen(bool w);
void SetNumLines(int n);//! these two are used to set the first line and numLine
void SetFirstLine(int n);
int GetNumLines();//! these return the line variables for this text
int GetFirstLine();
int GetLineHeight(int n);//! returns the height of the #n of lines including spacing if wrap mode is on
int GetTotalLines();
//!Constantly called to draw the text //!Constantly called to draw the text
void Draw(); void Draw();
protected: protected:
@ -745,6 +751,10 @@ class GuiText : public GuiElement
GXColor color; //!< Font color GXColor color; //!< Font color
FreeTypeGX *font; FreeTypeGX *font;
short widescreen; //added short widescreen; //added
//!these are default until the text is drawn
int firstLine; //!these are the first line and the number of lines drawn when the text is wrapped
int numLines;//! default is -1 and it means that all lines are drawn
int totalLines; //!this is the total # of lines when in wrap mode
}; };
//!Display, manage, and manipulate tooltips in the GUI. //!Display, manage, and manipulate tooltips in the GUI.

View File

@ -37,6 +37,9 @@ GuiText::GuiText(const char * t, int s, GXColor c)
scrollDelay = 0; scrollDelay = 0;
font = NULL; font = NULL;
widescreen = 0; //added widescreen = 0; //added
firstLine = 1;
numLines = -1;
totalLines = 1;
alignmentHor = ALIGN_CENTRE; alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE; alignmentVert = ALIGN_MIDDLE;
@ -62,6 +65,9 @@ GuiText::GuiText(const char * t)
scrollDelay = 0; scrollDelay = 0;
font = NULL; font = NULL;
widescreen = 0; //added widescreen = 0; //added
firstLine = 1;
numLines = -1;
totalLines = 1;
alignmentHor = presetAlignmentHor; alignmentHor = presetAlignmentHor;
alignmentVert = presetAlignmentVert; alignmentVert = presetAlignmentVert;
@ -82,6 +88,43 @@ GuiText::~GuiText()
} }
} }
void GuiText::SetNumLines(int n)
{
numLines = n;
}
void GuiText::SetFirstLine(int n)
{
firstLine = n;
}
int GuiText::GetNumLines()
{
return numLines;
}
int GuiText::GetFirstLine()
{
return firstLine;
}
int GuiText::GetTotalLines()
{
return totalLines;
}
int GuiText::GetLineHeight(int n)
{
int newSize = size*this->GetScale();
int lineheight = newSize + 6;
if (numLines <0)
return totalLines*lineheight+newSize;
else return numLines*lineheight+newSize;
}
void GuiText::SetText(const char * t) void GuiText::SetText(const char * t)
{ {
LOCK(this); LOCK(this);
@ -289,16 +332,37 @@ void GuiText::Draw()
ch++; ch++;
i++; i++;
} }
totalLines = linenum;
if(alignmentVert == ALIGN_MIDDLE) if(alignmentVert == ALIGN_MIDDLE)
voffset = voffset - (lineheight*linenum)/2 + lineheight/2; voffset = voffset - (lineheight*linenum)/2 + lineheight/2;
if (numLines <0){
for(i=0; i < linenum; i++) for(i=0; i < linenum; i++)
{ {
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style); (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style);
delete tmptext[i]; delete tmptext[i];
} }
} }
//put in for txt verticle txt scrolling
else {
int j;
i=0;
for(j=firstLine-1; j < numLines+firstLine-1; j++)
{
if (j<linenum)
(font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[j], c, style);
i++;
}
for(i=0; i < linenum; i++)
{
delete tmptext[i];
}
}
}
else if(wrapMode == GuiText::DOTTED) // text dotted else if(wrapMode == GuiText::DOTTED) // text dotted
{ {
wchar_t save[4]; wchar_t save[4];

View File

@ -33,8 +33,6 @@
#include "wpad.h" #include "wpad.h"
#include "fat.h" #include "fat.h"
#include <debug.h>
/* Constants */ /* Constants */
#define CONSOLE_XCOORD 260 #define CONSOLE_XCOORD 260
#define CONSOLE_YCOORD 115 #define CONSOLE_YCOORD 115
@ -120,8 +118,6 @@ main(int argc, char *argv[])
InitVideo(); // Initialise video InitVideo(); // Initialise video
InitAudio(); // Initialize audio InitAudio(); // Initialize audio
DEBUG_Init(GDBSTUB_DEVICE_USB, 1);// for debugging
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);

View File

@ -932,6 +932,8 @@ int MenuDiscList()
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]);
choice = showGameInfo(IDfull); choice = showGameInfo(IDfull);
gameInfo.ResetState(); gameInfo.ResetState();
if (choice==2)
homeBtn.SetState(STATE_CLICKED);
} }
if (Settings.gameDisplay==grid){ if (Settings.gameDisplay==grid){

View File

@ -15,6 +15,7 @@
#include "wpad.h" #include "wpad.h"
#include "fatmounter.h" #include "fatmounter.h"
#include "listfiles.h" #include "listfiles.h"
#include "prompts/PromptWindows.h"
#include "gameinfo.h" #include "gameinfo.h"
@ -34,6 +35,9 @@ extern void HaltGui();
***************************************************************************/ ***************************************************************************/
int showGameInfo(char *ID) int showGameInfo(char *ID)
{ {
HaltGui();//put this first to try to get rid of the code dump caused by loading this window at the same time as loading images from the SD card
mainWindow->SetState(STATE_DISABLED);
ResumeGui();
//load the xml shit //load the xml shit
bool databaseopened = true; bool databaseopened = true;
OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, false, true); // open file, do not load titles, keep in memory OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, false, true); // open file, do not load titles, keep in memory
@ -125,7 +129,7 @@ int showGameInfo(char *ID)
GuiWindow txtWindow(350,270); GuiWindow txtWindow(350,270);
txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT); txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT);
txtWindow.SetPosition(85, 50); txtWindow.SetPosition(95, 55);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume); GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume); GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
@ -145,7 +149,14 @@ int showGameInfo(char *ID)
trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
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);
GuiTrigger trigU;
trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP);
GuiTrigger trigD;
trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN);
GuiTrigger trigH;
trigH.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
//buttons for changing between synopsis and other info
GuiButton backBtn(0,0); GuiButton backBtn(0,0);
backBtn.SetPosition(-20,-20); backBtn.SetPosition(-20,-20);
backBtn.SetTrigger(&trigB); backBtn.SetTrigger(&trigB);
@ -156,7 +167,20 @@ int showGameInfo(char *ID)
nextBtn.SetTrigger(&trigA); nextBtn.SetTrigger(&trigA);
gameinfoWindow.Append(&nextBtn); gameinfoWindow.Append(&nextBtn);
char linebuf[1000] = ""; //buttons for scrolling the synopsis
GuiButton upBtn(0,0);
upBtn.SetPosition(0,0);
upBtn.SetTrigger(&trigU);
GuiButton dnBtn(0,0);
dnBtn.SetPosition(0,0);
dnBtn.SetTrigger(&trigD);
GuiButton homeBtn(0,0);
homeBtn.SetPosition(0,0);
homeBtn.SetTrigger(&trigH);
char linebuf[3000] = "";
char linebuf2[100] = ""; char linebuf2[100] = "";
// enable icons for required accessories // enable icons for required accessories
@ -577,11 +601,15 @@ int showGameInfo(char *ID)
} }
//synopsis //synopsis
int pagesize=12;
if (strcmp(gameinfo.synopsis,"") != 0) { if (strcmp(gameinfo.synopsis,"") != 0) {
snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis); snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis);
synopsisTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255}); synopsisTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255});
synopsisTxt->SetMaxWidth(350,GuiText::WRAP); synopsisTxt->SetMaxWidth(350,GuiText::WRAP);
synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); synopsisTxt->SetPosition(0,0); synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); synopsisTxt->SetPosition(0,0);
synopsisTxt->SetNumLines(pagesize);
//synopsisTxt->SetFirstLine(12);
dialogBoxImg11 = new GuiImage(&dialogBox1); dialogBoxImg11 = new GuiImage(&dialogBox1);
dialogBoxImg11->SetAlignment(0,3); dialogBoxImg11->SetAlignment(0,3);
dialogBoxImg11->SetPosition(-9,0); dialogBoxImg11->SetPosition(-9,0);
@ -604,6 +632,8 @@ int showGameInfo(char *ID)
gameinfoWindow2.Append(dialogBoxImg44); gameinfoWindow2.Append(dialogBoxImg44);
txtWindow.Append(synopsisTxt); txtWindow.Append(synopsisTxt);
txtWindow.Append(&upBtn);
txtWindow.Append(&dnBtn);
coverImg2 = new GuiImage(cover); coverImg2 = new GuiImage(cover);
coverImg2->SetWidescreen(CFG.widescreen); coverImg2->SetWidescreen(CFG.widescreen);
coverImg2->SetPosition(15,30); coverImg2->SetPosition(15,30);
@ -623,26 +653,43 @@ int showGameInfo(char *ID)
gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100); gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100);
HaltGui(); HaltGui();
mainWindow->SetState(STATE_DISABLED); //mainWindow->SetState(STATE_DISABLED);
mainWindow->Append(&gameinfoWindow); mainWindow->Append(&gameinfoWindow);
mainWindow->ChangeFocus(&gameinfoWindow); mainWindow->ChangeFocus(&gameinfoWindow);
ResumeGui(); ResumeGui();
while(choice == -1) while(choice == -1)
{ {
VIDEO_WaitVSync(); VIDEO_WaitVSync();
//u32 buttonshold = ButtonsHold();
if(shutdown == 1) if(shutdown == 1)
{ {
wiilight(0); wiilight(0);
Sys_Shutdown(); Sys_Shutdown();
} }
if(reset == 1) else if(reset == 1)
Sys_Reboot(); Sys_Reboot();
if ((backBtn.GetState()==STATE_CLICKED)||(backBtn.GetState()==STATE_HELD)){ else if ((backBtn.GetState()==STATE_CLICKED)||(backBtn.GetState()==STATE_HELD)){
choice=1; if(page==1)
{choice=1;
synopsisTxt = NULL; synopsisTxt = NULL;
break; break;}
else if (page==2)
{
HaltGui();
//backBtn.SetClickable(true);
gameinfoWindow2.SetVisible(false);
gameinfoWindow.SetVisible(true);
//gameinfoWindow.Append(&backBtn);
//gameinfoWindow.Append(&nextBtn);
//gameinfoWindow.Append(&homeBtn);
mainWindow->Remove(&gameinfoWindow2);
ResumeGui();
page=1;
}
} }
else if (((nextBtn.GetState()==STATE_CLICKED)||(nextBtn.GetState()==STATE_HELD))&& else if (((nextBtn.GetState()==STATE_CLICKED)||(nextBtn.GetState()==STATE_HELD))&&
(strcmp(gameinfo.synopsis,"") != 0)){ (strcmp(gameinfo.synopsis,"") != 0)){
@ -654,8 +701,10 @@ int showGameInfo(char *ID)
gameinfoWindow2.SetVisible(true); gameinfoWindow2.SetVisible(true);
coverImg->SetPosition(15,30); coverImg->SetPosition(15,30);
backBtn.SetClickable(false); //backBtn.SetClickable(false);
gameinfoWindow2.Append(&nextBtn); gameinfoWindow2.Append(&nextBtn);
gameinfoWindow2.Append(&backBtn);
gameinfoWindow2.Append(&homeBtn);
mainWindow->Append(&gameinfoWindow2); mainWindow->Append(&gameinfoWindow2);
ResumeGui(); ResumeGui();
page=2; page=2;
@ -663,16 +712,60 @@ int showGameInfo(char *ID)
else { else {
nextBtn.ResetState(); nextBtn.ResetState();
HaltGui(); HaltGui();
backBtn.SetClickable(true); //backBtn.SetClickable(true);
gameinfoWindow2.SetVisible(false); gameinfoWindow2.SetVisible(false);
gameinfoWindow.SetVisible(true); gameinfoWindow.SetVisible(true);
gameinfoWindow.Append(&backBtn); gameinfoWindow.Append(&backBtn);
gameinfoWindow.Append(&nextBtn); gameinfoWindow.Append(&nextBtn);
gameinfoWindow.Append(&homeBtn);
mainWindow->Remove(&gameinfoWindow2); mainWindow->Remove(&gameinfoWindow2);
ResumeGui(); ResumeGui();
page=1; page=1;
} }
nextBtn.ResetState(); nextBtn.ResetState();
}
else if ((upBtn.GetState()==STATE_CLICKED||upBtn.GetState()==STATE_HELD) && page==2)
{
int l=synopsisTxt->GetFirstLine()>1?synopsisTxt->GetFirstLine()-1:1;
synopsisTxt->SetFirstLine(l);
usleep(60000);
if (!((ButtonsHold() & WPAD_BUTTON_UP)||(ButtonsHold() & PAD_BUTTON_UP)))
upBtn.ResetState();
}
else if ((dnBtn.GetState()==STATE_CLICKED||dnBtn.GetState()==STATE_HELD) && page==2)
{
int l=0;
if(synopsisTxt->GetTotalLines()>pagesize)
l=synopsisTxt->GetFirstLine()+1;
if (l>synopsisTxt->GetTotalLines()+1-pagesize)
l=synopsisTxt->GetTotalLines()+1-pagesize;
synopsisTxt->SetFirstLine(l);
usleep(60000);
if (!((ButtonsHold() & WPAD_BUTTON_DOWN)||(ButtonsHold() & PAD_BUTTON_DOWN)))
dnBtn.ResetState();
}
//took this out cause it doesnt act right when not called from the main window and I don't feel like fixing it right now
else if (homeBtn.GetState()==STATE_CLICKED)
{
if(page==1)
{choice=2;
synopsisTxt = NULL;
break;}
else if (page==2)
{
HaltGui();
gameinfoWindow2.SetVisible(false);
gameinfoWindow.SetVisible(true);
//gameinfoWindow.Append(&backBtn);
//gameinfoWindow.Append(&nextBtn);
//gameinfoWindow.Append(&homeBtn);
mainWindow->Remove(&gameinfoWindow2);
ResumeGui();
page=1;
}
} }
} }
if (page==1){ if (page==1){

View File

@ -22,9 +22,9 @@ struct gameXMLinfo
char version[50]; char version[50];
char region[7]; char region[7];
char title[100]; char title[100];
char synopsis[2000]; char synopsis[3000];
char title_EN[100]; char title_EN[100];
char synopsis_EN[2000]; char synopsis_EN[3000];
char locales[XML_ELEMMAX+1][3]; char locales[XML_ELEMMAX+1][3];
int localeCnt; int localeCnt;
char developer[75]; char developer[75];