From 7b37039fedffb73006cdd05b59fd7da2ae84c018 Mon Sep 17 00:00:00 2001 From: Lendemor Date: Sun, 3 Jun 2018 22:33:39 +0200 Subject: [PATCH] fix bug from issue #16: input text not retracting in shell --- src/scene/gui/textinputnode.cpp | 151 ++++++++++++++++---------------- 1 file changed, 76 insertions(+), 75 deletions(-) diff --git a/src/scene/gui/textinputnode.cpp b/src/scene/gui/textinputnode.cpp index dd6f0ae..9be729f 100644 --- a/src/scene/gui/textinputnode.cpp +++ b/src/scene/gui/textinputnode.cpp @@ -41,98 +41,99 @@ TextInputNode::TextInputNode(glm::vec2 dimension): void TextInputNode::update() { - if(!m_hasFocus) return; + if(m_hasFocus) + { - std::wstring text = getEngine().getInput()->getText(); + std::wstring text = getEngine().getInput()->getText(); - auto input = getEngine().getInput(); - for(auto action : input->getActions()){ - if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){ - if (m_cursor_pos > 0){ - m_cursor_pos--; - m_cursor_pos_updated=true; - } - } - else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){ - if(m_cursor_pos < m_text.length()){ - m_cursor_pos++; - m_cursor_pos_updated=true; - } - } - else if(action.action == m_inputActions[HISTORY_PREVIOUS]){ - if(m_history_pos > 0) - { - m_history_pos--; - m_text = m_history[m_history_pos]; - m_cursor_pos = m_text.size(); - m_text_updated = true; - m_cursor_pos_updated = true; - } - } - else if(action.action == m_inputActions[HISTORY_NEXT]){ - if (m_history_pos < m_history.size()) - { - m_history_pos++; - if (m_history_pos == m_history.size()) - { - m_text.clear(); - m_cursor_pos = 0; + auto input = getEngine().getInput(); + for(auto action : input->getActions()){ + if (action.action == m_inputActions[MOVE_CURSOR_LEFT]){ + if (m_cursor_pos > 0){ + m_cursor_pos--; + m_cursor_pos_updated=true; } - else + } + else if(action.action == m_inputActions[MOVE_CURSOR_RIGHT]){ + if(m_cursor_pos < m_text.length()){ + m_cursor_pos++; + m_cursor_pos_updated=true; + } + } + else if(action.action == m_inputActions[HISTORY_PREVIOUS]){ + if(m_history_pos > 0) { + m_history_pos--; m_text = m_history[m_history_pos]; m_cursor_pos = m_text.size(); + m_text_updated = true; + m_cursor_pos_updated = true; + } + } + else if(action.action == m_inputActions[HISTORY_NEXT]){ + if (m_history_pos < m_history.size()) + { + m_history_pos++; + if (m_history_pos == m_history.size()) + { + m_text.clear(); + m_cursor_pos = 0; + } + else + { + m_text = m_history[m_history_pos]; + m_cursor_pos = m_text.size(); + } + m_text_updated = true; + m_cursor_pos_updated = true; } - m_text_updated = true; - m_cursor_pos_updated = true; } } - } - for(unsigned int i = 0 ; i < text.length() ; i++){ - char c = text[i]; - switch(c){ - case 8: - if(m_cursor_pos > 0) - m_text.erase(--m_cursor_pos,1); - m_text_updated = true; - m_cursor_pos_updated=true; - break; - case 13: - if (!m_text.empty()) - { - if(m_callback) - m_callback->exec(); + for(unsigned int i = 0 ; i < text.length() ; i++){ + char c = text[i]; + switch(c){ + case 8: + if(m_cursor_pos > 0) + m_text.erase(--m_cursor_pos,1); m_text_updated = true; - m_cursor_pos = 0; m_cursor_pos_updated=true; - } - break; - case 9: - if (!m_text.empty()) - { - if(m_tab_callback) - m_tab_callback->exec(); + break; + case 13: + if (!m_text.empty()) + { + if(m_callback) + m_callback->exec(); + m_text_updated = true; + m_cursor_pos = 0; + m_cursor_pos_updated=true; + } + break; + case 9: + if (!m_text.empty()) + { + if(m_tab_callback) + m_tab_callback->exec(); + m_text_updated = true; + m_cursor_pos_updated=true; + } + break; + case 127: + m_text.erase(m_cursor_pos,1); + m_text_updated = true; + break; + default: + m_text.insert(m_cursor_pos++,std::string(1,c)); m_text_updated = true; m_cursor_pos_updated=true; } - break; - case 127: - m_text.erase(m_cursor_pos,1); - m_text_updated = true; - break; - default: - m_text.insert(m_cursor_pos++,std::string(1,c)); - m_text_updated = true; - m_cursor_pos_updated=true; } + if(m_cursor_pos_updated) + updateCursorMesh(); + + if(m_text_updated) + updateTextMesh(); } - if(m_cursor_pos_updated) - updateCursorMesh(); - - if(m_text_updated) - updateTextMesh(); - GUINode::update(); }