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

sev at users.sourceforge.net sev at users.sourceforge.net
Sun Apr 16 03:25:08 CEST 2006


Revision: 21934
Author:   sev
Date:     2006-04-16 03:23:36 -0700 (Sun, 16 Apr 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=21934&view=rev

Log Message:
-----------
- Implemented text padding in ListWidget and PopUpWidget. Right padding does not work yet.
- Implemented highlisght padding in ListWidget
- Eval::getVar() method with default value
- Removed unused constructors for ListWidget and PoUpWidget
- cleanup
- bumped theme version

Modified Paths:
--------------
    scummvm/trunk/gui/ListWidget.cpp
    scummvm/trunk/gui/ListWidget.h
    scummvm/trunk/gui/PopUpWidget.cpp
    scummvm/trunk/gui/PopUpWidget.h
    scummvm/trunk/gui/ThemeNew.cpp
    scummvm/trunk/gui/eval.h
    scummvm/trunk/gui/theme-config.cpp
    scummvm/trunk/gui/themes/modern.ini
Modified: scummvm/trunk/gui/ListWidget.cpp
===================================================================
--- scummvm/trunk/gui/ListWidget.cpp	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/ListWidget.cpp	2006-04-16 10:23:36 UTC (rev 21934)
@@ -29,19 +29,19 @@
 
 namespace GUI {
 
-ListWidget::ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws)
-	: EditableWidget(boss, x, y, w, h, ws), CommandSender(boss) {
-	init(boss, w, ws);
-}
-
 ListWidget::ListWidget(GuiObject *boss, String name)
 	: EditableWidget(boss, name), CommandSender(boss) {
 	int w = g_gui.evaluator()->getVar(name + ".w");
 
-	init(boss, w, g_gui.getWidgetSize());
-}
+	WidgetSize ws = g_gui.getWidgetSize();
 
-void ListWidget::init(GuiObject *boss, int w, WidgetSize ws) {
+	_leftPadding = g_gui.evaluator()->getVar("ListWidget.leftPadding", 0);
+	_rightPadding = g_gui.evaluator()->getVar("ListWidget.rightPadding", 0);
+	_topPadding = g_gui.evaluator()->getVar("ListWidget.topPadding", 0);
+	_bottomPadding = g_gui.evaluator()->getVar("ListWidget.bottomPadding", 0);
+	_hlLeftPadding = g_gui.evaluator()->getVar("ListWidget.hlLeftPadding", 0);
+	_hlRightPadding = g_gui.evaluator()->getVar("ListWidget.hlRightPadding", 0);
+
 	if (ws == kBigWidgetSize) {
 		_w = w - kBigScrollBarWidth;
 	} else {
@@ -53,7 +53,7 @@
 	_type = kListWidget;
 	_editMode = false;
 	_numberingMode = kListNumberingOne;
-	_entriesPerPage = (_h - 2) / kLineHeight;
+	_entriesPerPage = (_h - _topPadding - _bottomPadding) / kLineHeight;
 	_currentPos = 0;
 	_selectedItem = -1;
 	_scrollBar = new ScrollBarWidget(boss, _x + _w, _y, (ws == kBigWidgetSize ? kBigScrollBarWidth : kNormalScrollBarWidth), _h);
@@ -171,7 +171,7 @@
 
 
 int ListWidget::findItem(int x, int y) const {
-	return (y - 1) / kLineHeight + _currentPos;
+	return (y - _topPadding) / kLineHeight + _currentPos;
 }
 
 static int matchingCharsIgnoringCase(const char *x, const char *y, bool &stop) {
@@ -324,7 +324,7 @@
 
 	// Draw the list items
 	for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) {
-		const int y = _y + 2 + kLineHeight * i;
+		const int y = _y + _topPadding + kLineHeight * i;
 		const int fontHeight = kLineHeight;
 		bool inverted = false;
 
@@ -337,13 +337,15 @@
 		}
 
 		Common::Rect r(getEditRect());
+		int pad = _leftPadding;
 
 		// If in numbering mode, we first print a number prefix
 		if (_numberingMode != kListNumberingOff) {
 			char temp[10];
 			sprintf(temp, "%2d. ", (pos + _numberingMode));
 			buffer = temp;
-			g_gui.theme()->drawText(Common::Rect(_x + 2, y, _x + r.left, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted);
+			g_gui.theme()->drawText(Common::Rect(_x, y, _x + r.left + _leftPadding, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, _leftPadding);
+			pad = 0;
 		}
 
 		int width;
@@ -351,20 +353,20 @@
 		if (_selectedItem == pos && _editMode) {
 			buffer = _editString;
 			adjustOffset();
-			width = _w - r.left - 2;
-			g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted);
+			width = _w - r.left - _hlRightPadding - _leftPadding - _rightPadding;
+			g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, pad);
 		} else {
 			int maxWidth = _textWidth[i];
 			buffer = _list[pos];
 			if (_selectedItem != pos) {
-				width = g_gui.getStringWidth(buffer);
-				if (width > _w - r.left - 2)
-					width = _w - r.left - 2;
+				width = g_gui.getStringWidth(buffer) + pad;
+				if (width > _w - r.left)
+					width = _w - r.left;
 			} else
-				width = _w - r.left - 2;
+				width = _w - r.left - _hlRightPadding;
 			if (width > maxWidth)
 				maxWidth = width;
-			g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + maxWidth, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted);
+			g_gui.theme()->drawText(Common::Rect(_x + r.left, y, _x + r.left + maxWidth, y + fontHeight - 1), buffer, Theme::kStateEnabled, Theme::kTextAlignLeft, inverted, pad);
 		}
 
 		_textWidth[i] = width;
@@ -372,7 +374,7 @@
 }
 
 Common::Rect ListWidget::getEditRect() const {
-	Common::Rect r(2, 1, _w - 2 , kLineHeight);
+	Common::Rect r(_hlLeftPadding, 1, _w - _hlLeftPadding - _hlRightPadding, kLineHeight);
 	const int offset = (_selectedItem - _currentPos) * kLineHeight;
 	r.top += offset;
 	r.bottom += offset;
@@ -381,7 +383,7 @@
 		char temp[10];
 		// FIXME: Assumes that all digits have the same width.
 		sprintf(temp, "%2d. ", (_list.size() - 1 + _numberingMode));
-		r.left += g_gui.getStringWidth(temp);
+		r.left += g_gui.getStringWidth(temp) + _leftPadding;
 	}
 
 	return r;

Modified: scummvm/trunk/gui/ListWidget.h
===================================================================
--- scummvm/trunk/gui/ListWidget.h	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/ListWidget.h	2006-04-16 10:23:36 UTC (rev 21934)
@@ -61,13 +61,17 @@
 	String			_quickSelectStr;
 	uint32			_quickSelectTime;
 
+	int				_hlLeftPadding;
+	int				_hlRightPadding;
+	int				_leftPadding;
+	int				_rightPadding;
+	int				_topPadding;
+	int				_bottomPadding;
+
 public:
-	ListWidget(GuiObject *boss, int x, int y, int w, int h, WidgetSize ws = kDefaultWidgetSize);
 	ListWidget(GuiObject *boss, String name);
 	virtual ~ListWidget();
 
-	void init(GuiObject *boss, int w, WidgetSize ws);
-
 	void setList(const StringList& list);
 	const StringList& getList()	const			{ return _list; }
 	int getSelected() const						{ return _selectedItem; }

Modified: scummvm/trunk/gui/PopUpWidget.cpp
===================================================================
--- scummvm/trunk/gui/PopUpWidget.cpp	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/PopUpWidget.cpp	2006-04-16 10:23:36 UTC (rev 21934)
@@ -22,6 +22,7 @@
 #include "common/stdafx.h"
 #include "common/system.h"
 #include "gui/dialog.h"
+#include "gui/eval.h"
 #include "gui/newgui.h"
 #include "gui/PopUpWidget.h"
 #include "base/engine.h"
@@ -41,6 +42,10 @@
 	uint32		_openTime;
 	bool		_twoColumns;
 	int			_entriesPerColumn;
+
+	int			_leftPadding;
+	int			_rightPadding;
+
 public:
 	PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize ws = kDefaultWidgetSize);
 
