[Scummvm-cvs-logs] CVS: scummvm/gui PopUpWidget.cpp,1.35,1.36 PopUpWidget.h,1.13,1.14 dialog.cpp,1.56,1.57 dialog.h,1.37,1.38 launcher.cpp,1.122,1.123 options.cpp,1.87,1.88

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Thu May 19 10:06:14 CEST 2005


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv695

Modified Files:
	PopUpWidget.cpp PopUpWidget.h dialog.cpp dialog.h launcher.cpp 
	options.cpp 
Log Message:
Big version of the popup widget. It could use a bit more polish, though...


Index: PopUpWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/PopUpWidget.cpp,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- PopUpWidget.cpp	12 Mar 2005 15:29:16 -0000	1.35
+++ PopUpWidget.cpp	19 May 2005 17:03:30 -0000	1.36
@@ -19,6 +19,7 @@
  */
 
 #include "stdafx.h"
+#include "common/system.h"
 #include "gui/dialog.h"
 #include "gui/newgui.h"
 #include "gui/PopUpWidget.h"
@@ -26,20 +27,6 @@
 
 namespace GUI {
 
-#define UP_DOWN_BOX_HEIGHT	10
-
-// Little up/down arrow
-static uint32 up_down_arrows[8] = {
-	0x00000000,
-	0x00001000,
-	0x00011100,
-	0x00111110,
-	0x00000000,
-	0x00111110,
-	0x00011100,
-	0x00001000,
-};
-
 //
 // PopUpDialog
 //
@@ -47,12 +34,14 @@
 class PopUpDialog : public Dialog {
 protected:
 	PopUpWidget	*_popUpBoss;
+	const Graphics::Font	*_font;
+	int		_lineHeight;
 	int			_clickX, _clickY;
 	byte		*_buffer;
 	int			_selection;
 	uint32		_openTime;
 public:
-	PopUpDialog(PopUpWidget *boss, int clickX, int clickY);
+	PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws = kDefaultWidgetSize);
 	
 	void drawDialog();
 
@@ -72,28 +61,44 @@
 	void moveDown();
 };
 
-PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY)
+PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws)
 	: Dialog(0, 0, 16, 16),
 	_popUpBoss(boss) {
+	switch (ws) {
+	case kNormalWidgetSize:
+		_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+		break;
+	case kBigWidgetSize:
+		_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+		break;
+	case kDefaultWidgetSize:
+		_font = &g_gui.getFont();
+		break;
+	}
+
+	_lineHeight = _font->getFontHeight() + 2;
+
 	// Copy the selection index
 	_selection = _popUpBoss->_selectedItem;
 
 	// Calculate real popup dimensions
 	_x = _popUpBoss->getAbsX() + _popUpBoss->_labelWidth;
-	_y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * kLineHeight;
-	_h = _popUpBoss->_entries.size() * kLineHeight + 2;
-	_w = _popUpBoss->_w - 10 - _popUpBoss->_labelWidth;
+	_y = _popUpBoss->getAbsY() - _popUpBoss->_selectedItem * _lineHeight;
+	_h = _popUpBoss->_entries.size() * _lineHeight + 2;
+	_w = _popUpBoss->_w - _lineHeight + 2 - _popUpBoss->_labelWidth;
 	
 	// Perform clipping / switch to scrolling mode if we don't fit on the screen
-	// FIXME - hard coded screen height 200. We really need an API in OSystem to query the
-	// screen height, and also OSystem should send out notification messages when the screen
+	// FIXME - OSystem should send out notification messages when the screen
 	// resolution changes... we could generalize CommandReceiver and CommandSender.
-	if (_h >= 200)
-		_h = 199;
+
+	const int screenH = g_system->getOverlayHeight();
+
+	if (_h >= screenH)
+		_h = screenH - 1;
 	if (_y < 0)
 		_y = 0;
-	else if (_y + _h >= 200)
-		_y = 199 - _h;
+	else if (_y + _h >= screenH)
+		_y = screenH - 1 - _h;
 
 	// TODO - implement scrolling if we had to move the menu, or if there are too many entries
 
@@ -187,7 +192,7 @@
 
 int PopUpDialog::findItem(int x, int y) const {
 	if (x >= 0 && x < _w && y >= 0 && y < _h) {
-		return (y - 2) / kLineHeight;
+		return (y - 2) / _lineHeight;
 	}
 	return -1;
 }
@@ -247,19 +252,19 @@
 	// Draw one entry of the popup menu, including selection
 	assert(entry >= 0);
 	int x = _x + 1;
-	int y = _y + 1 + kLineHeight * entry;
+	int y = _y + 1 + _lineHeight * entry;
 	int w = _w - 2;
 	Common::String &name = _popUpBoss->_entries[entry].name;
 
-	g_gui.fillRect(x, y, w, kLineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);
+	g_gui.fillRect(x, y, w, _lineHeight, hilite ? g_gui._textcolorhi : g_gui._bgcolor);
 	if (name.size() == 0) {
 		// Draw a separator
-		g_gui.hLine(x - 1, y + kLineHeight / 2, x + w, g_gui._shadowcolor);
-		g_gui.hLine(x, y + 1 + kLineHeight / 2, x + w, g_gui._color);
+		g_gui.hLine(x - 1, y + _lineHeight / 2, x + w, g_gui._shadowcolor);
+		g_gui.hLine(x, y + 1 + _lineHeight / 2, x + w, g_gui._color);
 	} else {
-		g_gui.drawString(name, x + 1, y + 2, w - 2, hilite ? g_gui._bgcolor : g_gui._textcolor);
+		g_gui.drawString(_font, name, x + 1, y + 2, w - 2, hilite ? g_gui._bgcolor : g_gui._textcolor);
 	}
-	g_gui.addDirtyRect(x, y, w, kLineHeight);
+	g_gui.addDirtyRect(x, y, w, _lineHeight);
 }
 
 
