cleanup; fixed return/enter in ListWidget when not in editing mode

svn-id: r11346
This commit is contained in:
Max Horn 2003-11-18 23:44:28 +00:00
parent 151a2dcc44
commit 7d0fcb71a8
3 changed files with 27 additions and 32 deletions

View File

@ -45,11 +45,7 @@ void EditTextWidget::handleTickle() {
uint32 time = g_system->get_msecs();
if (_caretTime < time) {
_caretTime = time + kCaretBlinkTime;
if (_caretVisible) {
drawCaret(true);
} else {
drawCaret(false);
}
drawCaret(_caretVisible);
}
}
@ -157,7 +153,7 @@ void EditTextWidget::drawWidget(bool hilite) {
g_gui.drawString(_label, _x + 2, _y + 3, _w - 6, g_gui._textcolor, kTextAlignLeft, -_labelOffset, false);
}
int EditTextWidget::getCaretPos() {
int EditTextWidget::getCaretPos() const {
int caretpos = 0;
for (int i = 0; i < _pos; i++)
caretpos += g_gui.getCharWidth(_label[i]);
@ -176,8 +172,7 @@ void EditTextWidget::drawCaret(bool erase) {
int x = getAbsX() + 2;
int y = getAbsY() + 1;
int width = getCaretPos();
x += width;
x += getCaretPos();
g_gui.vLine(x, y, y + kLineHeight, color);
g_gui.addDirtyRect(x, y, 2, kLineHeight);
@ -185,8 +180,6 @@ void EditTextWidget::drawCaret(bool erase) {
_caretVisible = !erase;
}
bool EditTextWidget::adjustOffset() {
// check if the caret is still within the textbox; if it isn't,
// adjust _labelOffset
@ -197,15 +190,11 @@ bool EditTextWidget::adjustOffset() {
// scroll left
_labelOffset += caretpos;
return true;
}
else if (caretpos >= _w - 6)
{
} else if (caretpos >= _w - 6) {
// scroll right
_labelOffset -= (_w - 6 - caretpos);
return true;
}
else if (_labelOffset > 0)
{
} else if (_labelOffset > 0) {
int width = g_gui.getStringWidth(_label);
if (width - _labelOffset < (_w - 6)) {
// scroll right

View File

@ -89,11 +89,7 @@ void ListWidget::handleTickle() {
uint32 time = g_system->get_msecs();
if (_editMode && _caretTime < time) {
_caretTime = time + kCaretBlinkTime;
if (_caretVisible) {
drawCaret(true);
} else {
drawCaret(false);
}
drawCaret(_caretVisible);
}
}
@ -178,7 +174,8 @@ bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
dirty = true;
_editMode = true;
_backupString = _list[_selectedItem];
}
} else
sendCommand(kListItemActivatedCmd, _selectedItem);
}
break;
case 256+17: // up arrow
@ -285,6 +282,21 @@ void ListWidget::drawWidget(bool hilite) {
}
}
int ListWidget::getCaretPos() const {
int caretpos = 0;
NewGui *gui = &g_gui;
if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
char temp[10];
sprintf(temp, "%2d. ", (_selectedItem + _numberingMode));
caretpos += gui->getStringWidth(temp);
}
caretpos += gui->getStringWidth(_list[_selectedItem]);
return caretpos;
}
void ListWidget::drawCaret(bool erase) {
// Only draw if item is visible
if (_selectedItem < _currentPos || _selectedItem >= _currentPos + _entriesPerPage)
@ -298,19 +310,10 @@ void ListWidget::drawCaret(bool erase) {
int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;
int x = getAbsX() + 3;
int y = getAbsY() + 1;
Common::String buffer;
y += (_selectedItem - _currentPos) * kLineHeight;
if (_numberingMode == kListNumberingZero || _numberingMode == kListNumberingOne) {
char temp[10];
sprintf(temp, "%2d. ", (_selectedItem + _numberingMode));
buffer = temp;
buffer += _list[_selectedItem];
} else
buffer = _list[_selectedItem];
x += gui->getStringWidth(buffer);
x += getCaretPos();
gui->vLine(x, y, y+kLineHeight, color);
gui->addDirtyRect(x, y, 2, kLineHeight);

View File

@ -89,7 +89,10 @@ public:
protected:
void drawWidget(bool hilite);
int getCaretPos() const;
void drawCaret(bool erase);
void lostFocusWidget();
void scrollToCurrent();
};