@@ -75,6 +80,9 @@
 	_h = _popUpBoss->_entries.size() * kLineHeight + 2;
 	_w = _popUpBoss->_w - kLineHeight + 2 - _popUpBoss->_labelWidth;
 
+	_leftPadding = _popUpBoss->_leftPadding;
+	_rightPadding = _popUpBoss->_rightPadding;
+
 	// Perform clipping / switch to scrolling mode if we don't fit on the screen
 	// FIXME - OSystem should send out notification messages when the screen
 	// resolution changes... we could generalize CommandReceiver and CommandSender.
@@ -323,7 +331,7 @@
 		g_gui.theme()->drawLineSeparator(Common::Rect(x, y, x+w, y+kLineHeight));
 	} else {
 		g_gui.theme()->drawText(Common::Rect(x+1, y+2, x+w, y+2+kLineHeight), name,	hilite ? Theme::kStateHighlight : Theme::kStateEnabled,
-								Theme::kTextAlignLeft);
+								Theme::kTextAlignLeft, false, _leftPadding);
 	}
 }
 
@@ -334,18 +342,13 @@
 // PopUpWidget
 //
 
-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) {
-	init();
-}
-
 PopUpWidget::PopUpWidget(GuiObject *boss, String name, const String &label, uint labelWidth)
 	: Widget(boss, name), CommandSender(boss), _label(label), _labelWidth(labelWidth) {
 	_ws = g_gui.getWidgetSize();
-	init();
-}
 
