diff --git a/source/ngc/gui/gui.h b/source/ngc/gui/gui.h index 3503674..712979a 100644 --- a/source/ngc/gui/gui.h +++ b/source/ngc/gui/gui.h @@ -59,6 +59,7 @@ extern FreeTypeGX *fontSystem; #define SAVELISTSIZE 6 #define MAX_SAVES 20 #define MAX_OPTIONS 30 +#define MAX_KEYBOARD_DISPLAY 32 typedef void (*UpdateCallback)(void * e); diff --git a/source/ngc/gui/gui_keyboard.cpp b/source/ngc/gui/gui_keyboard.cpp index 6f74158..954114e 100644 --- a/source/ngc/gui/gui_keyboard.cpp +++ b/source/ngc/gui/gui_keyboard.cpp @@ -9,6 +9,24 @@ ***************************************************************************/ #include "gui.h" + +static char tmptxt[MAX_KEYBOARD_DISPLAY]; + +static char * GetDisplayText(char * t) +{ + if(!t) + return NULL; + + int len = strlen(t); + + if(len < MAX_KEYBOARD_DISPLAY) + return t; + + strncpy(tmptxt, &t[len-MAX_KEYBOARD_DISPLAY], MAX_KEYBOARD_DISPLAY); + tmptxt[MAX_KEYBOARD_DISPLAY-1] = 0; + return &tmptxt[0]; +} + /** * Constructor for the GuiKeyboard class. */ @@ -90,7 +108,7 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max) keyTextboxImg->SetPosition(0, 0); this->Append(keyTextboxImg); - kbText = new GuiText(kbtextstr, 22, (GXColor){0, 0, 0, 0xff}); + kbText = new GuiText(GetDisplayText(kbtextstr), 22, (GXColor){0, 0, 0, 0xff}); kbText->SetAlignment(ALIGN_CENTRE, ALIGN_TOP); kbText->SetPosition(0, 13); this->Append(kbText); @@ -166,15 +184,18 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max) keySpace->SetEffectGrow(); this->Append(keySpace); + char txt[2] = { 0, 0 }; + for(int i=0; i<4; i++) { for(int j=0; j<11; j++) { if(keys[i][j].ch != '\0') { + txt[0] = keys[i][j].ch; keyImg[i][j] = new GuiImage(key); keyImgOver[i][j] = new GuiImage(keyOver); - keyTxt[i][j] = new GuiText(NULL, 22, (GXColor){0, 0, 0, 0xff}); + keyTxt[i][j] = new GuiText(txt, 22, (GXColor){0, 0, 0, 0xff}); keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); keyTxt[i][j]->SetPosition(0, -10); keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight()); @@ -251,6 +272,8 @@ void GuiKeyboard::Update(GuiTrigger * t) catch (const std::exception& e) { } } + bool update = false; + if(keySpace->GetState() == STATE_CLICKED) { if(strlen(kbtextstr) < kbtextmaxlen) @@ -263,18 +286,20 @@ void GuiKeyboard::Update(GuiTrigger * t) else if(keyBack->GetState() == STATE_CLICKED) { kbtextstr[strlen(kbtextstr)-1] = 0; - kbText->SetText(kbtextstr); + kbText->SetText(GetDisplayText(kbtextstr)); keyBack->SetState(STATE_SELECTED, t->chan); } else if(keyShift->GetState() == STATE_CLICKED) { shift ^= 1; keyShift->SetState(STATE_SELECTED, t->chan); + update = true; } else if(keyCaps->GetState() == STATE_CLICKED) { caps ^= 1; keyCaps->SetState(STATE_SELECTED, t->chan); + update = true; } char txt[2] = { 0, 0 }; @@ -285,12 +310,15 @@ void GuiKeyboard::Update(GuiTrigger * t) { if(keys[i][j].ch != '\0') { - if(shift || caps) - txt[0] = keys[i][j].chShift; - else - txt[0] = keys[i][j].ch; + if(update) + { + if(shift || caps) + txt[0] = keys[i][j].chShift; + else + txt[0] = keys[i][j].ch; - keyTxt[i][j]->SetText(txt); + keyTxt[i][j]->SetText(txt); + } if(keyBtn[i][j]->GetState() == STATE_CLICKED) { @@ -306,7 +334,7 @@ void GuiKeyboard::Update(GuiTrigger * t) kbtextstr[strlen(kbtextstr)] = keys[i][j].ch; } } - kbText->SetText(kbtextstr); + kbText->SetText(GetDisplayText(kbtextstr)); keyBtn[i][j]->SetState(STATE_SELECTED, t->chan); } } diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 3c6039e..98dc606 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -3335,9 +3335,9 @@ static int MenuSettingsFile() else if (GCSettings.SaveMethod == METHOD_MC_SLOTA) sprintf (options.value[1],"MC Slot A"); else if (GCSettings.SaveMethod == METHOD_MC_SLOTB) sprintf (options.value[1],"MC Slot B"); - snprintf (options.value[2], 256, "%s", GCSettings.LoadFolder); - snprintf (options.value[3], 256, "%s", GCSettings.SaveFolder); - snprintf (options.value[4], 256, "%s", GCSettings.CheatFolder); + snprintf (options.value[2], 30, "%s", GCSettings.LoadFolder); + snprintf (options.value[3], 30, "%s", GCSettings.SaveFolder); + snprintf (options.value[4], 30, "%s", GCSettings.CheatFolder); if (GCSettings.AutoLoad == 0) sprintf (options.value[5],"Off"); else if (GCSettings.AutoLoad == 1) sprintf (options.value[5],"SRAM"); @@ -3363,15 +3363,15 @@ static int MenuSettingsFile() break; case 2: - OnScreenKeyboard(GCSettings.LoadFolder, 30); + OnScreenKeyboard(GCSettings.LoadFolder, MAXPATHLEN); break; case 3: - OnScreenKeyboard(GCSettings.SaveFolder, 30); + OnScreenKeyboard(GCSettings.SaveFolder, MAXPATHLEN); break; case 4: - OnScreenKeyboard(GCSettings.CheatFolder, 30); + OnScreenKeyboard(GCSettings.CheatFolder, MAXPATHLEN); break; case 5: diff --git a/source/ngc/snes9xGX.h b/source/ngc/snes9xGX.h index 4450a80..109f80d 100644 --- a/source/ngc/snes9xGX.h +++ b/source/ngc/snes9xGX.h @@ -66,9 +66,9 @@ struct SGCSettings{ int AutoSave; int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB) int SaveMethod; // For SRAM, Freeze, Prefs: Auto, SD, Memory Card Slot A, Memory Card Slot B, USB, SMB - char LoadFolder[256]; // Path to game files - char SaveFolder[256]; // Path to save files - char CheatFolder[256]; // Path to cheat files + char LoadFolder[MAXPATHLEN]; // Path to game files + char SaveFolder[MAXPATHLEN]; // Path to save files + char CheatFolder[MAXPATHLEN]; // Path to cheat files char smbip[16]; char smbuser[20];