Virtual Keyboard:

* added support for submit, cancel, backspace, and cursor movement commands
* minor API modifications

svn-id: r33887
This commit is contained in:
Stephen Kennedy 2008-08-15 01:21:29 +00:00
parent c61294e70f
commit fca5a0ad34
7 changed files with 95 additions and 80 deletions

View file

@ -421,7 +421,7 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
// HACK to show/hide keyboard (keyboard is not shown if gui is active)
if (event.kbd.keycode == Common::KEYCODE_F6 && event.kbd.flags == 0) {
if (_vk->isDisplaying()) {
_vk->hide();
_vk->close(true);
} else {
bool isPaused = (g_engine) ? g_engine->isPaused() : true;
if (!isPaused) g_engine->pauseEngine(true);

View file

@ -114,7 +114,7 @@ void VirtualKeyboardGUI::run() {
_dispSurface.free();
}
void VirtualKeyboardGUI::hide() {
void VirtualKeyboardGUI::close() {
_displaying = false;
}

View file

@ -43,7 +43,7 @@ public:
void initMode(VirtualKeyboard::Mode *mode);
void run();
void hide();
void close();
bool isDisplaying() { return _displaying; }
void reset();
void startDrag(int16 x, int16 y);

View file

@ -235,17 +235,15 @@ bool VirtualKeyboardParser::parserCallback_Event() {
delete evt;
return parserError("Key event element must contain code and ascii attributes");
}
evt->type = VirtualKeyboard::kEventKey;
KeyCode code = (KeyCode)atoi(evtNode->values["code"].c_str());
uint16 ascii = atoi(evtNode->values["ascii"].c_str());
byte flags = 0;
KeyState *ks = (KeyState*) malloc(sizeof(KeyState));
ks->keycode = (KeyCode)atoi(evtNode->values["code"].c_str());
ks->ascii = atoi(evtNode->values["ascii"].c_str());
ks->flags = 0;
if (evtNode->values.contains("modifiers"))
flags = parseFlags(evtNode->values["modifiers"]);
evt->data = new KeyState(code, ascii, flags);
ks->flags = parseFlags(evtNode->values["modifiers"]);
evt->data = ks;
} else if (type == "modifier") {
if (!evtNode->values.contains("modifiers")) {
@ -254,7 +252,7 @@ bool VirtualKeyboardParser::parserCallback_Event() {
}
evt->type = VirtualKeyboard::kEventModifier;
byte *flags = new byte;
byte *flags = (byte*) malloc(sizeof(byte));
*(flags) = parseFlags(evtNode->values["modifiers"]);
evt->data = flags;
@ -265,9 +263,25 @@ bool VirtualKeyboardParser::parserCallback_Event() {
}
evt->type = VirtualKeyboard::kEventSwitchMode;
evt->data = new String(evtNode->values["mode"]);
} else if (type == "close") {
evt->type = VirtualKeyboard::kEventClose;
String& mode = evtNode->values["mode"];
char *str = (char*) malloc(sizeof(char) * mode.size() + 1);
memcpy(str, mode.c_str(), sizeof(char) * mode.size());
str[mode.size()] = 0;
evt->data = str;
} else if (type == "submit") {
evt->type = VirtualKeyboard::kEventSubmit;
evt->data = 0;
} else if (type == "cancel") {
evt->type = VirtualKeyboard::kEventCancel;
evt->data = 0;
} else if (type == "delete") {
evt->type = VirtualKeyboard::kEventDelete;
evt->data = 0;
} else if (type == "move_left") {
evt->type = VirtualKeyboard::kEventMoveLeft;
evt->data = 0;
} else if (type == "move_right") {
evt->type = VirtualKeyboard::kEventMoveRight;
evt->data = 0;
} else {
delete evt;

View file

@ -36,7 +36,7 @@ VirtualKeyboard::VirtualKeyboard() : _currentMode(0) {
_parser = new VirtualKeyboardParser(this);
_kbdGUI = new VirtualKeyboardGUI(this);
_loaded = false;
_submitKeys = _loaded = false;
}
VirtualKeyboard::~VirtualKeyboard() {
@ -139,12 +139,23 @@ void VirtualKeyboard::processAreaClick(const Common::String& area) {
break;
case kEventSwitchMode:
// switch to new mode
switchMode(*(Common::String *)evt->data);
switchMode((char *)evt->data);
_keyQueue.clearFlags();
break;
case kEventClose:
// close virtual keyboard
_kbdGUI->hide();
case kEventSubmit:
close(true);
break;
case kEventCancel:
close(false);
break;
case kEventDelete:
_keyQueue.deleteKey();
break;
case kEventMoveLeft:
_keyQueue.moveLeft();
break;
case kEventMoveRight:
_keyQueue.moveRight();
break;
}
}
@ -188,6 +199,7 @@ void VirtualKeyboard::show() {
_kbdGUI->run();
if (_submitKeys) {
EventManager *eventMan = _system->getEventManager();
assert(eventMan);
@ -201,10 +213,14 @@ void VirtualKeyboard::show() {
evt.type = Common::EVENT_KEYUP;
eventMan->pushEvent(evt);
}
} else {
_keyQueue.clear();
}
}
void VirtualKeyboard::hide() {
_kbdGUI->hide();
void VirtualKeyboard::close(bool submit) {
_submitKeys = submit;
_kbdGUI->close();
}
bool VirtualKeyboard::isDisplaying() {
@ -230,20 +246,6 @@ void VirtualKeyboard::KeyPressQueue::clearFlags() {
void VirtualKeyboard::KeyPressQueue::insertKey(KeyState key) {
_strChanged = true;
switch (key.keycode) {
case KEYCODE_LEFT:
moveLeft();
return;
case KEYCODE_RIGHT:
moveRight();
return;
case KEYCODE_BACKSPACE:
deleteKey();
return;
default:
;
}
key.flags ^= _keyFlags;
if ((key.keycode >= Common::KEYCODE_a) && (key.keycode <= Common::KEYCODE_z))
key.ascii = (key.flags & Common::KBD_SHIFT) ? key.keycode - 32 : key.keycode;

View file

@ -47,7 +47,11 @@ protected:
kEventKey,
kEventModifier,
kEventSwitchMode,
kEventClose
kEventSubmit,
kEventCancel,
kEventDelete,
kEventMoveLeft,
kEventMoveRight
};
struct Event {
@ -57,21 +61,7 @@ protected:
Event() : data(0) {}
~Event() {
if (data) {
switch (type) {
case kEventKey:
delete (KeyState*)data;
break;
case kEventModifier:
delete (byte*)data;
break;
case kEventSwitchMode:
delete (String*)data;
break;
case kEventClose:
break;
}
}
if (data) free(data);
}
};
@ -161,8 +151,15 @@ public:
/**
* Hides the keyboard, ending the event loop.
* @param submit if true all accumulated key presses are submitted to
* the event manager
*/
void hide();
void close(bool submit);
/**
* Hides the keyboard, submiting any key presses to the event manager
*/
void submit();
/**
* Returns true if the keyboard is currently being shown
@ -209,6 +206,8 @@ protected: // TODO : clean up all this stuff
String _areaDown;
bool _submitKeys;
};

Binary file not shown.