1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-23 00:37:10 +02:00

InputDialog: re-layouted code.

No functional changes.
This commit is contained in:
Maarten ter Huurne 2011-10-23 11:56:32 +02:00
parent 0b878c1b77
commit fa5a9816db

View File

@ -41,8 +41,9 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
this->text = text;
}
this->icon = "";
if (icon!="" && gmenu2x->sc[icon] != NULL)
if (icon != "" && gmenu2x->sc[icon] != NULL) {
this->icon = icon;
}
input = startvalue;
selCol = 0;
@ -85,19 +86,23 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
setKeyboard(0);
buttonbox = new ButtonBox(gmenu2x);
IconButton *btnBackspace = new IconButton(gmenu2x, "skin:imgs/buttons/l.png", gmenu2x->tr["Backspace"]);
IconButton *btnBackspace = new IconButton(gmenu2x,
"skin:imgs/buttons/l.png", gmenu2x->tr["Backspace"]);
btnBackspace->setAction(MakeDelegate(this, &InputDialog::backspace));
buttonbox->add(btnBackspace);
IconButton *btnSpace = new IconButton(gmenu2x, "skin:imgs/buttons/r.png", gmenu2x->tr["Space"]);
IconButton *btnSpace = new IconButton(gmenu2x,
"skin:imgs/buttons/r.png", gmenu2x->tr["Space"]);
btnSpace->setAction(MakeDelegate(this, &InputDialog::space));
buttonbox->add(btnSpace);
IconButton *btnConfirm = new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"]);
IconButton *btnConfirm = new IconButton(gmenu2x,
"skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"]);
btnConfirm->setAction(MakeDelegate(this, &InputDialog::confirm));
buttonbox->add(btnConfirm);
IconButton *btnChangeKeys = new IconButton(gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Change keys"]);
IconButton *btnChangeKeys = new IconButton(gmenu2x,
"skin:imgs/buttons/cancel.png", gmenu2x->tr["Change keys"]);
btnChangeKeys->setAction(MakeDelegate(this, &InputDialog::changeKeys));
buttonbox->add(btnChangeKeys);
}
@ -107,11 +112,12 @@ void InputDialog::setKeyboard(int kb) {
curKeyboard = kb;
this->kb = &(keyboard[kb]);
kbLength = this->kb->at(0).length();
for (int x = 0, l = kbLength; x<l; x++)
for (int x = 0, l = kbLength; x < l; x++) {
if (gmenu2x->font->utf8Code(this->kb->at(0)[x])) {
kbLength--;
x++;
}
}
kbLeft = 160 - kbLength * KEY_WIDTH / 2;
kbWidth = kbLength * KEY_WIDTH + 3;
@ -144,9 +150,11 @@ bool InputDialog::exec() {
box.x = 160 - box.w / 2;
gmenu2x->s->box(box.x, box.y, box.w, box.h,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->rectangle(box.x, box.y, box.w, box.h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->rectangle(box.x, box.y, box.w, box.h,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->write(gmenu2x->font, input, box.x+5, box.y+box.h-2, ASFont::HAlignLeft, ASFont::VAlignBottom);
gmenu2x->s->write(gmenu2x->font, input, box.x + 5, box.y + box.h - 2,
ASFont::HAlignLeft, ASFont::VAlignBottom);
curTick = SDL_GetTicks();
if (curTick - caretTick >= 600) {
@ -154,7 +162,10 @@ bool InputDialog::exec() {
caretTick = curTick;
}
if (caretOn) gmenu2x->s->box(box.x+box.w-12, box.y+3, 8, box.h-6, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
if (caretOn) {
gmenu2x->s->box(box.x + box.w - 12, box.y + 3, 8, box.h - 6,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
}
if (ts.initialized()) ts.poll();
action = drawVirtualKeyboard();
@ -199,25 +210,25 @@ bool InputDialog::exec() {
}
void InputDialog::backspace() {
// check for utf8 characters
input = input.substr(0,input.length()-( gmenu2x->font->utf8Code(input[input.length()-2]) ? 2 : 1 ));
// Check for UTF8 characters.
input = input.substr(0, input.length()
- (gmenu2x->font->utf8Code(input[input.length() - 2]) ? 2 : 1));
}
void InputDialog::space() {
// check for utf8 characters
input += " ";
}
void InputDialog::confirm() {
if (selRow == (int)kb->size()) {
if (selCol==0)
if (selCol == 0) {
ok = false;
}
close = true;
} else {
bool utf8;
int xc = 0;
for (uint x = 0; x < kb->at(selRow).length(); x++) {
utf8 = gmenu2x->font->utf8Code(kb->at(selRow)[x]);
bool utf8 = gmenu2x->font->utf8Code(kb->at(selRow)[x]);
if (xc == selCol) input += kb->at(selRow).substr(x, utf8 ? 2 : 1);
if (utf8) x++;
xc++;
@ -226,11 +237,12 @@ void InputDialog::confirm() {
}
void InputDialog::changeKeys() {
if (curKeyboard==6)
if (curKeyboard == 6) {
setKeyboard(0);
else
} else {
setKeyboard(curKeyboard + 1);
}
}
int InputDialog::drawVirtualKeyboard() {
int action = ID_NO_ACTION;
@ -245,12 +257,15 @@ int InputDialog::drawVirtualKeyboard() {
//selection
if (selRow<(int)kb->size())
gmenu2x->s->box(kbLeft+selCol*KEY_WIDTH-1, KB_TOP+selRow*KEY_HEIGHT, KEY_WIDTH-1, KEY_HEIGHT-2, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->box(kbLeft + selCol * KEY_WIDTH - 1,
KB_TOP + selRow * KEY_HEIGHT, KEY_WIDTH - 1, KEY_HEIGHT - 2,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
else {
if (selCol > 1) selCol = 0;
if (selCol < 0) selCol = 1;
gmenu2x->s->box(kbLeft + selCol * kbLength * KEY_WIDTH / 2 - 1,
KB_TOP+kb->size()*KEY_HEIGHT, kbLength*KEY_WIDTH/2-1, KEY_HEIGHT-1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
KB_TOP + kb->size() * KEY_HEIGHT, kbLength * KEY_WIDTH / 2 - 1,
KEY_HEIGHT - 1, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
}
//keys
@ -265,7 +280,10 @@ int InputDialog::drawVirtualKeyboard() {
} else
charX = line[x];
SDL_Rect re = {kbLeft+xc*KEY_WIDTH-1, KB_TOP+l*KEY_HEIGHT, KEY_WIDTH-1, KEY_HEIGHT-2};
SDL_Rect re = {
kbLeft + xc * KEY_WIDTH - 1, KB_TOP + l * KEY_HEIGHT,
KEY_WIDTH - 1, KEY_HEIGHT - 2
};
//if ts on rect, change selection
if (ts.initialized() && ts.pressed() && ts.inRect(re)) {
@ -273,8 +291,12 @@ int InputDialog::drawVirtualKeyboard() {
selRow = l;
}
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->write(gmenu2x->font, charX, kbLeft+xc*KEY_WIDTH+KEY_WIDTH/2-1, KB_TOP+l*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
gmenu2x->s->rectangle(re,
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
gmenu2x->s->write(gmenu2x->font, charX,
kbLeft + xc * KEY_WIDTH + KEY_WIDTH / 2 - 1,
KB_TOP + l * KEY_HEIGHT + KEY_HEIGHT / 2,
ASFont::HAlignCenter, ASFont::VAlignMiddle);
xc++;
}
}
@ -286,7 +308,10 @@ int InputDialog::drawVirtualKeyboard() {
selCol = 0;
selRow = kb->size();
}
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["Cancel"], (int)(160-kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["Cancel"],
(int)(160 - kbLength * KEY_WIDTH / 4),
KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
ASFont::HAlignCenter, ASFont::VAlignMiddle);
re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1;
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
@ -294,7 +319,10 @@ int InputDialog::drawVirtualKeyboard() {
selCol = 1;
selRow = kb->size();
}
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"], (int)(160+kbLength*KEY_WIDTH/4), KB_TOP+kb->size()*KEY_HEIGHT+KEY_HEIGHT/2, ASFont::HAlignCenter, ASFont::VAlignMiddle);
gmenu2x->s->write(gmenu2x->font, gmenu2x->tr["OK"],
(int)(160 + kbLength * KEY_WIDTH / 4),
KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
ASFont::HAlignCenter, ASFont::VAlignMiddle);
//if ts released
if (ts.initialized() && ts.released() && ts.inRect(kbRect)) {