-void PopUpWidget::init() {
+	_leftPadding = g_gui.evaluator()->getVar("PopUpWidget.leftPadding", 0);
+	_rightPadding = g_gui.evaluator()->getVar("PopUpWidget.rightPadding", 0);
+
 	_flags = WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS;
 	setHints(THEME_HINT_SAVE_BACKGROUND);
 	_type = kPopUpWidget;
@@ -433,7 +436,7 @@
 	if (_selectedItem >= 0) {
 		TextAlignment align = (g_gui.getStringWidth(_entries[_selectedItem].name) > w-6) ? kTextAlignRight : kTextAlignLeft;
 		g_gui.theme()->drawText(Common::Rect(x+2, _y+3, _x+2+w-6, _y+3+g_gui.theme()->getFontHeight()), _entries[_selectedItem].name,
-								isEnabled() ? Theme::kStateEnabled : Theme::kStateDisabled, g_gui.theme()->convertAligment(align));
+								isEnabled() ? Theme::kStateEnabled : Theme::kStateDisabled, g_gui.theme()->convertAligment(align), false, _leftPadding);
 	}
 }
 

Modified: scummvm/trunk/gui/PopUpWidget.h
===================================================================
--- scummvm/trunk/gui/PopUpWidget.h	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/PopUpWidget.h	2006-04-16 10:23:36 UTC (rev 21934)
@@ -56,12 +56,12 @@
 	String			_label;
 	uint			_labelWidth;
 
+	int				_leftPadding;
+	int				_rightPadding;
+
 public:
-	PopUpWidget(GuiObject *boss, int x, int y, int w, int h, const String &label, uint labelWidth = 0, WidgetSize ws = kDefaultWidgetSize);
 	PopUpWidget(GuiObject *boss, String name, const String &label, uint labelWidth = 0);
 
-	void init();
-
 	void handleMouseDown(int x, int y, int button, int clickCount);
 
 	void appendEntry(const String &entry, uint32 tag = (uint32)-1);

Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/ThemeNew.cpp	2006-04-16 10:23:36 UTC (rev 21934)
@@ -37,7 +37,7 @@
 #define kShadowTr3 64
 #define kShadowTr4 128
 
-#define THEME_VERSION 7
+#define THEME_VERSION 8
 
 using Graphics::Surface;
 

Modified: scummvm/trunk/gui/eval.h
===================================================================
--- scummvm/trunk/gui/eval.h	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/eval.h	2006-04-16 10:23:36 UTC (rev 21934)
@@ -63,7 +63,11 @@
 	void setVar(const String name, int val) { _vars[name] = val; }
 	void setAlias(const String name, const String val) { _aliases[name] = val; }
 
-	int getVar(String s) { return getVar_(s.c_str()); };
+	int getVar(String s) { return getVar_(s.c_str()); }
+	int getVar(String s, int def) {
+		int val = getVar_(s.c_str());
+		return (val == EVAL_UNDEF_VAR) ? def : val;
+	};
 
 	uint getNumVars() { return _vars.size(); }
 

Modified: scummvm/trunk/gui/theme-config.cpp
===================================================================
--- scummvm/trunk/gui/theme-config.cpp	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/theme-config.cpp	2006-04-16 10:23:36 UTC (rev 21934)
@@ -76,6 +76,15 @@
 "def_scummhelpW=370\n"
 "def_scummhelpX=((w - scummhelpW) / 2)\n"
 "def_midiControlsSpacing=2\n"
+"##### Widgets config\n"
+"ListWidget.leftPadding=4\n"
+"ListWidget.rightPadding=0\n"
+"ListWidget.topPadding=2\n"
+"ListWidget.bottomPadding=2\n"
+"ListWidget.hlLeftPadding=2\n"
+"ListWidget.hlRightPadding=1\n"
+"PopUpWidget.leftPadding=4\n"
+"PopUpWidget.rightPadding=0\n"
 "\n"
 "###### chooser\n"
 "opHeight=(h * 7 / 10)\n"

Modified: scummvm/trunk/gui/themes/modern.ini
===================================================================
--- scummvm/trunk/gui/themes/modern.ini	2006-04-16 10:12:33 UTC (rev 21933)
+++ scummvm/trunk/gui/themes/modern.ini	2006-04-16 10:23:36 UTC (rev 21934)
@@ -1,7 +1,7 @@
 # $URL$
 # $Id$
 [theme]
-version=7
+version=8
 
 [pixmaps]
 dialog_corner=dialog_bkgd_corner.bmp
@@ -157,6 +157,16 @@
 def_scummhelpX=((w - scummhelpW) / 2)
 def_midiControlsSpacing=4
 
+##### Widgets config
+ListWidget.leftPadding=7
+ListWidget.rightPadding=7
+ListWidget.topPadding=5
+ListWidget.bottomPadding=5
+ListWidget.hlLeftPadding=0
+ListWidget.hlRightPadding=0
+PopUpWidget.leftPadding=7
+PopUpWidget.rightPadding=7
+
 ###### chooser
 opHeight=(h * 7 / 10)
 useWithPrefix=chooser defaultChooser_


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