From 7aeadba863ed1893fa6095008d35b32ce5117749 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Tue, 2 Feb 2016 11:33:07 +0100 Subject: SCI: Removed ".data" from SciEvent Was the ScummVM-system-Keycode, sometimes modified. Changed Menu/Portrait/Controls32-code to use .character instead. Cleaned up a bit of code in getScummVMEvent() --- engines/sci/event.cpp | 32 +++++++++++++++++--------------- engines/sci/event.h | 9 +-------- engines/sci/graphics/controls32.cpp | 10 +++++----- engines/sci/graphics/menu.cpp | 6 +++--- engines/sci/graphics/portrait.cpp | 4 ++-- 5 files changed, 28 insertions(+), 33 deletions(-) (limited to 'engines/sci') diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp index d3225612a2..8a5d67d935 100644 --- a/engines/sci/event.cpp +++ b/engines/sci/event.cpp @@ -133,8 +133,8 @@ static int altify(int ch) { } SciEvent EventManager::getScummVMEvent() { - SciEvent input = { SCI_EVENT_NONE, 0, 0, 0, Common::Point(0, 0) }; - SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, 0, Common::Point(0, 0) }; + SciEvent input = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) }; + SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) }; Common::EventManager *em = g_system->getEventManager(); Common::Event ev; @@ -225,12 +225,14 @@ SciEvent EventManager::getScummVMEvent() { bool numlockOn = (ev.kbd.flags & Common::KBD_NUM); - input.data = ev.kbd.keycode; + Common::KeyCode scummVMKeycode = ev.kbd.keycode; + byte scummVMKeyFlags = ev.kbd.flags; + input.character = ev.kbd.ascii; input.type = SCI_EVENT_KEYBOARD; - if (input.data >= Common::KEYCODE_KP0 && input.data <= Common::KEYCODE_KP9) { - if (!(ev.kbd.flags & Common::KBD_NUM)) { + if (scummVMKeycode >= Common::KEYCODE_KP0 && scummVMKeycode <= Common::KEYCODE_KP9) { + if (!(scummVMKeyFlags & Common::KBD_NUM)) { // HACK: Num-Lock not enabled // We shouldn't get a valid ascii code in these cases. We fix it here, so that cursor keys // on the numpad work properly. @@ -254,24 +256,24 @@ SciEvent EventManager::getScummVMEvent() { // multilingual SCI01 games input.character = codepagemap_88591toDOS[input.character & 0x7f]; } - if (input.data == Common::KEYCODE_TAB) { - input.character = input.data = SCI_KEY_TAB; + if (scummVMKeycode == Common::KEYCODE_TAB) { + input.character = SCI_KEY_TAB; if (ourModifiers & Common::KBD_SHIFT) input.character = SCI_KEY_SHIFT_TAB; } - if (input.data == Common::KEYCODE_DELETE) - input.data = input.character = SCI_KEY_DELETE; - } else if ((input.data >= Common::KEYCODE_F1) && input.data <= Common::KEYCODE_F10) { + if (scummVMKeycode == Common::KEYCODE_DELETE) + input.character = SCI_KEY_DELETE; + } else if ((scummVMKeycode >= Common::KEYCODE_F1) && scummVMKeycode <= Common::KEYCODE_F10) { // SCI_K_F1 == 59 << 8 // SCI_K_SHIFT_F1 == 84 << 8 - input.character = input.data = SCI_KEY_F1 + ((input.data - Common::KEYCODE_F1)<<8); + input.character = SCI_KEY_F1 + ((scummVMKeycode - Common::KEYCODE_F1)<<8); if (ourModifiers & Common::KBD_SHIFT) - input.character = input.data + 0x1900; + input.character = scummVMKeycode + 0x1900; } else { // Special keys that need conversion for (int i = 0; i < ARRAYSIZE(keyMappings); i++) { - if (keyMappings[i].scummVMKey == ev.kbd.keycode) { - input.character = input.data = numlockOn ? keyMappings[i].sciKeyNumlockOn : keyMappings[i].sciKeyNumlockOff; + if (keyMappings[i].scummVMKey == scummVMKeycode) { + input.character = numlockOn ? keyMappings[i].sciKeyNumlockOn : keyMappings[i].sciKeyNumlockOff; break; } } @@ -315,7 +317,7 @@ void EventManager::updateScreen() { } SciEvent EventManager::getSciEvent(unsigned int mask) { - SciEvent event = { 0, 0, 0, 0, Common::Point(0, 0) }; + SciEvent event = { SCI_EVENT_NONE, 0, 0, Common::Point(0, 0) }; EventManager::updateScreen(); diff --git a/engines/sci/event.h b/engines/sci/event.h index 885ddcef03..1e76f8e6f6 100644 --- a/engines/sci/event.h +++ b/engines/sci/event.h @@ -30,16 +30,9 @@ namespace Sci { struct SciEvent { short type; - short data; // holds the ScummVM system keycode TODO: rename short modifiers; /** - * For keyboard events: 'data' after applying - * the effects of 'modifiers', e.g. if - * type == SCI_EVT_KEYBOARD - * data == 'a' - * buckybits == SCI_EVM_LSHIFT - * then - * character == 'A' + * For keyboard events: the actual character of the key that was pressed * For 'Alt', characters are interpreted by their * PC keyboard scancodes. */ diff --git a/engines/sci/graphics/controls32.cpp b/engines/sci/graphics/controls32.cpp index 90b5cd558c..1bd497ce98 100644 --- a/engines/sci/graphics/controls32.cpp +++ b/engines/sci/graphics/controls32.cpp @@ -79,7 +79,7 @@ void GfxControls32::kernelTexteditChange(reg_t controlObject) { // TODO: Implement mouse support for cursor change break; case SCI_EVENT_KEYBOARD: - switch (curEvent.data) { + switch (curEvent.character) { case SCI_KEY_BACKSPACE: if (cursorPos > 0) { cursorPos--; text.deleteChar(cursorPos); @@ -131,12 +131,12 @@ void GfxControls32::kernelTexteditChange(reg_t controlObject) { captureEvents = false; break; default: - if ((curEvent.modifiers & SCI_KEYMOD_CTRL) && curEvent.data == 99) { + if ((curEvent.modifiers & SCI_KEYMOD_CTRL) && curEvent.character == 'c') { // Control-C in earlier SCI games (SCI0 - SCI1 middle) // Control-C erases the whole line cursorPos = 0; text.clear(); textChanged = true; - } else if (curEvent.data > 31 && curEvent.data < 256 && textSize < maxChars) { + } else if (curEvent.character > 31 && curEvent.character < 256 && textSize < maxChars) { // insert pressed character textAddChar = true; textChanged = true; @@ -158,14 +158,14 @@ void GfxControls32::kernelTexteditChange(reg_t controlObject) { uint16 textWidth = 0; while (*textPtr) textWidth += font->getCharWidth((byte)*textPtr++); - textWidth += font->getCharWidth(curEvent.data); + textWidth += font->getCharWidth(curEvent.character); // Does it fit? if (textWidth >= rect.width()) { return; } - text.insertChar(curEvent.data, cursorPos++); + text.insertChar(curEvent.character, cursorPos++); // Note: the following checkAltInput call might make the text // too wide to fit, but SSCI fails to check that too. diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp index 9d92039111..eb3f5888c7 100644 --- a/engines/sci/graphics/menu.cpp +++ b/engines/sci/graphics/menu.cpp @@ -747,7 +747,7 @@ GuiMenuItemEntry *GfxMenu::interactiveWithKeyboard() { // - sierra didn't wrap around when changing item id // - sierra allowed item id to be 0, which didn't make any sense do { - switch (curEvent.data) { + switch (curEvent.character) { case SCI_KEY_ESC: _curMenuId = curItemEntry->menuId; _curItemId = curItemEntry->id; return NULL; @@ -776,10 +776,10 @@ GuiMenuItemEntry *GfxMenu::interactiveWithKeyboard() { newMenuId = newItemEntry->menuId; newItemId = newItemEntry->id; // if we do this step again because of a separator line -> don't repeat left/right, but go down - switch (curEvent.data) { + switch (curEvent.character) { case SCI_KEY_LEFT: case SCI_KEY_RIGHT: - curEvent.data = SCI_KEY_DOWN; + curEvent.character = SCI_KEY_DOWN; } } } while (newItemEntry->separatorLine); diff --git a/engines/sci/graphics/portrait.cpp b/engines/sci/graphics/portrait.cpp index cb425f3be9..045a923569 100644 --- a/engines/sci/graphics/portrait.cpp +++ b/engines/sci/graphics/portrait.cpp @@ -316,7 +316,7 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint g_sci->getEngineState()->wait(1); curEvent = _event->getSciEvent(SCI_EVENT_ANY); if (curEvent.type == SCI_EVENT_MOUSE_PRESS || - (curEvent.type == SCI_EVENT_KEYBOARD && curEvent.data == SCI_KEY_ESC) || + (curEvent.type == SCI_EVENT_KEYBOARD && curEvent.character == SCI_KEY_ESC) || g_sci->getEngineState()->abortScriptProcessing == kAbortQuitGame || g_sci->getEngineState()->_delayedRestoreGame) userAbort = true; @@ -339,7 +339,7 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint g_sci->getEngineState()->wait(1); curEvent = _event->getSciEvent(SCI_EVENT_ANY); if (curEvent.type == SCI_EVENT_MOUSE_PRESS || - (curEvent.type == SCI_EVENT_KEYBOARD && curEvent.data == SCI_KEY_ESC) || + (curEvent.type == SCI_EVENT_KEYBOARD && curEvent.character == SCI_KEY_ESC) || g_sci->getEngineState()->abortScriptProcessing == kAbortQuitGame) userAbort = true; curPosition = _audio->getAudioPosition(); -- cgit v1.2.3