mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 12:53:43 +02:00
InputDialog: re-layouted code.
No functional changes.
This commit is contained in:
parent
0b878c1b77
commit
fa5a9816db
@ -1,6 +1,6 @@
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2006 by Massimiliano Torromeo *
|
* Copyright (C) 2006 by Massimiliano Torromeo *
|
||||||
* massimiliano.torromeo@gmail.com *
|
* massimiliano.torromeo@gmail.com *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -33,7 +33,7 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
|
|||||||
, inputMgr(inputMgr_)
|
, inputMgr(inputMgr_)
|
||||||
, ts(ts_)
|
, ts(ts_)
|
||||||
{
|
{
|
||||||
if (title=="") {
|
if (title == "") {
|
||||||
this->title = text;
|
this->title = text;
|
||||||
this->text = "";
|
this->text = "";
|
||||||
} else {
|
} else {
|
||||||
@ -41,8 +41,9 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
|
|||||||
this->text = text;
|
this->text = text;
|
||||||
}
|
}
|
||||||
this->icon = "";
|
this->icon = "";
|
||||||
if (icon!="" && gmenu2x->sc[icon] != NULL)
|
if (icon != "" && gmenu2x->sc[icon] != NULL) {
|
||||||
this->icon = icon;
|
this->icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
input = startvalue;
|
input = startvalue;
|
||||||
selCol = 0;
|
selCol = 0;
|
||||||
@ -85,46 +86,51 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
|
|||||||
setKeyboard(0);
|
setKeyboard(0);
|
||||||
|
|
||||||
buttonbox = new ButtonBox(gmenu2x);
|
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));
|
btnBackspace->setAction(MakeDelegate(this, &InputDialog::backspace));
|
||||||
buttonbox->add(btnBackspace);
|
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));
|
btnSpace->setAction(MakeDelegate(this, &InputDialog::space));
|
||||||
buttonbox->add(btnSpace);
|
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));
|
btnConfirm->setAction(MakeDelegate(this, &InputDialog::confirm));
|
||||||
buttonbox->add(btnConfirm);
|
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));
|
btnChangeKeys->setAction(MakeDelegate(this, &InputDialog::changeKeys));
|
||||||
buttonbox->add(btnChangeKeys);
|
buttonbox->add(btnChangeKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::setKeyboard(int kb) {
|
void InputDialog::setKeyboard(int kb) {
|
||||||
kb = constrain(kb,0,keyboard.size()-1);
|
kb = constrain(kb, 0, keyboard.size() - 1);
|
||||||
curKeyboard = kb;
|
curKeyboard = kb;
|
||||||
this->kb = &(keyboard[kb]);
|
this->kb = &(keyboard[kb]);
|
||||||
kbLength = this->kb->at(0).length();
|
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])) {
|
if (gmenu2x->font->utf8Code(this->kb->at(0)[x])) {
|
||||||
kbLength--;
|
kbLength--;
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
kbLeft = 160 - kbLength*KEY_WIDTH/2;
|
kbLeft = 160 - kbLength * KEY_WIDTH / 2;
|
||||||
kbWidth = kbLength*KEY_WIDTH+3;
|
kbWidth = kbLength * KEY_WIDTH + 3;
|
||||||
kbHeight = (this->kb->size()+1)*KEY_HEIGHT+3;
|
kbHeight = (this->kb->size() + 1) * KEY_HEIGHT + 3;
|
||||||
|
|
||||||
kbRect.x = kbLeft-3;
|
kbRect.x = kbLeft - 3;
|
||||||
kbRect.y = KB_TOP-2;
|
kbRect.y = KB_TOP - 2;
|
||||||
kbRect.w = kbWidth;
|
kbRect.w = kbWidth;
|
||||||
kbRect.h = kbHeight;
|
kbRect.h = kbHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputDialog::exec() {
|
bool InputDialog::exec() {
|
||||||
SDL_Rect box = {0, 60, 0, gmenu2x->font->getHeight()+4};
|
SDL_Rect box = { 0, 60, 0, gmenu2x->font->getHeight() + 4 };
|
||||||
|
|
||||||
Uint32 caretTick = 0, curTick;
|
Uint32 caretTick = 0, curTick;
|
||||||
bool caretOn = true;
|
bool caretOn = true;
|
||||||
@ -140,85 +146,90 @@ bool InputDialog::exec() {
|
|||||||
|
|
||||||
buttonbox->paint(5);
|
buttonbox->paint(5);
|
||||||
|
|
||||||
box.w = gmenu2x->font->getTextWidth(input)+18;
|
box.w = gmenu2x->font->getTextWidth(input) + 18;
|
||||||
box.x = 160-box.w/2;
|
box.x = 160 - box.w / 2;
|
||||||
gmenu2x->s->box(box.x, box.y, box.w, box.h,
|
gmenu2x->s->box(box.x, box.y, box.w, box.h,
|
||||||
gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
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();
|
curTick = SDL_GetTicks();
|
||||||
if (curTick-caretTick>=600) {
|
if (curTick - caretTick >= 600) {
|
||||||
caretOn = !caretOn;
|
caretOn = !caretOn;
|
||||||
caretTick = curTick;
|
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();
|
if (ts.initialized()) ts.poll();
|
||||||
action = drawVirtualKeyboard();
|
action = drawVirtualKeyboard();
|
||||||
gmenu2x->s->flip();
|
gmenu2x->s->flip();
|
||||||
|
|
||||||
switch (inputMgr.waitForPressedButton()) {
|
switch (inputMgr.waitForPressedButton()) {
|
||||||
case InputManager::SETTINGS:
|
case InputManager::SETTINGS:
|
||||||
ok = false;
|
ok = false;
|
||||||
close = true;
|
close = true;
|
||||||
break;
|
break;
|
||||||
case InputManager::UP:
|
case InputManager::UP:
|
||||||
selRow--;
|
selRow--;
|
||||||
break;
|
break;
|
||||||
case InputManager::DOWN:
|
case InputManager::DOWN:
|
||||||
selRow++;
|
selRow++;
|
||||||
if (selRow==(int)kb->size()) selCol = selCol<8 ? 0 : 1;
|
if (selRow == (int)kb->size()) selCol = selCol < 8 ? 0 : 1;
|
||||||
break;
|
break;
|
||||||
case InputManager::LEFT:
|
case InputManager::LEFT:
|
||||||
selCol--;
|
selCol--;
|
||||||
break;
|
break;
|
||||||
case InputManager::RIGHT:
|
case InputManager::RIGHT:
|
||||||
selCol++;
|
selCol++;
|
||||||
break;
|
break;
|
||||||
case InputManager::ACCEPT:
|
case InputManager::ACCEPT:
|
||||||
confirm();
|
confirm();
|
||||||
break;
|
break;
|
||||||
case InputManager::CANCEL:
|
case InputManager::CANCEL:
|
||||||
changeKeys();
|
changeKeys();
|
||||||
break;
|
break;
|
||||||
case InputManager::ALTLEFT:
|
case InputManager::ALTLEFT:
|
||||||
backspace();
|
backspace();
|
||||||
break;
|
break;
|
||||||
case InputManager::ALTRIGHT:
|
case InputManager::ALTRIGHT:
|
||||||
space();
|
space();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::backspace() {
|
void InputDialog::backspace() {
|
||||||
// check for utf8 characters
|
// Check for UTF8 characters.
|
||||||
input = input.substr(0,input.length()-( gmenu2x->font->utf8Code(input[input.length()-2]) ? 2 : 1 ));
|
input = input.substr(0, input.length()
|
||||||
|
- (gmenu2x->font->utf8Code(input[input.length() - 2]) ? 2 : 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::space() {
|
void InputDialog::space() {
|
||||||
// check for utf8 characters
|
|
||||||
input += " ";
|
input += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::confirm() {
|
void InputDialog::confirm() {
|
||||||
if (selRow==(int)kb->size()) {
|
if (selRow == (int)kb->size()) {
|
||||||
if (selCol==0)
|
if (selCol == 0) {
|
||||||
ok = false;
|
ok = false;
|
||||||
|
}
|
||||||
close = true;
|
close = true;
|
||||||
} else {
|
} else {
|
||||||
bool utf8;
|
int xc = 0;
|
||||||
int xc=0;
|
for (uint x = 0; x < kb->at(selRow).length(); x++) {
|
||||||
for (uint x=0; x<kb->at(selRow).length(); x++) {
|
bool utf8 = gmenu2x->font->utf8Code(kb->at(selRow)[x]);
|
||||||
utf8 = gmenu2x->font->utf8Code(kb->at(selRow)[x]);
|
if (xc == selCol) input += kb->at(selRow).substr(x, utf8 ? 2 : 1);
|
||||||
if (xc==selCol) input += kb->at(selRow).substr(x, utf8 ? 2 : 1);
|
|
||||||
if (utf8) x++;
|
if (utf8) x++;
|
||||||
xc++;
|
xc++;
|
||||||
}
|
}
|
||||||
@ -226,10 +237,11 @@ void InputDialog::confirm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InputDialog::changeKeys() {
|
void InputDialog::changeKeys() {
|
||||||
if (curKeyboard==6)
|
if (curKeyboard == 6) {
|
||||||
setKeyboard(0);
|
setKeyboard(0);
|
||||||
else
|
} else {
|
||||||
setKeyboard(curKeyboard+1);
|
setKeyboard(curKeyboard + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputDialog::drawVirtualKeyboard() {
|
int InputDialog::drawVirtualKeyboard() {
|
||||||
@ -245,12 +257,15 @@ int InputDialog::drawVirtualKeyboard() {
|
|||||||
|
|
||||||
//selection
|
//selection
|
||||||
if (selRow<(int)kb->size())
|
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 {
|
else {
|
||||||
if (selCol>1) selCol = 0;
|
if (selCol > 1) selCol = 0;
|
||||||
if (selCol<0) selCol = 1;
|
if (selCol < 0) selCol = 1;
|
||||||
gmenu2x->s->box(kbLeft+selCol*kbLength*KEY_WIDTH/2-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
|
//keys
|
||||||
@ -265,7 +280,10 @@ int InputDialog::drawVirtualKeyboard() {
|
|||||||
} else
|
} else
|
||||||
charX = line[x];
|
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 on rect, change selection
|
||||||
if (ts.initialized() && ts.pressed() && ts.inRect(re)) {
|
if (ts.initialized() && ts.pressed() && ts.inRect(re)) {
|
||||||
@ -273,8 +291,12 @@ int InputDialog::drawVirtualKeyboard() {
|
|||||||
selRow = l;
|
selRow = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
gmenu2x->s->rectangle(re,
|
||||||
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->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++;
|
xc++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,15 +308,21 @@ int InputDialog::drawVirtualKeyboard() {
|
|||||||
selCol = 0;
|
selCol = 0;
|
||||||
selRow = kb->size();
|
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;
|
re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1;
|
||||||
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
gmenu2x->s->rectangle(re, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
|
||||||
if (ts.initialized() && ts.pressed() && ts.inRect(re)) {
|
if (ts.initialized() && ts.pressed() && ts.inRect(re)) {
|
||||||
selCol = 1;
|
selCol = 1;
|
||||||
selRow = kb->size();
|
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 released
|
||||||
if (ts.initialized() && ts.released() && ts.inRect(kbRect)) {
|
if (ts.initialized() && ts.released() && ts.inRect(kbRect)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user