Commit 3a9fc27b authored by Ian Wadham's avatar Ian Wadham

Halt the game if the window loses keyboard focus, the application is minimized...

Halt the game if the window loses keyboard focus, the application is minimized or, in playback, mouse or laptop mode, the pointer moves outside the KGoldrunner viewport.

svn path=/branches/work/kgoldrunner-qgv/; revision=1299188
parent c1b97822
......@@ -540,6 +540,18 @@ void KGrCanvas::mouseReleaseEvent (QMouseEvent * mouseEvent)
void KGrCanvas::getMousePos (int & i, int & j)
{
QPoint p = mapFromGlobal (m->pos());
int x = p.x();
int y = p.y();
if (! isActiveWindow()) {
i = -2; // The window lacks keyboard focus or is minimized.
j = -2;
return;
}
else if ((x < 0) || (y < 0) || (x >= width()) || (y >= height())) {
i = -1; // The pointer is outside the KGoldrunner viewport.
j = -1;
return;
}
// In KGoldrunner, the top-left visible cell is [1,1].
i = ((p.x() - topLeft.x()) / imgW) + 1;
......
......@@ -741,6 +741,15 @@ void KGrLevelPlayer::unstackEnemy (const int spriteId,
void KGrLevelPlayer::tick (bool missed, int scaledTime)
{
int i, j;
emit getMousePos (i, j);
if (i == -2) {
return; // The KGoldrunner window is inactive.
}
if ((i == -1) && (playback || (controlMode != KEYBOARD))) {
return; // The pointer is outside the KGoldrunner viewport.
}
if (playback) { // Replay a recorded move.
if (! doRecordedMove()) {
playback = false;
......@@ -750,9 +759,7 @@ void KGrLevelPlayer::tick (bool missed, int scaledTime)
}
}
else if ((controlMode == MOUSE) || (controlMode == LAPTOP)) {
int i, j; // Make and record a live pointer-move.
emit getMousePos (i, j);
setTarget (i, j);
setTarget (i, j); // Make and record a live pointer-move.
}
else if (controlMode == KEYBOARD) {
if (holdKeyOption == CLICK_KEY) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment