[Scummvm-cvs-logs] SF.net SVN: scummvm: [23663] scummvm/trunk/gui

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Aug 4 17:48:47 CEST 2006


Revision: 23663
Author:   fingolfin
Date:     2006-08-04 08:48:37 -0700 (Fri, 04 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23663&view=rev

Log Message:
-----------
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)

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/dialogs.cpp
    scummvm/trunk/engines/scumm/dialogs.h
    scummvm/trunk/gui/EditTextWidget.cpp
    scummvm/trunk/gui/PopUpWidget.cpp
    scummvm/trunk/gui/console.cpp
    scummvm/trunk/gui/editable.cpp
    scummvm/trunk/gui/editable.h
    scummvm/trunk/gui/newgui.cpp
Modified: scummvm/trunk/engines/scumm/dialogs.cpp
===================================================================
--- scummvm/trunk/engines/scumm/dialogs.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/engines/scumm/dialogs.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -261,8 +261,6 @@
 	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::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::open() {
-	reflowLayout();
-	Dialog::open();
-}
-
 #pragma mark -
 
 enum {
@@ -780,8 +759,6 @@
 
 	// Width and height are dummy
 	_text = new StaticTextWidget(this, 4, 4, 10, 10, _message, kTextAlignCenter);
-
-	reflowLayout();
 }
 
 void InfoDialog::reflowLayout() {
@@ -873,6 +850,22 @@
 	: 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 @@
 		_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 @@
 	_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)

Modified: scummvm/trunk/engines/scumm/dialogs.h
===================================================================
--- scummvm/trunk/engines/scumm/dialogs.h	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/engines/scumm/dialogs.h	2006-08-04 15:48:37 UTC (rev 23663)
@@ -76,8 +76,7 @@
 	void setList(const StringList& list);
 	int runModal();
 
-	void reflowLayout();
-	
+	virtual void reflowLayout();
 };
 
 class MainMenuDialog : public ScummDialog {
@@ -85,7 +84,6 @@
 	MainMenuDialog(ScummEngine *scumm);
 	~MainMenuDialog();
 	virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
-	virtual void reflowLayout();
 
 protected:
 	ScummEngine		*_vm;
@@ -100,7 +98,6 @@
 
 	void save();
 	void load();
-	void open();
 };
 
 #ifndef DISABLE_HELP
@@ -219,6 +216,8 @@
 	}
 	virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
 
+	virtual void reflowLayout();
+
 protected:
 	enum {
 		kPercentBarWidth = 50,

Modified: scummvm/trunk/gui/EditTextWidget.cpp
===================================================================
--- scummvm/trunk/gui/EditTextWidget.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/EditTextWidget.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -32,7 +32,6 @@
 	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE;
 	_type = kEditTextWidget;
 
-	reflowLayout();
 	setEditString(text);
 }
 
@@ -42,7 +41,6 @@
 	_type = kEditTextWidget;
 	_hints |= THEME_HINT_USE_SHADOW;
 
-	reflowLayout();
 	setEditString(text);
 }
 
@@ -52,11 +50,12 @@
 }
 
 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();
 }
 
 

Modified: scummvm/trunk/gui/PopUpWidget.cpp
===================================================================
--- scummvm/trunk/gui/PopUpWidget.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/PopUpWidget.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -344,8 +344,6 @@
 
 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;

Modified: scummvm/trunk/gui/console.cpp
===================================================================
--- scummvm/trunk/gui/console.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/console.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -157,13 +157,6 @@
 	_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);

Modified: scummvm/trunk/gui/editable.cpp
===================================================================
--- scummvm/trunk/gui/editable.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/editable.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -50,15 +50,19 @@
 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) {

Modified: scummvm/trunk/gui/editable.h
===================================================================
--- scummvm/trunk/gui/editable.h	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/editable.h	2006-08-04 15:48:37 UTC (rev 23663)
@@ -62,6 +62,8 @@
 	virtual void handleTickle();
 	virtual bool handleKeyDown(uint16 ascii, int keycode, int modifiers);
 
+	virtual void reflowLayout();
+
 protected:
 	virtual void startEditMode() = 0;
 	virtual void endEditMode() = 0;

Modified: scummvm/trunk/gui/newgui.cpp
===================================================================
--- scummvm/trunk/gui/newgui.cpp	2006-08-04 13:55:53 UTC (rev 23662)
+++ scummvm/trunk/gui/newgui.cpp	2006-08-04 15:48:37 UTC (rev 23663)
@@ -56,7 +56,6 @@
 // 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::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() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list