diff options
| author | Johannes Schickel | 2012-01-08 02:33:34 +0100 |
|---|---|---|
| committer | Willem Jan Palenstijn | 2012-01-29 16:26:20 +0100 |
| commit | 9f3fbe1bd773664b1e86241e71875cd97230d791 (patch) | |
| tree | 1eae5b18934a2433aef7205a86bdd9a999261346 /gui/widgets | |
| parent | d21ae1aa40f7ef5442d98c377800a0157af069c8 (diff) | |
| download | scummvm-rg350-9f3fbe1bd773664b1e86241e71875cd97230d791.tar.gz scummvm-rg350-9f3fbe1bd773664b1e86241e71875cd97230d791.tar.bz2 scummvm-rg350-9f3fbe1bd773664b1e86241e71875cd97230d791.zip | |
GRAPHICS/GUI: Implement kerning support for Font.
This adapts the related graphics code, which is the generic Font API and the
TTF font implementation.
It furthermore adapts the GUI to properly take care of kerning in text input
widgets.
Diffstat (limited to 'gui/widgets')
| -rw-r--r-- | gui/widgets/editable.cpp | 11 | ||||
| -rw-r--r-- | gui/widgets/edittext.cpp | 5 |
2 files changed, 13 insertions, 3 deletions
diff --git a/gui/widgets/editable.cpp b/gui/widgets/editable.cpp index 4a0ee54828..6fae9346b2 100644 --- a/gui/widgets/editable.cpp +++ b/gui/widgets/editable.cpp @@ -238,8 +238,13 @@ void EditableWidget::defaultKeyDownHandler(Common::KeyState &state, bool &dirty, int EditableWidget::getCaretOffset() const { int caretpos = 0; - for (int i = 0; i < _caretPos; i++) - caretpos += g_gui.getCharWidth(_editString[i], _font); + + uint last = 0; + for (int i = 0; i < _caretPos; ++i) { + const uint cur = _editString[i]; + caretpos += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font); + last = cur; + } caretpos -= _editScrollOffset; @@ -270,6 +275,8 @@ void EditableWidget::drawCaret(bool erase) { if ((uint)_caretPos < _editString.size()) { GUI::EditableWidget::String chr(_editString[_caretPos]); 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); } } diff --git a/gui/widgets/edittext.cpp b/gui/widgets/edittext.cpp index 0337fe1e87..af8ab8aa5b 100644 --- a/gui/widgets/edittext.cpp +++ b/gui/widgets/edittext.cpp @@ -67,10 +67,13 @@ void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { int width = 0; uint i; + uint last = 0; for (i = 0; i < _editString.size(); ++i) { - width += g_gui.theme()->getCharWidth(_editString[i], _font); + const uint cur = _editString[i]; + width += g_gui.getCharWidth(cur, _font) + g_gui.getKerningOffset(last, cur, _font); if (width >= x) break; + last = cur; } if (setCaretPos(i)) draw(); |
