aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2007-03-18 18:27:52 +0000
committerMax Horn2007-03-18 18:27:52 +0000
commit888e68f433659a1c021d79f89534841e64676987 (patch)
tree9af7d4f573de71695bd010be83865f7aa18514ad
parent8ba2a5bb83c23a9633ae532a02ffdb60760a3cb9 (diff)
downloadscummvm-rg350-888e68f433659a1c021d79f89534841e64676987.tar.gz
scummvm-rg350-888e68f433659a1c021d79f89534841e64676987.tar.bz2
scummvm-rg350-888e68f433659a1c021d79f89534841e64676987.zip
KYRA: Changed to use EventManager::getMousePos (should improve some things: the old code did not properly track the mouse upon click events, and KyraEngine::waitForEvent ignored _flags.useHiResOverlay)
svn-id: r26221
-rw-r--r--engines/kyra/animator.cpp3
-rw-r--r--engines/kyra/gui.cpp27
-rw-r--r--engines/kyra/items.cpp10
-rw-r--r--engines/kyra/kyra.cpp59
-rw-r--r--engines/kyra/kyra.h10
-rw-r--r--engines/kyra/saveload.cpp2
-rw-r--r--engines/kyra/scene.cpp2
-rw-r--r--engines/kyra/script_v1.cpp7
8 files changed, 53 insertions, 67 deletions
diff --git a/engines/kyra/animator.cpp b/engines/kyra/animator.cpp
index 6ab6307880..322009bc8c 100644
--- a/engines/kyra/animator.cpp
+++ b/engines/kyra/animator.cpp
@@ -575,7 +575,8 @@ void ScreenAnimator::refreshObject(AnimObject *object) {
void ScreenAnimator::makeBrandonFaceMouse() {
debugC(9, kDebugLevelAnimator, "ScreenAnimator::makeBrandonFaceMouse()");
- if (_vm->mouseX() >= _vm->_currentCharacter->x1) {
+ Common::Point mouse = _vm->getMousePos();
+ if (mouse.x >= _vm->_currentCharacter->x1) {
_vm->_currentCharacter->facing = 3;
} else {
_vm->_currentCharacter->facing = 5;
diff --git a/engines/kyra/gui.cpp b/engines/kyra/gui.cpp
index 3704617baa..4da2998131 100644
--- a/engines/kyra/gui.cpp
+++ b/engines/kyra/gui.cpp
@@ -316,7 +316,8 @@ void KyraEngine::processButtonList(Button *list) {
}
y += _screen->_screenDimTable[list->dimTableIndex].sy;
- if (_mouseX >= x && _mouseY >= y && x + list->width >= _mouseX && y + list->height >= _mouseY) {
+ Common::Point mouse = getMousePos();
+ if (mouse.x >= x && mouse.y >= y && x + list->width >= mouse.x && y + list->height >= mouse.y) {
int processMouseClick = 0;
if (list->flags & 0x400) {
if (_mousePressFlag) {
@@ -820,12 +821,6 @@ void KyraEngine::gui_getInput() {
_mousePressFlag = false;
break;
case Common::EVENT_MOUSEMOVE:
- _mouseX = event.mouse.x;
- _mouseY = event.mouse.y;
- if (_flags.useHiResOverlay) {
- _mouseX >>= 1;
- _mouseY >>= 1;
- }
_system->updateScreen();
lastScreenUpdate = now;
break;
@@ -1378,6 +1373,7 @@ int KyraEngine::gui_scrollDown(Button *button) {
void KyraEngine::gui_processHighlights(Menu &menu) {
int x1, y1, x2, y2;
+ Common::Point mouse = getMousePos();
for (int i = 0; i < menu.nrOfItems; i++) {
if (!menu.item[i].enabled)
continue;
@@ -1388,8 +1384,8 @@ void KyraEngine::gui_processHighlights(Menu &menu) {
x2 = x1 + menu.item[i].width;
y2 = y1 + menu.item[i].height;
- if (_mouseX > x1 && _mouseX < x2 &&
- _mouseY > y1 && _mouseY < y2) {
+ if (mouse.x > x1 && mouse.x < x2 &&
+ mouse.y > y1 && mouse.y < y2) {
if (menu.highlightedItem != i) {
if (menu.item[menu.highlightedItem].enabled )
@@ -1481,14 +1477,6 @@ bool KyraEngine::gui_mainMenuGetInput() {
case Common::EVENT_QUIT:
quitGame();
break;
- case Common::EVENT_MOUSEMOVE:
- _mouseX = event.mouse.x;
- _mouseY = event.mouse.y;
- if (_flags.useHiResOverlay) {
- _mouseX >>= 1;
- _mouseY >>= 1;
- }
- break;
case Common::EVENT_LBUTTONUP:
return true;
default:
@@ -1541,8 +1529,9 @@ int KyraEngine::gui_handleMainMenu() {
gui_updateMainMenuAnimation();
bool mousePressed = gui_mainMenuGetInput();
- if (menuRect.contains(mouseX(), mouseY())) {
- int item = (mouseY() - menuRect.top) / fh;
+ Common::Point mouse = getMousePos();
+ if (menuRect.contains(mouse)) {
+ int item = (mouse.y - menuRect.top) / fh;
if (item != selected) {
gui_printString(strings[selected], textPos, menuRect.top + selected * fh, 0x80, 0, 5);
diff --git a/engines/kyra/items.cpp b/engines/kyra/items.cpp
index 2cceb4bc00..21d263446c 100644
--- a/engines/kyra/items.cpp
+++ b/engines/kyra/items.cpp
@@ -694,8 +694,9 @@ void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) {
_screen->_curPage = 0;
int x = 0, y = 0;
if (itemPos == -1) {
- x = _mouseX - 12;
- y = _mouseY - 18;
+ Common::Point mouse = getMousePos();
+ x = mouse.x - 12;
+ y = mouse.y - 18;
} else {
x = _itemPosX[itemPos] - 4;
y = _itemPosY[itemPos] - 3;
@@ -781,8 +782,9 @@ void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) {
_screen->_curPage = 0;
int x = 0, y = 0;
if (itemPos == -1) {
- x = _mouseX - 12;
- y = _mouseY - 18;
+ Common::Point mouse = getMousePos();
+ x = mouse.x - 12;
+ y = mouse.y - 18;
} else {
x = _itemPosX[itemPos] - 4;
y = _itemPosX[itemPos] - 3;
diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp
index de953faffd..6b3a2dc3a1 100644
--- a/engines/kyra/kyra.cpp
+++ b/engines/kyra/kyra.cpp
@@ -265,7 +265,6 @@ int KyraEngine::init() {
_abortWalkFlag2 = false;
_talkingCharNum = -1;
_charSayUnk3 = -1;
- _mouseX = _mouseY = -1;
memset(_currSentenceColor, 0, 3);
_startSentencePalIndex = -1;
_fadeText = false;
@@ -636,12 +635,6 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) {
break;
case Common::EVENT_MOUSEMOVE:
- _mouseX = event.mouse.x;
- _mouseY = event.mouse.y;
- if (_flags.useHiResOverlay) {
- _mouseX >>= 1;
- _mouseY >>= 1;
- }
_animator->_updateScreen = true;
break;
case Common::EVENT_QUIT:
@@ -653,19 +646,12 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) {
case Common::EVENT_LBUTTONUP:
_mousePressFlag = false;
- _mouseX = event.mouse.x;
- _mouseY = event.mouse.y;
- if (_flags.useHiResOverlay) {
- _mouseX >>= 1;
- _mouseY >>= 1;
- }
-
if (_abortWalkFlag2)
_abortWalkFlag = true;
if (_handleInput) {
_handleInput = false;
- processInput(_mouseX, _mouseY);
+ processInput();
_handleInput = true;
} else
_skipFlag = true;
@@ -703,6 +689,15 @@ void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) {
}
+Common::Point KyraEngine::getMousePos() const {
+ Common::Point mouse = g_system->getEventManager()->getMousePos();
+ if (_flags.useHiResOverlay) {
+ mouse.x >>= 1;
+ mouse.y >>= 1;
+ }
+ return mouse;
+}
+
void KyraEngine::waitForEvent() {
bool finished = false;
Common::Event event;
@@ -713,10 +708,6 @@ void KyraEngine::waitForEvent() {
case Common::EVENT_KEYDOWN:
finished = true;
break;
- case Common::EVENT_MOUSEMOVE:
- _mouseX = event.mouse.x;
- _mouseY = event.mouse.y;
- break;
case Common::EVENT_QUIT:
quitGame();
break;
@@ -843,7 +834,11 @@ void KyraEngine::resetBrandonPoisonFlags() {
#pragma mark - Input
#pragma mark -
-void KyraEngine::processInput(int xpos, int ypos) {
+void KyraEngine::processInput() {
+ Common::Point mouse = getMousePos();
+ int xpos = mouse.x;
+ int ypos = mouse.y;
+
debugC(9, kDebugLevelMain, "KyraEngine::processInput(%d, %d)", xpos, ypos);
_abortWalkFlag2 = false;
@@ -952,9 +947,10 @@ void KyraEngine::updateMousePointer(bool forceUpdate) {
int newMouseState = 0;
int newX = 0;
int newY = 0;
- if (_mouseY <= 158) {
- if (_mouseX >= 12) {
- if (_mouseX >= 308) {
+ Common::Point mouse = getMousePos();
+ if (mouse.y <= 158) {
+ if (mouse.x >= 12) {
+ if (mouse.x >= 308) {
if (_walkBlockEast == 0xFFFF) {
newMouseState = -2;
} else {
@@ -963,7 +959,7 @@ void KyraEngine::updateMousePointer(bool forceUpdate) {
newX = 7;
newY = 5;
}
- } else if (_mouseY >= 136) {
+ } else if (mouse.y >= 136) {
if (_walkBlockSouth == 0xFFFF) {
newMouseState = -2;
} else {
@@ -972,7 +968,7 @@ void KyraEngine::updateMousePointer(bool forceUpdate) {
newX = 5;
newY = 7;
}
- } else if (_mouseY < 12) {
+ } else if (mouse.y < 12) {
if (_walkBlockNorth == 0xFFFF) {
newMouseState = -2;
} else {
@@ -993,8 +989,8 @@ void KyraEngine::updateMousePointer(bool forceUpdate) {
}
}
- if (_mouseX >= _entranceMouseCursorTracks[0] && _mouseY >= _entranceMouseCursorTracks[1]
- && _mouseX <= _entranceMouseCursorTracks[2] && _mouseY <= _entranceMouseCursorTracks[3]) {
+ if (mouse.x >= _entranceMouseCursorTracks[0] && mouse.y >= _entranceMouseCursorTracks[1]
+ && mouse.x <= _entranceMouseCursorTracks[2] && mouse.y <= _entranceMouseCursorTracks[3]) {
switch (_entranceMouseCursorTracks[4]) {
case 0:
newMouseState = -6;
@@ -1044,7 +1040,7 @@ void KyraEngine::updateMousePointer(bool forceUpdate) {
if (!newMouseState) {
if (_mouseState != _itemInHand || forceUpdate) {
- if (_mouseY > 158 || (_mouseX >= 12 && _mouseX < 308 && _mouseY < 136 && _mouseY >= 12) || forceUpdate) {
+ if (mouse.y > 158 || (mouse.x >= 12 && mouse.x < 308 && mouse.y < 136 && mouse.y >= 12) || forceUpdate) {
_mouseState = _itemInHand;
_screen->hideMouse();
if (_itemInHand == -1) {
@@ -1073,10 +1069,13 @@ bool KyraEngine::hasClickedOnExit(int xpos, int ypos) {
void KyraEngine::clickEventHandler2() {
debugC(9, kDebugLevelMain, "KyraEngine::clickEventHandler2()");
+
+ Common::Point mouse = getMousePos();
+
_scriptInterpreter->initScript(_scriptClick, _scriptClickData);
_scriptClick->variables[0] = _currentCharacter->sceneId;
- _scriptClick->variables[1] = _mouseX;
- _scriptClick->variables[2] = _mouseY;
+ _scriptClick->variables[1] = mouse.x;
+ _scriptClick->variables[2] = mouse.y;
_scriptClick->variables[4] = _itemInHand;
_scriptInterpreter->startScript(_scriptClick, 6);
diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h
index ea3a67c02f..8b337eb058 100644
--- a/engines/kyra/kyra.h
+++ b/engines/kyra/kyra.h
@@ -305,13 +305,12 @@ public:
void disableTimer(uint8 timer);
void delayWithTicks(int ticks);
-
+
void saveGame(const char *fileName, const char *saveName);
void loadGame(const char *fileName);
- int mouseX() { return _mouseX; }
- int mouseY() { return _mouseY; }
-
+ Common::Point getMousePos() const;
+
int setGameFlag(int flag);
int queryGameFlag(int flag);
int resetGameFlag(int flag);
@@ -531,7 +530,7 @@ protected:
void setBrandonPoisonFlags(int reset);
void resetBrandonPoisonFlags();
- void processInput(int xpos, int ypos);
+ void processInput();
int processInputHelper(int xpos, int ypos);
int clickEventHandler(int xpos, int ypos);
void clickEventHandler2();
@@ -707,7 +706,6 @@ protected:
uint16 _gameSpeed;
uint16 _tickLength;
int _lang;
- int _mouseX, _mouseY;
int8 _itemInHand;
int _mouseState;
bool _handleInput;
diff --git a/engines/kyra/saveload.cpp b/engines/kyra/saveload.cpp
index 8245a8753f..f401148613 100644
--- a/engines/kyra/saveload.cpp
+++ b/engines/kyra/saveload.cpp
@@ -255,8 +255,6 @@ void KyraEngine::loadGame(const char *fileName) {
_abortWalkFlag = true;
_abortWalkFlag2 = false;
_mousePressFlag = false;
- _mouseX = brandonX;
- _mouseY = brandonY;
_system->warpMouse(brandonX, brandonY);
if (in->ioFailed())
diff --git a/engines/kyra/scene.cpp b/engines/kyra/scene.cpp
index 067edfc0e7..bd728cfd52 100644
--- a/engines/kyra/scene.cpp
+++ b/engines/kyra/scene.cpp
@@ -958,7 +958,7 @@ int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) {
_currentCharacter->currentAnimFrame = 7;
_animator->animRefreshNPC(0);
_animator->updateAllObjectShapes();
- processInput(_mouseX, _mouseY);
+ processInput();
return 0;
}
bool forceContinue = false;
diff --git a/engines/kyra/script_v1.cpp b/engines/kyra/script_v1.cpp
index 1670e705a6..9edca16747 100644
--- a/engines/kyra/script_v1.cpp
+++ b/engines/kyra/script_v1.cpp
@@ -1377,8 +1377,9 @@ int KyraEngine::o1_waitForConfirmationMouseClick(ScriptState *script) {
// }
processButtonList(_buttonList);
_skipFlag = false;
- script->variables[1] = _mouseX;
- script->variables[2] = _mouseY;
+ Common::Point mouse = getMousePos();
+ script->variables[1] = mouse.x;
+ script->variables[2] = mouse.y;
return 0;
}
@@ -1514,8 +1515,6 @@ int KyraEngine::o1_restoreBrandonsMovementDelay(ScriptState *script) {
int KyraEngine::o1_setMousePos(ScriptState *script) {
debugC(3, kDebugLevelScriptFuncs, "o1_setMousePos(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1));
_system->warpMouse(stackPos(0), stackPos(1));
- _mouseX = stackPos(0);
- _mouseY = stackPos(1);
return 0;
}