Jeck - Quick crashfix when loading without a profiles directory, slight keypad modifications.

This commit is contained in:
wagic.jeck
2009-08-27 03:17:25 +00:00
parent 5aa0aa9374
commit 6728794ce9
7 changed files with 1315 additions and 1305 deletions
+1 -1
View File
@@ -101,7 +101,7 @@ public:
~GameSettings(); ~GameSettings();
int save(); int save();
SimplePad * keypadStart(string input, string * _dest = NULL, int _x = SCREEN_WIDTH/2, int _y = SCREEN_HEIGHT/2); SimplePad * keypadStart(string input, string * _dest = NULL, bool _cancel=true, bool _numpad=false, int _x = SCREEN_WIDTH/2, int _y = SCREEN_HEIGHT/2);
string keypadFinish(); string keypadFinish();
void keypadShutdown(); void keypadShutdown();
void keypadTitle(string set); void keypadTitle(string set);
+1 -1
View File
@@ -40,7 +40,7 @@ public:
SimplePad(bool numbers=false); SimplePad();
~SimplePad(); ~SimplePad();
int mX; int mY; int mX; int mY;
File diff suppressed because it is too large Load Diff
-1
View File
@@ -95,7 +95,6 @@ void GameApp::Create()
manaIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green"); manaIcons[Constants::MTG_COLOR_GREEN] = GameApp::CommonRes->GetQuad("c_green");
for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i) manaIcons[i]->SetHotSpot(16,16); for (int i = sizeof(manaIcons)/sizeof(manaIcons[0]) - 1; i >= 0; --i) manaIcons[i]->SetHotSpot(16,16);
CommonRes->CreateTexture("sets/back.jpg"); CommonRes->CreateTexture("sets/back.jpg");
CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285); CommonRes->CreateQuad("back", "sets/back.jpg", 0, 0, 200, 285);
CommonRes->GetQuad("back")->SetHotSpot(100, 145); CommonRes->GetQuad("back")->SetHotSpot(100, 145);
+6 -1
View File
@@ -282,6 +282,7 @@ string GameSettings::themeGraphic(string filename)
{ {
char buf[4096]; char buf[4096];
string theme = (*this)[Options::ACTIVE_THEME].str; string theme = (*this)[Options::ACTIVE_THEME].str;
if(theme == "" || theme == "default"){ if(theme == "" || theme == "default"){
sprintf(buf,"graphics/%s",filename.c_str()); sprintf(buf,"graphics/%s",filename.c_str());
return buf; return buf;
@@ -304,6 +305,8 @@ void GameSettings::checkProfile(){
if(profileOptions != NULL) if(profileOptions != NULL)
SAFE_DELETE(profileOptions); SAFE_DELETE(profileOptions);
//Force our directories to exist.
MAKEDIR(RESPATH"/profiles");
string temp = profileFile("","",false,false); string temp = profileFile("","",false,false);
MAKEDIR(temp.c_str()); MAKEDIR(temp.c_str());
temp+="/stats"; temp+="/stats";
@@ -394,9 +397,11 @@ void GameSettings::keypadTitle(string set){
if(keypad != NULL) if(keypad != NULL)
keypad->title = set; keypad->title = set;
} }
SimplePad * GameSettings::keypadStart(string input, string * _dest,int _x,int _y){ SimplePad * GameSettings::keypadStart(string input, string * _dest,bool _cancel, bool _numpad, int _x,int _y ){
if(keypad == NULL) if(keypad == NULL)
keypad = new SimplePad(); keypad = new SimplePad();
keypad->bShowCancel = _cancel;
keypad->bShowNumpad = _numpad;
keypad->mX = _x; keypad->mX = _x;
keypad->mY = _y; keypad->mY = _y;
keypad->Start(input,_dest); keypad->Start(input,_dest);
+6
View File
@@ -331,6 +331,9 @@ void OptionDirectory::Reload(){
char buf[4096]; char buf[4096];
mDip = opendir(root.c_str()); mDip = opendir(root.c_str());
if(!mDip)
return;
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
if(mDit->d_name[0] != '.'){ if(mDit->d_name[0] != '.'){
sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); sprintf(buf,"%s/%s",root.c_str(),mDit->d_name);
@@ -356,6 +359,9 @@ OptionDirectory::OptionDirectory(string _root, string _id, string _displayValue)
root = _root; root = _root;
mDip = opendir(root.c_str()); mDip = opendir(root.c_str());
if(!mDip)
return;
while ((mDit = readdir(mDip))){ while ((mDit = readdir(mDip))){
if(mDit->d_name[0] != '.'){ if(mDit->d_name[0] != '.'){
sprintf(buf,"%s/%s",root.c_str(),mDit->d_name); sprintf(buf,"%s/%s",root.c_str(),mDit->d_name);
+358 -358
View File
@@ -1,349 +1,349 @@
#include "../include/config.h" #include "../include/config.h"
#include "../include/SimplePad.h" #include "../include/SimplePad.h"
#include "JTypes.h" #include "JTypes.h"
#include "../include/GameApp.h" #include "../include/GameApp.h"
#include "../include/Translate.h" #include "../include/Translate.h"
#define ALPHA_COLUMNS 8 #define ALPHA_COLUMNS 8
#define ALPHA_ROWS 8 #define ALPHA_ROWS 8
#define KPD_UP 0 #define KPD_UP 0
#define KPD_DOWN 1 #define KPD_DOWN 1
#define KPD_LEFT 2 #define KPD_LEFT 2
#define KPD_RIGHT 3 #define KPD_RIGHT 3
SimpleKey::SimpleKey( string _ds, int _id){ SimpleKey::SimpleKey( string _ds, int _id){
displayValue = _ds; id = _id; displayValue = _ds; id = _id;
for(int x=0;x<4;x++) for(int x=0;x<4;x++)
adjacency[4] = KPD_NOWHERE; adjacency[4] = KPD_NOWHERE;
} }
void SimplePad::linkKeys(int from, int to, int dir){ void SimplePad::linkKeys(int from, int to, int dir){
if(keys[from] && keys[to]){ if(keys[from] && keys[to]){
keys[from]->adjacency[dir] = to; keys[from]->adjacency[dir] = to;
switch(dir){ switch(dir){
case KPD_UP: case KPD_UP:
case KPD_LEFT: case KPD_LEFT:
dir++; dir++;
break; break;
default: default:
dir--; dir--;
}
keys[to]->adjacency[dir] = from;
}
}
SimplePad::SimplePad(bool numbers){
nbitems = 0;
bActive = false;
selected = 0;
priorKey = 0;
cursor = 0;
bShowCancel = false;
bShowNumpad = false;
bCapslock = true;
char buf[2];
buf[1] = '\0';
SimpleKey * k;
for(int x=0;x<KPD_MAX;x++)
keys[x] = NULL;
//Add the alphabet. We cheat a bit here.
for(int x='a';x<='z';x++)
{
buf[0] = x;
k=Add(buf,x);
int idx = x-'a';
if(idx > KPD_A)
k->adjacency[KPD_LEFT] = idx-1;
if(idx < KPD_Z)
k->adjacency[KPD_RIGHT] = idx+1;
if(idx > ALPHA_COLUMNS)
k->adjacency[KPD_UP] = idx-1-ALPHA_COLUMNS;
else
k->adjacency[KPD_UP] = KPD_INPUT;
if(idx < 25-ALPHA_COLUMNS)
k->adjacency[KPD_DOWN] = idx+1+ALPHA_COLUMNS;
} }
keys[to]->adjacency[dir] = from;
Add("Spacebar",KPD_SPACE); }
}
for(int x=25-ALPHA_COLUMNS;x<26;x++)
keys[x]->adjacency[KPD_DOWN] = KPD_SPACE; SimplePad::SimplePad(){
nbitems = 0;
k=Add("Confirm",KPD_OK); bActive = false;
keys[KPD_Z]->adjacency[KPD_RIGHT] = KPD_OK; selected = 0;
k->adjacency[KPD_UP] = KPD_CAPS; priorKey = 0;
k->adjacency[KPD_LEFT] = KPD_Z; cursor = 0;
k->adjacency[KPD_DOWN] = KPD_CANCEL; bShowCancel = false;
bShowNumpad = false;
k=Add("Cancel",KPD_CANCEL); bCapslock = true;
k->adjacency[KPD_UP] = KPD_OK; char buf[2];
k->adjacency[KPD_LEFT] = KPD_SPACE; buf[1] = '\0';
SimpleKey * k;
k=Add("Del",KPD_DEL);
keys[KPD_I]->adjacency[KPD_RIGHT] = KPD_DEL; for(int x=0;x<KPD_MAX;x++)
k->adjacency[KPD_UP] = KPD_9; keys[x] = NULL;
k->adjacency[KPD_DOWN] = KPD_CAPS;
k->adjacency[KPD_LEFT] = KPD_I; //Add the alphabet. We cheat a bit here.
for(int x='a';x<='z';x++)
k=Add("Caps",KPD_CAPS); {
keys[KPD_R]->adjacency[KPD_RIGHT] = KPD_CAPS; buf[0] = x;
keys[KPD_R]->adjacency[KPD_DOWN] = KPD_Z; k=Add(buf,x);
k->adjacency[KPD_UP] = KPD_DEL; int idx = x-'a';
k->adjacency[KPD_DOWN] = KPD_OK;
k->adjacency[KPD_LEFT] = KPD_R; if(idx > KPD_A)
k->adjacency[KPD_LEFT] = idx-1;
if(idx < KPD_Z)
for(int x=0;x<10;x++){ k->adjacency[KPD_RIGHT] = idx+1;
buf[0] = '0'+x; if(idx > ALPHA_COLUMNS)
Add(buf,KPD_0+x); k->adjacency[KPD_UP] = idx-1-ALPHA_COLUMNS;
if(x < 8) else
linkKeys(KPD_0+x,KPD_A+x,KPD_DOWN); k->adjacency[KPD_UP] = KPD_INPUT;
if(x > 0) if(idx < 25-ALPHA_COLUMNS)
linkKeys(KPD_0+x,KPD_0+x-1,KPD_LEFT); k->adjacency[KPD_DOWN] = idx+1+ALPHA_COLUMNS;
} }
keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL; Add("Spacebar",KPD_SPACE);
keys[KPD_9]->adjacency[KPD_DOWN] = KPD_DEL;
for(int x=25-ALPHA_COLUMNS;x<26;x++)
keys[KPD_0]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[x]->adjacency[KPD_DOWN] = KPD_SPACE;
keys[KPD_A]->adjacency[KPD_LEFT] = KPD_NOWHERE;
keys[KPD_J]->adjacency[KPD_LEFT] = KPD_NOWHERE; k=Add("Confirm",KPD_OK);
keys[KPD_S]->adjacency[KPD_LEFT] = KPD_NOWHERE; keys[KPD_Z]->adjacency[KPD_RIGHT] = KPD_OK;
k->adjacency[KPD_UP] = KPD_CAPS;
} k->adjacency[KPD_LEFT] = KPD_Z;
k->adjacency[KPD_DOWN] = KPD_CANCEL;
SimplePad::~SimplePad()
{ k=Add("Cancel",KPD_CANCEL);
for(int x=0;x<KPD_MAX;x++) k->adjacency[KPD_UP] = KPD_OK;
SAFE_DELETE(keys[x]); k->adjacency[KPD_LEFT] = KPD_SPACE;
}
k=Add("Del",KPD_DEL);
keys[KPD_I]->adjacency[KPD_RIGHT] = KPD_DEL;
SimpleKey * SimplePad::Add(string display, unsigned char id){ k->adjacency[KPD_UP] = KPD_9;
if(nbitems >= KPD_MAX) k->adjacency[KPD_DOWN] = KPD_CAPS;
return NULL; k->adjacency[KPD_LEFT] = KPD_I;
keys[nbitems++] = NEW SimpleKey(display,id); k=Add("Caps",KPD_CAPS);
return keys[nbitems-1]; keys[KPD_R]->adjacency[KPD_RIGHT] = KPD_CAPS;
} keys[KPD_R]->adjacency[KPD_DOWN] = KPD_Z;
void SimplePad::pressKey(unsigned char key){ k->adjacency[KPD_UP] = KPD_DEL;
string input = ""; k->adjacency[KPD_DOWN] = KPD_OK;
int tCursor = cursor; k->adjacency[KPD_LEFT] = KPD_R;
if(isalpha(key)) {
if(bCapslock) for(int x=0;x<10;x++){
input += toupper(key); buf[0] = '0'+x;
else Add(buf,KPD_0+x);
input += key; if(x < 8)
linkKeys(KPD_0+x,KPD_A+x,KPD_DOWN);
if(cursor < 0 || cursor > buffer.size()) if(x > 0)
tCursor = buffer.size(); linkKeys(KPD_0+x,KPD_0+x-1,KPD_LEFT);
else }
cursor++;
buffer.insert(tCursor,input); keys[KPD_8]->adjacency[KPD_DOWN] = KPD_DEL;
} keys[KPD_9]->adjacency[KPD_DOWN] = KPD_DEL;
else if(key == KPD_CAPS)
bCapslock = !bCapslock; keys[KPD_0]->adjacency[KPD_LEFT] = KPD_NOWHERE;
else if(key == KPD_DEL) { keys[KPD_A]->adjacency[KPD_LEFT] = KPD_NOWHERE;
if(cursor < 0 || cursor > buffer.size()) keys[KPD_J]->adjacency[KPD_LEFT] = KPD_NOWHERE;
cursor = buffer.size(); keys[KPD_S]->adjacency[KPD_LEFT] = KPD_NOWHERE;
if(cursor == buffer.size())
buffer = buffer.substr(0,cursor-1); }
else if(cursor > 0)
buffer = buffer.substr(0,cursor) + buffer.substr(cursor+1); SimplePad::~SimplePad()
else {
return; for(int x=0;x<KPD_MAX;x++)
SAFE_DELETE(keys[x]);
cursor--; }
}
else if(key == KPD_OK)
Finish(); SimpleKey * SimplePad::Add(string display, unsigned char id){
else if(key == KPD_CANCEL) { if(nbitems >= KPD_MAX)
bCanceled = true; return NULL;
Finish();
} keys[nbitems++] = NEW SimpleKey(display,id);
return keys[nbitems-1];
} }
void SimplePad::MoveSelection(unsigned char moveto) void SimplePad::pressKey(unsigned char key){
{ string input = "";
if(!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9 ) int tCursor = cursor;
moveto = KPD_INPUT;
else if(!bShowCancel && moveto == KPD_CANCEL ) if(isalpha(key)) {
moveto = KPD_SPACE; if(bCapslock)
input += toupper(key);
if(selected < KPD_MAX && selected >= 0) else
priorKey = selected; input += key;
if(moveto < KPD_MAX && moveto >= 0) { if(cursor < 0 || cursor > buffer.size())
selected = moveto; tCursor = buffer.size();
} else
else if(moveto == KPD_INPUT) cursor++;
selected = KPD_INPUT; buffer.insert(tCursor,input);
} }
else if(key == KPD_CAPS)
bCapslock = !bCapslock;
else if(key == KPD_DEL) {
if(cursor < 0 || cursor > buffer.size())
cursor = buffer.size();
if(cursor == buffer.size())
buffer = buffer.substr(0,cursor-1);
else if(cursor > 0)
buffer = buffer.substr(0,cursor) + buffer.substr(cursor+1);
else
return;
cursor--;
}
else if(key == KPD_OK)
Finish();
else if(key == KPD_CANCEL) {
bCanceled = true;
Finish();
}
}
void SimplePad::MoveSelection(unsigned char moveto)
{
if(!bShowNumpad && moveto >= KPD_0 && moveto <= KPD_9 )
moveto = KPD_INPUT;
else if(!bShowCancel && moveto == KPD_CANCEL )
moveto = KPD_SPACE;
if(selected < KPD_MAX && selected >= 0)
priorKey = selected;
if(moveto < KPD_MAX && moveto >= 0) {
selected = moveto;
}
else if(moveto == KPD_INPUT)
selected = KPD_INPUT;
}
void SimplePad::Update(float dt){ void SimplePad::Update(float dt){
JGE * mEngine = JGE::GetInstance(); JGE * mEngine = JGE::GetInstance();
//We can always confirm! //We can always confirm!
if(mEngine->GetButtonClick(PSP_CTRL_START)) if(mEngine->GetButtonClick(PSP_CTRL_START))
{ {
if(selected != KPD_OK) if(selected != KPD_OK)
selected = KPD_OK; selected = KPD_OK;
else else
Finish(); Finish();
return; return;
} }
if(selected == KPD_SPACE){ if(selected == KPD_SPACE){
if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT)) if(bShowCancel && mEngine->GetButtonClick(PSP_CTRL_RIGHT))
selected = KPD_CANCEL; selected = KPD_CANCEL;
else if (mEngine->GetButtonClick(PSP_CTRL_LEFT)||mEngine->GetButtonClick(PSP_CTRL_RIGHT) else if (mEngine->GetButtonClick(PSP_CTRL_LEFT)||mEngine->GetButtonClick(PSP_CTRL_RIGHT)
||mEngine->GetButtonClick(PSP_CTRL_UP)||mEngine->GetButtonClick(PSP_CTRL_DOWN)) ||mEngine->GetButtonClick(PSP_CTRL_UP)||mEngine->GetButtonClick(PSP_CTRL_DOWN))
selected = priorKey; selected = priorKey;
} //Moving in/from the text field. } //Moving in/from the text field.
else if(selected == KPD_INPUT){ else if(selected == KPD_INPUT){
if (mEngine->GetButtonClick(PSP_CTRL_DOWN) ) if (mEngine->GetButtonClick(PSP_CTRL_DOWN) )
selected = priorKey; selected = priorKey;
if (mEngine->GetButtonClick(PSP_CTRL_LEFT) && cursor > -1){ if (mEngine->GetButtonClick(PSP_CTRL_LEFT) && cursor > -1){
if(cursor > buffer.size()) if(cursor > buffer.size())
cursor = buffer.size() - 1; cursor = buffer.size() - 1;
else else
cursor--; cursor--;
} }
else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT)) else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT))
if(cursor < buffer.size()) if(cursor < buffer.size())
cursor++; cursor++;
else else
cursor = buffer.size() + 1; cursor = buffer.size() + 1;
} }
else if(selected >= 0 && keys[selected]){ else if(selected >= 0 && keys[selected]){
if (mEngine->GetButtonClick(PSP_CTRL_LEFT)) if (mEngine->GetButtonClick(PSP_CTRL_LEFT))
MoveSelection(keys[selected]->adjacency[KPD_LEFT]); MoveSelection(keys[selected]->adjacency[KPD_LEFT]);
else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT)) else if (mEngine->GetButtonClick(PSP_CTRL_RIGHT))
MoveSelection(keys[selected]->adjacency[KPD_RIGHT]); MoveSelection(keys[selected]->adjacency[KPD_RIGHT]);
if (mEngine->GetButtonClick(PSP_CTRL_DOWN)) if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
MoveSelection(keys[selected]->adjacency[KPD_DOWN]); MoveSelection(keys[selected]->adjacency[KPD_DOWN]);
else if (mEngine->GetButtonClick(PSP_CTRL_UP)) else if (mEngine->GetButtonClick(PSP_CTRL_UP))
MoveSelection(keys[selected]->adjacency[KPD_UP]); MoveSelection(keys[selected]->adjacency[KPD_UP]);
} }
//These bits require a valid key... //These bits require a valid key...
if(selected >= 0 && selected < nbitems && keys[selected]){ if(selected >= 0 && selected < nbitems && keys[selected]){
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE))
pressKey(keys[selected]->id); pressKey(keys[selected]->id);
} }
if (mEngine->GetButtonClick(PSP_CTRL_CROSS) && buffer.size() > 0) if (mEngine->GetButtonClick(PSP_CTRL_CROSS) && buffer.size() > 0)
buffer = buffer.substr(0,buffer.size() - 1); buffer = buffer.substr(0,buffer.size() - 1);
if (mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)){ if (mEngine->GetButtonClick(PSP_CTRL_LTRIGGER)){
if(buffer.size() != 0 && cursor != 0) if(buffer.size() != 0 && cursor != 0)
if(cursor < 0 || cursor >= buffer.size()) if(cursor < 0 || cursor >= buffer.size())
cursor = buffer.size() - 1; cursor = buffer.size() - 1;
else else
cursor--; cursor--;
} }
else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)){ else if (mEngine->GetButtonClick(PSP_CTRL_RTRIGGER)){
if(cursor > -1 && cursor < buffer.size()) if(cursor > -1 && cursor < buffer.size())
cursor++; cursor++;
else{ else{
buffer += ' '; buffer += ' ';
cursor = buffer.size(); cursor = buffer.size();
} }
} }
mX = 50; mX = 50;
mY = 50; mY = 50;
} }
void SimplePad::Start(string value, string * _dest) { void SimplePad::Start(string value, string * _dest) {
bActive = true; bActive = true;
bCanceled=false; bCanceled=false;
buffer = value; buffer = value;
original = buffer; original = buffer;
dest = _dest; dest = _dest;
cursor = buffer.size(); cursor = buffer.size();
} }
string SimplePad::Finish() { string SimplePad::Finish() {
bActive = false; bActive = false;
if(bCanceled){ if(bCanceled){
dest = NULL; dest = NULL;
return original; return original;
} }
if(dest != NULL){ if(dest != NULL){
dest->clear(); dest->insert(0,buffer); dest->clear(); dest->insert(0,buffer);
dest = NULL; dest = NULL;
} }
return buffer; return buffer;
} }
void SimplePad::Render(){ void SimplePad::Render(){
//This could use some cleaning up to make margins more explicit //This could use some cleaning up to make margins more explicit
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3"); JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
int offX = 0, offY = 0; int offX = 0, offY = 0;
int kH = mFont->GetHeight(); int kH = mFont->GetHeight();
int hSpacing = mFont->GetStringWidth("W"); int hSpacing = mFont->GetStringWidth("W");
int vSpacing = 0; int vSpacing = 0;
int kW = hSpacing; int kW = hSpacing;
JRenderer * renderer = JRenderer::GetInstance(); JRenderer * renderer = JRenderer::GetInstance();
if(title != "") if(title != "")
vSpacing = kH+8; vSpacing = kH+8;
else else
vSpacing = 0; vSpacing = 0;
offY = vSpacing; offY = vSpacing;
if(bShowNumpad) if(bShowNumpad)
offY += kH+14; offY += kH+14;
//Draw Keypad Background. //Draw Keypad Background.
renderer->FillRoundRect(mX-kW,mY-kH,(kW+12)*11,(kH+14)*5+offY,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,0,0,0))); renderer->FillRoundRect(mX-kW,mY-kH,(kW+12)*11,(kH+14)*5+offY,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,0,0,0)));
offY = vSpacing; offY = vSpacing;
//Draw text entry bubble //Draw text entry bubble
renderer->FillRoundRect(mX-kW/2,mY+offY,(kW+12)*9+kW/2,kH,2,options[Metrics::KEYPAD_FCH].asColor(ARGB(255,255,255,255))); renderer->FillRoundRect(mX-kW/2,mY+offY,(kW+12)*9+kW/2,kH,2,options[Metrics::KEYPAD_FCH].asColor(ARGB(255,255,255,255)));
//Draw text-entry title, if we've got one. //Draw text-entry title, if we've got one.
if(title != ""){ if(title != ""){
mFont->DrawString(title.c_str(),mX,mY); mFont->DrawString(title.c_str(),mX,mY);
mY+=kH+12; mY+=kH+12;
} }
//Draw cursor. //Draw cursor.
int cPos = cursor; int cPos = cursor;
if(cPos > -1 && cPos < buffer.size()) if(cPos > -1 && cPos < buffer.size())
{ {
kW = mFont->GetStringWidth(buffer.substr(cPos,1).c_str()); kW = mFont->GetStringWidth(buffer.substr(cPos,1).c_str());
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cPos).c_str()),mY+kH-4, renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cPos).c_str()),mY+kH-4,
kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0))); kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0)));
} }
else else
{ {
cPos = buffer.size(); cPos = buffer.size();
renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cPos).c_str()),mY+kH-4, renderer->FillRoundRect(mX+mFont->GetStringWidth(buffer.substr(0,cPos).c_str()),mY+kH-4,
kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0))); kW,4,2,options[Metrics::KEY_FCH].asColor(ARGB(150,150,150,0)));
} }
mFont->SetColor(options[Metrics::KEYPAD_TC].asColor(ARGB(255,0,0,0))); mFont->SetColor(options[Metrics::KEYPAD_TC].asColor(ARGB(255,0,0,0)));
mFont->DrawString(buffer.c_str(),mX,mY); mFont->DrawString(buffer.c_str(),mX,mY);
offY += kH + 12; offY += kH + 12;
int rowLen[4]; int rowLen[4];
if(!bShowNumpad) if(!bShowNumpad)
vSpacing -= kH + 12; vSpacing -= kH + 12;
for(int x=0;x<nbitems;x++) for(int x=0;x<nbitems;x++)
if(keys[x]){ if(keys[x]){
if((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad)) if((x == KPD_CANCEL && !bShowCancel) || (x >= KPD_0 && x <= KPD_9 && !bShowNumpad))
continue; continue;
switch(x){ switch(x){
case KPD_0: case KPD_0:
@@ -392,35 +392,35 @@ void SimplePad::Render(){
break; break;
} }
kW = mFont->GetStringWidth(keys[x]->displayValue.c_str()); kW = mFont->GetStringWidth(keys[x]->displayValue.c_str());
//Render a key. //Render a key.
if(x != selected){ if(x != selected){
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,50,50,50))); renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(180,50,50,50)));
mFont->SetColor(options[Metrics::POPUP_MENU_TCH].asColor(ARGB(255,255,255,0))); mFont->SetColor(options[Metrics::POPUP_MENU_TCH].asColor(ARGB(255,255,255,0)));
} }
else{ else{
renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(255,100,100,100))); renderer->FillRoundRect(mX+offX-4,mY+offY-4,kW+8,kH+4,2,options[Metrics::POPUP_MENU_FC].asColor(ARGB(255,100,100,100)));
mFont->SetColor(options[Metrics::POPUP_MENU_TC].asColor(ARGB(255,255,255,255))); mFont->SetColor(options[Metrics::POPUP_MENU_TC].asColor(ARGB(255,255,255,255)));
} }
char vkey[2]; char vkey[2];
vkey[1] = '\0'; vkey[1] = '\0';
vkey[0] = keys[x]->id; vkey[0] = keys[x]->id;
if(isalpha(vkey[0])) { if(isalpha(vkey[0])) {
if(bCapslock) vkey[0] = toupper(vkey[0]); if(bCapslock) vkey[0] = toupper(vkey[0]);
mFont->DrawString(vkey,mX+offX,mY+offY); mFont->DrawString(vkey,mX+offX,mY+offY);
} }
else else
mFont->DrawString(keys[x]->displayValue.c_str(),mX+offX,mY+offY); mFont->DrawString(keys[x]->displayValue.c_str(),mX+offX,mY+offY);
offX += kW + 14; offX += kW + 14;
} }
} }
int SimplePad::cursorPos(){ int SimplePad::cursorPos(){
if(cursor < 0 || cursor > buffer.size()) if(cursor < 0 || cursor > buffer.size())
return buffer.size(); return buffer.size();
return cursor; return cursor;
} }