[Scummvm-cvs-logs] CVS: scummvm/gui ListWidget.cpp,1.10,1.11 ListWidget.h,1.8,1.9 dialog.h,1.11,1.12
Max Horn
fingolfin at users.sourceforge.net
Wed Oct 23 07:01:12 CEST 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory usw-pr-cvs1:/tmp/cvs-serv20450
Modified Files:
ListWidget.cpp ListWidget.h dialog.h
Log Message:
use a 'real' caret instead of appending an understcore while editing
Index: ListWidget.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ListWidget.cpp 22 Oct 2002 22:35:07 -0000 1.10
+++ ListWidget.cpp 23 Oct 2002 14:00:47 -0000 1.11
@@ -23,6 +23,7 @@
#include "ScrollBarWidget.h"
#include "dialog.h"
#include "newgui.h"
+#include "common/engine.h"
ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h)
@@ -37,6 +38,9 @@
_scrollBar = new ScrollBarWidget(boss, _x + _w, _y, kScrollBarWidth, _h);
_scrollBar->setTarget(this);
_currentKeyDown = 0;
+
+ _caretVisible = false;
+ _caretTime = 0;
// FIXME: This flag should come from widget definition
_editable = true;
@@ -50,6 +54,8 @@
void ListWidget::setList(const StringList& list)
{
+ if (_editMode && _caretVisible)
+ drawCaret(true);
int size = list.size();
_list = list;
if (_currentPos >= size)
@@ -67,6 +73,53 @@
_scrollBar->recalc();
}
+void ListWidget::handleTickle()
+{
+ uint32 time = g_system->get_msecs();
+ if (_editMode && _caretTime < time) {
+ _caretTime = time + 300;
+ if (_caretVisible) {
+ drawCaret(true);
+ } else {
+ drawCaret(false);
+ }
+ }
+}
+
+void ListWidget::drawCaret(bool erase)
+{
+ // Only draw if item is visible
+ if (_selectedItem < _currentPos || _selectedItem >= _currentPos + _entriesPerPage)
+ return;
+ if (!isVisible() || !_boss->isVisible())
+ return;
+
+ NewGui *gui = _boss->getGui();
+
+ // The item is selected, thus _bgcolor is used to draw the caret and _textcolorhi to erase it
+ int16 color = erase ? gui->_textcolorhi : gui->_bgcolor;
+ int x = _x + _boss->getX() + 3;
+ int y = _y + _boss->getY() + 1;
+ ScummVM::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);
+
+ gui->vline(x, y, y+kLineHeight, color);
+ gui->addDirtyRect(x, y, 2, kLineHeight);
+
+ _caretVisible = !erase;
+}
+
void ListWidget::handleMouseDown(int x, int y, int button, int clickCount)
{
if (isEnabled()) {
@@ -80,6 +133,7 @@
// undo any changes made
_list[oldSelectedItem] = _backupString;
_editMode = false;
+ drawCaret(true);
}
sendCommand(kListSelectionChangedCmd, _selectedItem);
}
@@ -109,8 +163,8 @@
if (_editMode) {
- // get rid of caret
- _list[_selectedItem].deleteLastChar();
+ if (_caretVisible)
+ drawCaret(true);
if (key == '\n' || key == '\r') {
// enter, confirm edit and exit editmode
@@ -184,10 +238,6 @@
scrollToCurrent();
}
- if (_editMode)
- // re-add caret
- _list[_selectedItem] += '_';
-
if (dirty || _selectedItem != oldSelectedItem)
draw();
@@ -218,12 +268,8 @@
void ListWidget::lostFocusWidget()
{
- if (_editMode) {
- // loose caret
- _list[_selectedItem].deleteLastChar();
- _editMode = false;
- }
-
+ _editMode = false;
+ drawCaret(true);
draw();
}
@@ -256,18 +302,17 @@
char temp[10];
sprintf(temp, "%2d. ", (pos + _numberingMode));
buffer = temp;
+ buffer += _list[pos];
} else
- buffer = "";
+ buffer = _list[pos];
- buffer += _list[pos];
-
if (_selectedItem == pos) {
if (_hasFocus)
gui->fillRect(_x+1, _y+1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi);
else
gui->frameRect(_x+1, _y+1 + kLineHeight * i, _w - 1, kLineHeight, gui->_textcolorhi);
}
- gui->drawString(buffer.c_str(), _x+2, _y+3 + kLineHeight * i, _w - 4,
+ gui->drawString(buffer, _x+2, _y+3 + kLineHeight * i, _w - 4,
(_selectedItem == pos && _hasFocus) ? gui->_bgcolor : gui->_textcolor);
}
}
@@ -295,7 +340,6 @@
if (_editable && !_editMode && _selectedItem >= 0) {
_editMode = true;
_backupString = _list[_selectedItem];
- _list[_selectedItem] += '_';
draw();
}
}
@@ -305,6 +349,7 @@
if (_editMode) {
_editMode = false;
_list[_selectedItem] = _backupString;
+ drawCaret(true);
draw();
}
}
Index: ListWidget.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/ListWidget.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ListWidget.h 19 Oct 2002 01:22:41 -0000 1.8
+++ ListWidget.h 23 Oct 2002 14:00:47 -0000 1.9
@@ -54,6 +54,8 @@
ScrollBarWidget *_scrollBar;
int _currentKeyDown;
String _backupString;
+ bool _caretVisible;
+ uint32 _caretTime;
public:
ListWidget(Dialog *boss, int x, int y, int w, int h);
virtual ~ListWidget();
@@ -66,6 +68,7 @@
bool isEditable() const { return _editable; }
void setEditable(bool editable) { _editable = editable; }
+ virtual void handleTickle();
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
virtual void handleMouseWheel(int x, int y, int direction);
@@ -82,6 +85,7 @@
protected:
void drawWidget(bool hilite);
+ void drawCaret(bool erase);
void lostFocusWidget();
void scrollToCurrent();
};
Index: dialog.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/dialog.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- dialog.h 19 Oct 2002 01:22:41 -0000 1.11
+++ dialog.h 23 Oct 2002 14:00:47 -0000 1.12
@@ -54,6 +54,8 @@
NewGui *getGui() { return _gui; }
bool isVisible() const { return _visible; }
+ int16 getX() const { return _x; }
+ int16 getY() const { return _y; }
protected:
virtual void open();
More information about the Scummvm-git-logs
mailing list