diff options
author | Eugene Sandulenko | 2006-04-16 10:23:36 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2006-04-16 10:23:36 +0000 |
commit | 924ec172ff6604ff0a701c00517038e6170f7267 (patch) | |
tree | 39cf56e8268e54ace1380c1cc67ac1f7c77216aa | |
parent | cadafb0689fc96fc77f09dc70b4b32cc8c572714 (diff) | |
download | scummvm-rg350-924ec172ff6604ff0a701c00517038e6170f7267.tar.gz scummvm-rg350-924ec172ff6604ff0a701c00517038e6170f7267.tar.bz2 scummvm-rg350-924ec172ff6604ff0a701c00517038e6170f7267.zip |
- 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
svn-id: r21934
-rw-r--r-- | gui/ListWidget.cpp | 44 | ||||
-rw-r--r-- | gui/ListWidget.h | 10 | ||||
-rw-r--r-- | gui/PopUpWidget.cpp | 23 | ||||
-rw-r--r-- | gui/PopUpWidget.h | 6 | ||||
-rw-r--r-- | gui/ThemeNew.cpp | 2 | ||||
-rw-r--r-- | gui/eval.h | 6 | ||||
-rw-r--r-- | gui/theme-config.cpp | 9 | ||||
-rw-r--r-- | gui/themes/modern.ini | 12 |
8 files changed, 72 insertions, 40 deletions
diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 04c9e8d049..240223f760 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -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(); + + _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); -void ListWidget::init(GuiObject *boss, int w, WidgetSize ws) { if (ws == kBigWidgetSize) { _w = w - kBigScrollBarWidth; } else { @@ -53,7 +53,7 @@ void ListWidget::init(GuiObject *boss, int w, WidgetSize ws) { _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 @@ void ListWidget::handleMouseWheel(int x, int y, int direction) { 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 @@ void ListWidget::drawWidget(bool hilite) { // 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 @@ void ListWidget::drawWidget(bool hilite) { } 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 @@ void ListWidget::drawWidget(bool hilite) { 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 @@ void ListWidget::drawWidget(bool hilite) { } 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 @@ Common::Rect ListWidget::getEditRect() const { 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; diff --git a/gui/ListWidget.h b/gui/ListWidget.h index 4cb89f020b..3457620ac3 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -61,13 +61,17 @@ protected: 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; } diff --git a/gui/PopUpWidget.cpp b/gui/PopUpWidget.cpp index ed6f64e814..dd40c911be 100644 --- a/gui/PopUpWidget.cpp +++ b/gui/PopUpWidget.cpp @@ -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 @@ protected: 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 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY, WidgetSize w _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 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) { 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 @@ void PopUpDialog::drawMenuEntry(int entry, bool hilite) { // 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 @@ void PopUpWidget::drawWidget(bool hilite) { 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); } } diff --git a/gui/PopUpWidget.h b/gui/PopUpWidget.h index bfa549c05a..471e5c9154 100644 --- a/gui/PopUpWidget.h +++ b/gui/PopUpWidget.h @@ -56,12 +56,12 @@ protected: 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); diff --git a/gui/ThemeNew.cpp b/gui/ThemeNew.cpp index 0f064baa29..1a225c3ab8 100644 --- a/gui/ThemeNew.cpp +++ b/gui/ThemeNew.cpp @@ -37,7 +37,7 @@ #define kShadowTr3 64 #define kShadowTr4 128 -#define THEME_VERSION 7 +#define THEME_VERSION 8 using Graphics::Surface; diff --git a/gui/eval.h b/gui/eval.h index 1a0b6f91ff..574dd8a936 100644 --- a/gui/eval.h +++ b/gui/eval.h @@ -63,7 +63,11 @@ public: 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(); } diff --git a/gui/theme-config.cpp b/gui/theme-config.cpp index 9e490ff358..060c38cfc4 100644 --- a/gui/theme-config.cpp +++ b/gui/theme-config.cpp @@ -76,6 +76,15 @@ const char *Theme::_defaultConfigINI = "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" diff --git a/gui/themes/modern.ini b/gui/themes/modern.ini index 21ecacc6c7..0b841448c9 100644 --- a/gui/themes/modern.ini +++ b/gui/themes/modern.ini @@ -1,7 +1,7 @@ # $URL$ # $Id$ [theme] -version=7 +version=8 [pixmaps] dialog_corner=dialog_bkgd_corner.bmp @@ -157,6 +157,16 @@ def_scummhelpW=370 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_ |