From 5d973af02f4eaad39c92760096c5e09359190dc7 Mon Sep 17 00:00:00 2001 From: giantpune Date: Mon, 11 May 2009 23:26:39 +0000 Subject: [PATCH] Changed prototype for OnScreenKeyboard. It now accepts minimum entry length to keep people from removing any part of "SD:/" and crashing when trying to download. Also added clear button to delete all text back to the set minimum. --- gui.pnproj | 2 +- source/libwiigui/gui.h | 6 ++- source/libwiigui/gui_keyboard.cpp | 31 ++++++++++++++-- source/menu.cpp | 61 +++++++++++++++++++++---------- 4 files changed, 75 insertions(+), 25 deletions(-) diff --git a/gui.pnproj b/gui.pnproj index 433bcf92..57e0c7ea 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/libwiigui/gui.h b/source/libwiigui/gui.h index 640ddbc7..a32e7a5c 100644 --- a/source/libwiigui/gui.h +++ b/source/libwiigui/gui.h @@ -786,7 +786,7 @@ typedef struct _keytype { class GuiKeyboard : public GuiWindow { public: - GuiKeyboard(char * t, u32 m); + GuiKeyboard(char * t, u32 m, int min); ~GuiKeyboard(); void Update(GuiTrigger * t); char kbtextstr[256]; @@ -809,6 +809,10 @@ class GuiKeyboard : public GuiWindow GuiImage * keyBackImg; GuiImage * keyBackOverImg; GuiButton * keyBack; + GuiText * keyClearText; + GuiImage * keyClearImg; + GuiImage * keyClearOverImg; + GuiButton * keyClear; GuiImage * keySpaceImg; GuiImage * keySpaceOverImg; GuiButton * keySpace; diff --git a/source/libwiigui/gui_keyboard.cpp b/source/libwiigui/gui_keyboard.cpp index 6c002c6b..b816907f 100644 --- a/source/libwiigui/gui_keyboard.cpp +++ b/source/libwiigui/gui_keyboard.cpp @@ -13,12 +13,14 @@ * Constructor for the GuiKeyboard class. */ extern const int vol; -GuiKeyboard::GuiKeyboard(char * t, u32 max) +unsigned int m; +GuiKeyboard::GuiKeyboard(char * t, u32 max, int min) { width = 540; height = 400; shift = 0; caps = 0; + m = min; selectable = true; focus = 0; // allow focus alignmentHor = ALIGN_CENTRE; @@ -123,6 +125,20 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max) keyBack->SetPosition(10*42+40, 0*42+120);//(10*42+40, 0*42+80); keyBack->SetEffectGrow(); this->Append(keyBack); + + keyClearImg = new GuiImage(keyMedium); + keyClearOverImg = new GuiImage(keyMediumOver); + keyClearText = new GuiText("clear", 20, (GXColor){0, 0, 0, 0xff}); + keyClear = new GuiButton(keyMedium->GetWidth(), keyMedium->GetHeight()); + keyClear->SetImage(keyClearImg); + keyClear->SetImageOver(keyClearOverImg); + keyClear->SetLabel(keyClearText); + keyClear->SetSoundOver(keySoundOver); + keyClear->SetSoundClick(keySoundClick); + keyClear->SetTrigger(trigA); + keyClear->SetPosition(10*42+40, 4*42+120);//(10*42+40, 0*42+80); + keyClear->SetEffectGrow(); + this->Append(keyClear); keyCapsImg = new GuiImage(keyMedium); keyCapsOverImg = new GuiImage(keyMediumOver); @@ -261,11 +277,20 @@ void GuiKeyboard::Update(GuiTrigger * t) } keySpace->SetState(STATE_SELECTED, t->chan); } - else if(keyBack->GetState() == STATE_CLICKED) + else if(keyBack->GetState() == STATE_CLICKED) { + if (strlen(kbtextstr) >(m)){ + kbtextstr[strlen(kbtextstr)-1] = 0; + kbText->SetText(kbtextstr);} + keyBack->SetState(STATE_SELECTED, t->chan); + } + else if(keyClear->GetState() == STATE_CLICKED) + { clearMore: + if (strlen(kbtextstr) >(m)){ kbtextstr[strlen(kbtextstr)-1] = 0; kbText->SetText(kbtextstr); - keyBack->SetState(STATE_SELECTED, t->chan); + goto clearMore;} + keyClear->SetState(STATE_SELECTED, t->chan); } else if(keyShift->GetState() == STATE_CLICKED) { diff --git a/source/menu.cpp b/source/menu.cpp index ae892f99..c98ac281 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -19,6 +19,7 @@ #include //CLOCK #include +#include #include "libwiigui/gui.h" #include "menu.h" #include "main.h" @@ -1891,11 +1892,12 @@ err: * Opens an on-screen keyboard window, with the data entered being stored * into the specified variable. ***************************************************************************/ -static int OnScreenKeyboard(char * var, u32 maxlen) + extern int min; +static int OnScreenKeyboard(char * var, u32 maxlen, int min) { int save = -1; - GuiKeyboard keyboard(var, maxlen); + GuiKeyboard keyboard(var, maxlen, min); GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, vol); GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, vol); @@ -2224,8 +2226,10 @@ static int MenuInstall() static int MenuDiscList() { - int menu = MENU_NONE; + datagB=0; + int menu = MENU_NONE, dataef=0; char imgPath[100]; + char buf[4]; f32 freespace, used, size = 0.0; u32 nolist; @@ -2515,17 +2519,30 @@ static int MenuDiscList() //CLOCK time_t rawtime = time(0); //this fixes code dump caused by the clock - if (Settings.hddinfo == Clock && rawtime != lastrawtime) {//only update the clock every 2000 loops + if (Settings.hddinfo == Clock && rawtime != lastrawtime) { lastrawtime = rawtime; timeinfo = localtime (&rawtime); - if(rawtime & 1) - strftime(theTime, sizeof(theTime), "%H:%M", timeinfo); - else - strftime(theTime, sizeof(theTime), "%H %M", timeinfo); - clockTime.SetText(theTime); + if (dataed < 1){ + if(rawtime & 1) + strftime(theTime, sizeof(theTime), "%H:%M", timeinfo); + else + strftime(theTime, sizeof(theTime), "%H %M", timeinfo); + clockTime.SetText(theTime); + } + else if (dataed > 0){ + + sprintf(buf, "%i", (dataed-1)); + clockTime.SetText(buf); + //delete buf; + } + } + + + + //////////////////////end clock code////////////////////////////// - if ((datagB<1)&&(Settings.cios==1)&&(Settings.video == ntsc)&&(Settings.hddinfo == Clock)&&(Settings.qboot==1)&&(Settings.wsprompt==0)&&(Settings.language==ger)&&(Settings.tooltips==0)){dataed=1;}if (dataed==1){if (cosa>7){cosa=1;}datag++;if (sina==3){wiiBtn.SetAlignment(ALIGN_LEFT,ALIGN_BOTTOM);wiiBtnImg.SetAngle(0);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((cosa)*70),(-2*(datag)+120));}else if(62<=datag){wiiBtn.SetPosition(((cosa)*70),((datag*2)-130));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==2){wiiBtn.SetAlignment(ALIGN_RIGHT,ALIGN_TOP);wiiBtnImg.SetAngle(270);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((-2*(datag)+130)),((cosa)*50));}else if(62<=datag){wiiBtn.SetPosition((2*(datag)-120),((cosa)*50));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==1){wiiBtn.SetAlignment(ALIGN_TOP,ALIGN_LEFT);wiiBtnImg.SetAngle(180);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((cosa)*70),(2*(datag)-120));}else if(62<=datag){wiiBtn.SetPosition(((cosa)*70),(-2*(datag)+130));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==0){wiiBtn.SetAlignment(ALIGN_TOP,ALIGN_LEFT);wiiBtnImg.SetAngle(90);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((2*(datag)-130)),((cosa)*50));}else if(62<=datag){wiiBtn.SetPosition((-2*(datag)+120),((cosa)*50));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}} + if ((datagB<1)&&(Settings.cios==1)&&(Settings.video == ntsc)&&(Settings.hddinfo == Clock)&&(Settings.qboot==1)&&(Settings.wsprompt==0)&&(Settings.language==ger)&&(Settings.tooltips==0)){dataed=1;dataef=1;}if (dataef==1){if (cosa>7){cosa=1;}datag++;if (sina==3){wiiBtn.SetAlignment(ALIGN_LEFT,ALIGN_BOTTOM);wiiBtnImg.SetAngle(0);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((cosa)*70),(-2*(datag)+120));}else if(62<=datag){wiiBtn.SetPosition(((cosa)*70),((datag*2)-130));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==2){wiiBtn.SetAlignment(ALIGN_RIGHT,ALIGN_TOP);wiiBtnImg.SetAngle(270);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((-2*(datag)+130)),((cosa)*50));}else if(62<=datag){wiiBtn.SetPosition((2*(datag)-120),((cosa)*50));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==1){wiiBtn.SetAlignment(ALIGN_TOP,ALIGN_LEFT);wiiBtnImg.SetAngle(180);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((cosa)*70),(2*(datag)-120));}else if(62<=datag){wiiBtn.SetPosition(((cosa)*70),(-2*(datag)+130));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}if (sina==0){wiiBtn.SetAlignment(ALIGN_TOP,ALIGN_LEFT);wiiBtnImg.SetAngle(90);if(datag>163){datag=1;}else if (datag<62){wiiBtn.SetPosition(((2*(datag)-130)),((cosa)*50));}else if(62<=datag){wiiBtn.SetPosition((-2*(datag)+120),((cosa)*50));}if (datag>162){wiiBtn.SetPosition(700,700);w.Remove(&wiiBtn);datagB=2;cosa++;sina=lastrawtime%4;}w.Append(&wiiBtn);}} #ifdef HW_RVL @@ -2608,6 +2625,11 @@ static int MenuDiscList() } } + else if(wiiBtn.GetState() == STATE_CLICKED) + { dataed++; + wiiBtn.ResetState(); + gameBrowser.SetFocus(1); + } else if(installBtn.GetState() == STATE_CLICKED) { choice = WindowPrompt("Install a game?",0,"Yes","No",0,0); @@ -3023,7 +3045,7 @@ static int MenuDiscList() char entered[40]; snprintf(entered, sizeof(entered), "%s", get_title(header)); entered[39] = '\0'; - OnScreenKeyboard(entered, 40); + OnScreenKeyboard(entered, 40,0); WBFS_RenameGame(header->id, entered); __Menu_GetEntries(); menu = MENU_DISCLIST; @@ -3731,7 +3753,7 @@ static int MenuSettings() w.Remove(&lockBtn); char entered[20] = ""; strncpy(entered, Settings.unlockCode, sizeof(entered)); - int result = OnScreenKeyboard(entered, 20); + int result = OnScreenKeyboard(entered, 20,0); mainWindow->Append(&optionBrowser2); mainWindow->Append(&tabBtn); mainWindow->Append(&page1Btn); @@ -3780,7 +3802,7 @@ static int MenuSettings() w.Remove(&lockBtn); char entered[43] = ""; strncpy(entered, CFG.covers_path, sizeof(entered)); - int result = OnScreenKeyboard(entered,43); + int result = OnScreenKeyboard(entered,43,4); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn); @@ -3789,8 +3811,7 @@ static int MenuSettings() w.Append(&backBtn); w.Append(&lockBtn); if ( result == 1 ) - { - strncpy(CFG.covers_path, entered, sizeof(CFG.covers_path)); + { strncpy(CFG.covers_path, entered, sizeof(CFG.covers_path)); WindowPrompt("Coverpath Changed",0,"OK",0,0,0); cfg_save_global(); } @@ -3812,7 +3833,7 @@ static int MenuSettings() w.Remove(&lockBtn); char entered[43] = ""; strncpy(entered, CFG.disc_path, sizeof(entered)); - int result = OnScreenKeyboard(entered, 43); + int result = OnScreenKeyboard(entered, 43,4); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn); @@ -3821,7 +3842,7 @@ static int MenuSettings() w.Append(&backBtn); w.Append(&lockBtn); if ( result == 1 ) - { + { strncpy(CFG.disc_path, entered, sizeof(CFG.disc_path)); WindowPrompt("Discpath Changed",0,"OK",0,0,0); cfg_save_global(); @@ -3844,7 +3865,7 @@ static int MenuSettings() w.Remove(&lockBtn); char entered[43] = ""; strncpy(entered, CFG.theme_path, sizeof(entered)); - int result = OnScreenKeyboard(entered, 43); + int result = OnScreenKeyboard(entered, 43,4); mainWindow->Append(&optionBrowser2); mainWindow->Append(&page1Btn); mainWindow->Append(&page2Btn); @@ -3853,7 +3874,7 @@ static int MenuSettings() w.Append(&backBtn); w.Append(&lockBtn); if ( result == 1 ) - { + { strncpy(CFG.theme_path, entered, sizeof(CFG.theme_path)); WindowPrompt("Themepath Changed",0,"OK",0,0,0); cfg_save_global(); @@ -3971,7 +3992,7 @@ static int MenuSettings() w.Remove(&backBtn); w.Remove(&lockBtn); char entered[20] = ""; - int result = OnScreenKeyboard(entered, 20); + int result = OnScreenKeyboard(entered, 20,0); // mainWindow->Append(&page1Btn); // mainWindow->Append(&page2Btn); mainWindow->Append(&optionBrowser2);