aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorMax Horn2003-11-02 02:18:16 +0000
committerMax Horn2003-11-02 02:18:16 +0000
commitb27a871f870df854a6db0f4530d4596483927bb1 (patch)
treef6c75300cd5dcd22b67044256e36a01f985a054d /gui
parentf2c4bbbdbfb06b5296eb3fcdcb7235292e6ac039 (diff)
downloadscummvm-rg350-b27a871f870df854a6db0f4530d4596483927bb1.tar.gz
scummvm-rg350-b27a871f870df854a6db0f4530d4596483927bb1.tar.bz2
scummvm-rg350-b27a871f870df854a6db0f4530d4596483927bb1.zip
turned NewGui into a singleton, and made OSystem a pseudo-singleton; added Widget::findWidget (preparing to add support for nested widgets, for the tab widget)
svn-id: r11045
Diffstat (limited to 'gui')
-rw-r--r--gui/EditTextWidget.cpp34
-rw-r--r--gui/EditTextWidget.h6
-rw-r--r--gui/ListWidget.cpp6
-rw-r--r--gui/PopUpWidget.cpp28
-rw-r--r--gui/ScrollBarWidget.cpp2
-rw-r--r--gui/about.cpp4
-rw-r--r--gui/about.h2
-rw-r--r--gui/browser.cpp10
-rw-r--r--gui/browser.h2
-rw-r--r--gui/chooser.cpp4
-rw-r--r--gui/chooser.h2
-rw-r--r--gui/console.cpp24
-rw-r--r--gui/console.h6
-rw-r--r--gui/dialog.cpp16
-rw-r--r--gui/dialog.h6
-rw-r--r--gui/launcher.cpp26
-rw-r--r--gui/launcher.h2
-rw-r--r--gui/message.cpp17
-rw-r--r--gui/message.h4
-rw-r--r--gui/newgui.cpp9
-rw-r--r--gui/newgui.h17
-rw-r--r--gui/options.cpp6
-rw-r--r--gui/options.h2
-rw-r--r--gui/widget.cpp14
-rw-r--r--gui/widget.h4
25 files changed, 127 insertions, 126 deletions
diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp
index 7807683978..9a72badb5b 100644
--- a/gui/EditTextWidget.cpp
+++ b/gui/EditTextWidget.cpp
@@ -33,14 +33,13 @@ EditTextWidget::EditTextWidget(Dialog *boss, int x, int y, int w, int h, const S
_pos = _label.size();
- NewGui *gui = _boss->getGui();
- _labelOffset = (gui->getStringWidth(_label) - (_w - 6));
+ _labelOffset = (g_gui.getStringWidth(_label) - (_w - 6));
if (_labelOffset < 0)
_labelOffset = 0;
}
void EditTextWidget::handleTickle() {
- uint32 time = _boss->getGui()->get_time();
+ uint32 time = g_system->get_msecs();
if (_caretTime < time) {
_caretTime = time + kCaretBlinkTime;
if (_caretVisible) {
@@ -56,7 +55,7 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount){
if (_caretVisible)
drawCaret(true);
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
x += _labelOffset;
@@ -90,7 +89,7 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
case 27: // escape
_label = _backupString;
_pos = _label.size() - 1;
- _labelOffset = (_boss->getGui()->getStringWidth(_label) - (_w-6));
+ _labelOffset = (g_gui.getStringWidth(_label) - (_w-6));
if (_labelOffset < 0)
_labelOffset = 0;
_boss->releaseFocus();
@@ -144,24 +143,21 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
}
void EditTextWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
-
// Draw a thin frame around us.
- gui->hLine(_x, _y, _x + _w - 1, gui->_color);
- gui->hLine(_x, _y + _h - 1, _x +_w - 1, gui->_shadowcolor);
- gui->vLine(_x, _y, _y + _h - 1, gui->_color);
- gui->vLine(_x + _w - 1, _y, _y + _h - 1, gui->_shadowcolor);
+ g_gui.hLine(_x, _y, _x + _w - 1, g_gui._color);
+ g_gui.hLine(_x, _y + _h - 1, _x +_w - 1, g_gui._shadowcolor);
+ g_gui.vLine(_x, _y, _y + _h - 1, g_gui._color);
+ g_gui.vLine(_x + _w - 1, _y, _y + _h - 1, g_gui._shadowcolor);
// Draw the text
adjustOffset();
- gui->drawString(_label, _x + 2, _y + 3, _w - 6, gui->_textcolor, kTextAlignLeft, -_labelOffset);
+ g_gui.drawString(_label, _x + 2, _y + 3, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset);
}
int EditTextWidget::getCaretPos() {
- NewGui *gui = _boss->getGui();
int caretpos = 0;
for (int i = 0; i < _pos; i++)
- caretpos += gui->getCharWidth(_label[i]);
+ caretpos += g_gui.getCharWidth(_label[i]);
caretpos -= _labelOffset;
@@ -173,17 +169,15 @@ void EditTextWidget::drawCaret(bool erase) {
if (!isVisible() || !_boss->isVisible())
return;
- NewGui *gui = _boss->getGui();
-
- int16 color = erase ? gui->_bgcolor : gui->_textcolorhi;
+ int16 color = erase ? g_gui._bgcolor : g_gui._textcolorhi;
int x = _x + _boss->getX() + 2;
int y = _y + _boss->getY() + 1;
int width = getCaretPos();
x += width;
- gui->vLine(x, y, y + kLineHeight, color);
- gui->addDirtyRect(x, y, 2, kLineHeight);
+ g_gui.vLine(x, y, y + kLineHeight, color);
+ g_gui.addDirtyRect(x, y, 2, kLineHeight);
_caretVisible = !erase;
}
@@ -209,7 +203,7 @@ bool EditTextWidget::adjustOffset() {
}
else if (_labelOffset > 0)
{
- int width = _boss->getGui()->getStringWidth(_label);
+ int width = g_gui.getStringWidth(_label);
if (width - _labelOffset < (_w - 6)) {
// scroll right
_labelOffset = (width - (_w - 6));
diff --git a/gui/EditTextWidget.h b/gui/EditTextWidget.h
index 1b121c0a1f..a6fe8dbdce 100644
--- a/gui/EditTextWidget.h
+++ b/gui/EditTextWidget.h
@@ -31,10 +31,10 @@ class EditTextWidget : public StaticTextWidget {
typedef Common::String String;
protected:
String _backupString;
- bool _caretVisible;
+ bool _caretVisible;
uint32 _caretTime;
- int _pos;
- int _labelOffset;
+ int _pos;
+ int _labelOffset;
public:
EditTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text);
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp
index 2d3e9a7161..a205528cd4 100644
--- a/gui/ListWidget.cpp
+++ b/gui/ListWidget.cpp
@@ -84,7 +84,7 @@ void ListWidget::scrollBarRecalc() {
}
void ListWidget::handleTickle() {
- uint32 time = _boss->getGui()->get_time();
+ uint32 time = g_system->get_msecs();
if (_editMode && _caretTime < time) {
_caretTime = time + kCaretBlinkTime;
if (_caretVisible) {
@@ -253,7 +253,7 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
}
void ListWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
int i, pos, len = _list.size();
Common::String buffer;
@@ -290,7 +290,7 @@ void ListWidget::drawCaret(bool erase) {
if (!isVisible() || !_boss->isVisible())
return;
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
// The item is selected, thus _bgcolor is used to draw the caret and _textcolorhi to erase it
int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;
diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp
index d6b5af978d..62735a17b5 100644
--- a/gui/PopUpWidget.cpp
+++ b/gui/PopUpWidget.cpp
@@ -75,7 +75,7 @@ protected:
};
PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
- : Dialog(boss->_boss->getGui(), 0, 0, 16, 16),
+ : Dialog(0, 0, 16, 16),
_popUpBoss(boss) {
// Copy the selection index
_selection = _popUpBoss->_selectedItem;
@@ -104,15 +104,15 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
_clickY = clickY - _y;
// Time the popup was opened
- _openTime = _gui->get_time();
+ _openTime = g_system->get_msecs();
}
void PopUpDialog::drawDialog() {
// Draw the menu border
- _gui->hLine(_x, _y, _x+_w - 1, _gui->_color);
- _gui->hLine(_x, _y + _h - 1, _x + _w - 1, _gui->_shadowcolor);
- _gui->vLine(_x, _y, _y+_h - 1, _gui->_color);
- _gui->vLine(_x + _w - 1, _y, _y + _h - 1, _gui->_shadowcolor);
+ g_gui.hLine(_x, _y, _x+_w - 1, g_gui._color);
+ g_gui.hLine(_x, _y + _h - 1, _x + _w - 1, g_gui._shadowcolor);
+ g_gui.vLine(_x, _y, _y+_h - 1, g_gui._color);
+ g_gui.vLine(_x + _w - 1, _y, _y + _h - 1, g_gui._shadowcolor);
// Draw the entries
int count = _popUpBoss->_entries.size();
@@ -120,14 +120,14 @@ void PopUpDialog::drawDialog() {
drawMenuEntry(i, i == _selection);
}
- _gui->addDirtyRect(_x, _y, _w, _h);
+ g_gui.addDirtyRect(_x, _y, _w, _h);
}
void PopUpDialog::handleMouseUp(int x, int y, int button, int clickCount) {
// Mouse was released. If it wasn't moved much since the original mouse down,
// let the popup stay open. If it did move, assume the user made his selection.
int dist = (_clickX - x) * (_clickX - x) + (_clickY - y) * (_clickY - y);
- if (dist > 3 * 3 || _gui->get_time() - _openTime > 300) {
+ if (dist > 3 * 3 || g_system->get_msecs() - _openTime > 300) {
setResult(_selection);
close();
}
@@ -253,15 +253,15 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) {
int w = _w - 2;
Common::String &name = _popUpBoss->_entries[entry].name;
- _gui->fillRect(x, y, w, kLineHeight, hilite ? _gui->_textcolorhi : _gui->_bgcolor);
+ g_gui.fillRect(x, y, w, kLineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);
if (name.size() == 0) {
// Draw a seperator
- _gui->hLine(x, y + kLineHeight / 2, x + w - 1, _gui->_color);
- _gui->hLine(x + 1, y + 1 + kLineHeight / 2, x + w - 1, _gui->_shadowcolor);
+ g_gui.hLine(x, y + kLineHeight / 2, x + w - 1, g_gui._color);
+ g_gui.hLine(x + 1, y + 1 + kLineHeight / 2, x + w - 1, g_gui._shadowcolor);
} else {
- _gui->drawString(name, x + 1, y + 2, w - 2, hilite ? _gui->_bgcolor : _gui->_textcolor);
+ g_gui.drawString(name, x + 1, y + 2, w - 2, hilite ? g_gui._bgcolor : g_gui._textcolor);
}
- _gui->addDirtyRect(x, y, w, kLineHeight);
+ g_gui.addDirtyRect(x, y, w, kLineHeight);
}
@@ -315,7 +315,7 @@ void PopUpWidget::setSelected(int item) {
}
void PopUpWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
// Draw a thin frame around us.
// TODO - should look different than the EditTextWidget fram
diff --git a/gui/ScrollBarWidget.cpp b/gui/ScrollBarWidget.cpp
index 50bcde0e1f..a77752b570 100644
--- a/gui/ScrollBarWidget.cpp
+++ b/gui/ScrollBarWidget.cpp
@@ -212,7 +212,7 @@ void ScrollBarWidget::recalc() {
}
void ScrollBarWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
int bottomY = _y + _h;
bool isSinglePage = (_numEntries <= _entriesPerPage);
diff --git a/gui/about.cpp b/gui/about.cpp
index e94a6b9598..5ef2188c4c 100644
--- a/gui/about.cpp
+++ b/gui/about.cpp
@@ -24,8 +24,8 @@
#include "base/engine.h"
#include "common/str.h"
-AboutDialog::AboutDialog(NewGui *gui)
- : Dialog(gui, 10, 20, 300, 124) {
+AboutDialog::AboutDialog()
+ : Dialog(10, 20, 300, 124) {
addButton((_w - kButtonWidth)/2, 100, "OK", kCloseCmd, '\r'); // Close dialog - FIXME
Common::String version("ScummVM ");
diff --git a/gui/about.h b/gui/about.h
index 2453447896..744fbb9c6f 100644
--- a/gui/about.h
+++ b/gui/about.h
@@ -25,7 +25,7 @@
class AboutDialog : public Dialog {
public:
- AboutDialog(NewGui *gui);
+ AboutDialog();
};
#endif
diff --git a/gui/browser.cpp b/gui/browser.cpp
index af935c3c0b..44d4034068 100644
--- a/gui/browser.cpp
+++ b/gui/browser.cpp
@@ -19,9 +19,9 @@
*/
#include "stdafx.h"
-#include "browser.h"
-#include "newgui.h"
-#include "ListWidget.h"
+#include "gui/browser.h"
+#include "gui/newgui.h"
+#include "gui/ListWidget.h"
#include "backends/fs/fs.h"
@@ -36,8 +36,8 @@ enum {
kGoUpCmd = 'GoUp'
};
-BrowserDialog::BrowserDialog(NewGui *gui, const char *title)
- : Dialog(gui, 20, 10, 320 -2 * 20, 200 - 2 * 10),
+BrowserDialog::BrowserDialog(const char *title)
+ : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10),
_node(0), _nodeContent(0) {
_fileList = NULL;
diff --git a/gui/browser.h b/gui/browser.h
index 640570ad41..847a50a24f 100644
--- a/gui/browser.h
+++ b/gui/browser.h
@@ -35,7 +35,7 @@ class BrowserDialog : public Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
public:
- BrowserDialog(NewGui *gui, const char *title);
+ BrowserDialog(const char *title);
virtual ~BrowserDialog();
virtual void open();
diff --git a/gui/chooser.cpp b/gui/chooser.cpp
index ae88e1f007..b62dabdd70 100644
--- a/gui/chooser.cpp
+++ b/gui/chooser.cpp
@@ -27,8 +27,8 @@ enum {
kChooseCmd = 'Chos'
};
-ChooserDialog::ChooserDialog(NewGui *gui, const String title, const StringList& list)
- : Dialog(gui, 8, 24, 320 -2 * 8, 141) {
+ChooserDialog::ChooserDialog(const String title, const StringList& list)
+ : Dialog(8, 24, 320 -2 * 8, 141) {
// Headline
new StaticTextWidget(this, 10, 8, _w - 2 * 10, kLineHeight, title, kTextAlignCenter);
diff --git a/gui/chooser.h b/gui/chooser.h
index 81374bf3dc..3ba83b5cd4 100644
--- a/gui/chooser.h
+++ b/gui/chooser.h
@@ -36,7 +36,7 @@ class ChooserDialog : public Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
public:
- ChooserDialog(NewGui *gui, const String title, const StringList &list);
+ ChooserDialog(const String title, const StringList &list);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
diff --git a/gui/console.cpp b/gui/console.cpp
index c0fa4c0843..cc387dadbc 100644
--- a/gui/console.cpp
+++ b/gui/console.cpp
@@ -34,8 +34,8 @@
* to erase a single character, do scrolling etc.
* - a *lot* of others things, this code is in no way complete and heavily under progress
*/
-ConsoleDialog::ConsoleDialog(NewGui *gui, float widthPercent, float heightPercent)
- : Dialog(gui, 0, 0, 1, 1),
+ConsoleDialog::ConsoleDialog(float widthPercent, float heightPercent)
+ : Dialog(0, 0, 1, 1),
_widthPercent(widthPercent), _heightPercent(heightPercent) {
// Setup basic layout/dialog size
@@ -95,10 +95,10 @@ void ConsoleDialog::open() {
void ConsoleDialog::drawDialog() {
// Blend over the background
- _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor, 2);
+ g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor, 2);
// Draw a border
- _gui->hLine(_x, _y + _h - 1, _x + _w - 1, _gui->_color);
+ g_gui.hLine(_x, _y + _h - 1, _x + _w - 1, g_gui._color);
// Draw text
int start = _scrollLine - _linesPerPage + 1;
@@ -108,7 +108,7 @@ void ConsoleDialog::drawDialog() {
for (int column = 0; column < _lineWidth; column++) {
int l = (start + line) % _linesInBuffer;
byte c = _buffer[l * _lineWidth + column];
- _gui->drawChar(c, x, y, _gui->_textcolor);
+ g_gui.drawChar(c, x, y, g_gui._textcolor);
x += kCharWidth;
}
y += kLineHeight;
@@ -118,11 +118,11 @@ void ConsoleDialog::drawDialog() {
_scrollBar->draw();
// Finally blit it all to the screen
- _gui->addDirtyRect(_x, _y, _w, _h);
+ g_gui.addDirtyRect(_x, _y, _w, _h);
}
void ConsoleDialog::handleTickle() {
- uint32 time = _gui->get_time();
+ uint32 time = g_system->get_msecs();
if (_caretTime < time) {
_caretTime = time + kCaretBlinkTime;
if (_caretVisible) {
@@ -506,13 +506,13 @@ void ConsoleDialog::drawCaret(bool erase) {
char c = _buffer[getBufferPos()];
if (erase) {
- _gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_bgcolor);
- _gui->drawChar(c, x, y + 2, _gui->_textcolor);
+ g_gui.fillRect(x, y, kCharWidth, kLineHeight, g_gui._bgcolor);
+ g_gui.drawChar(c, x, y + 2, g_gui._textcolor);
} else {
- _gui->fillRect(x, y, kCharWidth, kLineHeight, _gui->_textcolor);
- _gui->drawChar(c, x, y + 2, _gui->_bgcolor);
+ g_gui.fillRect(x, y, kCharWidth, kLineHeight, g_gui._textcolor);
+ g_gui.drawChar(c, x, y + 2, g_gui._bgcolor);
}
- _gui->addDirtyRect(x, y, kCharWidth, kLineHeight);
+ g_gui.addDirtyRect(x, y, kCharWidth, kLineHeight);
_caretVisible = !erase;
}
diff --git a/gui/console.h b/gui/console.h
index b0f4a89970..ebe5fc0972 100644
--- a/gui/console.h
+++ b/gui/console.h
@@ -21,8 +21,8 @@
#ifndef CONSOLE_DIALOG_H
#define CONSOLE_DIALOG_H
-#include "dialog.h"
-#include "newgui.h"
+#include "gui/dialog.h"
+#include "gui/newgui.h"
#include <stdarg.h>
@@ -79,7 +79,7 @@ protected:
void reflowLayout();
public:
- ConsoleDialog(NewGui *gui, float widthPercent, float heightPercent);
+ ConsoleDialog(float widthPercent, float heightPercent);
void open();
void drawDialog();
diff --git a/gui/dialog.cpp b/gui/dialog.cpp
index 0c0e4a73b7..a0c3d41405 100644
--- a/gui/dialog.cpp
+++ b/gui/dialog.cpp
@@ -54,7 +54,7 @@ int Dialog::runModal() {
open();
// Start processing events
- _gui->runLoop();
+ g_gui.runLoop();
// Return the result code
return _result;
@@ -65,7 +65,7 @@ void Dialog::open() {
_result = 0;
_visible = true;
- _gui->openDialog(this);
+ g_gui.openDialog(this);
// Search for the first objects that wantsFocus() (if any) and give it the focus
while (w && !w->wantsFocus()) {
@@ -80,7 +80,7 @@ void Dialog::open() {
void Dialog::close() {
_visible = false;
- _gui->closeTopDialog();
+ g_gui.closeTopDialog();
if (_mouseWidget) {
_mouseWidget->handleMouseLeft(0);
@@ -97,7 +97,7 @@ void Dialog::releaseFocus() {
}
void Dialog::draw() {
- _gui->_needRedraw = true;
+ g_gui._needRedraw = true;
}
void Dialog::drawDialog() {
@@ -106,15 +106,15 @@ void Dialog::drawDialog() {
if (!isVisible())
return;
- _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor);
- _gui->box(_x, _y, _w, _h);
+ g_gui.blendRect(_x, _y, _w, _h, g_gui._bgcolor);
+ g_gui.box(_x, _y, _w, _h);
while (w) {
w->draw();
w = w->_next;
}
- _gui->addDirtyRect(_x, _y, _w, _h);
+ g_gui.addDirtyRect(_x, _y, _w, _h);
}
void Dialog::handleMouseDown(int x, int y, int button, int clickCount) {
@@ -276,6 +276,8 @@ Widget *Dialog::findWidget(int x, int y) {
break;
w = w->_next;
}
+ if (w)
+ w = w->findWidget(x - w->_x, y - w->_y);
return w;
}
diff --git a/gui/dialog.h b/gui/dialog.h
index 02fd13324a..f5a35b691a 100644
--- a/gui/dialog.h
+++ b/gui/dialog.h
@@ -37,7 +37,6 @@ class Dialog : public CommandReceiver {
friend class Widget;
friend class NewGui;
protected:
- NewGui *_gui;
int16 _x, _y;
uint16 _w, _h;
Widget *_firstWidget;
@@ -49,15 +48,14 @@ private:
int _result;
public:
- Dialog(NewGui *gui, int x, int y, int w, int h)
- : _gui(gui), _x(x), _y(y), _w(w), _h(h), _firstWidget(0),
+ Dialog(int x, int y, int w, int h)
+ : _x(x), _y(y), _w(w), _h(h), _firstWidget(0),
_mouseWidget(0), _focusedWidget(0), _visible(false) {
}
virtual ~Dialog();
virtual int runModal();
- NewGui *getGui() { return _gui; }
bool isVisible() const { return _visible; }
int16 getX() const { return _x; }
int16 getY() const { return _y; }
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index 48d3b64408..814624f4d7 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -78,7 +78,7 @@ class EditGameDialog : public Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
public:
- EditGameDialog(NewGui *gui, const String &domain, GameSettings target);
+ EditGameDialog(const String &domain, GameSettings target);
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
@@ -89,8 +89,8 @@ protected:
CheckboxWidget *_fullscreenCheckbox;
};
-EditGameDialog::EditGameDialog(NewGui *gui, const String &domain, GameSettings target)
- : Dialog(gui, 8, 50, 320 - 2 * 8, 200 - 2 * 40),
+EditGameDialog::EditGameDialog(const String &domain, GameSettings target)
+ : Dialog(8, 50, 320 - 2 * 8, 200 - 2 * 40),
_domain(domain) {
// Determine the description string
@@ -130,7 +130,7 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
String newDomain(_domainWidget->getLabel());
if (newDomain != _domain) {
if (newDomain.isEmpty() || ConfMan.hasGameDomain(newDomain)) {
- MessageDialog alert(_gui, "This game ID is already taken. Please choose another one.");
+ MessageDialog alert("This game ID is already taken. Please choose another one.");
alert.runModal();
return;
}
@@ -156,8 +156,8 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
* - ...
*/
-LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
- : Dialog(gui, 0, 0, 320, 200), _detector(detector) {
+LauncherDialog::LauncherDialog(GameDetector &detector)
+ : Dialog(0, 0, 320, 200), _detector(detector) {
// Show game name
new StaticTextWidget(this, 10, 8, 300, kLineHeight, gScummVMFullVersion, kTextAlignCenter);
@@ -194,7 +194,7 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector)
updateButtons();
// Create file browser dialog
- _browser = new BrowserDialog(_gui, "Select directory with game data");
+ _browser = new BrowserDialog("Select directory with game data");
}
LauncherDialog::~LauncherDialog() {
@@ -286,7 +286,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
int idx;
if (candidates.isEmpty()) {
// No game was found in the specified directory
- MessageDialog alert(_gui, "ScummVM could not find any game in the specified directory!");
+ MessageDialog alert("ScummVM could not find any game in the specified directory!");
alert.runModal();
idx = -1;
} else if (candidates.size() == 1) {
@@ -298,7 +298,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
for (idx = 0; idx < candidates.size(); idx++)
list.push_back(candidates[idx].description);
- ChooserDialog dialog(_gui, "Pick the game:", list);
+ ChooserDialog dialog("Pick the game:", list);
idx = dialog.runModal();
}
if (0 <= idx && idx < candidates.size()) {
@@ -323,7 +323,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
ConfMan.set("path", dir->path(), domain);
// Display edit dialog for the new entry
- EditGameDialog editDialog(_gui, domain, result);
+ EditGameDialog editDialog(domain, result);
if (editDialog.runModal()) {
// User pressed OK, so make changes permanent
@@ -363,7 +363,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
String gameId(ConfMan.get("gameid", _domains[item]));
if (gameId.isEmpty())
gameId = _domains[item];
- EditGameDialog editDialog(_gui, _domains[item], GameDetector::findGame(gameId));
+ EditGameDialog editDialog(_domains[item], GameDetector::findGame(gameId));
if (editDialog.runModal()) {
// User pressed OK, so make changes permanent
@@ -382,12 +382,12 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
// - music & graphics driver (but see also the comments on EditGameDialog
// for some techincal difficulties with this)
// - default volumes (sfx/master/music)
- GlobalOptionsDialog options(_gui, _detector);
+ GlobalOptionsDialog options(_detector);
options.runModal();
}
break;
case kAboutCmd: {
- AboutDialog about(_gui);
+ AboutDialog about;
about.runModal();
}
break;
diff --git a/gui/launcher.h b/gui/launcher.h
index f65c7cb1a4..d7f7b6dc81 100644
--- a/gui/launcher.h
+++ b/gui/launcher.h
@@ -33,7 +33,7 @@ class LauncherDialog : public Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
public:
- LauncherDialog(NewGui *gui, GameDetector &detector);
+ LauncherDialog(GameDetector &detector);
~LauncherDialog();
virtual void open();
diff --git a/gui/message.cpp b/gui/message.cpp
index 3df501225f..f82f0086c9 100644
--- a/gui/message.cpp
+++ b/gui/message.cpp
@@ -29,8 +29,8 @@ enum {
kCancelCmd = 'CNCL'
};
-MessageDialog::MessageDialog(NewGui *gui, const String &message, const char *defaultButton, const char *altButton)
- : Dialog(gui, 30, 20, 260, 124) {
+MessageDialog::MessageDialog(const String &message, const char *defaultButton, const char *altButton)
+ : Dialog(30, 20, 260, 124) {
// First, determine the size the dialog needs. For this we have to break
// down the string into lines, and taking the maximum of their widths.
// Using this, and accounting for the space the button(s) need, we can set
@@ -95,9 +95,10 @@ int MessageDialog::addLine(StringList &lines, const char *line, int size) {
int width = 0, maxWidth = 0;
const char *start = line, *pos = line, *end = start + size;
String tmp;
+ NewGui *gui = &g_gui;
while (pos < end) {
- int w = _gui->getCharWidth(*pos);
+ int w = gui->getCharWidth(*pos);
// Check if we exceed the maximum line width, if so, split the line.
// If possible we split at whitespaces.
@@ -114,7 +115,7 @@ int MessageDialog::addLine(StringList &lines, const char *line, int size) {
lines.push_back(tmp);
// Determine the width of the string, and adjust maxWidth accordingly
- width = _gui->getStringWidth(tmp);
+ width = gui->getStringWidth(tmp);
if (maxWidth < width)
maxWidth = width;
@@ -148,13 +149,13 @@ void MessageDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
}
}
-TimedMessageDialog::TimedMessageDialog(NewGui *gui, const Common::String &message, uint32 duration)
- : MessageDialog(gui, message, 0, 0) {
- _timer = _gui->get_time() + duration;
+TimedMessageDialog::TimedMessageDialog(const Common::String &message, uint32 duration)
+ : MessageDialog(message, 0, 0) {
+ _timer = g_system->get_msecs() + duration;
}
void TimedMessageDialog::handleTickle() {
MessageDialog::handleTickle();
- if (_gui->get_time() > _timer)
+ if (g_system->get_msecs() > _timer)
close();
}
diff --git a/gui/message.h b/gui/message.h
index 32b94573d2..d2e018ecb8 100644
--- a/gui/message.h
+++ b/gui/message.h
@@ -35,7 +35,7 @@ class MessageDialog : public Dialog {
typedef Common::String String;
typedef Common::StringList StringList;
public:
- MessageDialog(NewGui *gui, const Common::String &message, const char *defaultButton = "OK", const char *altButton = 0);
+ MessageDialog(const Common::String &message, const char *defaultButton = "OK", const char *altButton = 0);
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
@@ -48,7 +48,7 @@ protected:
*/
class TimedMessageDialog : public MessageDialog {
public:
- TimedMessageDialog(NewGui *gui, const Common::String &message, uint32 duration);
+ TimedMessageDialog(const Common::String &message, uint32 duration);
void handleTickle();
diff --git a/gui/newgui.cpp b/gui/newgui.cpp
index b6f7808b24..0a9b44074c 100644
--- a/gui/newgui.cpp
+++ b/gui/newgui.cpp
@@ -82,8 +82,11 @@ static byte guifont[] = {
#endif
// Constructor
-NewGui::NewGui(OSystem *system) : _system(system), _screen(0), _needRedraw(false),
+NewGui::NewGui() : _screen(0), _needRedraw(false),
_stateIsSaved(false), _cursorAnimateCounter(0), _cursorAnimateTimer(0) {
+
+ _system = OSystem::instance();
+
// Clear the cursor
memset(_cursor, 0xFF, sizeof(_cursor));
@@ -144,7 +147,7 @@ void NewGui::runLoop() {
_system->update_screen();
OSystem::Event event;
- uint32 time = get_time();
+ uint32 time = _system->get_msecs();
while (_system->poll_event(&event)) {
switch (event.event_code) {
@@ -504,7 +507,7 @@ void NewGui::drawBitmap(uint32 *bitmap, int x, int y, NewGuiColor color, int h)
// We could plug in a different cursor here if we like to.
//
void NewGui::animateCursor() {
- int time = get_time();
+ int time = _system->get_msecs();
if (time > _cursorAnimateTimer + kCursorAnimateDelay) {
const byte colors[4] = { 15, 15, 7, 8 };
const byte color = colors[_cursorAnimateCounter];
diff --git a/gui/newgui.h b/gui/newgui.h
index b610825b3d..7cec44d567 100644
--- a/gui/newgui.h
+++ b/gui/newgui.h
@@ -22,14 +22,18 @@
#define NEWGUI_H
#include "common/scummsys.h"
-#include "common/system.h" // For events
+#include "common/singleton.h"
#include "common/str.h"
+#include "common/system.h" // For events
class Dialog;
#define hLine(x, y, x2, color) line(x, y, x2, y, color);
#define vLine(x, y, y2, color) line(x, y, x, y2, color);
+#define g_gui (NewGui::instance())
+
+
// Height of a single text line
enum {
kLineHeight = 11
@@ -60,9 +64,11 @@ public:
};
// This class hopefully will replace the old Gui class completly one day
-class NewGui {
- friend class Dialog;
+class NewGui : public Common::Singleton<NewGui> {
typedef Common::String String;
+ friend class Dialog;
+ friend class Common::Singleton<NewGui>;
+ NewGui();
public:
// Main entry for the GUI: this will start an event loop that keeps running
@@ -71,8 +77,6 @@ public:
bool isActive() { return ! _dialogStack.empty(); }
- NewGui(OSystem *system);
-
protected:
OSystem *_system;
NewGuiColor *_screen;
@@ -122,9 +126,6 @@ public:
NewGuiColor _textcolor;
NewGuiColor _textcolorhi;
- // Misc util
- uint32 get_time() const { return _system->get_msecs(); }
-
// Drawing primitives
NewGuiColor *getBasePtr(int x, int y);
void box(int x, int y, int width, int height, bool inverted = false);
diff --git a/gui/options.cpp b/gui/options.cpp
index 819fcac070..4f8582af0a 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -61,8 +61,8 @@ enum {
kOKCmd = 'ok '
};
-GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui, GameDetector &detector)
- : Dialog(gui, 10, 15, 320 - 2 * 10, 200 - 2 * 15) {
+GlobalOptionsDialog::GlobalOptionsDialog(GameDetector &detector)
+ : Dialog(10, 15, 320 - 2 * 10, 200 - 2 * 15) {
// The GFX mode popup & a label
// TODO - add an API to query the list of available GFX modes, and to get/set the mode
new StaticTextWidget(this, 5, 10+1, 100, kLineHeight, "Graphics mode: ", kTextAlignRight);
@@ -156,7 +156,7 @@ GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui, GameDetector &detector)
addButton(_w - (kButtonWidth + 10), _h - 24, "OK", kOKCmd, 0);
// Create file browser dialog
- _browser = new BrowserDialog(_gui, "Select directory for savegames");
+ _browser = new BrowserDialog("Select directory for savegames");
}
GlobalOptionsDialog::~GlobalOptionsDialog() {
diff --git a/gui/options.h b/gui/options.h
index 71f3011c8c..e589563ab6 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -32,7 +32,7 @@ class PopUpWidget;
class GlobalOptionsDialog : public Dialog {
typedef Common::String String;
public:
- GlobalOptionsDialog(NewGui *gui, GameDetector &detector);
+ GlobalOptionsDialog(GameDetector &detector);
~GlobalOptionsDialog();
void open();
diff --git a/gui/widget.cpp b/gui/widget.cpp
index ea032b1bc5..f20dbf4624 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -23,7 +23,7 @@
#include "dialog.h"
#include "newgui.h"
-Widget::Widget (Dialog *boss, int x, int y, int w, int h)
+Widget::Widget(Dialog *boss, int x, int y, int w, int h)
: _type(0), _boss(boss), _x(x), _y(y), _w(w), _h(h),
_id(0), _flags(0), _hasFocus(false) {
// Insert into the widget list of the boss
@@ -32,7 +32,7 @@ Widget::Widget (Dialog *boss, int x, int y, int w, int h)
}
void Widget::draw() {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
if (!isVisible() || !_boss->isVisible())
return;
@@ -75,7 +75,7 @@ void Widget::draw() {
#pragma mark -
StaticTextWidget::StaticTextWidget(Dialog *boss, int x, int y, int w, int h, const String &text, int align)
- : Widget (boss, x, y, w, h), _align(align) {
+ : Widget(boss, x, y, w, h), _align(align) {
_type = kStaticTextWidget;
setLabel(text);
}
@@ -87,7 +87,7 @@ void StaticTextWidget::setValue(int value) {
}
void StaticTextWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y, _w, gui->_textcolor, _align);
}
@@ -106,7 +106,7 @@ void ButtonWidget::handleMouseUp(int x, int y, int button, int clickCount) {
}
void ButtonWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
gui->drawString(_label, _x, _y, _w,
!isEnabled() ? gui->_color :
hilite ? gui->_textcolorhi : gui->_textcolor, _align);
@@ -156,7 +156,7 @@ void CheckboxWidget::handleMouseUp(int x, int y, int button, int clickCount) {
}
void CheckboxWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
// Draw the box
gui->box(_x, _y, 14, 14);
@@ -213,7 +213,7 @@ void SliderWidget::handleMouseUp(int x, int y, int button, int clickCount) {
}
void SliderWidget::drawWidget(bool hilite) {
- NewGui *gui = _boss->getGui();
+ NewGui *gui = &g_gui;
// Draw the box
gui->box(_x, _y, _w, _h);
diff --git a/gui/widget.h b/gui/widget.h
index e938985ac5..de650dcfa4 100644
--- a/gui/widget.h
+++ b/gui/widget.h
@@ -87,7 +87,7 @@ public:
/* Widget */
class Widget {
-friend class Dialog;
+ friend class Dialog;
protected:
uint32 _type;
Dialog *_boss;
@@ -129,6 +129,8 @@ protected:
virtual void receivedFocusWidget() {}
virtual void lostFocusWidget() {}
+
+ virtual Widget *findWidget(int x, int y) { return this; }
};
/* StaticTextWidget */