aboutsummaryrefslogtreecommitdiff
path: root/gui/widgets/editable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/widgets/editable.cpp')
-rw-r--r--gui/widgets/editable.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp
index 667850d6cc..6f550b5642 100644
--- a/gui/widgets/editable.cpp
+++ b/gui/widgets/editable.cpp
@@ -261,23 +261,45 @@ void EditableWidget::drawCaret(bool erase) {
int x = editRect.left;
int y = editRect.top;
- x += getCaretOffset();
+ const int caretOffset = getCaretOffset();
+ x += caretOffset;
- if (y < 0 || y + editRect.height() - 2 >= _h)
+ if (y < 0 || y + editRect.height() > _h)
return;
x += getAbsX();
y += getAbsY();
- g_gui.theme()->drawCaret(Common::Rect(x, y, x + 1, y + editRect.height() - 2), 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() - 2), 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 = " ";
+ }
+
+ // TODO: Right now we manually prevent text from being drawn outside
+ // the edit area here. We might want to consider to use
+ // setTextDrawableArea for this. However, it seems that only
+ // EditTextWidget uses that but not ListWidget. Thus, one should check
+ // whether we can unify the drawing in the text area first to avoid
+ // possible glitches due to different methods used.
+ width = MIN(editRect.width() - caretOffset, width);
+ if (width > 0) {
+ 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);
}
}