diff options
author | Max Horn | 2006-08-04 15:48:37 +0000 |
---|---|---|
committer | Max Horn | 2006-08-04 15:48:37 +0000 |
commit | 0485f76c8d3e4220dd7977eac829bd85525f2da3 (patch) | |
tree | be6b831af891f1f5621f6ba52f8a25f8c2e2e2cc | |
parent | 1a10cacfb900c822ef5a53f455af7874675d37c5 (diff) | |
download | scummvm-rg350-0485f76c8d3e4220dd7977eac829bd85525f2da3.tar.gz scummvm-rg350-0485f76c8d3e4220dd7977eac829bd85525f2da3.tar.bz2 scummvm-rg350-0485f76c8d3e4220dd7977eac829bd85525f2da3.zip |
Changed GUI code to do 'lazy'/'just-in-time' reflowing, so that client code doesn't have to forward EVENT_SCREEN_CHANGED to us (this may initially cause some regressions, please report any induced crashes or oddities you observe to me)
svn-id: r23663
-rw-r--r-- | engines/scumm/dialogs.cpp | 54 | ||||
-rw-r--r-- | engines/scumm/dialogs.h | 7 | ||||
-rw-r--r-- | gui/EditTextWidget.cpp | 5 | ||||
-rw-r--r-- | gui/PopUpWidget.cpp | 2 | ||||
-rw-r--r-- | gui/console.cpp | 7 | ||||
-rw-r--r-- | gui/editable.cpp | 12 | ||||
-rw-r--r-- | gui/editable.h | 2 | ||||
-rw-r--r-- | gui/newgui.cpp | 14 |
8 files changed, 45 insertions, 58 deletions
diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp index 267822a565..d96f840373 100644 --- a/engines/scumm/dialogs.cpp +++ b/engines/scumm/dialogs.cpp @@ -261,8 +261,6 @@ SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, new GUI::ButtonWidget(this, "scummsaveload_cancel", "Cancel", kCloseCmd, 0); _chooseButton = new GUI::ButtonWidget(this, "scummsaveload_choose", buttonLabel, kChooseCmd, 0); _chooseButton->setEnabled(false); - - reflowLayout(); } SaveLoadChooser::~SaveLoadChooser() { @@ -512,20 +510,6 @@ void MainMenuDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat } } -void MainMenuDialog::reflowLayout() { - ScummDialog::reflowLayout(); - - _optionsDialog->reflowLayout(); - _aboutDialog->reflowLayout(); - - _saveDialog->reflowLayout(); - _loadDialog->reflowLayout(); - -#ifndef DISABLE_HELP - _helpDialog->reflowLayout(); -#endif -} - void MainMenuDialog::save() { int idx; _saveDialog->setList(generateSavegameList(_vm, true)); @@ -555,11 +539,6 @@ void MainMenuDialog::load() { } } -void MainMenuDialog::open() { - reflowLayout(); - Dialog::open(); -} - #pragma mark - enum { @@ -780,8 +759,6 @@ void InfoDialog::setInfoText(const String& message) { // Width and height are dummy _text = new StaticTextWidget(this, 4, 4, 10, 10, _message, kTextAlignCenter); - - reflowLayout(); } void InfoDialog::reflowLayout() { @@ -873,6 +850,22 @@ ValueDisplayDialog::ValueDisplayDialog(const Common::String& label, int minVal, : GUI::Dialog("scummDummyDialog"), _label(label), _min(minVal), _max(maxVal), _value(val), _incKey(incKey), _decKey(decKey) { assert(_min <= _value && _value <= _max); +} + +void ValueDisplayDialog::drawDialog() { + const int labelWidth = _w - 8 - _percentBarWidth; + g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x+_w, _y+_h), GUI::THEME_HINT_SAVE_BACKGROUND | GUI::THEME_HINT_FIRST_DRAW); + g_gui.theme()->drawText(Common::Rect(_x+4, _y+4, _x+labelWidth+4, _y+g_gui.theme()->getFontHeight()+4), _label); + g_gui.theme()->drawSlider(Common::Rect(_x+4+labelWidth, _y+4, _x+_w-4, _y+_h-4), _percentBarWidth * (_value - _min) / (_max - _min)); +} + +void ValueDisplayDialog::handleTickle() { + if (getMillis() > _timer) { + close(); + } +} + +void ValueDisplayDialog::reflowLayout() { const int screenW = g_system->getOverlayWidth(); const int screenH = g_system->getOverlayHeight(); @@ -882,7 +875,7 @@ ValueDisplayDialog::ValueDisplayDialog(const Common::String& label, int minVal, _percentBarWidth = kPercentBarWidth; } - int width = g_gui.getStringWidth(label) + 16 + _percentBarWidth; + int width = g_gui.getStringWidth(_label) + 16 + _percentBarWidth; int height = g_gui.getFontHeight() + 4 * 2; _x = (screenW - width) / 2; @@ -891,19 +884,6 @@ ValueDisplayDialog::ValueDisplayDialog(const Common::String& label, int minVal, _h = height; } -void ValueDisplayDialog::drawDialog() { - const int labelWidth = _w - 8 - _percentBarWidth; - g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x+_w, _y+_h), GUI::THEME_HINT_SAVE_BACKGROUND | GUI::THEME_HINT_FIRST_DRAW); - g_gui.theme()->drawText(Common::Rect(_x+4, _y+4, _x+labelWidth+4, _y+g_gui.theme()->getFontHeight()+4), _label); - g_gui.theme()->drawSlider(Common::Rect(_x+4+labelWidth, _y+4, _x+_w-4, _y+_h-4), _percentBarWidth * (_value - _min) / (_max - _min)); -} - -void ValueDisplayDialog::handleTickle() { - if (getMillis() > _timer) { - close(); - } -} - void ValueDisplayDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) { if (ascii == _incKey || ascii == _decKey) { if (ascii == _incKey && _value < _max) diff --git a/engines/scumm/dialogs.h b/engines/scumm/dialogs.h index 0be19815e8..772414d649 100644 --- a/engines/scumm/dialogs.h +++ b/engines/scumm/dialogs.h @@ -76,8 +76,7 @@ public: void setList(const StringList& list); int runModal(); - void reflowLayout(); - + virtual void reflowLayout(); }; class MainMenuDialog : public ScummDialog { @@ -85,7 +84,6 @@ public: MainMenuDialog(ScummEngine *scumm); ~MainMenuDialog(); virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data); - virtual void reflowLayout(); protected: ScummEngine *_vm; @@ -100,7 +98,6 @@ protected: void save(); void load(); - void open(); }; #ifndef DISABLE_HELP @@ -219,6 +216,8 @@ public: } virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers); + virtual void reflowLayout(); + protected: enum { kPercentBarWidth = 50, diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index 239c4a613a..7df68c1f82 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -32,7 +32,6 @@ EditTextWidget::EditTextWidget(GuiObject *boss, int x, int y, int w, int h, cons _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE; _type = kEditTextWidget; - reflowLayout(); setEditString(text); } @@ -42,7 +41,6 @@ EditTextWidget::EditTextWidget(GuiObject *boss, const String &name, const String _type = kEditTextWidget; _hints |= THEME_HINT_USE_SHADOW; - reflowLayout(); setEditString(text); } @@ -52,11 +50,12 @@ void EditTextWidget::setEditString(const String &str) { } void EditTextWidget::reflowLayout() { - EditableWidget::reflowLayout(); _leftPadding = g_gui.evaluator()->getVar("EditTextWidget.leftPadding", 0); _rightPadding = g_gui.evaluator()->getVar("EditTextWidget.rightPadding", 0); _font = (Theme::FontStyle)g_gui.evaluator()->getVar("EditTextWidget.font", Theme::kFontStyleNormal); + + EditableWidget::reflowLayout(); } diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp index f7cd8c22e8..14f998d6f8 100644 --- a/gui/PopUpWidget.cpp +++ b/gui/PopUpWidget.cpp @@ -344,8 +344,6 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) { PopUpWidget::PopUpWidget(GuiObject *boss, const String &name, const String &label, uint labelWidth) : Widget(boss, name), CommandSender(boss), _label(label), _labelWidth(labelWidth) { - reflowLayout(); - _flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS; setHints(THEME_HINT_SAVE_BACKGROUND); _type = kPopUpWidget; diff --git a/gui/console.cpp b/gui/console.cpp index a8ad636761..ad0c265214 100644 --- a/gui/console.cpp +++ b/gui/console.cpp @@ -157,13 +157,6 @@ void ConsoleDialog::open() { _slideTime = g_system->getMillis(); _slideMode = kDownSlideMode; - // The screen may have changed since the console was created. We have - // to make sure things are properly adjusted, or we may get garbage in - // the console, or even outright crashes. This means _scrollLine is not - // preserved, but that's a tiny sacrifice. - - reflowLayout(); - Dialog::open(); if (_promptStartPos == -1) { print(PROMPT); diff --git a/gui/editable.cpp b/gui/editable.cpp index 67691861bf..10f8c125e8 100644 --- a/gui/editable.cpp +++ b/gui/editable.cpp @@ -50,15 +50,19 @@ void EditableWidget::init() { EditableWidget::~EditableWidget() { } +void EditableWidget::reflowLayout() { + Widget::reflowLayout(); + + _editScrollOffset = g_gui.getStringWidth(_editString, _font) - getEditRect().width(); + if (_editScrollOffset < 0) + _editScrollOffset = 0; +} + void EditableWidget::setEditString(const String &str) { // TODO: We probably should filter the input string here, // e.g. using tryInsertChar. _editString = str; _caretPos = _editString.size(); - - _editScrollOffset = g_gui.getStringWidth(_editString, _font) - getEditRect().width(); - if (_editScrollOffset < 0) - _editScrollOffset = 0; } bool EditableWidget::tryInsertChar(byte c, int pos) { diff --git a/gui/editable.h b/gui/editable.h index 4c6def3731..520c4cf689 100644 --- a/gui/editable.h +++ b/gui/editable.h @@ -62,6 +62,8 @@ public: virtual void handleTickle(); virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers); + virtual void reflowLayout(); + protected: virtual void startEditMode() = 0; virtual void endEditMode() = 0; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index a4904c5b8c..7cd0708597 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -56,7 +56,6 @@ enum { // HACK. FIXME. This doesn't belong here. But otherwise it creates compilation problems GuiObject::GuiObject(const Common::String &name) : _firstWidget(0) { _name = name; - reflowLayout(); } void GuiObject::reflowLayout() { @@ -318,6 +317,19 @@ void NewGui::restoreState() { void NewGui::openDialog(Dialog *dialog) { _dialogStack.push(dialog); _needRedraw = true; + + // TODO: No need to always reflow everything. Rather, we should + // check for the value of OSystem::getScreenChangeID() and + // only do a full update when that changed... + if (true) { + // reinit the whole theme + _theme->refresh(); + // refresh all dialogs + for (int i = 0; i < _dialogStack.size(); ++i) { + _dialogStack[i]->reflowLayout(); + } + } else + dialog->reflowLayout(); } void NewGui::closeTopDialog() { |