[Scummvm-cvs-logs] SF.net SVN: scummvm:[33887] scummvm/branches/gsoc2008-vkeybd/backends

kenny-d at users.sourceforge.net kenny-d at users.sourceforge.net
Fri Aug 15 03:21:30 CEST 2008


Revision: 33887
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33887&view=rev
Author:   kenny-d
Date:     2008-08-15 01:21:29 +0000 (Fri, 15 Aug 2008)

Log Message:
-----------
Virtual Keyboard:
* added support for submit, cancel, backspace, and cursor movement commands
* minor API modifications

Modified Paths:
--------------
    scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.h
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-parser.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.cpp
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.h
    scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/vkeybd.zip

Modified: scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/events/default/default-events.cpp	2008-08-15 01:21:29 UTC (rev 33887)
@@ -421,7 +421,7 @@
 			// 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);

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.cpp	2008-08-15 01:21:29 UTC (rev 33887)
@@ -114,7 +114,7 @@
 	_dispSurface.free();
 }
 
-void VirtualKeyboardGUI::hide() {
+void VirtualKeyboardGUI::close() {
 	_displaying = false;
 }
 

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.h	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-gui.h	2008-08-15 01:21:29 UTC (rev 33887)
@@ -43,7 +43,7 @@
 	
 	void initMode(VirtualKeyboard::Mode *mode);
 	void run();
-	void hide();
+	void close();
 	bool isDisplaying() { return _displaying; }
 	void reset();
 	void startDrag(int16 x, int16 y);

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-parser.cpp	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard-parser.cpp	2008-08-15 01:21:29 UTC (rev 33887)
@@ -235,18 +235,16 @@
 			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"]);
+			ks->flags = parseFlags(evtNode->values["modifiers"]);
+		evt->data = ks;
 
-		evt->data = new KeyState(code, ascii, flags);
-
 	} else if (type == "modifier") {
 		if (!evtNode->values.contains("modifiers")) {
 			delete evt;
@@ -254,7 +252,7 @@
 		}
 		
 		evt->type = VirtualKeyboard::kEventModifier;
-		byte *flags = new byte;
+		byte *flags = (byte*) malloc(sizeof(byte));
 		*(flags) = parseFlags(evtNode->values["modifiers"]);
 		evt->data = flags;
 
@@ -265,10 +263,26 @@
 		}
 
 		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;
 		return parserError("Event type '%s' not known", type.c_str());

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.cpp
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.cpp	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.cpp	2008-08-15 01:21:29 UTC (rev 33887)
@@ -36,7 +36,7 @@
 
 	_parser = new VirtualKeyboardParser(this);
 	_kbdGUI = new VirtualKeyboardGUI(this);
-	_loaded = false;
+	_submitKeys = _loaded = false;
 }
 
 VirtualKeyboard::~VirtualKeyboard() {
@@ -139,13 +139,24 @@
 		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,23 +199,28 @@
 
 	_kbdGUI->run();
 
-	EventManager *eventMan = _system->getEventManager();
-	assert(eventMan);
+	if (_submitKeys) {
+		EventManager *eventMan = _system->getEventManager();
+		assert(eventMan);
 
-	// push keydown & keyup events into the event manager
-	Common::Event evt;
-	evt.synthetic = false;
-	while (!_keyQueue.empty()) {
-		evt.kbd = _keyQueue.pop();
-		evt.type = Common::EVENT_KEYDOWN;
-		eventMan->pushEvent(evt);
-		evt.type = Common::EVENT_KEYUP;
-		eventMan->pushEvent(evt);
+		// push keydown & keyup events into the event manager
+		Common::Event evt;
+		evt.synthetic = false;
+		while (!_keyQueue.empty()) {
+			evt.kbd = _keyQueue.pop();
+			evt.type = Common::EVENT_KEYDOWN;
+			eventMan->pushEvent(evt);
+			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::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;

Modified: scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.h
===================================================================
--- scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.h	2008-08-14 23:46:37 UTC (rev 33886)
+++ scummvm/branches/gsoc2008-vkeybd/backends/vkeybd/virtual-keyboard.h	2008-08-15 01:21:29 UTC (rev 33887)
@@ -47,7 +47,11 @@
 		kEventKey,
 		kEventModifier,
 		kEventSwitchMode,
-		kEventClose
+		kEventSubmit,
+		kEventCancel,
+		kEventDelete,
+		kEventMoveLeft,
+		kEventMoveRight
 	};
 
 	struct Event {
@@ -57,21 +61,7 @@
 		
 		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);
 		}
 	};
 	
@@ -144,34 +134,41 @@
 	virtual ~VirtualKeyboard();
 	
 	/**
-	  * Loads the keyboard pack with the given name.
-	  * The system first looks for an uncompressed keyboard pack by searching 
-	  * for packName.xml in the filesystem, if this does not exist then it 
-	  * searches for a compressed keyboard pack by looking for packName.zip.
-	  * @param packName name of the keyboard pack
-	  */
+	 * Loads the keyboard pack with the given name.
+	 * The system first looks for an uncompressed keyboard pack by searching 
+	 * for packName.xml in the filesystem, if this does not exist then it 
+	 * searches for a compressed keyboard pack by looking for packName.zip.
+	 * @param packName	name of the keyboard pack
+	 */
 	bool loadKeyboardPack(Common::String packName);
 
 	/**
-	  * Shows the keyboard, starting an event loop that will intercept all
-	  * user input (like a modal GUI dialog).
-	  * It is assumed that the game has been paused, before this is called
-	  */
+	 * Shows the keyboard, starting an event loop that will intercept all
+	 * user input (like a modal GUI dialog).
+	 * It is assumed that the game has been paused, before this is called
+	 */
 	void show();
 
 	/**
-	  * Hides the keyboard, ending the event loop.
-	  */
-	void hide();
+	 * Hides the keyboard, ending the event loop.
+	 * @param submit	if true all accumulated key presses are submitted to 
+	 *					the event manager
+	 */
+	void close(bool submit);
 
 	/**
-	  * Returns true if the keyboard is currently being shown
-	  */
+	 * Hides the keyboard, submiting any key presses to the event manager
+	 */
+	void submit();
+
+	/**
+	 * Returns true if the keyboard is currently being shown
+	 */
 	bool isDisplaying();
 
 	/**
-	  * Returns true if the keyboard is loaded and ready to be shown
-	  */
+	 * Returns true if the keyboard is loaded and ready to be shown
+	 */
 	bool isLoaded() {
 		return _loaded;
 	}
@@ -209,6 +206,8 @@
 
 	String _areaDown;
 
+	bool _submitKeys;
+
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list