aboutsummaryrefslogtreecommitdiff
path: root/gui/gui-manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/gui-manager.cpp')
-rw-r--r--gui/gui-manager.cpp155
1 files changed, 93 insertions, 62 deletions
diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index a0ef4216aa..999d61e854 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -27,6 +27,7 @@
#include "common/rect.h"
#include "common/textconsole.h"
#include "common/translation.h"
+#include "gui/EventRecorder.h"
#include "backends/keymapper/keymapper.h"
@@ -253,12 +254,15 @@ Dialog *GuiManager::getTopDialog() const {
void GuiManager::runLoop() {
Dialog * const activeDialog = getTopDialog();
bool didSaveState = false;
- int button;
- uint32 time;
if (activeDialog == 0)
return;
+#ifdef ENABLE_EVENTRECORDER
+ // Suspend recording while GUI is shown
+ g_eventRec.suspendRecording();
+#endif
+
if (!_stateIsSaved) {
saveState();
_theme->enable();
@@ -296,15 +300,28 @@ void GuiManager::runLoop() {
// _theme->updateScreen();
// _system->updateScreen();
- if (lastRedraw + waitTime < _system->getMillis()) {
+ if (lastRedraw + waitTime < _system->getMillis(true)) {
_theme->updateScreen();
_system->updateScreen();
- lastRedraw = _system->getMillis();
+ lastRedraw = _system->getMillis(true);
}
Common::Event event;
while (eventMan->pollEvent(event)) {
+ // We will need to check whether the screen changed while polling
+ // for an event here. While we do send EVENT_SCREEN_CHANGED
+ // whenever this happens we still cannot be sure that we get such
+ // an event immediately. For example, we might have an mouse move
+ // event queued before an screen changed event. In some rare cases
+ // this would make the GUI redraw (with the code a few lines
+ // below) when it is not yet updated for new overlay dimensions.
+ // As a result ScummVM would crash because it tries to copy data
+ // outside the actual overlay screen.
+ if (event.type != Common::EVENT_SCREEN_CHANGED) {
+ checkScreenChange();
+ }
+
// The top dialog can change during the event loop. In that case, flush all the
// dialog-related events since they were probably generated while the old dialog
// was still visible, and therefore not intended for the new one.
@@ -314,72 +331,21 @@ void GuiManager::runLoop() {
if (activeDialog != getTopDialog() && event.type != Common::EVENT_SCREEN_CHANGED)
continue;
- Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
-
- switch (event.type) {
- case Common::EVENT_KEYDOWN:
- activeDialog->handleKeyDown(event.kbd);
- break;
- case Common::EVENT_KEYUP:
- activeDialog->handleKeyUp(event.kbd);
- break;
- case Common::EVENT_MOUSEMOVE:
- activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
-
- if (mouse.x != _lastMousePosition.x || mouse.y != _lastMousePosition.y) {
- _lastMousePosition.x = mouse.x;
- _lastMousePosition.y = mouse.y;
- _lastMousePosition.time = _system->getMillis();
- }
+ processEvent(event, activeDialog);
+ if (event.type == Common::EVENT_MOUSEMOVE) {
tooltipCheck = true;
- break;
- // We don't distinguish between mousebuttons (for now at least)
- case Common::EVENT_LBUTTONDOWN:
- case Common::EVENT_RBUTTONDOWN:
- button = (event.type == Common::EVENT_LBUTTONDOWN ? 1 : 2);
- time = _system->getMillis();
- if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
- && ABS(_lastClick.x - event.mouse.x) < 3
- && ABS(_lastClick.y - event.mouse.y) < 3) {
- _lastClick.count++;
- } else {
- _lastClick.x = event.mouse.x;
- _lastClick.y = event.mouse.y;
- _lastClick.count = 1;
- }
- _lastClick.time = time;
- activeDialog->handleMouseDown(mouse.x, mouse.y, button, _lastClick.count);
- break;
- case Common::EVENT_LBUTTONUP:
- case Common::EVENT_RBUTTONUP:
- button = (event.type == Common::EVENT_LBUTTONUP ? 1 : 2);
- activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
- break;
- case Common::EVENT_WHEELUP:
- activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
- break;
- case Common::EVENT_WHEELDOWN:
- activeDialog->handleMouseWheel(mouse.x, mouse.y, 1);
- break;
- case Common::EVENT_SCREEN_CHANGED:
- screenChange();
- break;
- default:
-#ifdef ENABLE_KEYMAPPER
- activeDialog->handleOtherEvent(event);
-#endif
- break;
}
- if (lastRedraw + waitTime < _system->getMillis()) {
+
+ if (lastRedraw + waitTime < _system->getMillis(true)) {
_theme->updateScreen();
_system->updateScreen();
- lastRedraw = _system->getMillis();
+ lastRedraw = _system->getMillis(true);
}
}
- if (tooltipCheck && _lastMousePosition.time + kTooltipDelay < _system->getMillis()) {
+ if (tooltipCheck && _lastMousePosition.time + kTooltipDelay < _system->getMillis(true)) {
Widget *wdg = activeDialog->findWidget(_lastMousePosition.x, _lastMousePosition.y);
if (wdg && wdg->hasTooltip() && !(wdg->getFlags() & WIDGET_PRESSED)) {
Tooltip *tooltip = new Tooltip();
@@ -409,6 +375,11 @@ void GuiManager::runLoop() {
restoreState();
_useStdCursor = false;
}
+
+#ifdef ENABLE_EVENTRECORDER
+ // Resume recording once GUI is shown
+ g_eventRec.resumeRecording();
+#endif
}
#pragma mark -
@@ -492,7 +463,7 @@ void GuiManager::setupCursor() {
// very much. We could plug in a different cursor here if we like to.
void GuiManager::animateCursor() {
- int time = _system->getMillis();
+ int time = _system->getMillis(true);
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
for (int i = 0; i < 15; i++) {
if ((i < 6) || (i > 8)) {
@@ -537,4 +508,64 @@ void GuiManager::screenChange() {
_system->updateScreen();
}
+void GuiManager::processEvent(const Common::Event &event, Dialog *const activeDialog) {
+ int button;
+ uint32 time;
+ Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
+ switch (event.type) {
+ case Common::EVENT_KEYDOWN:
+ activeDialog->handleKeyDown(event.kbd);
+ break;
+ case Common::EVENT_KEYUP:
+ activeDialog->handleKeyUp(event.kbd);
+ break;
+ case Common::EVENT_MOUSEMOVE:
+ activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
+
+ if (mouse.x != _lastMousePosition.x || mouse.y != _lastMousePosition.y) {
+ _lastMousePosition.x = mouse.x;
+ _lastMousePosition.y = mouse.y;
+ _lastMousePosition.time = _system->getMillis(true);
+ }
+
+ break;
+ // We don't distinguish between mousebuttons (for now at least)
+ case Common::EVENT_LBUTTONDOWN:
+ case Common::EVENT_RBUTTONDOWN:
+ button = (event.type == Common::EVENT_LBUTTONDOWN ? 1 : 2);
+ time = _system->getMillis(true);
+ if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay)
+ && ABS(_lastClick.x - event.mouse.x) < 3
+ && ABS(_lastClick.y - event.mouse.y) < 3) {
+ _lastClick.count++;
+ } else {
+ _lastClick.x = event.mouse.x;
+ _lastClick.y = event.mouse.y;
+ _lastClick.count = 1;
+ }
+ _lastClick.time = time;
+ activeDialog->handleMouseDown(mouse.x, mouse.y, button, _lastClick.count);
+ break;
+ case Common::EVENT_LBUTTONUP:
+ case Common::EVENT_RBUTTONUP:
+ button = (event.type == Common::EVENT_LBUTTONUP ? 1 : 2);
+ activeDialog->handleMouseUp(mouse.x, mouse.y, button, _lastClick.count);
+ break;
+ case Common::EVENT_WHEELUP:
+ activeDialog->handleMouseWheel(mouse.x, mouse.y, -1);
+ break;
+ case Common::EVENT_WHEELDOWN:
+ activeDialog->handleMouseWheel(mouse.x, mouse.y, 1);
+ break;
+ case Common::EVENT_SCREEN_CHANGED:
+ screenChange();
+ break;
+ default:
+ #ifdef ENABLE_KEYMAPPER
+ activeDialog->handleOtherEvent(event);
+ #endif
+ break;
+ }
+}
+
} // End of namespace GUI