aboutsummaryrefslogtreecommitdiff
path: root/engines/gob/util.cpp
diff options
context:
space:
mode:
authorSven Hesse2007-06-23 17:00:27 +0000
committerSven Hesse2007-06-23 17:00:27 +0000
commit8953674a2f7d29cae0bcc5a3f8f42fae4db0ea81 (patch)
tree3e2aec869bca0fa2dceae836c9e4d7badd1d5bbb /engines/gob/util.cpp
parent1665d158f4a09a57c33bdfe742394a76d310e69a (diff)
downloadscummvm-rg350-8953674a2f7d29cae0bcc5a3f8f42fae4db0ea81.tar.gz
scummvm-rg350-8953674a2f7d29cae0bcc5a3f8f42fae4db0ea81.tar.bz2
scummvm-rg350-8953674a2f7d29cae0bcc5a3f8f42fae4db0ea81.zip
Fixed the FIXME (by making Util::_keyBuffer an array of Common::KeyState)
svn-id: r27679
Diffstat (limited to 'engines/gob/util.cpp')
-rw-r--r--engines/gob/util.cpp72
1 files changed, 35 insertions, 37 deletions
diff --git a/engines/gob/util.cpp b/engines/gob/util.cpp
index f970a550cc..ff6333aa9e 100644
--- a/engines/gob/util.cpp
+++ b/engines/gob/util.cpp
@@ -40,8 +40,6 @@ namespace Gob {
Util::Util(GobEngine *vm) : _vm(vm) {
_mouseButtons = 0;
- for (int i = 0; i < KEYBUFSIZE; i++)
- _keyBuffer[i] = 0;
_keyBufferHead = 0;
_keyBufferTail = 0;
_fastMode = 0;
@@ -114,7 +112,7 @@ void Util::processInput(bool scroll) {
_fastMode ^= 2;
break;
}
- addKeyToBuffer(event.kbd.ascii);
+ addKeyToBuffer(event.kbd);
break;
case Common::EVENT_KEYUP:
break;
@@ -145,7 +143,7 @@ bool Util::keyBufferEmpty() {
return (_keyBufferHead == _keyBufferTail);
}
-void Util::addKeyToBuffer(int16 key) {
+void Util::addKeyToBuffer(const Common::KeyState &key) {
if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) {
warning("key buffer overflow");
return;
@@ -155,7 +153,7 @@ void Util::addKeyToBuffer(int16 key) {
_keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE;
}
-bool Util::getKeyFromBuffer(int16& key) {
+bool Util::getKeyFromBuffer(Common::KeyState &key) {
if (_keyBufferHead == _keyBufferTail) return false;
key = _keyBuffer[_keyBufferTail];
@@ -164,48 +162,49 @@ bool Util::getKeyFromBuffer(int16& key) {
return true;
}
-int16 Util::translateKey(int16 key) {
- // FIXME: This currently maps KeyState::ascii values, when
- // it really should map keycodes! To fix this, addKeyToBuffer()
- // will have to be called with kbd.keycode instead of kbd.ascii,
- // and of course this will in turn require subsequent changes...
+int16 Util::translateKey(const Common::KeyState &key) {
static struct keyS {
int16 from;
int16 to;
} keys[] = {
- {Common::KEYCODE_BACKSPACE, 0x0E08}, // Backspace
- {Common::KEYCODE_SPACE, 0x3920}, // Space
- {Common::KEYCODE_RETURN, 0x1C0D}, // Enter
- {Common::KEYCODE_ESCAPE, 0x011B}, // ESC
- {Common::KEYCODE_DELETE, 0x5300}, // Del
- {Common::KEYCODE_UP, 0x4800}, // Up arrow
- {Common::KEYCODE_DOWN, 0x5000}, // Down arrow
- {Common::KEYCODE_RIGHT, 0x4D00}, // Right arrow
- {Common::KEYCODE_LEFT, 0x4B00}, // Left arrow
- {Common::ASCII_F1, 0x3B00}, // F1
- {Common::ASCII_F2, 0x3C00}, // F2
- {Common::ASCII_F3, 0x3D00}, // F3
- {Common::ASCII_F4, 0x3E00}, // F4
- {Common::ASCII_F5, 0x011B}, // F5
- {Common::ASCII_F6, 0x4000}, // F6
- {Common::ASCII_F7, 0x4100}, // F7
- {Common::ASCII_F8, 0x4200}, // F8
- {Common::ASCII_F9, 0x4300}, // F9
- {Common::ASCII_F10, 0x4400} // F10
+ {Common::KEYCODE_INVALID, 0x0000},
+ {Common::KEYCODE_BACKSPACE, 0x0E08},
+ {Common::KEYCODE_SPACE, 0x3920},
+ {Common::KEYCODE_RETURN, 0x1C0D},
+ {Common::KEYCODE_ESCAPE, 0x011B},
+ {Common::KEYCODE_DELETE, 0x5300},
+ {Common::KEYCODE_UP, 0x4800},
+ {Common::KEYCODE_DOWN, 0x5000},
+ {Common::KEYCODE_RIGHT, 0x4D00},
+ {Common::KEYCODE_LEFT, 0x4B00},
+ {Common::KEYCODE_F1, 0x3B00},
+ {Common::KEYCODE_F2, 0x3C00},
+ {Common::KEYCODE_F3, 0x3D00},
+ {Common::KEYCODE_F4, 0x3E00},
+ {Common::KEYCODE_F5, 0x011B},
+ {Common::KEYCODE_F6, 0x4000},
+ {Common::KEYCODE_F7, 0x4100},
+ {Common::KEYCODE_F8, 0x4200},
+ {Common::KEYCODE_F9, 0x4300},
+ {Common::KEYCODE_F10, 0x4400}
};
for (int i = 0; i < ARRAYSIZE(keys); i++)
- if (key == keys[i].from)
+ if (key.keycode == keys[i].from)
return keys[i].to;
- if ((key < 32) || (key >= 128))
- return 0;
+ if ((key.keycode >= Common::KEYCODE_SPACE) &&
+ (key.keycode <= Common::KEYCODE_DELETE)) {
+
+ // Used as a user input in Gobliins 2 notepad, in the save dialog, ...
+ return key.ascii;
+ }
- return key;
+ return 0;
}
int16 Util::getKey(void) {
- int16 key;
+ Common::KeyState key;
while (!getKeyFromBuffer(key)) {
processInput();
@@ -217,10 +216,9 @@ int16 Util::getKey(void) {
}
int16 Util::checkKey(void) {
- int16 key;
+ Common::KeyState key;
- if (!getKeyFromBuffer(key))
- key = 0;
+ getKeyFromBuffer(key);
return translateKey(key);
}