aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gui/dialog.cpp12
-rw-r--r--gui/widget.cpp8
-rw-r--r--gui/widget.h4
-rw-r--r--newgui.cpp35
-rw-r--r--newgui.h13
5 files changed, 46 insertions, 26 deletions
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index 4523e473cd..36694ab8ff 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -74,11 +74,7 @@ Widget *Dialog::findWidget(int x, int y)
void Dialog::close()
{
- // FIXME - this code should be inside the Gui class, and should be
- // extended to support nested dialogs.
- _gui->restoreState();
- _gui->_active = false;
- _gui->_activeDialog = 0;
+ _gui->closeTopDialog();
}
void Dialog::addResText(int x, int y, int w, int h, int resID)
@@ -116,7 +112,7 @@ enum {
};
SaveLoadDialog::SaveLoadDialog(NewGui *gui)
-:Dialog (gui, 30, 20, 260, 124)
+ : Dialog (gui, 30, 20, 260, 124)
{
addResText(10, 7, 240, 16, 1);
// addResText(10, 7, 240, 16, 2);
@@ -135,6 +131,8 @@ void SaveLoadDialog::handleCommand(uint32 cmd)
case kSaveCmd:
break;
case kLoadCmd:
+ // FIXME HACK - just to demo the nesting ability
+ _gui->pauseDialog();
break;
case kPlayCmd:
close();
@@ -152,7 +150,7 @@ void SaveLoadDialog::handleCommand(uint32 cmd)
PauseDialog::PauseDialog(NewGui *gui)
-:Dialog (gui, 50, 80, 220, 16)
+ : Dialog (gui, 50, 80, 220, 16)
{
addResText(2, 2, 220, 16, 10);
}
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 8384089541..0fbcfd20ba 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -25,7 +25,7 @@
Widget::Widget (Dialog *boss, int x, int y, int w, int h)
-: _boss(boss), _x(x), _y(y), _w(w), _h(h), _id(0), _flags(0)
+ : _boss(boss), _x(x), _y(y), _w(w), _h(h), _id(0), _flags(0)
{
// Insert into the widget list of the boss
_next = _boss->_firstWidget;
@@ -51,6 +51,7 @@ void Widget::draw()
_x += 4;
_y += 4;
}
+
// Now perform the actual widget draw
drawWidget(_flags & WIDGET_HILITED);
@@ -58,6 +59,7 @@ void Widget::draw()
_x -= 4;
_y -= 4;
}
+
// Restore x/y
_x -= _boss->_x;
_y -= _boss->_y;
@@ -68,7 +70,7 @@ void Widget::draw()
StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const char *text)
-:Widget (boss, x, y, w, h)
+ : Widget (boss, x, y, w, h)
{
// FIXME - maybe we should make a real copy of the string?
_text = text;
@@ -85,7 +87,7 @@ void StaticTextWidget::drawWidget(bool hilite)
ButtonWidget::ButtonWidget(Dialog *boss, int x, int y, int w, int h, const char *label, uint32 cmd)
-:StaticTextWidget(boss, x, y, w, h, label), _cmd(cmd), _hotkey(0)
+ : StaticTextWidget(boss, x, y, w, h, label), _cmd(cmd), _hotkey(0)
{
_flags = WIDGET_ENABLED | WIDGET_BORDER /* | WIDGET_CLEARBG */ ;
}
diff --git a/gui/widget.h b/gui/widget.h
index ec83d723ad..58e04d48a9 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -87,8 +87,8 @@ public:
uint32 getCmd();
void handleClick(int button);
- void handleMouseEntered(int button) { printf("handleMouseEntered\n"); setFlags(WIDGET_HILITED); draw(); }
- void handleMouseLeft(int button) { printf("handleMouseLeft\n"); clearFlags(WIDGET_HILITED); draw(); }
+ void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
+ void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
};
diff --git a/newgui.cpp b/newgui.cpp
index 66a75d28dc..f660673304 100644
--- a/newgui.cpp
+++ b/newgui.cpp
@@ -28,7 +28,7 @@
#define vline(x, y, y2, color) line(x, y, x, y2, color);
-NewGui::NewGui(Scumm *s):_s(s), _active(false), _need_redraw(false), _activeDialog(0)
+NewGui::NewGui(Scumm *s) : _s(s), _need_redraw(false)
{
_pauseDialog = new PauseDialog(this);
_saveLoadDialog = new SaveLoadDialog(this);
@@ -36,33 +36,31 @@ NewGui::NewGui(Scumm *s):_s(s), _active(false), _need_redraw(false), _activeDial
void NewGui::pauseDialog()
{
- _active = true;
- _activeDialog = _pauseDialog;
- _need_redraw = true;
+ openDialog(_pauseDialog);
}
void NewGui::saveloadDialog()
{
- _active = true;
- _activeDialog = _saveLoadDialog;
- _need_redraw = true;
+ openDialog(_saveLoadDialog);
}
void NewGui::loop()
{
+ Dialog *activeDialog = _dialogStack.top();
+
if (_need_redraw) {
- _activeDialog->draw();
+ activeDialog->draw();
saveState();
_need_redraw = false;
}
_s->animateCursor();
_s->getKeyInput(0);
if (_s->_mouseButStat & MBS_LEFT_CLICK) {
- _activeDialog->handleClick(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
+ activeDialog->handleClick(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
} else if (_s->_lastKeyHit) {
- _activeDialog->handleKey(_s->_lastKeyHit, 0);
+ activeDialog->handleKey(_s->_lastKeyHit, 0);
} else if (_old_mouse.x != _s->mouse.x || _old_mouse.y != _s->mouse.y) {
- _activeDialog->handleMouseMoved(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
+ activeDialog->handleMouseMoved(_s->mouse.x, _s->mouse.y, _s->_mouseButStat);
_old_mouse.x = _s->mouse.x;
_old_mouse.y = _s->mouse.y;
}
@@ -109,6 +107,21 @@ void NewGui::restoreState()
_s->pauseSounds(_old_soundsPaused);
}
+void NewGui::openDialog(Dialog *dialog)
+{
+ _dialogStack.push(dialog);
+ _need_redraw = true;
+}
+
+void NewGui::closeTopDialog()
+{
+ _dialogStack.pop();
+ if (_dialogStack.empty())
+ restoreState();
+ else
+ _dialogStack.top()->draw();
+}
+
#pragma mark -
const char *NewGui::queryString(int stringno)
diff --git a/newgui.h b/newgui.h
index e4c17d6aaf..8b52e15fcd 100644
--- a/newgui.h
+++ b/newgui.h
@@ -21,11 +21,15 @@
#ifndef NEWGUI_H
#define NEWGUI_H
+#include <stack>
+
#include "scummsys.h"
class Scumm;
class Dialog;
+typedef std::stack<Dialog *> DialogStack;
+
class NewGui {
friend class Dialog;
public:
@@ -39,15 +43,15 @@ public:
void saveloadDialog();
void loop();
- bool isActive() { return _active; }
+ bool isActive() { return ! _dialogStack.empty(); }
NewGui(Scumm *s);
protected:
Scumm *_s;
- bool _active;
bool _need_redraw;
- Dialog *_activeDialog;
+// Dialog *_activeDialog;
+ DialogStack _dialogStack;
Dialog *_pauseDialog;
Dialog *_saveLoadDialog;
@@ -67,6 +71,9 @@ protected:
void saveState();
void restoreState();
+
+ void openDialog(Dialog *dialog);
+ void closeTopDialog();
public:
// Drawing