@@ -269,21 +274,35 @@
 // PopUpWidget
 //
 
-PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth)
-	: Widget(boss, x, y - 1, w, h + 2), CommandSender(boss), _label(label), _labelWidth(labelWidth) {
+PopUpWidget::PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth, WidgetSize ws)
+	: Widget(boss, x, y - 1, w, h + 2), CommandSender(boss), _ws(ws), _label(label), _labelWidth(labelWidth) {
 	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
 	_type = kPopUpWidget;
 
 	_selectedItem = -1;
 
+	switch (_ws) {
+	case kNormalWidgetSize:
+		_font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+		break;
+	case kBigWidgetSize:
+		_font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+		break;
+	case kDefaultWidgetSize:
+		_font = &g_gui.getFont();
+		break;
+	}
+
+	_lineHeight = _font->getFontHeight() + 2;
+
 	if (!_label.isEmpty() && _labelWidth == 0)
-		_labelWidth = g_gui.getStringWidth(_label);
+		_labelWidth = _font->getStringWidth(_label);
 }
 
 void PopUpWidget::handleMouseDown(int x, int y, int button, int clickCount) {
 
 	if (isEnabled()) {
-		PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY());
+		PopUpDialog popupDialog(this, x + getAbsX(), y + getAbsY(), _ws);
 		int newSel = popupDialog.runModal();
 		if (newSel != -1 && _selectedItem != newSel) {
 			_selectedItem = newSel;
@@ -332,7 +351,7 @@
 
 	// Draw the label, if any
 	if (_labelWidth > 0)
-		gui->drawString(_label, _x, _y + 3, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
+		gui->drawString(_font, _label, _x, _y + 3, _labelWidth, isEnabled() ? gui->_textcolor : gui->_color, kTextAlignRight);
 
 	// Draw a thin frame around us.
 	gui->hLine(x, _y, x + w - 1, gui->_color);
@@ -340,13 +359,26 @@
 	gui->vLine(x, _y, _y+_h-1, gui->_color);
 	gui->vLine(x + w - 1, _y, _y +_h - 1, gui->_shadowcolor);
 
-	// Draw an arrow pointing down at the right end to signal this is a dropdown/popup
-	gui->drawBitmap(up_down_arrows, x+w - 10, _y+2, !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor);
+	// Draw a set of arrows at the right end to signal this is a dropdown/popup
+	Common::Point p0, p1;
+
+	p0 = Common::Point(x + w + 1 - _h / 2, _y + 4);
+	p1 = Common::Point(x + w + 1 - _h / 2, _y + _h - 4);
+
+	Graphics::Surface &surf = g_gui.getScreen();
+	OverlayColor color = !isEnabled() ? gui->_color : hilite ? gui->_textcolorhi : gui->_textcolor;
+
+	// Evil HACK to draw filled triangles
+	// FIXME: The "big" version is pretty ugly.
+	for (; p1.y - p0.y > 1; p0.y++, p0.x--, p1.y--, p1.x++) {
+		surf.drawLine(p0.x, p0.y, p1.x, p0.y, color);
+		surf.drawLine(p0.x, p1.y, p1.x, p1.y, color);
+	}
 
 	// Draw the selected entry, if any
 	if (_selectedItem >= 0) {
-		TextAlignment align = (gui->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
-		gui->drawString(_entries[_selectedItem].name, x+2, _y+3, w-6, !isEnabled() ? gui->_color : gui->_textcolor, align);
+		TextAlignment align = (_font->getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
+		gui->drawString(_font, _entries[_selectedItem].name, x+2, _y+3, w-6, !isEnabled() ? gui->_color : gui->_textcolor, align);
 	}
 }
 

Index: PopUpWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/PopUpWidget.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- PopUpWidget.h	1 Jan 2005 16:09:06 -0000	1.13
+++ PopUpWidget.h	19 May 2005 17:03:30 -0000	1.14
@@ -48,14 +48,17 @@
 	};
 	typedef Common::Array<Entry> EntryList;
 protected:
+	const WidgetSize		_ws;
+	const Graphics::Font	*_font;
 	EntryList		_entries;
+	int				_lineHeight;
 	int				_selectedItem;
 
 	String			_label;
 	uint			_labelWidth;
 
 public:
-	PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth = 0);
+	PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
 
 	void handleMouseDown(int x, int y, int button, int clickCount);
 

Index: dialog.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- dialog.cpp	18 May 2005 15:58:38 -0000	1.56
+++ dialog.cpp	19 May 2005 17:03:30 -0000	1.57
@@ -24,6 +24,7 @@
 #include "gui/newgui.h"
 #include "gui/dialog.h"
 #include "gui/widget.h"
+#include "gui/PopUpWidget.h"
 
 #include "common/system.h"
 
@@ -341,6 +342,22 @@
 	return new SliderWidget(boss, x, y, w, h, cmd);
 }
 
+PopUpWidget *Dialog::addPopUp(int x, int y, int w, const Common::String &label, uint labelWidth, WidgetSize ws) {
+	return addPopUp(this, x, y, w, label, labelWidth, ws);
+}
+
+PopUpWidget *Dialog::addPopUp(GuiObject *boss, int x, int y, int w, const Common::String &label, uint labelWidth, WidgetSize ws) {
+	const Graphics::Font *font;
+
+	if (ws == kBigWidgetSize) {
+		font = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
+	} else {
+		font = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
+	}
+
+	return new PopUpWidget(boss, x, y, w, font->getFontHeight() + 2, label, labelWidth, ws);
+}
+
 uint32 GuiObject::getMillis() {
 	return g_system->getMillis();
 }

Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- dialog.h	18 May 2005 15:58:39 -0000	1.37
+++ dialog.h	19 May 2005 17:03:30 -0000	1.38
@@ -30,7 +30,7 @@
 namespace GUI {
 
 class NewGui;
-class ButtonWidget;
+class PopUpWidget;
 
 // Some "common" commands sent to handleCommand()
 enum {
@@ -96,6 +96,9 @@
 	SliderWidget *addSlider(GuiObject *boss, int x, int y, uint32 cmd, WidgetSize ws = kDefaultWidgetSize);
 	SliderWidget *addSlider(int x, int y, uint32 cmd, WidgetSize ws = kDefaultWidgetSize);
 
+	PopUpWidget *addPopUp(GuiObject *boss, int x, int y, int w, const Common::String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
+	PopUpWidget *addPopUp(int x, int y, int w, const Common::String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
+
 	void setResult(int result) { _result = result; }
 	int getResult() const { return _result; }
 };

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- launcher.cpp	19 May 2005 13:10:57 -0000	1.122
+++ launcher.cpp	19 May 2005 17:03:31 -0000	1.123
@@ -147,22 +147,24 @@
 	GUI::WidgetSize ws;
 	int buttonHeight;
 	int buttonWidth;
+	int labelWidth;
 
 	if (screenW >= 400 && screenH >= 300) {
 		ws = GUI::kBigWidgetSize;
 		_h = screenH - 2 * 40;	// TODO/FIXME
 		buttonHeight = kBigButtonHeight;
 		buttonWidth = kBigButtonWidth;
+		labelWidth = 90;
 	} else {
 		ws = GUI::kNormalWidgetSize;
 		_h = screenH - 2 * 30;	// TODO/FIXME
 		buttonHeight = kButtonHeight;
 		buttonWidth = kButtonWidth;
+		labelWidth = 60;
 	}
 	
 	const int x = 5;
 	const int w = _w - 15;
-	const int labelWidth = 65;
 	const int vBorder = 5;	// Tab border
 	int yoffset;
 
@@ -197,8 +199,8 @@
 	yoffset += 16;
 
 	// Language popup
-	_langPopUp = new PopUpWidget(tab, x, yoffset, w, kLineHeight, "Language: ", labelWidth);
-	yoffset += 16;
+	_langPopUp = addPopUp(tab, x, yoffset, w, "Language: ", labelWidth, ws);
+	yoffset += _langPopUp->getHeight() + 4;
 	_langPopUp->appendEntry("<default>");
 	_langPopUp->appendEntry("");
 	const Common::LanguageDescription *l = Common::g_languages;
@@ -207,8 +209,8 @@
 	}
 
 	// Platform popup
-	_platformPopUp = new PopUpWidget(tab, x, yoffset, w, kLineHeight, "Platform: ", labelWidth);
-	yoffset += 16;
+	_platformPopUp = addPopUp(tab, x, yoffset, w, "Platform: ", labelWidth, ws);
+	yoffset += _platformPopUp->getHeight() + 4;
 	_platformPopUp->appendEntry("<default>");
 	_platformPopUp->appendEntry("");
 	const Common::PlatformDescription *p = Common::g_platforms;

Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- options.cpp	19 May 2005 13:10:57 -0000	1.87
+++ options.cpp	19 May 2005 17:03:31 -0000	1.88
@@ -313,9 +313,17 @@
 	const int w = _w - 2 * 10;
 	const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
 
+	int labelWidth;
+
+	if (ws == kBigWidgetSize) {
+		labelWidth = 150;
+	} else {
+		labelWidth = 100;
+	}
+
 	// The GFX mode popup
-	_gfxPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Graphics mode: ", 100);
-	yoffset += 16;
+	_gfxPopUp = addPopUp(boss, x-5, yoffset, w+5, "Graphics mode: ", labelWidth, ws);
+	yoffset += _gfxPopUp->getHeight() + 4;
 
 	_gfxPopUp->appendEntry("<default>");
 	_gfxPopUp->appendEntry("");
@@ -325,8 +333,8 @@
 	}
 
 	// RenderMode popup
-	_renderModePopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Render mode: ", 100);
-	yoffset += 16;
+	_renderModePopUp = addPopUp(boss, x-5, yoffset, w+5, "Render mode: ", labelWidth, ws);
+	yoffset += _renderModePopUp->getHeight() + 4;
 	_renderModePopUp->appendEntry("<default>", Common::kRenderDefault);
 	_renderModePopUp->appendEntry("");
 	const Common::RenderModeDescription *rm = Common::g_renderModes;
@@ -357,9 +365,17 @@
 	const int x = 10;
 	const int w = _w - 20;
 
+	int labelWidth;
+
+	if (ws == kBigWidgetSize) {
+		labelWidth = 150;
+	} else {
+		labelWidth = 100;
+	}
+
 	// The MIDI mode popup & a label
-	_midiPopUp = new PopUpWidget(boss, x-5, yoffset, w+5, kLineHeight, "Music driver: ", 100);
-	yoffset += 18;
+	_midiPopUp = addPopUp(boss, x-5, yoffset, w+5, "Music driver: ", labelWidth, ws);
+	yoffset += _midiPopUp->getHeight() + 4;
 	
 	// Populate it
 	const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();





More information about the Scummvm-git-logs mailing list