improvements to onscreen keyboard

This commit is contained in:
dborth 2009-07-08 05:56:38 +00:00
parent 5899078870
commit ae13bd130e
4 changed files with 47 additions and 18 deletions

View File

@ -59,6 +59,7 @@ extern FreeTypeGX *fontSystem;
#define SAVELISTSIZE 6 #define SAVELISTSIZE 6
#define MAX_SAVES 20 #define MAX_SAVES 20
#define MAX_OPTIONS 30 #define MAX_OPTIONS 30
#define MAX_KEYBOARD_DISPLAY 32
typedef void (*UpdateCallback)(void * e); typedef void (*UpdateCallback)(void * e);

View File

@ -9,6 +9,24 @@
***************************************************************************/ ***************************************************************************/
#include "gui.h" #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. * Constructor for the GuiKeyboard class.
*/ */
@ -90,7 +108,7 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max)
keyTextboxImg->SetPosition(0, 0); keyTextboxImg->SetPosition(0, 0);
this->Append(keyTextboxImg); 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->SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
kbText->SetPosition(0, 13); kbText->SetPosition(0, 13);
this->Append(kbText); this->Append(kbText);
@ -166,15 +184,18 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max)
keySpace->SetEffectGrow(); keySpace->SetEffectGrow();
this->Append(keySpace); this->Append(keySpace);
char txt[2] = { 0, 0 };
for(int i=0; i<4; i++) for(int i=0; i<4; i++)
{ {
for(int j=0; j<11; j++) for(int j=0; j<11; j++)
{ {
if(keys[i][j].ch != '\0') if(keys[i][j].ch != '\0')
{ {
txt[0] = keys[i][j].ch;
keyImg[i][j] = new GuiImage(key); keyImg[i][j] = new GuiImage(key);
keyImgOver[i][j] = new GuiImage(keyOver); 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]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
keyTxt[i][j]->SetPosition(0, -10); keyTxt[i][j]->SetPosition(0, -10);
keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight()); keyBtn[i][j] = new GuiButton(key->GetWidth(), key->GetHeight());
@ -251,6 +272,8 @@ void GuiKeyboard::Update(GuiTrigger * t)
catch (const std::exception& e) { } catch (const std::exception& e) { }
} }
bool update = false;
if(keySpace->GetState() == STATE_CLICKED) if(keySpace->GetState() == STATE_CLICKED)
{ {
if(strlen(kbtextstr) < kbtextmaxlen) if(strlen(kbtextstr) < kbtextmaxlen)
@ -263,18 +286,20 @@ void GuiKeyboard::Update(GuiTrigger * t)
else if(keyBack->GetState() == STATE_CLICKED) else if(keyBack->GetState() == STATE_CLICKED)
{ {
kbtextstr[strlen(kbtextstr)-1] = 0; kbtextstr[strlen(kbtextstr)-1] = 0;
kbText->SetText(kbtextstr); kbText->SetText(GetDisplayText(kbtextstr));
keyBack->SetState(STATE_SELECTED, t->chan); keyBack->SetState(STATE_SELECTED, t->chan);
} }
else if(keyShift->GetState() == STATE_CLICKED) else if(keyShift->GetState() == STATE_CLICKED)
{ {
shift ^= 1; shift ^= 1;
keyShift->SetState(STATE_SELECTED, t->chan); keyShift->SetState(STATE_SELECTED, t->chan);
update = true;
} }
else if(keyCaps->GetState() == STATE_CLICKED) else if(keyCaps->GetState() == STATE_CLICKED)
{ {
caps ^= 1; caps ^= 1;
keyCaps->SetState(STATE_SELECTED, t->chan); keyCaps->SetState(STATE_SELECTED, t->chan);
update = true;
} }
char txt[2] = { 0, 0 }; char txt[2] = { 0, 0 };
@ -284,6 +309,8 @@ void GuiKeyboard::Update(GuiTrigger * t)
for(int j=0; j<11; j++) for(int j=0; j<11; j++)
{ {
if(keys[i][j].ch != '\0') if(keys[i][j].ch != '\0')
{
if(update)
{ {
if(shift || caps) if(shift || caps)
txt[0] = keys[i][j].chShift; txt[0] = keys[i][j].chShift;
@ -291,6 +318,7 @@ void GuiKeyboard::Update(GuiTrigger * t)
txt[0] = keys[i][j].ch; txt[0] = keys[i][j].ch;
keyTxt[i][j]->SetText(txt); keyTxt[i][j]->SetText(txt);
}
if(keyBtn[i][j]->GetState() == STATE_CLICKED) if(keyBtn[i][j]->GetState() == STATE_CLICKED)
{ {
@ -306,7 +334,7 @@ void GuiKeyboard::Update(GuiTrigger * t)
kbtextstr[strlen(kbtextstr)] = keys[i][j].ch; kbtextstr[strlen(kbtextstr)] = keys[i][j].ch;
} }
} }
kbText->SetText(kbtextstr); kbText->SetText(GetDisplayText(kbtextstr));
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan); keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
} }
} }

View File

@ -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_SLOTA) sprintf (options.value[1],"MC Slot A");
else if (GCSettings.SaveMethod == METHOD_MC_SLOTB) sprintf (options.value[1],"MC Slot B"); 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[2], 30, "%s", GCSettings.LoadFolder);
snprintf (options.value[3], 256, "%s", GCSettings.SaveFolder); snprintf (options.value[3], 30, "%s", GCSettings.SaveFolder);
snprintf (options.value[4], 256, "%s", GCSettings.CheatFolder); snprintf (options.value[4], 30, "%s", GCSettings.CheatFolder);
if (GCSettings.AutoLoad == 0) sprintf (options.value[5],"Off"); if (GCSettings.AutoLoad == 0) sprintf (options.value[5],"Off");
else if (GCSettings.AutoLoad == 1) sprintf (options.value[5],"SRAM"); else if (GCSettings.AutoLoad == 1) sprintf (options.value[5],"SRAM");
@ -3363,15 +3363,15 @@ static int MenuSettingsFile()
break; break;
case 2: case 2:
OnScreenKeyboard(GCSettings.LoadFolder, 30); OnScreenKeyboard(GCSettings.LoadFolder, MAXPATHLEN);
break; break;
case 3: case 3:
OnScreenKeyboard(GCSettings.SaveFolder, 30); OnScreenKeyboard(GCSettings.SaveFolder, MAXPATHLEN);
break; break;
case 4: case 4:
OnScreenKeyboard(GCSettings.CheatFolder, 30); OnScreenKeyboard(GCSettings.CheatFolder, MAXPATHLEN);
break; break;
case 5: case 5:

View File

@ -66,9 +66,9 @@ struct SGCSettings{
int AutoSave; int AutoSave;
int LoadMethod; // For ROMS: Auto, SD, DVD, USB, Network (SMB) 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 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 LoadFolder[MAXPATHLEN]; // Path to game files
char SaveFolder[256]; // Path to save files char SaveFolder[MAXPATHLEN]; // Path to save files
char CheatFolder[256]; // Path to cheat files char CheatFolder[MAXPATHLEN]; // Path to cheat files
char smbip[16]; char smbip[16];
char smbuser[20]; char smbuser[20];