From b487c1fc38405ca80683b0d30318d0c4bd408b67 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 24 Nov 2013 00:38:47 +0100 Subject: GUI: Fix undrawing caret glitch when the edit text is inversed. This is prominently visible in the list based save/load chooser since the edit string is drawn on a special green background there. When the caret is at the end of the edit string this would result in the green color missing at the place of the (undrawn) caret. To avoid this we simply draw a fake space now. --- gui/widgets/editable.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index fca9702690..9ce4defde4 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -272,13 +272,25 @@ void EditableWidget::drawCaret(bool erase) { g_gui.theme()->drawCaret(Common::Rect(x, y, x + 1, y + editRect.height()), erase); if (erase) { + GUI::EditableWidget::String character; + int width; + if ((uint)_caretPos < _editString.size()) { - GUI::EditableWidget::String chr(_editString[_caretPos]); - int chrWidth = g_gui.getCharWidth(_editString[_caretPos], _font); + const byte chr = _editString[_caretPos]; + width = g_gui.getCharWidth(chr, _font); + character = chr; + const uint last = (_caretPos > 0) ? _editString[_caretPos - 1] : 0; - x += g_gui.getKerningOffset(last, _editString[_caretPos], _font); - g_gui.theme()->drawText(Common::Rect(x, y, x + chrWidth, y + editRect.height()), chr, _state, Graphics::kTextAlignLeft, _inversion, 0, false, _font, ThemeEngine::kFontColorNormal, true, _textDrawableArea); + x += g_gui.getKerningOffset(last, chr, _font); + } else { + // We draw a fake space here to assure that removing the caret + // does not result in color glitches in case the edit rect is + // drawn with an inversion. + width = g_gui.getCharWidth(' ', _font); + character = " "; } + + g_gui.theme()->drawText(Common::Rect(x, y, x + width, y + editRect.height()), character, _state, Graphics::kTextAlignLeft, _inversion, 0, false, _font, ThemeEngine::kFontColorNormal, true, _textDrawableArea); } _caretVisible = !erase; -- cgit v1.2.3