diff options
author | Torbjörn Andersson | 2003-09-23 15:59:52 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2003-09-23 15:59:52 +0000 |
commit | 57d99796ea8e5d42989d876d35078b686aebda61 (patch) | |
tree | 5acf4eb1fb36a47aba53ecd53c361ed1adb7baa1 | |
parent | d0de9fff86c9e44e9c10b181028d759ebf770f29 (diff) | |
download | scummvm-rg350-57d99796ea8e5d42989d876d35078b686aebda61.tar.gz scummvm-rg350-57d99796ea8e5d42989d876d35078b686aebda61.tar.bz2 scummvm-rg350-57d99796ea8e5d42989d876d35078b686aebda61.zip |
Changed the keyboard handling to store "keyboard events", rather than just
characters. Hopefully this will make things work smoother on the Mac, but I
have no way of testing that.
svn-id: r10376
-rw-r--r-- | sword2/controls.cpp | 33 | ||||
-rw-r--r-- | sword2/driver/d_draw.cpp | 4 | ||||
-rw-r--r-- | sword2/driver/driver96.h | 11 | ||||
-rw-r--r-- | sword2/driver/keyboard.cpp | 23 | ||||
-rw-r--r-- | sword2/driver/keyboard.h | 2 | ||||
-rw-r--r-- | sword2/driver/rdwin.cpp | 2 | ||||
-rw-r--r-- | sword2/function.cpp | 6 | ||||
-rw-r--r-- | sword2/logic.cpp | 6 | ||||
-rw-r--r-- | sword2/mem_view.cpp | 9 | ||||
-rw-r--r-- | sword2/resman.cpp | 12 | ||||
-rw-r--r-- | sword2/startup.cpp | 6 | ||||
-rw-r--r-- | sword2/sword2.cpp | 21 |
12 files changed, 77 insertions, 58 deletions
diff --git a/sword2/controls.cpp b/sword2/controls.cpp index 227eca7ee2..75d8f95860 100644 --- a/sword2/controls.cpp +++ b/sword2/controls.cpp @@ -243,7 +243,7 @@ public: virtual void onMouseMove(int x, int y) {} virtual void onMouseDown(int x, int y) {} virtual void onMouseUp(int x, int y) {} - virtual void onKey(char key) {} + virtual void onKey(_keyboardEvent *ke) {} virtual void onTick() {} virtual void releaseMouse(int x, int y) {} @@ -376,14 +376,14 @@ int Sword2Dialog::run() { int16 newMouseX = mousex; int16 newMouseY = mousey + 40; - char key; - int32 keyboardStatus = ReadKey(&key); _mouseEvent *me = MouseEvent(); + _keyboardEvent ke; + int32 keyboardStatus = ReadKey(&ke); if (keyboardStatus == RD_OK) { - if (key == 27) + if (ke.keycode == 27) setResult(0); - else if (key == 13) + else if (ke.keycode == '\n' || ke.keycode == '\r') setResult(1); } @@ -416,8 +416,8 @@ int Sword2Dialog::run() { } } - if (keyboardStatus == RD_OK && key != 0) - _widgets[i]->onKey(key); + if (keyboardStatus == RD_OK) + _widgets[i]->onKey(&ke); _widgets[i]->onTick(); } @@ -972,9 +972,13 @@ public: } } - virtual void onKey(char key) { - if (_editable && (key == 8 || (key >= ' ' && key <= 'z'))) - _parent->onAction(this, key); + virtual void onKey(_keyboardEvent *ke) { + if (_editable) { + if (ke->keycode == 8) + _parent->onAction(this, 8); + else if (ke->ascii >= ' ' && ke->ascii <= 'z') + _parent->onAction(this, ke->ascii); + } } virtual void onTick() { @@ -1347,7 +1351,7 @@ void Restart_control(void) { //Tony4Apr97 return; } - // Stop music instantly! (James22aug97) + // Stop music instantly! (James 22aug97) Kill_music(); //in case we were dead - well we're not anymore! @@ -1410,13 +1414,14 @@ void Control_error(char* text) { //Tony13May97 // Wait for ESC or mouse click while (1) { _mouseEvent *me; - char c; ServiceWindows(); if (KeyWaiting()) { - ReadKey(&c); - if (c == 27) + _keyboardEvent ke; + + ReadKey(&ke); + if (ke.keycode == 27) break; } diff --git a/sword2/driver/d_draw.cpp b/sword2/driver/d_draw.cpp index d17c7d3fbf..a893c5ef7f 100644 --- a/sword2/driver/d_draw.cpp +++ b/sword2/driver/d_draw.cpp @@ -463,9 +463,9 @@ int32 PlaySmacker(char *filename, _movieTextObject *text[], uint8 *musicOut) { ServiceWindows(); - char key; + _keyboardEvent ke; - if (ReadKey(&key) == RD_OK && key == 27) { + if (ReadKey(&ke) == RD_OK && ke.keycode == 27) { g_sword2->_mixer->stopHandle(handle); break; } diff --git a/sword2/driver/driver96.h b/sword2/driver/driver96.h index 1fd32aa760..a0281534e2 100644 --- a/sword2/driver/driver96.h +++ b/sword2/driver/driver96.h @@ -1207,11 +1207,16 @@ typedef int BOOL; // --------------------- // -typedef struct -{ +typedef struct { uint16 buttons; } _mouseEvent; +typedef struct { + uint16 ascii; + int keycode; + int modifiers; +} _keyboardEvent; + #if !defined(__GNUC__) #pragma START_PACK_STRUCTS #endif @@ -1369,7 +1374,7 @@ extern void ResetRenderEngine(void); // Keyboard functions - from keyboard.c //----------------------------------------------------------------------------- extern BOOL KeyWaiting(void); -extern int32 ReadKey(char *key); +extern int32 ReadKey(_keyboardEvent *ke); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/sword2/driver/keyboard.cpp b/sword2/driver/keyboard.cpp index 6babe45ed4..0297b8073d 100644 --- a/sword2/driver/keyboard.cpp +++ b/sword2/driver/keyboard.cpp @@ -66,11 +66,15 @@ uint8 keyBacklog = 0; // The number of key presses waiting to be processed. uint8 keyPointer = 0; // Index of the next key to read from the buffer. -char keyBuffer[MAX_KEY_BUFFER]; // The keyboard buffer +_keyboardEvent keyBuffer[MAX_KEY_BUFFER]; // The keyboard buffer -void WriteKey(char key) { +void WriteKey(uint16 ascii, int keycode, int modifiers) { if (keyBuffer && keyBacklog < MAX_KEY_BUFFER) { - keyBuffer[(keyPointer + keyBacklog) % MAX_KEY_BUFFER] = key; + _keyboardEvent *slot = &keyBuffer[(keyPointer + keyBacklog) % MAX_KEY_BUFFER]; + + slot->ascii = ascii; + slot->keycode = keycode; + slot->modifiers = modifiers; keyBacklog++; } } @@ -82,16 +86,19 @@ BOOL KeyWaiting(void) { return FALSE; } - - -int32 ReadKey(char *key) { +int32 ReadKey(_keyboardEvent *ev) { if (!keyBacklog) return RDERR_NOKEYWAITING; - if (key == NULL) + if (ev == NULL) return RDERR_INVALIDPOINTER; - *key = keyBuffer[keyPointer++]; + ev->ascii = keyBuffer[keyPointer].ascii; + ev->keycode = keyBuffer[keyPointer].keycode; + ev->modifiers = keyBuffer[keyPointer].modifiers; + + keyPointer++; + if (keyPointer == MAX_KEY_BUFFER) keyPointer = 0; diff --git a/sword2/driver/keyboard.h b/sword2/driver/keyboard.h index fb181a384d..458438d795 100644 --- a/sword2/driver/keyboard.h +++ b/sword2/driver/keyboard.h @@ -40,6 +40,6 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -void WriteKey(char key); // Adds a keypress to the buffer +void WriteKey(uint16 ascii, int keycode, int modifier); // Adds a keypress to the buffer #endif diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp index dfa96190bf..e29d10d355 100644 --- a/sword2/driver/rdwin.cpp +++ b/sword2/driver/rdwin.cpp @@ -155,7 +155,7 @@ void Sword2State::parseEvents() { if (event.kbd.keycode == 'w') GrabScreenShot(); } - WriteKey(event.kbd.ascii); + WriteKey(event.kbd.ascii, event.kbd.keycode, event.kbd.flags); break; case OSystem::EVENT_MOUSEMOVE: mousex = event.mouse.x; diff --git a/sword2/function.cpp b/sword2/function.cpp index f9a2ee6af4..70da452f29 100644 --- a/sword2/function.cpp +++ b/sword2/function.cpp @@ -426,8 +426,6 @@ int32 FN_play_credits(int32 *params) { debug(0, "Credits music length: ~%d ms", music_length); while (g_sound->MusicTimeRemaining()) { - char key; - EraseBackBuffer(); // FIXME: Draw the credits text. The actual text @@ -436,7 +434,9 @@ int32 FN_play_credits(int32 *params) { ServiceWindows(); - if (ReadKey(&key) == RD_OK && key == 27) + _keyboardEvent ke; + + if (ReadKey(&ke) == RD_OK && ke.keycode == 27) break; g_system->delay_msecs(30); diff --git a/sword2/logic.cpp b/sword2/logic.cpp index fc0a25107c..893305014c 100644 --- a/sword2/logic.cpp +++ b/sword2/logic.cpp @@ -328,7 +328,7 @@ uint32 logic::Examine_run_list(void) { // Tony25Oct96 uint32 *game_object_list; _standardHeader *file_header; int scrolls = 0; - char c; + _keyboardEvent ke; if (current_run_list) { // open and lock in place @@ -353,8 +353,8 @@ uint32 logic::Examine_run_list(void) { // Tony25Oct96 } while(!KeyWaiting()); // kill the key we just pressed - ReadKey(&c); - if (c == 27) + ReadKey(&ke); + if (ke.keycode == 27) break; // clear the Press Esc message ready for the diff --git a/sword2/mem_view.cpp b/sword2/mem_view.cpp index de6df195a4..22885c4b2a 100644 --- a/sword2/mem_view.cpp +++ b/sword2/mem_view.cpp @@ -34,7 +34,7 @@ void Console_mem_display(void) { // Tony13Aug96 int pass, found_end, k, j, free = 0; _standardHeader *file_header; int scrolls = 0; - char c; + _keyboardEvent ke; char inf[][20] = { { "M_null " }, @@ -98,8 +98,7 @@ void Console_mem_display(void) { // Tony13Aug96 Build_display(); - - if (scrolls==18) { + if (scrolls == 18) { Temp_print_to_console("- Press ESC to stop or any other key to continue"); Build_display(); @@ -107,8 +106,8 @@ void Console_mem_display(void) { // Tony13Aug96 ServiceWindows(); } while(!KeyWaiting()); - ReadKey(&c); //kill the key we just pressed - if (c == 27) //ESC + ReadKey(&ke); //kill the key we just pressed + if (ke.keycode == 27) //ESC break; // clear the Press Esc message ready for the new line diff --git a/sword2/resman.cpp b/sword2/resman.cpp index 2c715eb9b7..943fc9f24f 100644 --- a/sword2/resman.cpp +++ b/sword2/resman.cpp @@ -956,7 +956,7 @@ void resMan::Kill_all_res(uint8 wantInfo) { //Tony29Nov96 uint32 nuked = 0; _standardHeader *header; int scrolls = 0; - char c; + _keyboardEvent ke; j = base_mem_block; @@ -990,8 +990,8 @@ void resMan::Kill_all_res(uint8 wantInfo) { //Tony29Nov96 ServiceWindows(); } while(!KeyWaiting()); - ReadKey(&c); //kill the key we just pressed - if (c == 27) //ESC + ReadKey(&ke); //kill the key we just pressed + if (ke.keycode == 27) //ESC break; // clear the Press Esc message ready for the new line @@ -1029,7 +1029,7 @@ void resMan::Kill_all_objects(uint8 wantInfo) { // James17jan97 uint32 nuked = 0; _standardHeader *header; int scrolls = 0; - char c; + _keyboardEvent ke; j = base_mem_block; @@ -1063,8 +1063,8 @@ void resMan::Kill_all_objects(uint8 wantInfo) { // James17jan97 } while(!KeyWaiting()); - ReadKey(&c); //kill the key we just pressed - if (c == 27) // ESC + ReadKey(&ke); //kill the key we just pressed + if (ke.keycode == 27) // ESC break; // clear the Press Esc message ready for the new line diff --git a/sword2/startup.cpp b/sword2/startup.cpp index b522e1542c..8b76e6c770 100644 --- a/sword2/startup.cpp +++ b/sword2/startup.cpp @@ -176,7 +176,7 @@ uint32 Con_print_start_menu(void) { // Tony14Oct96 uint32 j; int scrolls = 0; - char c; + _keyboardEvent ke; if (!total_startups) { Print_to_console("Sorry - no startup positions registered?"); @@ -201,8 +201,8 @@ uint32 Con_print_start_menu(void) { // Tony14Oct96 } while(!KeyWaiting()); // kill the key we just pressed - ReadKey(&c); - if (c == 27) + ReadKey(&ke); + if (ke.keycode == 27) break; // clear the Press Esc message ready for the diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp index 0456a99d76..bdfbc89961 100644 --- a/sword2/sword2.cpp +++ b/sword2/sword2.cpp @@ -258,8 +258,8 @@ int32 GameCycle(void) { void Sword2State::go() { OSystem::Property prop; uint32 rv; - uint8 breakOut = 0; - char c; + uint8 breakOut = 0; + _keyboardEvent ke; // Zdebug("[%s]", lpCmdLine); @@ -377,16 +377,19 @@ void Sword2State::go() { #endif if (KeyWaiting()) { - ReadKey(&c); + ReadKey(&ke); + + char c = toupper(ke.ascii); + #ifdef _SWORD2_DEBUG // ESC whether paused or not - if (c == 27) { + if (ke.keycode == 27) { PauseAllSound(); // see sound.cpp StartConsole(); // start the console } else #endif if (gamePaused) { // if currently paused - if (toupper(c) == 'P') { + if (c == 'P') { // 'P' while paused = unpause! UnpauseGame(); } @@ -394,21 +397,21 @@ void Sword2State::go() { // frame-skipping only allowed on // debug version - else if (toupper(c) == ' ') { + else if (c == ' ') { // SPACE bar while paused = // step one frame! stepOneCycle = 1; UnpauseGame(); } #endif - } else if (toupper(c) == 'P') { + } else if (c == 'P') { // 'P' while not paused = pause! PauseGame(); - } else if (toupper(c) == 'C' && _gameId == GID_SWORD2) { + } else if (c == 'C' && _gameId == GID_SWORD2) { FN_play_credits(NULL); } #ifdef _SWORD2_DEBUG - else if (toupper(c) == 'S') { + else if (c == 'S') { // 'S' toggles speed up (by skipping // display rendering) renderSkip = 1 - renderSkip; |