aboutsummaryrefslogtreecommitdiff
path: root/gui/widgets/list.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/widgets/list.cpp')
-rw-r--r--gui/widgets/list.cpp58
1 files changed, 21 insertions, 37 deletions
diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp
index e5690fb6f2..df12d6fd5f 100644
--- a/gui/widgets/list.cpp
+++ b/gui/widgets/list.cpp
@@ -37,7 +37,6 @@ ListWidget::ListWidget(Dialog *boss, const String &name, const char *tooltip, ui
: EditableWidget(boss, name, tooltip), _cmd(cmd) {
_scrollBar = NULL;
- _textWidth = NULL;
// This ensures that _entriesPerPage is properly initialized.
reflowLayout();
@@ -69,7 +68,6 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const char *too
: EditableWidget(boss, x, y, w, h, tooltip), _cmd(cmd) {
_scrollBar = NULL;
- _textWidth = NULL;
// This ensures that _entriesPerPage is properly initialized.
reflowLayout();
@@ -97,10 +95,6 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const char *too
_editColor = ThemeEngine::kFontColorNormal;
}
-ListWidget::~ListWidget() {
- delete[] _textWidth;
-}
-
bool ListWidget::containsWidget(Widget *w) const {
if (w == _scrollBar || _scrollBar->containsWidget(w))
return true;
@@ -145,7 +139,7 @@ void ListWidget::setSelected(int item) {
_currentPos = _selectedItem - _entriesPerPage / 2;
scrollToCurrent();
- draw();
+ markAsDirty();
}
}
@@ -251,7 +245,7 @@ void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
// TODO: Determine where inside the string the user clicked and place the
// caret accordingly.
// See _editScrollOffset and EditTextWidget::handleMouseDown.
- draw();
+ markAsDirty();
}
@@ -446,12 +440,12 @@ bool ListWidget::handleKeyDown(Common::KeyState state) {
}
if (dirty || _selectedItem != oldSelectedItem)
- draw();
+ markAsDirty();
if (_selectedItem != oldSelectedItem) {
sendCommand(kListSelectionChangedCmd, _selectedItem);
// also draw scrollbar
- _scrollBar->draw();
+ _scrollBar->markAsDirty();
}
return handled;
@@ -467,7 +461,7 @@ void ListWidget::receivedFocusWidget() {
_inversion = ThemeEngine::kTextInversionFocus;
// Redraw the widget so the selection color will change
- draw();
+ markAsDirty();
}
void ListWidget::lostFocusWidget() {
@@ -477,7 +471,7 @@ void ListWidget::lostFocusWidget() {
_editMode = false;
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
drawCaret(true);
- draw();
+ markAsDirty();
}
void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
@@ -486,7 +480,7 @@ void ListWidget::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
if (_currentPos != (int)data) {
_currentPos = data;
checkBounds();
- draw();
+ markAsDirty();
// Scrollbar actions cause list focus (which triggers a redraw)
// NOTE: ListWidget's boss is always GUI::Dialog
@@ -502,7 +496,6 @@ void ListWidget::drawWidget() {
// Draw a thin frame around the list.
g_gui.theme()->drawWidgetBackgroundClip(Common::Rect(_x, _y, _x + _w, _y + _h), getBossClipRect(), 0, ThemeEngine::kWidgetBackgroundBorder);
- const int scrollbarW = (_scrollBar && _scrollBar->isVisible()) ? _scrollBarWidth : 0;
// Draw the list items
for (i = 0, pos = _currentPos; i < _entriesPerPage && pos < len; i++, pos++) {
@@ -520,13 +513,11 @@ void ListWidget::drawWidget() {
// If in numbering mode, we first print a number prefix
if (_numberingMode != kListNumberingOff) {
buffer = Common::String::format("%2d. ", (pos + _numberingMode));
- g_gui.theme()->drawTextClip(Common::Rect(_x, y, _x + r.left + _leftPadding, y + fontHeight - 2), getBossClipRect(),
- buffer, _state, Graphics::kTextAlignLeft, inverted, _leftPadding, true);
+ g_gui.theme()->drawTextClip(Common::Rect(_x + _hlLeftPadding, y, _x + r.left + _leftPadding, y + fontHeight - 2),
+ getBossClipRect(), buffer, _state, Graphics::kTextAlignLeft, inverted, _leftPadding, true);
pad = 0;
}
- int width;
-
ThemeEngine::FontColor color = ThemeEngine::kFontColorNormal;
if (!_listColors.empty()) {
@@ -540,22 +531,21 @@ void ListWidget::drawWidget() {
buffer = _editString;
color = _editColor;
adjustOffset();
- width = _w - r.left - _hlRightPadding - _leftPadding - scrollbarW;
- g_gui.theme()->drawTextClip(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight - 2), getBossClipRect(), buffer, _state,
- Graphics::kTextAlignLeft, inverted, pad, true, ThemeEngine::kFontStyleBold, color);
+ g_gui.theme()->drawTextClip(Common::Rect(_x + r.left, y, _x + r.right, y + fontHeight - 2),
+ getBossClipRect(), buffer, _state,
+ Graphics::kTextAlignLeft, inverted, pad, true, ThemeEngine::kFontStyleBold, color);
} else {
buffer = _list[pos];
- width = _w - r.left - scrollbarW;
- g_gui.theme()->drawTextClip(Common::Rect(_x + r.left, y, _x + r.left + width, y + fontHeight - 2), getBossClipRect(), buffer, _state,
- Graphics::kTextAlignLeft, inverted, pad, true, ThemeEngine::kFontStyleBold, color);
+ g_gui.theme()->drawTextClip(Common::Rect(_x + r.left, y, _x + r.right, y + fontHeight - 2),
+ getBossClipRect(), buffer, _state,
+ Graphics::kTextAlignLeft, inverted, pad, true, ThemeEngine::kFontStyleBold, color);
}
-
- _textWidth[i] = width;
}
}
Common::Rect ListWidget::getEditRect() const {
- Common::Rect r(_hlLeftPadding, 0, _w - _hlLeftPadding - _hlRightPadding, kLineHeight - 2);
+ const int scrollbarW = (_scrollBar && _scrollBar->isVisible()) ? _scrollBarWidth : 0;
+ Common::Rect r(_hlLeftPadding, 0, _w - _hlRightPadding - scrollbarW, kLineHeight - 2);
const int offset = (_selectedItem - _currentPos) * kLineHeight + _topPadding;
r.top += offset;
r.bottom += offset;
@@ -600,7 +590,7 @@ void ListWidget::scrollToEnd() {
_scrollBar->_currentPos = _currentPos;
_scrollBar->recalc();
- _scrollBar->draw();
+ _scrollBar->markAsDirty();
}
void ListWidget::startEditMode() {
@@ -616,7 +606,7 @@ void ListWidget::startEditMode() {
else
_editColor = _listColors[_listIndex[_selectedItem]];
}
- draw();
+ markAsDirty();
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
}
}
@@ -636,7 +626,7 @@ void ListWidget::abortEditMode() {
assert(_selectedItem >= 0);
_editMode = false;
//drawCaret(true);
- //draw();
+ //markAsDirty();
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
}
@@ -668,12 +658,6 @@ void ListWidget::reflowLayout() {
_entriesPerPage = fracToInt(entriesPerPage);
assert(_entriesPerPage > 0);
- delete[] _textWidth;
- _textWidth = new int[_entriesPerPage];
-
- for (int i = 0; i < _entriesPerPage; i++)
- _textWidth[i] = 0;
-
if (_scrollBar) {
_scrollBar->resize(_w - _scrollBarWidth + 1, 0, _scrollBarWidth, _h);
scrollBarRecalc();
@@ -744,7 +728,7 @@ void ListWidget::setFilter(const String &filter, bool redraw) {
// Such a widget could also (optionally) draw a border (or even different
// kinds of borders) around the objects it groups; and also a 'title'
// (I am borrowing these "ideas" from the NSBox class in Cocoa :).
- _boss->draw();
+ g_gui.scheduleTopDialogRedraw();
}
}