Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/CInput.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | CInput::CInput(CGUI& pGUI) | ||||
m_PrevTime(), | m_PrevTime(), | ||||
m_CursorVisState(true), | m_CursorVisState(true), | ||||
m_CursorBlinkRate(0.5), | m_CursorBlinkRate(0.5), | ||||
m_ComposingText(), | m_ComposingText(), | ||||
m_GeneratedPlaceholderTextValid(false), | m_GeneratedPlaceholderTextValid(false), | ||||
m_iComposedLength(), | m_iComposedLength(), | ||||
m_iComposedPos(), | m_iComposedPos(), | ||||
m_iInsertPos(), | m_iInsertPos(), | ||||
m_BufferPosition(), | m_BufferPosition(this, "buffer_position"), | ||||
m_BufferZone(), | m_BufferZone(this, "buffer_zone"), | ||||
m_Caption(), | m_Caption(this, "caption"), | ||||
m_Font(), | m_Font(this, "font"), | ||||
m_MaskChar(), | m_MaskChar(this, "mask_char"), | ||||
m_Mask(), | m_Mask(this, "mask"), | ||||
m_MaxLength(), | m_MaxLength(this, "max_length"), | ||||
m_MultiLine(), | m_MultiLine(this, "multiline"), | ||||
m_Readonly(), | m_Readonly(this, "readonly"), | ||||
m_ScrollBar(), | m_ScrollBar(this, "scrollbar"), | ||||
m_ScrollBarStyle(), | m_ScrollBarStyle(this, "scrollbar_style"), | ||||
m_Sprite(), | m_Sprite(this, "sprite"), | ||||
m_SpriteSelectArea(), | m_SpriteSelectArea(this, "sprite_selectarea"), | ||||
m_TextColor(), | m_TextColor(this, "textcolor"), | ||||
m_TextColorSelected() | m_TextColorSelected(this, "textcolor_selected"), | ||||
{ | m_PlaceholderText(this, "placeholder_text"), | ||||
RegisterSetting("buffer_position", m_BufferPosition); | m_PlaceholderColor(this, "placeholder_color") | ||||
RegisterSetting("buffer_zone", m_BufferZone); | { | ||||
RegisterSetting("caption", m_Caption); | |||||
RegisterSetting("font", m_Font); | |||||
RegisterSetting("mask_char", m_MaskChar); | |||||
RegisterSetting("mask", m_Mask); | |||||
RegisterSetting("max_length", m_MaxLength); | |||||
RegisterSetting("multiline", m_MultiLine); | |||||
RegisterSetting("readonly", m_Readonly); | |||||
RegisterSetting("scrollbar", m_ScrollBar); | |||||
RegisterSetting("scrollbar_style", m_ScrollBarStyle); | |||||
RegisterSetting("sprite", m_Sprite); | |||||
RegisterSetting("sprite_selectarea", m_SpriteSelectArea); | |||||
RegisterSetting("textcolor", m_TextColor); | |||||
RegisterSetting("textcolor_selected", m_TextColorSelected); | |||||
RegisterSetting("placeholder_text", m_PlaceholderText); | |||||
RegisterSetting("placeholder_color", m_PlaceholderColor); | |||||
CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); | CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); | ||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); | CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); | ||||
bar->SetRightAligned(true); | bar->SetRightAligned(true); | ||||
AddScrollBar(bar); | AddScrollBar(bar); | ||||
} | } | ||||
CInput::~CInput() | CInput::~CInput() | ||||
{ | { | ||||
} | } | ||||
void CInput::UpdateBufferPositionSetting() | void CInput::UpdateBufferPositionSetting() | ||||
{ | { | ||||
SetSetting<i32>("buffer_position", m_iBufferPos, false); | m_BufferPosition.Set(m_iBufferPos, false); | ||||
} | } | ||||
void CInput::ClearComposedText() | void CInput::ClearComposedText() | ||||
{ | { | ||||
m_Caption.erase(m_iInsertPos, m_iComposedLength); | m_Caption->erase(m_iInsertPos, m_iComposedLength); | ||||
m_iBufferPos = m_iInsertPos; | m_iBufferPos = m_iInsertPos; | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
m_iComposedLength = 0; | m_iComposedLength = 0; | ||||
m_iComposedPos = 0; | m_iComposedPos = 0; | ||||
} | } | ||||
InReaction CInput::ManuallyHandleKeys(const SDL_Event_* ev) | InReaction CInput::ManuallyHandleKeys(const SDL_Event_* ev) | ||||
{ | { | ||||
Show All 14 Lines | InReaction CInput::ManuallyHandleKeys(const SDL_Event_* ev) | ||||
{ | { | ||||
if (m_Readonly) | if (m_Readonly) | ||||
return IN_PASS; | return IN_PASS; | ||||
// Text has been committed, either single key presses or through an IME | // Text has been committed, either single key presses or through an IME | ||||
std::wstring text = wstring_from_utf8(ev->ev.text.text); | std::wstring text = wstring_from_utf8(ev->ev.text.text); | ||||
// Check max length | // Check max length | ||||
if (m_MaxLength != 0 && m_Caption.length() + text.length() > static_cast<size_t>(m_MaxLength)) | if (m_MaxLength != 0 && m_Caption->length() + text.length() > static_cast<size_t>(m_MaxLength)) | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (m_ComposingText) | if (m_ComposingText) | ||||
{ | { | ||||
ClearComposedText(); | ClearComposedText(); | ||||
m_ComposingText = false; | m_ComposingText = false; | ||||
} | } | ||||
if (m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_iBufferPos == static_cast<int>(m_Caption->length())) | ||||
m_Caption.append(text); | m_Caption->append(text); | ||||
else | else | ||||
m_Caption.insert(m_iBufferPos, text); | m_Caption->insert(m_iBufferPos, text); | ||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); | UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); | ||||
m_iBufferPos += text.length(); | m_iBufferPos += text.length(); | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
Show All 24 Lines | case SDL_TEXTEDITING: | ||||
{ | { | ||||
// Composed text is replaced each time | // Composed text is replaced each time | ||||
ClearComposedText(); | ClearComposedText(); | ||||
} | } | ||||
m_ComposingText = ev->ev.edit.start != 0 || rawLength != 0; | m_ComposingText = ev->ev.edit.start != 0 || rawLength != 0; | ||||
if (m_ComposingText) | if (m_ComposingText) | ||||
{ | { | ||||
m_Caption.insert(m_iInsertPos, wtext); | m_Caption->insert(m_iInsertPos, wtext); | ||||
// The text buffer is limited to SDL_TEXTEDITINGEVENT_TEXT_SIZE bytes, yet start | // The text buffer is limited to SDL_TEXTEDITINGEVENT_TEXT_SIZE bytes, yet start | ||||
// increases without limit, so don't let it advance beyond the composed text length | // increases without limit, so don't let it advance beyond the composed text length | ||||
m_iComposedLength = wtext.length(); | m_iComposedLength = wtext.length(); | ||||
m_iComposedPos = ev->ev.edit.start < m_iComposedLength ? ev->ev.edit.start : m_iComposedLength; | m_iComposedPos = ev->ev.edit.start < m_iComposedLength ? ev->ev.edit.start : m_iComposedLength; | ||||
m_iBufferPos = m_iInsertPos + m_iComposedPos; | m_iBufferPos = m_iInsertPos + m_iComposedPos; | ||||
// TODO: composed text selection - what does ev.edit.length do? | // TODO: composed text selection - what does ev.edit.length do? | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | case SDLK_BACKSPACE: | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
else | else | ||||
{ | { | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
if (m_Caption.empty() || m_iBufferPos == 0) | if (m_Caption->empty() || m_iBufferPos == 0) | ||||
break; | break; | ||||
if (m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_iBufferPos == static_cast<int>(m_Caption->length())) | ||||
m_Caption = m_Caption.Left(static_cast<long>(m_Caption.length()) - 1); | m_Caption.Get() = m_Caption->Left(static_cast<long>(m_Caption->length()) - 1); | ||||
else | else | ||||
m_Caption = | m_Caption.Get() = | ||||
m_Caption.Left(m_iBufferPos - 1) + | m_Caption->Left(m_iBufferPos - 1) + | ||||
m_Caption.Right(static_cast<long>(m_Caption.length()) - m_iBufferPos); | m_Caption->Right(static_cast<long>(m_Caption->length()) - m_iBufferPos); | ||||
--m_iBufferPos; | --m_iBufferPos; | ||||
UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos); | UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos); | ||||
} | } | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
break; | break; | ||||
} | } | ||||
case SDLK_DELETE: | case SDLK_DELETE: | ||||
{ | { | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
else | else | ||||
{ | { | ||||
if (m_Caption.empty() || m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_Caption->empty() || m_iBufferPos == static_cast<int>(m_Caption->length())) | ||||
break; | break; | ||||
m_Caption = | m_Caption.Get() = | ||||
m_Caption.Left(m_iBufferPos) + | m_Caption->Left(m_iBufferPos) + | ||||
m_Caption.Right(static_cast<long>(m_Caption.length()) - (m_iBufferPos + 1)); | m_Caption->Right(static_cast<long>(m_Caption->length()) - (m_iBufferPos + 1)); | ||||
UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos); | UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos); | ||||
} | } | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
break; | break; | ||||
} | } | ||||
Show All 13 Lines | void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode) | ||||
} | } | ||||
default: // Insert a character | default: // Insert a character | ||||
{ | { | ||||
// Regular input is handled via SDL_TEXTINPUT, so we should ignore it here. | // Regular input is handled via SDL_TEXTINPUT, so we should ignore it here. | ||||
if (cooked == 0) | if (cooked == 0) | ||||
return; | return; | ||||
// Check max length | // Check max length | ||||
if (m_MaxLength != 0 && m_Caption.length() >= static_cast<size_t>(m_MaxLength)) | if (m_MaxLength != 0 && m_Caption->length() >= static_cast<size_t>(m_MaxLength)) | ||||
break; | break; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
if (m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_iBufferPos == static_cast<int>(m_Caption->length())) | ||||
m_Caption += cooked; | m_Caption.Get() += cooked; | ||||
else | else | ||||
m_Caption = | m_Caption.Get() = | ||||
m_Caption.Left(m_iBufferPos) + cooked + | m_Caption->Left(m_iBufferPos) + cooked + | ||||
m_Caption.Right(static_cast<long>(m_Caption.length()) - m_iBufferPos); | m_Caption->Right(static_cast<long>(m_Caption->length()) - m_iBufferPos); | ||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos + 1); | UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos + 1); | ||||
++m_iBufferPos; | ++m_iBufferPos; | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
break; | break; | ||||
Show All 36 Lines | if (!shiftKeyPressed) | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
} | } | ||||
else if (!SelectingText()) | else if (!SelectingText()) | ||||
{ | { | ||||
// Place tail at the current point: | // Place tail at the current point: | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
} | } | ||||
m_iBufferPos = static_cast<long>(m_Caption.length()); | m_iBufferPos = static_cast<long>(m_Caption->length()); | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
break; | break; | ||||
} | } | ||||
/** | /** | ||||
* Conventions for Left/Right when text is selected: | * Conventions for Left/Right when text is selected: | ||||
* | * | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | case SDLK_RIGHT: | ||||
if (shiftKeyPressed || !SelectingText()) | if (shiftKeyPressed || !SelectingText()) | ||||
{ | { | ||||
if (!shiftKeyPressed) | if (!shiftKeyPressed) | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
else if (!SelectingText()) | else if (!SelectingText()) | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
if (m_iBufferPos < static_cast<int>(m_Caption.length())) | if (m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
++m_iBufferPos; | ++m_iBufferPos; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (m_iBufferPos_Tail > m_iBufferPos) | if (m_iBufferPos_Tail > m_iBufferPos) | ||||
m_iBufferPos = m_iBufferPos_Tail; | m_iBufferPos = m_iBufferPos_Tail; | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | void CInput::ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode) | ||||
{ | { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CInput::SetupGeneratedPlaceholderText() | void CInput::SetupGeneratedPlaceholderText() | ||||
{ | { | ||||
m_GeneratedPlaceholderText = CGUIText(m_pGUI, m_PlaceholderText, m_Font, 0, m_BufferZone, this); | m_GeneratedPlaceholderText = CGUIText(m_pGUI, m_PlaceholderText, m_Font, 0, m_BufferZone, EAlign::LEFT, this); | ||||
m_GeneratedPlaceholderTextValid = true; | m_GeneratedPlaceholderTextValid = true; | ||||
} | } | ||||
InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) | InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) | ||||
{ | { | ||||
bool shiftKeyPressed = g_scancodes[SDL_SCANCODE_LSHIFT] || g_scancodes[SDL_SCANCODE_RSHIFT]; | bool shiftKeyPressed = g_scancodes[SDL_SCANCODE_LSHIFT] || g_scancodes[SDL_SCANCODE_RSHIFT]; | ||||
std::string hotkey = static_cast<const char*>(ev->ev.user.data1); | std::string hotkey = static_cast<const char*>(ev->ev.user.data1); | ||||
if (hotkey == "paste") | if (hotkey == "paste") | ||||
{ | { | ||||
if (m_Readonly) | if (m_Readonly) | ||||
return IN_PASS; | return IN_PASS; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
char* utf8_text = SDL_GetClipboardText(); | char* utf8_text = SDL_GetClipboardText(); | ||||
if (!utf8_text) | if (!utf8_text) | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
std::wstring text = wstring_from_utf8(utf8_text); | std::wstring text = wstring_from_utf8(utf8_text); | ||||
SDL_free(utf8_text); | SDL_free(utf8_text); | ||||
// Check max length | // Check max length | ||||
if (m_MaxLength != 0 && m_Caption.length() + text.length() > static_cast<size_t>(m_MaxLength)) | if (m_MaxLength != 0 && m_Caption->length() + text.length() > static_cast<size_t>(m_MaxLength)) | ||||
text = text.substr(0, static_cast<size_t>(m_MaxLength) - m_Caption.length()); | text = text.substr(0, static_cast<size_t>(m_MaxLength) - m_Caption->length()); | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (m_iBufferPos == static_cast<int>(m_Caption.length())) | if (m_iBufferPos == static_cast<int>(m_Caption->length())) | ||||
m_Caption += text; | m_Caption.Get() += text; | ||||
else | else | ||||
m_Caption = | m_Caption.Get() = | ||||
m_Caption.Left(m_iBufferPos) + text + | m_Caption->Left(m_iBufferPos) + text + | ||||
m_Caption.Right(static_cast<long>(m_Caption.length()) - m_iBufferPos); | m_Caption->Right(static_cast<long>(m_Caption->length()) - m_iBufferPos); | ||||
UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); | UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); | ||||
m_iBufferPos += static_cast<int>(text.size()); | m_iBufferPos += static_cast<int>(text.size()); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
Show All 18 Lines | if (SelectingText()) | ||||
virtualTo = m_iBufferPos_Tail; | virtualTo = m_iBufferPos_Tail; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
virtualFrom = m_iBufferPos_Tail; | virtualFrom = m_iBufferPos_Tail; | ||||
virtualTo = m_iBufferPos; | virtualTo = m_iBufferPos; | ||||
} | } | ||||
CStrW text = m_Caption.Left(virtualTo).Right(virtualTo - virtualFrom); | CStrW text = m_Caption->Left(virtualTo).Right(virtualTo - virtualFrom); | ||||
SDL_SetClipboardText(text.ToUTF8().c_str()); | SDL_SetClipboardText(text.ToUTF8().c_str()); | ||||
if (hotkey == "cut") | if (hotkey == "cut") | ||||
{ | { | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
} | } | ||||
} | } | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
else if (hotkey == "text.delete.left") | else if (hotkey == "text.delete.left") | ||||
{ | { | ||||
if (m_Readonly) | if (m_Readonly) | ||||
return IN_PASS; | return IN_PASS; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (!m_Caption.empty() && m_iBufferPos != 0) | if (!m_Caption->empty() && m_iBufferPos != 0) | ||||
{ | { | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
CStrW searchString = m_Caption.Left(m_iBufferPos); | CStrW searchString = m_Caption->Left(m_iBufferPos); | ||||
// If we are starting in whitespace, adjust position until we get a non whitespace | // If we are starting in whitespace, adjust position until we get a non whitespace | ||||
while (m_iBufferPos > 0) | while (m_iBufferPos > 0) | ||||
{ | { | ||||
if (!iswspace(searchString[m_iBufferPos - 1])) | if (!iswspace(searchString[m_iBufferPos - 1])) | ||||
break; | break; | ||||
m_iBufferPos--; | m_iBufferPos--; | ||||
Show All 26 Lines | else if (hotkey == "text.delete.right") | ||||
if (m_Readonly) | if (m_Readonly) | ||||
return IN_PASS; | return IN_PASS; | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (SelectingText()) | if (SelectingText()) | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
if (!m_Caption.empty() && m_iBufferPos < static_cast<int>(m_Caption.length())) | if (!m_Caption->empty() && m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
// Delete the word to the right of the cursor | // Delete the word to the right of the cursor | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
// Delete chars to the right unit we hit whitespace | // Delete chars to the right unit we hit whitespace | ||||
while (++m_iBufferPos < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos]) || iswpunct(m_Caption[m_iBufferPos])) | if (iswspace(m_Caption.Get()[m_iBufferPos]) || iswpunct(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
} | } | ||||
// Eliminate any whitespace behind the word we just deleted | // Eliminate any whitespace behind the word we just deleted | ||||
while (m_iBufferPos < static_cast<int>(m_Caption.length())) | while (m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (!iswspace(m_Caption[m_iBufferPos])) | if (!iswspace(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
++m_iBufferPos; | ++m_iBufferPos; | ||||
} | } | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
DeleteCurSelection(); | DeleteCurSelection(); | ||||
} | } | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | SendEvent(GUIM_TEXTEDIT, EventNameTextEdit); | ||||
return IN_HANDLED; | return IN_HANDLED; | ||||
} | } | ||||
else if (hotkey == "text.move.left") | else if (hotkey == "text.move.left") | ||||
{ | { | ||||
m_WantedX = 0.0f; | m_WantedX = 0.0f; | ||||
if (shiftKeyPressed || !SelectingText()) | if (shiftKeyPressed || !SelectingText()) | ||||
{ | { | ||||
if (!shiftKeyPressed) | if (!shiftKeyPressed) | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
else if (!SelectingText()) | else if (!SelectingText()) | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
if (!m_Caption.empty() && m_iBufferPos != 0) | if (!m_Caption->empty() && m_iBufferPos != 0) | ||||
{ | { | ||||
CStrW searchString = m_Caption.Left(m_iBufferPos); | CStrW searchString = m_Caption->Left(m_iBufferPos); | ||||
// If we are starting in whitespace, adjust position until we get a non whitespace | // If we are starting in whitespace, adjust position until we get a non whitespace | ||||
while (m_iBufferPos > 0) | while (m_iBufferPos > 0) | ||||
{ | { | ||||
if (!iswspace(searchString[m_iBufferPos - 1])) | if (!iswspace(searchString[m_iBufferPos - 1])) | ||||
break; | break; | ||||
m_iBufferPos--; | m_iBufferPos--; | ||||
Show All 34 Lines | else if (hotkey == "text.move.right") | ||||
if (shiftKeyPressed || !SelectingText()) | if (shiftKeyPressed || !SelectingText()) | ||||
{ | { | ||||
if (!shiftKeyPressed) | if (!shiftKeyPressed) | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
else if (!SelectingText()) | else if (!SelectingText()) | ||||
m_iBufferPos_Tail = m_iBufferPos; | m_iBufferPos_Tail = m_iBufferPos; | ||||
if (!m_Caption.empty() && m_iBufferPos < static_cast<int>(m_Caption.length())) | if (!m_Caption->empty() && m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
// Select chars to the right until we hit whitespace | // Select chars to the right until we hit whitespace | ||||
while (++m_iBufferPos < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos]) || iswpunct(m_Caption[m_iBufferPos])) | if (iswspace(m_Caption.Get()[m_iBufferPos]) || iswpunct(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
} | } | ||||
// Also select any whitespace following the word we just selected | // Also select any whitespace following the word we just selected | ||||
while (m_iBufferPos < static_cast<int>(m_Caption.length())) | while (m_iBufferPos < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (!iswspace(m_Caption[m_iBufferPos])) | if (!iswspace(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
++m_iBufferPos; | ++m_iBufferPos; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | case GUIM_MOUSE_PRESS_LEFT: | ||||
// for the user though. | // for the user though. | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_DBLCLICK_LEFT: | case GUIM_MOUSE_DBLCLICK_LEFT: | ||||
{ | { | ||||
if (m_ComposingText) | if (m_ComposingText) | ||||
break; | break; | ||||
if (m_Caption.empty()) | if (m_Caption->empty()) | ||||
break; | break; | ||||
m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition(); | m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition(); | ||||
if (m_iBufferPos >= (int)m_Caption.length()) | if (m_iBufferPos >= (int)m_Caption->length()) | ||||
m_iBufferPos = m_iBufferPos_Tail = m_Caption.length() - 1; | m_iBufferPos = m_iBufferPos_Tail = m_Caption->length() - 1; | ||||
// See if we are clicking over whitespace | // See if we are clicking over whitespace | ||||
if (iswspace(m_Caption[m_iBufferPos])) | if (iswspace(m_Caption.Get()[m_iBufferPos])) | ||||
{ | { | ||||
// see if we are in a section of whitespace greater than one character | // see if we are in a section of whitespace greater than one character | ||||
if ((m_iBufferPos + 1 < (int) m_Caption.length() && iswspace(m_Caption[m_iBufferPos + 1])) || | if ((m_iBufferPos + 1 < (int) m_Caption->length() && iswspace(m_Caption.Get()[m_iBufferPos + 1])) || | ||||
(m_iBufferPos - 1 > 0 && iswspace(m_Caption[m_iBufferPos - 1]))) | (m_iBufferPos - 1 > 0 && iswspace(m_Caption.Get()[m_iBufferPos - 1]))) | ||||
{ | { | ||||
// | // | ||||
// We are clicking in an area with more than one whitespace character | // We are clicking in an area with more than one whitespace character | ||||
// so we select both the word to the left and then the word to the right | // so we select both the word to the left and then the word to the right | ||||
// | // | ||||
// [1] First the left | // [1] First the left | ||||
// skip the whitespace | // skip the whitespace | ||||
while (m_iBufferPos > 0) | while (m_iBufferPos > 0) | ||||
{ | { | ||||
if (!iswspace(m_Caption[m_iBufferPos - 1])) | if (!iswspace(m_Caption.Get()[m_iBufferPos - 1])) | ||||
break; | break; | ||||
m_iBufferPos--; | m_iBufferPos--; | ||||
} | } | ||||
// now go until we hit white space or punctuation | // now go until we hit white space or punctuation | ||||
while (m_iBufferPos > 0) | while (m_iBufferPos > 0) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos - 1])) | if (iswspace(m_Caption.Get()[m_iBufferPos - 1])) | ||||
break; | break; | ||||
m_iBufferPos--; | m_iBufferPos--; | ||||
if (iswpunct(m_Caption[m_iBufferPos])) | if (iswpunct(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
} | } | ||||
// [2] Then the right | // [2] Then the right | ||||
// go right until we are not in whitespace | // go right until we are not in whitespace | ||||
while (++m_iBufferPos_Tail < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos_Tail < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (!iswspace(m_Caption[m_iBufferPos_Tail])) | if (!iswspace(m_Caption.Get()[m_iBufferPos_Tail])) | ||||
break; | break; | ||||
} | } | ||||
if (m_iBufferPos_Tail == static_cast<int>(m_Caption.length())) | if (m_iBufferPos_Tail == static_cast<int>(m_Caption->length())) | ||||
break; | break; | ||||
// now go to the right until we hit whitespace or punctuation | // now go to the right until we hit whitespace or punctuation | ||||
while (++m_iBufferPos_Tail < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos_Tail < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos_Tail]) || iswpunct(m_Caption[m_iBufferPos_Tail])) | if (iswspace(m_Caption.Get()[m_iBufferPos_Tail]) || iswpunct(m_Caption.Get()[m_iBufferPos_Tail])) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// single whitespace so select word to the right | // single whitespace so select word to the right | ||||
while (++m_iBufferPos_Tail < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos_Tail < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (!iswspace(m_Caption[m_iBufferPos_Tail])) | if (!iswspace(m_Caption.Get()[m_iBufferPos_Tail])) | ||||
break; | break; | ||||
} | } | ||||
if (m_iBufferPos_Tail == static_cast<int>(m_Caption.length())) | if (m_iBufferPos_Tail == static_cast<int>(m_Caption->length())) | ||||
break; | break; | ||||
// Don't include the leading whitespace | // Don't include the leading whitespace | ||||
m_iBufferPos = m_iBufferPos_Tail; | m_iBufferPos = m_iBufferPos_Tail; | ||||
// now go to the right until we hit whitespace or punctuation | // now go to the right until we hit whitespace or punctuation | ||||
while (++m_iBufferPos_Tail < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos_Tail < static_cast<int>(m_Caption->length())) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos_Tail]) || iswpunct(m_Caption[m_iBufferPos_Tail])) | if (iswspace(m_Caption.Get()[m_iBufferPos_Tail]) || iswpunct(m_Caption.Get()[m_iBufferPos_Tail])) | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// clicked on non-whitespace so select current word | // clicked on non-whitespace so select current word | ||||
// go until we hit white space or punctuation | // go until we hit white space or punctuation | ||||
while (m_iBufferPos > 0) | while (m_iBufferPos > 0) | ||||
{ | { | ||||
if (iswspace(m_Caption[m_iBufferPos - 1])) | if (iswspace(m_Caption.Get()[m_iBufferPos - 1])) | ||||
break; | break; | ||||
m_iBufferPos--; | m_iBufferPos--; | ||||
if (iswpunct(m_Caption[m_iBufferPos])) | if (iswpunct(m_Caption.Get()[m_iBufferPos])) | ||||
break; | break; | ||||
} | } | ||||
// go to the right until we hit whitespace or punctuation | // go to the right until we hit whitespace or punctuation | ||||
while (++m_iBufferPos_Tail < static_cast<int>(m_Caption.length())) | while (++m_iBufferPos_Tail < static_cast<int>(m_Caption->length())) | ||||
if (iswspace(m_Caption[m_iBufferPos_Tail]) || iswpunct(m_Caption[m_iBufferPos_Tail])) | if (iswspace(m_Caption.Get()[m_iBufferPos_Tail]) || iswpunct(m_Caption.Get()[m_iBufferPos_Tail])) | ||||
break; | break; | ||||
} | } | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_RELEASE_LEFT: | case GUIM_MOUSE_RELEASE_LEFT: | ||||
{ | { | ||||
if (m_SelectingText) | if (m_SelectingText) | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | void CInput::Draw() | ||||
else | else | ||||
// should always be visible | // should always be visible | ||||
m_CursorVisState = true; | m_CursorVisState = true; | ||||
// First call draw on ScrollBarOwner | // First call draw on ScrollBarOwner | ||||
if (m_ScrollBar && m_MultiLine) | if (m_ScrollBar && m_MultiLine) | ||||
IGUIScrollBarOwner::Draw(); | IGUIScrollBarOwner::Draw(); | ||||
CStrIntern font_name(m_Font.ToUTF8()); | CStrIntern font_name(m_Font->ToUTF8()); | ||||
wchar_t mask_char = L'*'; | wchar_t mask_char = L'*'; | ||||
if (m_Mask && m_MaskChar.length() > 0) | if (m_Mask && m_MaskChar->length() > 0) | ||||
mask_char = m_MaskChar[0]; | mask_char = m_MaskChar.Get()[0]; | ||||
m_pGUI.DrawSprite(m_Sprite, bz, m_CachedActualSize); | m_pGUI.DrawSprite(m_Sprite, bz, m_CachedActualSize); | ||||
float scroll = 0.f; | float scroll = 0.f; | ||||
if (m_ScrollBar && m_MultiLine) | if (m_ScrollBar && m_MultiLine) | ||||
scroll = GetScrollBar(0).GetPos(); | scroll = GetScrollBar(0).GetPos(); | ||||
CFontMetrics font(font_name); | CFontMetrics font(font_name); | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | for (std::list<SRow>::const_iterator it = m_CharacterPositions.begin(); | ||||
} | } | ||||
m_pGUI.DrawSprite(m_SpriteSelectArea, bz + 0.05f, rect); | m_pGUI.DrawSprite(m_SpriteSelectArea, bz + 0.05f, rect); | ||||
} | } | ||||
if (i < (int)it->m_ListOfX.size()) | if (i < (int)it->m_ListOfX.size()) | ||||
{ | { | ||||
if (!m_Mask) | if (!m_Mask) | ||||
x_pointer += font.GetCharacterWidth(m_Caption[it->m_ListStart + i]); | x_pointer += font.GetCharacterWidth(m_Caption.Get()[it->m_ListStart + i]); | ||||
else | else | ||||
x_pointer += font.GetCharacterWidth(mask_char); | x_pointer += font.GetCharacterWidth(mask_char); | ||||
} | } | ||||
} | } | ||||
if (done) | if (done) | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | if (buffered_y + m_BufferZone >= -ls || !m_MultiLine) | ||||
{ | { | ||||
using_selected_color = true; | using_selected_color = true; | ||||
textRenderer.Color(m_TextColorSelected); | textRenderer.Color(m_TextColorSelected); | ||||
} | } | ||||
if (i != (int)it->m_ListOfX.size()) | if (i != (int)it->m_ListOfX.size()) | ||||
{ | { | ||||
if (!m_Mask) | if (!m_Mask) | ||||
textRenderer.PrintfAdvance(L"%lc", m_Caption[it->m_ListStart + i]); | textRenderer.PrintfAdvance(L"%lc", m_Caption.Get()[it->m_ListStart + i]); | ||||
else | else | ||||
textRenderer.PrintfAdvance(L"%lc", mask_char); | textRenderer.PrintfAdvance(L"%lc", mask_char); | ||||
} | } | ||||
// check it's now outside a one-liner, then we'll break | // check it's now outside a one-liner, then we'll break | ||||
if (!m_MultiLine && i < (int)it->m_ListOfX.size() && | if (!m_MultiLine && i < (int)it->m_ListOfX.size() && | ||||
it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth() - m_BufferZone) | it->m_ListOfX[i] - m_HorizontalScroll > m_CachedActualSize.GetWidth() - m_BufferZone) | ||||
break; | break; | ||||
Show All 17 Lines | void CInput::Draw() | ||||
textRenderer.Render(); | textRenderer.Render(); | ||||
if (cliparea != CRect()) | if (cliparea != CRect()) | ||||
glDisable(GL_SCISSOR_TEST); | glDisable(GL_SCISSOR_TEST); | ||||
tech->EndPass(); | tech->EndPass(); | ||||
if (m_Caption.empty() && !m_PlaceholderText.GetRawString().empty()) | if (m_Caption->empty() && !m_PlaceholderText->GetRawString().empty()) | ||||
DrawPlaceholderText(bz, cliparea); | DrawPlaceholderText(bz, cliparea); | ||||
} | } | ||||
void CInput::DrawPlaceholderText(float z, const CRect& clipping) | void CInput::DrawPlaceholderText(float z, const CRect& clipping) | ||||
{ | { | ||||
if (!m_GeneratedPlaceholderTextValid) | if (!m_GeneratedPlaceholderTextValid) | ||||
SetupGeneratedPlaceholderText(); | SetupGeneratedPlaceholderText(); | ||||
m_GeneratedPlaceholderText.Draw(m_pGUI, m_PlaceholderColor, m_CachedActualSize.TopLeft(), z, clipping); | m_GeneratedPlaceholderText.Draw(m_pGUI, m_PlaceholderColor, m_CachedActualSize.TopLeft(), z, clipping); | ||||
} | } | ||||
void CInput::UpdateText(int from, int to_before, int to_after) | void CInput::UpdateText(int from, int to_before, int to_after) | ||||
{ | { | ||||
if (m_MaxLength != 0 && m_Caption.length() > static_cast<size_t>(m_MaxLength)) | if (m_MaxLength != 0 && m_Caption->length() > static_cast<size_t>(m_MaxLength)) | ||||
m_Caption = m_Caption.substr(0, m_MaxLength); | m_Caption.Get() = m_Caption->substr(0, m_MaxLength); | ||||
CStrIntern font_name(m_Font.ToUTF8()); | CStrIntern font_name(m_Font->ToUTF8()); | ||||
wchar_t mask_char = L'*'; | wchar_t mask_char = L'*'; | ||||
if (m_Mask && m_MaskChar.length() > 0) | if (m_Mask && m_MaskChar->length() > 0) | ||||
mask_char = m_MaskChar[0]; | mask_char = m_MaskChar.Get()[0]; | ||||
// Ensure positions are valid after caption changes | // Ensure positions are valid after caption changes | ||||
m_iBufferPos = std::min(m_iBufferPos, static_cast<int>(m_Caption.size())); | m_iBufferPos = std::min(m_iBufferPos, static_cast<int>(m_Caption->size())); | ||||
m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, static_cast<int>(m_Caption.size())); | m_iBufferPos_Tail = std::min(m_iBufferPos_Tail, static_cast<int>(m_Caption->size())); | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
if (font_name.empty()) | if (font_name.empty()) | ||||
{ | { | ||||
// Destroy everything stored, there's no font, so there can be no data. | // Destroy everything stored, there's no font, so there can be no data. | ||||
m_CharacterPositions.clear(); | m_CharacterPositions.clear(); | ||||
return; | return; | ||||
} | } | ||||
SRow row; | SRow row; | ||||
row.m_ListStart = 0; | row.m_ListStart = 0; | ||||
int to = 0; // make sure it's initialized | int to = 0; // make sure it's initialized | ||||
if (to_before == -1) | if (to_before == -1) | ||||
to = static_cast<int>(m_Caption.length()); | to = static_cast<int>(m_Caption->length()); | ||||
CFontMetrics font(font_name); | CFontMetrics font(font_name); | ||||
std::list<SRow>::iterator current_line; | std::list<SRow>::iterator current_line; | ||||
// Used to ... TODO | // Used to ... TODO | ||||
int check_point_row_start = -1; | int check_point_row_start = -1; | ||||
int check_point_row_end = -1; | int check_point_row_end = -1; | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | else | ||||
// set 'from' to the row we'll destroy from | // set 'from' to the row we'll destroy from | ||||
// and 'to' to the row we'll destroy to | // and 'to' to the row we'll destroy to | ||||
from = destroy_row_from->m_ListStart; | from = destroy_row_from->m_ListStart; | ||||
if (destroy_row_to != m_CharacterPositions.end()) | if (destroy_row_to != m_CharacterPositions.end()) | ||||
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to. | to = destroy_row_to->m_ListStart; // notice it will iterate [from, to), so it will never reach to. | ||||
else | else | ||||
to = static_cast<int>(m_Caption.length()); | to = static_cast<int>(m_Caption->length()); | ||||
// Setup the first row | // Setup the first row | ||||
row.m_ListStart = destroy_row_from->m_ListStart; | row.m_ListStart = destroy_row_from->m_ListStart; | ||||
std::list<SRow>::iterator temp_it = destroy_row_to; | std::list<SRow>::iterator temp_it = destroy_row_to; | ||||
--temp_it; | --temp_it; | ||||
Show All 10 Lines | if (delta != 0) | ||||
it != m_CharacterPositions.end(); | it != m_CharacterPositions.end(); | ||||
++it) | ++it) | ||||
it->m_ListStart += delta; | it->m_ListStart += delta; | ||||
// Update our check point too! | // Update our check point too! | ||||
check_point_row_start += delta; | check_point_row_start += delta; | ||||
check_point_row_end += delta; | check_point_row_end += delta; | ||||
if (to != static_cast<int>(m_Caption.length())) | if (to != static_cast<int>(m_Caption->length())) | ||||
to += delta; | to += delta; | ||||
} | } | ||||
} | } | ||||
int last_word_started = from; | int last_word_started = from; | ||||
float x_pos = 0.f; | float x_pos = 0.f; | ||||
//if (to_before != -1) | //if (to_before != -1) | ||||
// return; | // return; | ||||
for (int i = from; i < to; ++i) | for (int i = from; i < to; ++i) | ||||
{ | { | ||||
if (m_Caption[i] == L'\n' && m_MultiLine) | if (m_Caption.Get()[i] == L'\n' && m_MultiLine) | ||||
{ | { | ||||
if (i == to-1 && to != static_cast<int>(m_Caption.length())) | if (i == to-1 && to != static_cast<int>(m_Caption->length())) | ||||
break; // it will be added outside | break; // it will be added outside | ||||
current_line = m_CharacterPositions.insert(current_line, row); | current_line = m_CharacterPositions.insert(current_line, row); | ||||
++current_line; | ++current_line; | ||||
// Setup the next row: | // Setup the next row: | ||||
row.m_ListOfX.clear(); | row.m_ListOfX.clear(); | ||||
row.m_ListStart = i+1; | row.m_ListStart = i+1; | ||||
x_pos = 0.f; | x_pos = 0.f; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (m_Caption[i] == L' '/* || TODO Gee (2004-10-13): the '-' disappears, fix. | if (m_Caption.Get()[i] == L' '/* || TODO Gee (2004-10-13): the '-' disappears, fix. | ||||
m_Caption[i] == L'-'*/) | m_Caption.Get()[i] == L'-'*/) | ||||
last_word_started = i+1; | last_word_started = i+1; | ||||
if (!m_Mask) | if (!m_Mask) | ||||
x_pos += font.GetCharacterWidth(m_Caption[i]); | x_pos += font.GetCharacterWidth(m_Caption.Get()[i]); | ||||
else | else | ||||
x_pos += font.GetCharacterWidth(mask_char); | x_pos += font.GetCharacterWidth(mask_char); | ||||
if (x_pos >= GetTextAreaWidth() && m_MultiLine) | if (x_pos >= GetTextAreaWidth() && m_MultiLine) | ||||
{ | { | ||||
// The following decides whether it will word-wrap a word, | // The following decides whether it will word-wrap a word, | ||||
// or if it's only one word on the line, where it has to | // or if it's only one word on the line, where it has to | ||||
// break the word apart. | // break the word apart. | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | if (to_before != -1 && i == to-1 && current_line != m_CharacterPositions.end()) | ||||
{ | { | ||||
destroy_row_to = m_CharacterPositions.end(); | destroy_row_to = m_CharacterPositions.end(); | ||||
check_point_row_start = check_point_row_end = -1; | check_point_row_start = check_point_row_end = -1; | ||||
} | } | ||||
if (destroy_row_to != m_CharacterPositions.end()) | if (destroy_row_to != m_CharacterPositions.end()) | ||||
to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to. | to = destroy_row_to->m_ListStart; // notice it will iterate [from, to[, so it will never reach to. | ||||
else | else | ||||
to = static_cast<int>(m_Caption.length()); | to = static_cast<int>(m_Caption->length()); | ||||
// Set current line, new rows will be added before current_line, so | // Set current line, new rows will be added before current_line, so | ||||
// we'll choose the destroy_row_to, because it won't be deleted | // we'll choose the destroy_row_to, because it won't be deleted | ||||
// in the coming erase. | // in the coming erase. | ||||
current_line = destroy_row_to; | current_line = destroy_row_to; | ||||
m_CharacterPositions.erase(destroy_row_from, destroy_row_to); | m_CharacterPositions.erase(destroy_row_from, destroy_row_to); | ||||
Show All 36 Lines | int CInput::GetMouseHoveringTextPosition() const | ||||
if (m_MultiLine) | if (m_MultiLine) | ||||
{ | { | ||||
float scroll = 0.f; | float scroll = 0.f; | ||||
if (m_ScrollBar) | if (m_ScrollBar) | ||||
scroll = GetScrollBarPos(0); | scroll = GetScrollBarPos(0); | ||||
// Now get the height of the font. | // Now get the height of the font. | ||||
// TODO: Get the real font | // TODO: Get the real font | ||||
CFontMetrics font(CStrIntern(m_Font.ToUTF8())); | CFontMetrics font(CStrIntern(m_Font->ToUTF8())); | ||||
float spacing = (float)font.GetLineSpacing(); | float spacing = (float)font.GetLineSpacing(); | ||||
// Change mouse position relative to text. | // Change mouse position relative to text. | ||||
mouse -= m_CachedActualSize.TopLeft(); | mouse -= m_CachedActualSize.TopLeft(); | ||||
mouse.X -= m_BufferZone; | mouse.X -= m_BufferZone; | ||||
mouse.Y += scroll - m_BufferZone; | mouse.Y += scroll - m_BufferZone; | ||||
int row = (int)((mouse.Y) / spacing); | int row = (int)((mouse.Y) / spacing); | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | if (m_iBufferPos_Tail >= m_iBufferPos) | ||||
virtualTo = m_iBufferPos_Tail; | virtualTo = m_iBufferPos_Tail; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
virtualFrom = m_iBufferPos_Tail; | virtualFrom = m_iBufferPos_Tail; | ||||
virtualTo = m_iBufferPos; | virtualTo = m_iBufferPos; | ||||
} | } | ||||
m_Caption = | m_Caption.Get() = | ||||
m_Caption.Left(virtualFrom) + | m_Caption->Left(virtualFrom) + | ||||
m_Caption.Right(static_cast<long>(m_Caption.length()) - virtualTo); | m_Caption->Right(static_cast<long>(m_Caption->length()) - virtualTo); | ||||
UpdateText(virtualFrom, virtualTo, virtualFrom); | UpdateText(virtualFrom, virtualTo, virtualFrom); | ||||
// Remove selection | // Remove selection | ||||
m_iBufferPos_Tail = -1; | m_iBufferPos_Tail = -1; | ||||
m_iBufferPos = virtualFrom; | m_iBufferPos = virtualFrom; | ||||
UpdateBufferPositionSetting(); | UpdateBufferPositionSetting(); | ||||
} | } | ||||
Show All 19 Lines | void CInput::UpdateAutoScroll() | ||||
{ | { | ||||
if (!m_ScrollBar) | if (!m_ScrollBar) | ||||
return; | return; | ||||
const float scroll = GetScrollBar(0).GetPos(); | const float scroll = GetScrollBar(0).GetPos(); | ||||
// Now get the height of the font. | // Now get the height of the font. | ||||
// TODO: Get the real font | // TODO: Get the real font | ||||
CFontMetrics font(CStrIntern(m_Font.ToUTF8())); | CFontMetrics font(CStrIntern(m_Font->ToUTF8())); | ||||
float spacing = (float)font.GetLineSpacing(); | float spacing = (float)font.GetLineSpacing(); | ||||
//float height = font.GetHeight(); | //float height = font.GetHeight(); | ||||
// TODO Gee (2004-11-21): Okay, I need a 'std::list' for some reasons, but I would really like to | // TODO Gee (2004-11-21): Okay, I need a 'std::list' for some reasons, but I would really like to | ||||
// be able to get the specific element here. This is hopefully a temporary hack. | // be able to get the specific element here. This is hopefully a temporary hack. | ||||
std::list<SRow>::iterator current = m_CharacterPositions.begin(); | std::list<SRow>::iterator current = m_CharacterPositions.begin(); | ||||
int row = 0; | int row = 0; | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator