From d5bcb63f829f4c4aecd45cb60e492ca896ad77a5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 16 Oct 2002 17:37:30 +0000 Subject: dialogs now can be run 'modal' svn-id: r5168 --- gui/dialog.cpp | 12 ++++++++++++ gui/dialog.h | 11 ++++++----- gui/newgui.cpp | 43 ++++++++++++++++++++++++------------------- gui/newgui.h | 2 ++ 4 files changed, 44 insertions(+), 24 deletions(-) (limited to 'gui') diff --git a/gui/dialog.cpp b/gui/dialog.cpp index ec386f90f2..09f76edb1c 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -50,6 +50,18 @@ Dialog::~Dialog() _firstWidget = 0; } +int Dialog::runModal() +{ + // Open up + open(); + + // Start processing events + _gui->runLoop(); + + // FIXME - for now always return 0.... + return 0; +} + void Dialog::open() { Widget *w = _firstWidget; diff --git a/gui/dialog.h b/gui/dialog.h index 509ae6d385..7d7224c480 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -49,7 +49,13 @@ public: _mouseWidget(0), _focusedWidget(0), _visible(false) {} virtual ~Dialog(); + + virtual int runModal(); + + NewGui *getGui() { return _gui; } + bool isVisible() const { return _visible; } +protected: virtual void open(); virtual void close(); @@ -63,11 +69,6 @@ public: virtual void handleMouseMoved(int x, int y, int button); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); - NewGui *getGui() { return _gui; } - - bool isVisible() const { return _visible; } - -protected: Widget* findWidget(int x, int y); // Find the widget at pos x,y if any Widget* addButton(int x, int y, const ScummVM::String &label, uint32 cmd, char hotkey); diff --git a/gui/newgui.cpp b/gui/newgui.cpp index aed586fe04..61f50e2b72 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -82,7 +82,7 @@ static byte guifont[] = { // Constructor NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false), - _currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0) + _stateIsSaved(false), _currentKeyDown(0), _cursorAnimateCounter(0), _cursorAnimateTimer(0) { // Setup some default GUI colors. // TODO - either use nicer values, or maybe make this configurable? @@ -98,23 +98,18 @@ NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false void NewGui::runLoop() { - if (!isActive()) - return; - - Dialog *activeDialog; - int i; - OSystem::Event event; + Dialog *activeDialog = _dialogStack.top(); + bool didSaveState = false; - saveState(); - - _currentKeyDown = 0; + if (activeDialog == 0) + return; - _lastClick.x = _lastClick.y = 0; - _lastClick.time = 0; - _lastClick.count = 0; + if (!_stateIsSaved) { + saveState(); + didSaveState = true; + } - while (isActive()) { - activeDialog = _dialogStack.top(); + while (activeDialog == _dialogStack.top()) { activeDialog->handleTickle(); @@ -123,15 +118,15 @@ void NewGui::runLoop() // This is necessary to get the blending right. _system->clear_overlay(); _system->grab_overlay(_screen, _screenPitch); - for (i = 0; i < _dialogStack.size(); i++) + for (int i = 0; i < _dialogStack.size(); i++) _dialogStack[i]->draw(); _needRedraw = false; } animateCursor(); - _system->update_screen(); + OSystem::Event event; uint32 time = _system->get_msecs(); while (_system->poll_event(&event)) { @@ -192,7 +187,8 @@ void NewGui::runLoop() _system->delay_msecs(10); } - restoreState(); + if (didSaveState) + restoreState(); } #pragma mark - @@ -209,6 +205,13 @@ void NewGui::saveState() // _screen = new int16[_system->get_width() * _system->get_height()]; // _screenPitch = _system->get_width(); _system->grab_overlay(_screen, _screenPitch); + + _currentKeyDown = 0; + _lastClick.x = _lastClick.y = 0; + _lastClick.time = 0; + _lastClick.count = 0; + + _stateIsSaved = true; } void NewGui::restoreState() @@ -221,7 +224,9 @@ void NewGui::restoreState() _screen = 0; } - _system->update_screen(); + _system->update_screen(); + + _stateIsSaved = false; } void NewGui::openDialog(Dialog *dialog) diff --git a/gui/newgui.h b/gui/newgui.h index bd97bcaaf0..957c63c1fa 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -81,6 +81,8 @@ protected: bool _needRedraw; DialogStack _dialogStack; + bool _stateIsSaved; + // for continuous events (keyDown) int _currentKeyDown, _currentKeyDownFlags; uint32 _keyRepeatTime; -- cgit v1.2.3