diff options
-rw-r--r-- | engines/sci/gfx/gfx_driver.cpp | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/engines/sci/gfx/gfx_driver.cpp b/engines/sci/gfx/gfx_driver.cpp index 28c16ee820..c2a0292ede 100644 --- a/engines/sci/gfx/gfx_driver.cpp +++ b/engines/sci/gfx/gfx_driver.cpp @@ -42,6 +42,14 @@ struct _scummvm_driver_state { #define S ((struct _scummvm_driver_state *)(drv->state)) +enum modifierKeysStates { + capslockState = 0, + numlockState = 1, + scrollockState = 2 +}; + +bool modifierStates[3]; + static int scummvm_init_specific(gfx_driver_t *drv, int xfact, int yfact, int bytespp) { int i; @@ -81,6 +89,12 @@ scummvm_init_specific(gfx_driver_t *drv, int xfact, int yfact, int bytespp) { } static int scummvm_init(gfx_driver_t *drv) { + // FIXME: This is wrong. The initial states of capslock etc are not known initially + // + // The best solution likely would be to add code to the EventManager class + // for tracking which keys are pressed and which are not... + modifierStates[capslockState] = modifierStates[numlockState] = modifierStates[scrollockState] = false; + return scummvm_init_specific(drv, 1, 1, GFX_COLOR_MODE_INDEX); } @@ -332,30 +346,41 @@ static sci_event_t scummvm_get_event(gfx_driver_t *drv) { input.buckybits = ((modifiers & Common::KBD_ALT) ? SCI_EVM_ALT : 0) | ((modifiers & Common::KBD_CTRL) ? SCI_EVM_CTRL : 0) | - ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0); + ((modifiers & Common::KBD_SHIFT) ? SCI_EVM_LSHIFT | SCI_EVM_RSHIFT : 0) | + (modifierStates[capslockState] ? SCI_EVM_CAPSLOCK : 0) | + (modifierStates[numlockState] ? SCI_EVM_NUMLOCK : 0) | + (modifierStates[scrollockState] ? SCI_EVM_SCRLOCK : 0); // We add the modifier key status to buckybits // SDL sends a keydown event if a modifier key is turned on and a keyup event if it's off - // - // FIXME: This code is semi-bogus. It only records the modifier key being *pressed*. - // It does not track correctly whether capslock etc. is active. To do that, we - // would have to record the fact that the modifier was pressed in global var, - // and also watch for Common::EVENT_KEYUP events. - // But this is still not quite good enough, because not all events might - // pass through here (e.g. the GUI might be running with its own event loop). - // - // The best solution likely would be to add code to the EventManager class - // for tracking which keys are pressed and which are not... - if (ev.type == Common::EVENT_KEYDOWN) { + if (ev.type == Common::EVENT_KEYDOWN || ev.type == Common::EVENT_KEYUP) { switch (ev.kbd.keycode) { case Common::KEYCODE_CAPSLOCK: - input.buckybits |= SCI_EVM_CAPSLOCK; + if (ev.type == Common::EVENT_KEYDOWN) { + input.buckybits |= SCI_EVM_CAPSLOCK; + modifierStates[capslockState] = true; + } else { + input.buckybits &= ~SCI_EVM_CAPSLOCK; + modifierStates[capslockState] = false; + } break; case Common::KEYCODE_NUMLOCK: - input.buckybits |= SCI_EVM_NUMLOCK; + if (ev.type == Common::EVENT_KEYDOWN) { + input.buckybits |= SCI_EVM_NUMLOCK; + modifierStates[numlockState] = true; + } else { + input.buckybits &= ~SCI_EVM_NUMLOCK; + modifierStates[numlockState] = false; + } break; case Common::KEYCODE_SCROLLOCK: - input.buckybits |= SCI_EVM_SCRLOCK; + if (ev.type == Common::EVENT_KEYDOWN) { + input.buckybits |= SCI_EVM_SCRLOCK; + modifierStates[scrollockState] = true; + } else { + input.buckybits &= ~SCI_EVM_SCRLOCK; + modifierStates[scrollockState] = false; + } break; default: break; @@ -425,7 +450,27 @@ static sci_event_t scummvm_get_event(gfx_driver_t *drv) { case Common::KEYCODE_DELETE: input.data = SCI_K_DELETE; break; - //TODO: SCI_K_CENTER + // Keypad keys + case Common::KEYCODE_KP8: // up + if (!modifierStates[numlockState]) + input.data = SCI_K_UP; + break; + case Common::KEYCODE_KP2: // down + if (!modifierStates[numlockState]) + input.data = SCI_K_DOWN; + break; + case Common::KEYCODE_KP6: // right + if (!modifierStates[numlockState]) + input.data = SCI_K_RIGHT; + break; + case Common::KEYCODE_KP4: // left + if (!modifierStates[numlockState]) + input.data = SCI_K_LEFT; + break; + case Common::KEYCODE_KP5: // center + if (!modifierStates[numlockState]) + input.data = SCI_K_CENTER; + break; default: input.type = SCI_EVT_NONE; break; |