From aaad08c9fe25f00813ddd19458a9c98d06e723cf Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 23 Nov 2013 23:50:21 +0100 Subject: GUI: Fix character redrawing behind caret in EditTextWidgets. This fixes an ugly y position change when the caret is moved to a character in an edit text widget. --- gui/widgets/editable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 667850d6cc..c3354e53ea 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -277,7 +277,7 @@ void EditableWidget::drawCaret(bool erase) { int chrWidth = g_gui.getCharWidth(_editString[_caretPos], _font); 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); + 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); } } -- cgit v1.2.3 From bb4a730a88f69917b02abcff943f7cdf2a9de8c7 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 23 Nov 2013 23:56:54 +0100 Subject: GUI: Fix out-of-bounds check in EditableWidget::drawCaret. The line "y + editRect.height() + 2" is not included in drawing anymore. Thus it is allowed to equal EditableWidget::_h. --- gui/widgets/editable.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index c3354e53ea..112995424f 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -263,7 +263,7 @@ void EditableWidget::drawCaret(bool erase) { x += getCaretOffset(); - if (y < 0 || y + editRect.height() - 2 >= _h) + if (y < 0 || y + editRect.height() - 2 > _h) return; x += getAbsX(); -- cgit v1.2.3 From 3be846cfd7fdacf985334e05e60cd5a12aae526a Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 24 Nov 2013 00:11:01 +0100 Subject: GUI: Draw caret over the whole height of the edit rect. This improves the look of the editable widgets. --- gui/widgets/editable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 112995424f..fca9702690 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -263,13 +263,13 @@ void EditableWidget::drawCaret(bool erase) { x += getCaretOffset(); - 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) { if ((uint)_caretPos < _editString.size()) { -- cgit v1.2.3 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 From fe7f28bf6c955715f1180a0da315ec4ade38fdd0 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 24 Nov 2013 00:49:18 +0100 Subject: GUI: Do not draw text outside edit rect in EditableWidget. --- gui/widgets/editable.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gui/widgets/editable.cpp') diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 9ce4defde4..6f550b5642 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -261,7 +261,8 @@ 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() > _h) return; @@ -290,7 +291,16 @@ void EditableWidget::drawCaret(bool erase) { 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); + // 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); + } } _caretVisible = !erase; -- cgit v1.2.3