diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/ThemeEngine.cpp | 4 | ||||
-rw-r--r-- | gui/ThemeEngine.h | 2 | ||||
-rw-r--r-- | gui/gui-manager.h | 1 | ||||
-rw-r--r-- | gui/widgets/editable.cpp | 11 | ||||
-rw-r--r-- | gui/widgets/edittext.cpp | 5 |
5 files changed, 20 insertions, 3 deletions
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 585789b515..46a0eda0c5 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -1373,6 +1373,10 @@ int ThemeEngine::getCharWidth(byte c, FontStyle font) const { return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getCharWidth(c) : 0; } +int ThemeEngine::getKerningOffset(byte left, byte right, FontStyle font) const { + return ready() ? _texts[fontStyleToData(font)]->_fontPtr->getKerningOffset(left, right) : 0; +} + TextData ThemeEngine::getTextData(DrawData ddId) const { return _widgets[ddId] ? (TextData)_widgets[ddId]->_textDataId : kTextDataNone; } diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index c49952ba0f..f041f85ab9 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -310,6 +310,8 @@ public: int getCharWidth(byte c, FontStyle font = kFontStyleBold) const; + int getKerningOffset(byte left, byte right, FontStyle font = kFontStyleBold) const; + //@} diff --git a/gui/gui-manager.h b/gui/gui-manager.h index addd2e6611..49542fd001 100644 --- a/gui/gui-manager.h +++ b/gui/gui-manager.h @@ -81,6 +81,7 @@ public: int getFontHeight(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getFontHeight(style); } int getStringWidth(const Common::String &str, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getStringWidth(str, style); } int getCharWidth(byte c, ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getCharWidth(c, style); } + int getKerningOffset(byte left, byte right, ThemeEngine::FontStyle font = ThemeEngine::kFontStyleBold) const { return _theme->getKerningOffset(left, right, font); } /** * Tell the GuiManager to check whether the screen resolution has changed. 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(); |