[Scummvm-cvs-logs] scummvm master -> 463e475bd654104aab1e19cbc6f315b3341ef470

lordhoto lordhoto at gmail.com
Wed Mar 9 01:25:08 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
463e475bd6 SCI: Save mouse position in SciEvent.


Commit: 463e475bd654104aab1e19cbc6f315b3341ef470
    https://github.com/scummvm/scummvm/commit/463e475bd654104aab1e19cbc6f315b3341ef470
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-08T16:19:12-08:00

Commit Message:
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.

Changed paths:
    engines/sci/engine/kevent.cpp
    engines/sci/event.cpp
    engines/sci/event.h
    engines/sci/graphics/menu.cpp



diff --git a/engines/sci/engine/kevent.cpp b/engines/sci/engine/kevent.cpp
index e5a9931..2540861 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 7832864..cb0e6b3 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 42ca163..be0322f 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 b2e564c..b0d1203 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);






More information about the Scummvm-git-logs mailing list