From c64467af1ab23643b7cfe575463bdeb825b6b846 Mon Sep 17 00:00:00 2001 From: Torbjörn Andersson Date: Mon, 16 May 2005 13:43:31 +0000 Subject: Fixed drawing of the caret. (It was drawn using the GUI font, rather than the widget's font.) svn-id: r18130 --- gui/ListWidget.h | 1 - gui/editable.cpp | 20 ++++++++++++-------- gui/editable.h | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gui/ListWidget.h b/gui/ListWidget.h index 0681c6cb29..652489cfa3 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -57,7 +57,6 @@ protected: ScrollBarWidget *_scrollBar; int _currentKeyDown; int _lineHeight; - const Graphics::Font *_font; String _quickSelectStr; uint32 _quickSelectTime; diff --git a/gui/editable.cpp b/gui/editable.cpp index 5a556ee561..3cac9d487c 100644 --- a/gui/editable.cpp +++ b/gui/editable.cpp @@ -34,6 +34,8 @@ EditableWidget::EditableWidget(GuiObject *boss, int x, int y, int w, int h) _caretInverse = false; _editScrollOffset = 0; + + _font = &(g_gui.getFont()); // Most widgets will probably set this to something else. } EditableWidget::~EditableWidget() { @@ -45,7 +47,7 @@ void EditableWidget::setEditString(const String &str) { _editString = str; _caretPos = _editString.size(); - _editScrollOffset = (g_gui.getStringWidth(_editString) - (getEditRect().width())); + _editScrollOffset = (_font->getStringWidth(_editString) - (getEditRect().width())); if (_editScrollOffset < 0) _editScrollOffset = 0; } @@ -130,7 +132,7 @@ bool EditableWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) { int EditableWidget::getCaretOffset() const { int caretpos = 0; for (int i = 0; i < _caretPos; i++) - caretpos += g_gui.getCharWidth(_editString[i]); + caretpos += _font->getCharWidth(_editString[i]); caretpos -= _editScrollOffset; @@ -142,20 +144,22 @@ void EditableWidget::drawCaret(bool erase) { if (!isVisible() || !_boss->isVisible()) return; + Common::Rect editRect = getEditRect(); + int16 color = (erase ^ _caretInverse) ? g_gui._bgcolor : g_gui._textcolorhi; - int x = getEditRect().left; - int y = getEditRect().top; + int x = editRect.left; + int y = editRect.top; x += getCaretOffset(); - if (y < 0 || y + kLineHeight >= _h) + if (y < 0 || y + editRect.height() >= _h) return; x += getAbsX(); y += getAbsY(); - g_gui.vLine(x, y, y + kLineHeight, color); - g_gui.addDirtyRect(x, y, 2, kLineHeight); + g_gui.vLine(x, y, y + editRect.height(), color); + g_gui.addDirtyRect(x, y, 2, editRect.height()); _caretVisible = !erase; } @@ -182,7 +186,7 @@ bool EditableWidget::adjustOffset() { _editScrollOffset -= (editWidth - caretpos); return true; } else if (_editScrollOffset > 0) { - const int strWidth = g_gui.getStringWidth(_editString); + const int strWidth = _font->getStringWidth(_editString); if (strWidth - _editScrollOffset < editWidth) { // scroll right _editScrollOffset = (strWidth - editWidth); diff --git a/gui/editable.h b/gui/editable.h index 2d637316c8..0b20bd072d 100644 --- a/gui/editable.h +++ b/gui/editable.h @@ -35,6 +35,7 @@ class EditableWidget : public Widget { public: typedef Common::String String; protected: + const Graphics::Font *_font; String _editString; bool _caretVisible; -- cgit v1.2.3