Skip to content

Commit

Permalink
fix #5904
Browse files Browse the repository at this point in the history
  • Loading branch information
rt committed Feb 21, 2018
1 parent 195f47b commit 88ae46e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions rts/Game/GameControllerTextInput.cpp
Expand Up @@ -46,18 +46,20 @@ void GameControllerTextInput::Draw() {
const float fontScale = 1.0f; // TODO: make configurable again
const float fontSize = fontScale * font->GetSize();

const std::string tempstring = userPrompt + userInput + editText;
const std::string userString = userPrompt + userInput + editText;

if (drawTextCaret) {
int caretIdx = writingPos + editingPos;
char32_t c = utf8::GetNextChar(userInput + editText, caretIdx);
int curCaretIdx = writingPos + editingPos; // advanced by GetNextChar
int prvCaretIdx = curCaretIdx;

char32_t c = utf8::GetNextChar(userInput + editText, curCaretIdx);

// make caret always visible
if (c == 0)
c = ' ';


const float caretRelPos = fontSize * font->GetTextWidth(tempstring.substr(0, userPrompt.length() + caretIdx)) * globalRendering->pixelX;
const float caretRelPos = fontSize * font->GetTextWidth(userString.substr(0, userPrompt.length() + prvCaretIdx)) * globalRendering->pixelX;
const float caretHeight = fontSize * font->GetLineHeight() * globalRendering->pixelY;
const float caretWidth = fontSize * font->GetCharacterWidth(c) * globalRendering->pixelX;

Expand Down Expand Up @@ -94,7 +96,7 @@ void GameControllerTextInput::Draw() {

// draw the text
font->SetColors(textColor, nullptr);
font->glPrint(inputTextPosX, inputTextPosY, fontSize, FONT_DESCENDER | (FONT_OUTLINE * guihandler->GetOutlineFonts()) | FONT_NORM | FONT_BUFFERED, tempstring);
font->glPrint(inputTextPosX, inputTextPosY, fontSize, FONT_DESCENDER | (FONT_OUTLINE * guihandler->GetOutlineFonts()) | FONT_NORM | FONT_BUFFERED, userString);
font->DrawBufferedGL4();
}

Expand Down

0 comments on commit 88ae46e

Please sign in to comment.