aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorStrangerke2011-11-30 19:52:19 +0100
committerStrangerke2011-11-30 19:52:19 +0100
commita12ba5f6a6fc29107b5b785203af71caa014a0da (patch)
tree68a710749b2f5cedfd6176b499e8b1844f6eca3c /engines
parent9edd0f2903fd10dc06e22f37442d9787f964fab4 (diff)
downloadscummvm-rg350-a12ba5f6a6fc29107b5b785203af71caa014a0da.tar.gz
scummvm-rg350-a12ba5f6a6fc29107b5b785203af71caa014a0da.tar.bz2
scummvm-rg350-a12ba5f6a6fc29107b5b785203af71caa014a0da.zip
CGE: Simplify keyboard handling
Diffstat (limited to 'engines')
-rw-r--r--engines/cge/cge_main.cpp16
-rw-r--r--engines/cge/events.cpp142
-rw-r--r--engines/cge/events.h23
-rw-r--r--engines/cge/snail.cpp2
4 files changed, 46 insertions, 137 deletions
diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp
index db47c61d42..5af52cd1de 100644
--- a/engines/cge/cge_main.cpp
+++ b/engines/cge/cge_main.cpp
@@ -764,22 +764,6 @@ void System::touch(uint16 mask, int x, int y) {
_vm->_commandHandler->addCommand(kCmdClear, -1, 0, NULL);
return;
}
- switch (x) {
- case 'X':
- if (_vm->_keyboard->_key[kKeyAlt])
- _vm->quit();
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- if (_vm->_keyboard->_key[kKeyAlt]) {
- _vm->_commandHandler->addCommand(kCmdLevel, -1, x - '0', NULL);
- break;
- }
- break;
- }
} else {
if (_vm->_startupMode)
return;
diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp
index 5dbae80438..7c98f00b7b 100644
--- a/engines/cge/events.cpp
+++ b/engines/cge/events.cpp
@@ -39,55 +39,8 @@ namespace CGE {
/*----------------- KEYBOARD interface -----------------*/
-const uint16 Keyboard::_code[0x60] = {
- 0, Esc, '1', '2', '3',
- '4', '5', '6', '7', '8',
- '9', '0', '-', '+', BSp,
- Tab, 'Q', 'W', 'E', 'R',
- 'T', 'Y', 'U', 'I', 'O',
- 'P', '[', ']', Enter, 0/*Ctrl*/,
- 'A', 'S', 'D', 'F', 'G',
- 'H', 'J', 'K', 'L', ';',
- '\'', '`', 0/*LShift*/, '\\', 'Z',
- 'X', 'C', 'V', 'B', 'N',
- 'M', ',', '.', '/', 0/*RShift*/,
- '*', 0/*Alt*/, ' ', 0/*Caps*/, F1,
- F2, F3, F4, F5, F6,
- F7, F8, F9, F10, 0/*NumLock*/,
- 0/*ScrollLock*/, Home, Up, PgUp, '-',
- Left, Ctr, Right, '+', End,
- Down, PgDn, Ins, Del, 0 * 0x54,
- 0 * 0x55, 0 * 0x56, F11, F12, 0 * 0x59,
- 0 * 0x5A, 0 * 0x5B, 0 * 0x5C, 0 * 0x5D, 0 * 0x5E,
- 0 * 0x5F
-};
-
-const uint16 Keyboard::_scummVmCodes[0x60] = {
- 0, Common::KEYCODE_ESCAPE, Common::KEYCODE_1, Common::KEYCODE_2, Common::KEYCODE_3,
- Common::KEYCODE_4, Common::KEYCODE_5, Common::KEYCODE_6, Common::KEYCODE_7, Common::KEYCODE_8,
- Common::KEYCODE_9, Common::KEYCODE_0, Common::KEYCODE_MINUS, Common::KEYCODE_PLUS, Common::KEYCODE_BACKSPACE,
- Common::KEYCODE_TAB, Common::KEYCODE_q, Common::KEYCODE_w, Common::KEYCODE_e, Common::KEYCODE_r,
- Common::KEYCODE_t, Common::KEYCODE_y, Common::KEYCODE_u, Common::KEYCODE_i, Common::KEYCODE_o,
- Common::KEYCODE_p, Common::KEYCODE_LEFTBRACKET, Common::KEYCODE_RIGHTBRACKET, Common::KEYCODE_RETURN, 0/*Ctrl*/,
- Common::KEYCODE_a, Common::KEYCODE_s, Common::KEYCODE_d, Common::KEYCODE_f, Common::KEYCODE_g,
- Common::KEYCODE_h, Common::KEYCODE_j, Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_SEMICOLON,
- Common::KEYCODE_BACKSLASH, Common::KEYCODE_TILDE, Common::KEYCODE_LSHIFT, Common::KEYCODE_BACKSLASH, Common::KEYCODE_z,
- Common::KEYCODE_x, Common::KEYCODE_c, Common::KEYCODE_v, Common::KEYCODE_b, Common::KEYCODE_n,
- Common::KEYCODE_m, Common::KEYCODE_COMMA, Common::KEYCODE_PERIOD, Common::KEYCODE_SLASH, Common::KEYCODE_RSHIFT,
- Common::KEYCODE_KP_MULTIPLY, 0 /*Alt*/, Common::KEYCODE_SPACE, Common::KEYCODE_CAPSLOCK, Common::KEYCODE_F1,
- Common::KEYCODE_F2, Common::KEYCODE_F3, Common::KEYCODE_F4, Common::KEYCODE_F5, Common::KEYCODE_F6,
- Common::KEYCODE_F7, Common::KEYCODE_F8, Common::KEYCODE_F9, Common::KEYCODE_F10, Common::KEYCODE_NUMLOCK,
- Common::KEYCODE_SCROLLOCK, Common::KEYCODE_KP7, Common::KEYCODE_KP8, Common::KEYCODE_KP9, Common::KEYCODE_KP_MINUS,
- Common::KEYCODE_KP4, Common::KEYCODE_KP5, Common::KEYCODE_KP6, Common::KEYCODE_KP_PLUS, Common::KEYCODE_KP1,
- Common::KEYCODE_KP2, Common::KEYCODE_KP3, Common::KEYCODE_KP0, Common::KEYCODE_KP_PERIOD, 0,
- 0, 0, Common::KEYCODE_F11, Common::KEYCODE_F12, 0,
- 0, 0, 0, 0, 0,
- 0
-};
-
Keyboard::Keyboard(CGEEngine *vm) : _client(NULL), _vm(vm) {
- Common::fill(&_key[0], &_key[0x60], false);
- _current = 0;
+ _keyAlt = false;
}
Keyboard::~Keyboard() {
@@ -98,28 +51,23 @@ Sprite *Keyboard::setClient(Sprite *spr) {
return spr;
}
-bool Keyboard::getKey(Common::Event &event, int &cgeCode) {
+bool Keyboard::getKey(Common::Event &event) {
Common::KeyCode keycode = event.kbd.keycode;
- if ((keycode == Common::KEYCODE_LCTRL) || (keycode == Common::KEYCODE_RCTRL)) {
- cgeCode = kKeyCtrl;
- return true;
- }
- if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) {
- cgeCode = kKeyAlt;
- return true;
- }
- if (keycode == Common::KEYCODE_KP_ENTER) {
- cgeCode = 28;
- return true;
- }
- if (keycode == Common::KEYCODE_F1) {
+
+ if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT))
+ _keyAlt = true;
+ else
+ _keyAlt = false;
+
+ switch (keycode) {
+ case Common::KEYCODE_F1:
if (event.type == Common::EVENT_KEYUP)
return false;
// Display ScummVM version and translation strings
for (int i = 0; i < 5; i++)
_vm->_commandHandler->addCommand(kCmdInf, 1, kShowScummVMVersion + i, NULL);
return false;
- } else if (keycode == Common::KEYCODE_F5) {
+ case Common::KEYCODE_F5:
if (_vm->canSaveGameStateCurrently()) {
const EnginePlugin *plugin = NULL;
EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);
@@ -132,9 +80,9 @@ bool Keyboard::getKey(Common::Event &event, int &cgeCode) {
if (savegameId != -1)
_vm->saveGameState(savegameId, savegameDescription);
- }
+ }
return false;
- } else if (keycode == Common::KEYCODE_F7) {
+ case Common::KEYCODE_F7:
if (_vm->canLoadGameStateCurrently()) {
const EnginePlugin *plugin = NULL;
EngineMan.findGame(_vm->_gameDescription->gameid, &plugin);
@@ -148,52 +96,48 @@ bool Keyboard::getKey(Common::Event &event, int &cgeCode) {
_vm->loadGameState(savegameId);
}
return false;
- } else if ((keycode == Common::KEYCODE_d) && (event.kbd.flags & Common::KBD_CTRL)) {
+ case Common::KEYCODE_d:
+ if (event.kbd.flags & Common::KBD_CTRL) {
// Start the debugger
- _vm->getDebugger()->attach();
- _vm->getDebugger()->onFrame();
- return false;
- }
-
- // Scan through the ScummVM mapping list
- for (int idx = 0; idx < 0x60; idx++) {
- if (_scummVmCodes[idx] == event.kbd.ascii) {
- cgeCode = idx;
- return true;
+ _vm->getDebugger()->attach();
+ _vm->getDebugger()->onFrame();
+ return false;
}
+ break;
+ case Common::KEYCODE_x:
+ if (event.kbd.flags & Common::KBD_ALT) {
+ _vm->quit();
+ return false;
+ }
+ break;
+ case Common::KEYCODE_0:
+ case Common::KEYCODE_1:
+ case Common::KEYCODE_2:
+ case Common::KEYCODE_3:
+ case Common::KEYCODE_4:
+ if (event.kbd.flags & Common::KBD_ALT) {
+ _vm->_commandHandler->addCommand(kCmdLevel, -1, keycode - '0', NULL);
+ return false;
+ }
+ default:
+ break;
}
- return false;
+ return true;
}
void Keyboard::newKeyboard(Common::Event &event) {
- int keycode;
- if (!getKey(event, keycode))
+ if (!getKey(event))
return;
- if (event.type == Common::EVENT_KEYUP) {
- // Key release
- _key[keycode] = false;
- } else if (event.type == Common::EVENT_KEYDOWN) {
- // Key press
- _key[keycode] = true;
- _current = Keyboard::_code[keycode];
-
- if (_client) {
- CGEEvent &evt = _vm->_eventManager->getNextEvent();
- evt._x = _current; // Keycode
- evt._mask = kEventKeyb; // Event mask
- evt._spritePtr = _client; // Sprite pointer
- }
+ if ((event.type == Common::EVENT_KEYDOWN) && (_client)) {
+ CGEEvent &evt = _vm->_eventManager->getNextEvent();
+ evt._x = event.kbd.keycode; // Keycode
+ evt._mask = kEventKeyb; // Event mask
+ evt._spritePtr = _client; // Sprite pointer
}
}
-uint16 Keyboard::lastKey() {
- uint16 cur = _current;
- _current = 0;
- return cur;
-}
-
/*----------------- MOUSE interface -----------------*/
Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) {
diff --git a/engines/cge/events.h b/engines/cge/events.h
index 7ead4cbc7b..6bbd52e4a5 100644
--- a/engines/cge/events.h
+++ b/engines/cge/events.h
@@ -37,8 +37,6 @@ namespace CGE {
/*----------------- KEYBOARD interface -----------------*/
-#define kKeyCtrl 29
-#define kKeyAlt 56
#define kEventMax 256
enum EventMask {
@@ -51,31 +49,15 @@ enum EventMask {
kEventKeyb = 1 << 7
};
-enum Keys {
- BSp = 8, Tab,
- Enter = 13,
- Esc = 27,
- F11 = 256 + 87, F12,
- F1 = 256 + 59, F2, F3, F4, F5, F6, F7, F8, F9, F10,
- Home = 256 + 71, Up, PgUp,
- Left = 256 + 75, Ctr, Right,
- End = 256 + 79, Down, PgDn, Ins, Del
-};
-
class Keyboard {
private:
- bool getKey(Common::Event &event, int &cgeCode);
- uint16 _current;
+ bool getKey(Common::Event &event);
CGEEngine *_vm;
public:
- static const uint16 _code[0x60];
- static const uint16 _scummVmCodes[0x60];
-
Sprite *_client;
- bool _key[0x60];
+ bool _keyAlt;
void newKeyboard(Common::Event &event);
- uint16 lastKey();
Sprite *setClient(Sprite *spr);
Keyboard(CGEEngine *vm);
@@ -100,7 +82,6 @@ public:
bool _exist;
int _buttons;
Sprite *_busy;
- //Sprite *Touched;
Mouse(CGEEngine *vm);
~Mouse();
void on();
diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp
index 9db5406c25..f75510ad6c 100644
--- a/engines/cge/snail.cpp
+++ b/engines/cge/snail.cpp
@@ -493,7 +493,7 @@ void CGEEngine::snGame(Sprite *spr, int num) {
_sprK2->step(newRandom(6));
_sprK3->step(newRandom(6));
- if (spr->_ref == 1 && _keyboard->_key[kKeyAlt]) {
+ if (spr->_ref == 1 && _keyboard->_keyAlt) {
_sprK1->step(5);
_sprK2->step(5);
_sprK3->step(5);