diff options
-rw-r--r-- | engines/sci/engine/kevent.cpp | 26 | ||||
-rw-r--r-- | engines/sci/event.cpp | 17 | ||||
-rw-r--r-- | engines/sci/event.h | 8 | ||||
-rw-r--r-- | engines/sci/graphics/menu.cpp | 22 |
4 files changed, 50 insertions, 23 deletions
diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp index e5a9931605..2540861a93 100644 --- a/engines/sci/engine/kevent.cpp +++ b/engines/sci/engine/kevent.cpp @@ -46,17 +46,18 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { SegManager *segMan = s->_segMan; Common::Point mousePos; - // Limit the mouse cursor position, if necessary - g_sci->_gfxCursor->refreshPosition(); - mousePos = g_sci->_gfxCursor->getPosition(); -#ifdef ENABLE_SCI32 - if (getSciVersion() >= SCI_VERSION_2_1) - g_sci->_gfxCoordAdjuster->fromDisplayToScript(mousePos.y, mousePos.x); -#endif - // If there's a simkey pending, and the game wants a keyboard event, use the // simkey instead of a normal event if (g_debug_simulated_key && (mask & SCI_EVENT_KEYBOARD)) { + // In case we use a simulated event we query the current mouse position + mousePos = g_sci->_gfxCursor->getPosition(); +#ifdef ENABLE_SCI32 + if (getSciVersion() >= SCI_VERSION_2_1) + g_sci->_gfxCoordAdjuster->fromDisplayToScript(mousePos.y, mousePos.x); +#endif + // Limit the mouse cursor position, if necessary + g_sci->_gfxCursor->refreshPosition(); + writeSelectorValue(segMan, obj, SELECTOR(type), SCI_EVENT_KEYBOARD); // Keyboard event writeSelectorValue(segMan, obj, SELECTOR(message), g_debug_simulated_key); writeSelectorValue(segMan, obj, SELECTOR(modifiers), SCI_KEYMOD_NUMLOCK); // Numlock on @@ -68,6 +69,15 @@ reg_t kGetEvent(EngineState *s, int argc, reg_t *argv) { curEvent = g_sci->getEventManager()->getSciEvent(mask); + // For a real event we use its associated mouse position + mousePos = curEvent.mousePos; +#ifdef ENABLE_SCI32 + if (getSciVersion() >= SCI_VERSION_2_1) + g_sci->_gfxCoordAdjuster->fromDisplayToScript(mousePos.y, mousePos.x); +#endif + // Limit the mouse cursor position, if necessary + g_sci->_gfxCursor->refreshPosition(); + if (g_sci->getVocabulary()) g_sci->getVocabulary()->parser_event = NULL_REG; // Invalidate parser event diff --git a/engines/sci/event.cpp b/engines/sci/event.cpp index 7832864024..cb0e6b3c03 100644 --- a/engines/sci/event.cpp +++ b/engines/sci/event.cpp @@ -136,19 +136,28 @@ static int altify(int ch) { } SciEvent EventManager::getScummVMEvent() { - SciEvent input = { SCI_EVENT_NONE, 0, 0, 0 }; - SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, 0 }; + SciEvent input = { SCI_EVENT_NONE, 0, 0, 0, Common::Point(0, 0) }; + SciEvent noEvent = { SCI_EVENT_NONE, 0, 0, 0, Common::Point(0, 0) }; Common::EventManager *em = g_system->getEventManager(); Common::Event ev; bool found = em->pollEvent(ev); - Common::Point p = ev.mouse; // Don't generate events for mouse movement while (found && ev.type == Common::EVENT_MOUSEMOVE) found = em->pollEvent(ev); + // Save the mouse position + // + // We call getMousePos of the event manager here, since we also want to + // store the mouse position in case of keyboard events, which do not feature + // any mouse position information itself. + // This should be safe, since the mouse position in the event manager should + // only be updated when a mouse related event has been taken from the queue + // via pollEvent. + noEvent.mousePos = input.mousePos = em->getMousePos(); + if (!found || ev.type == Common::EVENT_MOUSEMOVE) return noEvent; @@ -277,7 +286,7 @@ void EventManager::updateScreen() { } SciEvent EventManager::getSciEvent(unsigned int mask) { - SciEvent event = { 0, 0, 0, 0 }; + SciEvent event = { 0, 0, 0, 0, Common::Point(0, 0) }; EventManager::updateScreen(); diff --git a/engines/sci/event.h b/engines/sci/event.h index 42ca16397d..be0322f2a4 100644 --- a/engines/sci/event.h +++ b/engines/sci/event.h @@ -27,6 +27,7 @@ #define SCI_EVENT_H #include "common/list.h" +#include "common/rect.h" namespace Sci { @@ -46,6 +47,13 @@ struct SciEvent { * PC keyboard scancodes. */ short character; + + /** + * The mouse position at the time the event was created. + * + * These are display coordinates! + */ + Common::Point mousePos; }; /*Values for type*/ diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp index b2e564c288..b0d12038e8 100644 --- a/engines/sci/graphics/menu.cpp +++ b/engines/sci/graphics/menu.cpp @@ -399,7 +399,6 @@ void GfxMenu::calculateMenuAndItemWidth() { reg_t GfxMenu::kernelSelect(reg_t eventObject, bool pauseSound) { int16 eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type)); int16 keyPress, keyModifier; - Common::Point mousePosition; GuiMenuItemList::iterator itemIterator = _itemList.begin(); GuiMenuItemList::iterator itemEnd = _itemList.end(); GuiMenuItemEntry *itemEntry = NULL; @@ -457,15 +456,17 @@ reg_t GfxMenu::kernelSelect(reg_t eventObject, bool pauseSound) { itemEntry = NULL; break; - case SCI_EVENT_MOUSE_PRESS: - mousePosition = _cursor->getPosition(); + case SCI_EVENT_MOUSE_PRESS: { + Common::Point mousePosition; + mousePosition.x = readSelectorValue(_segMan, eventObject, SELECTOR(x)); + mousePosition.y = readSelectorValue(_segMan, eventObject, SELECTOR(y)); if (mousePosition.y < 10) { interactiveStart(pauseSound); itemEntry = interactiveWithMouse(); interactiveEnd(pauseSound); forceClaimed = true; } - break; + } break; } if (!_menuSaveHandle.isNull()) { @@ -715,7 +716,6 @@ GuiMenuItemEntry *GfxMenu::interactiveWithKeyboard() { uint16 newItemId = _curItemId; GuiMenuItemEntry *curItemEntry = findItem(_curMenuId, _curItemId); GuiMenuItemEntry *newItemEntry = curItemEntry; - Common::Point mousePosition; // We don't 100% follow Sierra here: we select last item instead of // selecting first item of first menu every time. Also sierra sci didn't @@ -793,9 +793,9 @@ GuiMenuItemEntry *GfxMenu::interactiveWithKeyboard() { } break; - case SCI_EVENT_MOUSE_PRESS: - mousePosition = _cursor->getPosition(); - if (_cursor->getPosition().y < 10) { + case SCI_EVENT_MOUSE_PRESS: { + Common::Point mousePosition = curEvent.mousePos; + if (mousePosition.y < 10) { // Somewhere on the menubar newMenuId = mouseFindMenuSelection(mousePosition); if (newMenuId) { @@ -824,7 +824,8 @@ GuiMenuItemEntry *GfxMenu::interactiveWithKeyboard() { } newItemId = curItemEntry->id; } - break; + } break; + case SCI_EVENT_NONE: g_sci->sleep(2500 / 1000); break; @@ -840,7 +841,6 @@ GuiMenuItemEntry *GfxMenu::interactiveWithMouse() { SciEvent curEvent; uint16 newMenuId = 0, newItemId = 0; uint16 curMenuId = 0, curItemId = 0; - Common::Point mousePosition = _cursor->getPosition(); bool firstMenuChange = true; GuiMenuItemEntry *curItemEntry = NULL; @@ -871,7 +871,7 @@ GuiMenuItemEntry *GfxMenu::interactiveWithMouse() { } // Find out where mouse is currently pointing to - mousePosition = _cursor->getPosition(); + Common::Point mousePosition = curEvent.mousePos; if (mousePosition.y < 10) { // Somewhere on the menubar newMenuId = mouseFindMenuSelection(mousePosition); |