added dialog nesting code (for now using std::stack, I will provide my own stack class later
svn-id: r4483
This commit is contained in:
parent
aec2530529
commit
2b50e2a7c0
5 changed files with 46 additions and 26 deletions
|
@ -74,11 +74,7 @@ Widget *Dialog::findWidget(int x, int y)
|
||||||
|
|
||||||
void Dialog::close()
|
void Dialog::close()
|
||||||
{
|
{
|
||||||
// FIXME - this code should be inside the Gui class, and should be
|
_gui->closeTopDialog();
|
||||||
// extended to support nested dialogs.
|
|
||||||
_gui->restoreState();
|
|
||||||
_gui->_active = false;
|
|
||||||
_gui->_activeDialog = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::addResText(int x, int y, int w, int h, int resID)
|
void Dialog::addResText(int x, int y, int w, int h, int resID)
|
||||||
|
@ -116,7 +112,7 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
SaveLoadDialog::SaveLoadDialog(NewGui *gui)
|
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, 1);
|
||||||
// addResText(10, 7, 240, 16, 2);
|
// addResText(10, 7, 240, 16, 2);
|
||||||
|
@ -135,6 +131,8 @@ void SaveLoadDialog::handleCommand(uint32 cmd)
|
||||||
case kSaveCmd:
|
case kSaveCmd:
|
||||||
break;
|
break;
|
||||||
case kLoadCmd:
|
case kLoadCmd:
|
||||||
|
// FIXME HACK - just to demo the nesting ability
|
||||||
|
_gui->pauseDialog();
|
||||||
break;
|
break;
|
||||||
case kPlayCmd:
|
case kPlayCmd:
|
||||||
close();
|
close();
|
||||||
|
@ -152,7 +150,7 @@ void SaveLoadDialog::handleCommand(uint32 cmd)
|
||||||
|
|
||||||
|
|
||||||
PauseDialog::PauseDialog(NewGui *gui)
|
PauseDialog::PauseDialog(NewGui *gui)
|
||||||
:Dialog (gui, 50, 80, 220, 16)
|
: Dialog (gui, 50, 80, 220, 16)
|
||||||
{
|
{
|
||||||
addResText(2, 2, 220, 16, 10);
|
addResText(2, 2, 220, 16, 10);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
|
|
||||||
Widget::Widget (Dialog *boss, int x, int y, int w, int h)
|
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
|
// Insert into the widget list of the boss
|
||||||
_next = _boss->_firstWidget;
|
_next = _boss->_firstWidget;
|
||||||
|
@ -51,6 +51,7 @@ void Widget::draw()
|
||||||
_x += 4;
|
_x += 4;
|
||||||
_y += 4;
|
_y += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now perform the actual widget draw
|
// Now perform the actual widget draw
|
||||||
drawWidget(_flags & WIDGET_HILITED);
|
drawWidget(_flags & WIDGET_HILITED);
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ void Widget::draw()
|
||||||
_x -= 4;
|
_x -= 4;
|
||||||
_y -= 4;
|
_y -= 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore x/y
|
// Restore x/y
|
||||||
_x -= _boss->_x;
|
_x -= _boss->_x;
|
||||||
_y -= _boss->_y;
|
_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)
|
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?
|
// FIXME - maybe we should make a real copy of the string?
|
||||||
_text = text;
|
_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)
|
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 */ ;
|
_flags = WIDGET_ENABLED | WIDGET_BORDER /* | WIDGET_CLEARBG */ ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,8 +87,8 @@ public:
|
||||||
uint32 getCmd();
|
uint32 getCmd();
|
||||||
void handleClick(int button);
|
void handleClick(int button);
|
||||||
|
|
||||||
void handleMouseEntered(int button) { printf("handleMouseEntered\n"); setFlags(WIDGET_HILITED); draw(); }
|
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
|
||||||
void handleMouseLeft(int button) { printf("handleMouseLeft\n"); clearFlags(WIDGET_HILITED); draw(); }
|
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
35
newgui.cpp
35
newgui.cpp
|
@ -28,7 +28,7 @@
|
||||||
#define vline(x, y, y2, color) line(x, y, x, y2, color);
|
#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);
|
_pauseDialog = new PauseDialog(this);
|
||||||
_saveLoadDialog = new SaveLoadDialog(this);
|
_saveLoadDialog = new SaveLoadDialog(this);
|
||||||
|
@ -36,33 +36,31 @@ NewGui::NewGui(Scumm *s):_s(s), _active(false), _need_redraw(false), _activeDial
|
||||||
|
|
||||||
void NewGui::pauseDialog()
|
void NewGui::pauseDialog()
|
||||||
{
|
{
|
||||||
_active = true;
|
openDialog(_pauseDialog);
|
||||||
_activeDialog = _pauseDialog;
|
|
||||||
_need_redraw = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewGui::saveloadDialog()
|
void NewGui::saveloadDialog()
|
||||||
{
|
{
|
||||||
_active = true;
|
openDialog(_saveLoadDialog);
|
||||||
_activeDialog = _saveLoadDialog;
|
|
||||||
_need_redraw = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewGui::loop()
|
void NewGui::loop()
|
||||||
{
|
{
|
||||||
|
Dialog *activeDialog = _dialogStack.top();
|
||||||
|
|
||||||
if (_need_redraw) {
|
if (_need_redraw) {
|
||||||
_activeDialog->draw();
|
activeDialog->draw();
|
||||||
saveState();
|
saveState();
|
||||||
_need_redraw = false;
|
_need_redraw = false;
|
||||||
}
|
}
|
||||||
_s->animateCursor();
|
_s->animateCursor();
|
||||||
_s->getKeyInput(0);
|
_s->getKeyInput(0);
|
||||||
if (_s->_mouseButStat & MBS_LEFT_CLICK) {
|
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) {
|
} 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) {
|
} 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.x = _s->mouse.x;
|
||||||
_old_mouse.y = _s->mouse.y;
|
_old_mouse.y = _s->mouse.y;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +107,21 @@ void NewGui::restoreState()
|
||||||
_s->pauseSounds(_old_soundsPaused);
|
_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 -
|
#pragma mark -
|
||||||
|
|
||||||
const char *NewGui::queryString(int stringno)
|
const char *NewGui::queryString(int stringno)
|
||||||
|
|
13
newgui.h
13
newgui.h
|
@ -21,11 +21,15 @@
|
||||||
#ifndef NEWGUI_H
|
#ifndef NEWGUI_H
|
||||||
#define NEWGUI_H
|
#define NEWGUI_H
|
||||||
|
|
||||||
|
#include <stack>
|
||||||
|
|
||||||
#include "scummsys.h"
|
#include "scummsys.h"
|
||||||
|
|
||||||
class Scumm;
|
class Scumm;
|
||||||
class Dialog;
|
class Dialog;
|
||||||
|
|
||||||
|
typedef std::stack<Dialog *> DialogStack;
|
||||||
|
|
||||||
class NewGui {
|
class NewGui {
|
||||||
friend class Dialog;
|
friend class Dialog;
|
||||||
public:
|
public:
|
||||||
|
@ -39,15 +43,15 @@ public:
|
||||||
void saveloadDialog();
|
void saveloadDialog();
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
bool isActive() { return _active; }
|
bool isActive() { return ! _dialogStack.empty(); }
|
||||||
|
|
||||||
NewGui(Scumm *s);
|
NewGui(Scumm *s);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Scumm *_s;
|
Scumm *_s;
|
||||||
bool _active;
|
|
||||||
bool _need_redraw;
|
bool _need_redraw;
|
||||||
Dialog *_activeDialog;
|
// Dialog *_activeDialog;
|
||||||
|
DialogStack _dialogStack;
|
||||||
|
|
||||||
Dialog *_pauseDialog;
|
Dialog *_pauseDialog;
|
||||||
Dialog *_saveLoadDialog;
|
Dialog *_saveLoadDialog;
|
||||||
|
@ -68,6 +72,9 @@ protected:
|
||||||
void saveState();
|
void saveState();
|
||||||
void restoreState();
|
void restoreState();
|
||||||
|
|
||||||
|
void openDialog(Dialog *dialog);
|
||||||
|
void closeTopDialog();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Drawing
|
// Drawing
|
||||||
byte *getBasePtr(int x, int y);
|
byte *getBasePtr(int x, int y);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue