mirror of
https://github.com/scummvm/scummvm.git
synced 2026-06-20 05:45:29 +00:00
SCI: Save mouse position in SciEvent.
Instead of querying the event manager for the current mouse cursor coordinates kGetEvent now uses the saved mouse positions, which will assure every event will be processed with the correct coordinates instead of the current ones. Various other functions using SciEvent directly were adapted too. This fixes cursor click positions for the WinCE backend. Thanks to wjp and waltervn for helping me with this.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+13
-4
@@ -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();
|
||||
|
||||
|
||||
@@ -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*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user