Text selection in chat
* Remove fancy stuff from background * Improve text windows * More improvements to textedit
This commit is contained in:
parent
84dfd4f7f3
commit
c28596292f
|
@ -9,68 +9,6 @@ Panel
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin-top: 1
|
margin-top: 1
|
||||||
focusable: false
|
focusable: false
|
||||||
@onSetup: |
|
|
||||||
scheduleEvent(function()
|
|
||||||
local count = 0
|
|
||||||
cycleEvent(function()
|
|
||||||
if count > 360 then return end
|
|
||||||
self:setRotation(count)
|
|
||||||
count = count + 5
|
|
||||||
end, 10)
|
|
||||||
end, 10)
|
|
||||||
|
|
||||||
UIParticles
|
|
||||||
anchors.fill: parent
|
|
||||||
effect: background-effect
|
|
||||||
reference-pos: 0.5 0.25
|
|
||||||
|
|
||||||
Label
|
|
||||||
text: :O Just For Fun LOL ^.^
|
|
||||||
font: sans-bold-16px
|
|
||||||
color: black
|
|
||||||
background: #ffffff60
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
margin-left: 10
|
|
||||||
margin-top: 40
|
|
||||||
height: 24
|
|
||||||
rotation: -15
|
|
||||||
@onSetup: |
|
|
||||||
local count = 0
|
|
||||||
cycleEvent(function()
|
|
||||||
local text = ':O Just For Fun LOL ^.^'
|
|
||||||
self:setText(string.sub(text, 0, count))
|
|
||||||
if count > #text + 10 then count = 0 end
|
|
||||||
count = count + 1
|
|
||||||
end, 100)
|
|
||||||
|
|
||||||
Label
|
|
||||||
text: PLEASE REMOVE THAT SHIT!
|
|
||||||
font: sans-bold-16px
|
|
||||||
color: black
|
|
||||||
background: #ffffff60
|
|
||||||
anchors.bottom: parent.bottom
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
margin-left: 10
|
|
||||||
margin-bottom: 40
|
|
||||||
height: 24
|
|
||||||
rotation: 15
|
|
||||||
visible: false
|
|
||||||
@onSetup: scheduleEvent(function() self:show() end, 4000)
|
|
||||||
|
|
||||||
Label
|
|
||||||
text: WTF IS WRONG WITH THIS BACKGROUND?
|
|
||||||
font: sans-bold-16px
|
|
||||||
color: pink
|
|
||||||
background: #ffffff99
|
|
||||||
anchors.top: parent.top
|
|
||||||
anchors.right: parent.right
|
|
||||||
margin-left: 10
|
|
||||||
margin-top: 80
|
|
||||||
height: 24
|
|
||||||
rotation: 10
|
|
||||||
visible: false
|
|
||||||
@onSetup: scheduleEvent(function() self:show() end, 8000)
|
|
||||||
|
|
||||||
UILabel
|
UILabel
|
||||||
id: clientVersionLabel
|
id: clientVersionLabel
|
||||||
|
|
|
@ -87,6 +87,22 @@ function init()
|
||||||
consoleTabBar:setTabSpacing(-1)
|
consoleTabBar:setTabSpacing(-1)
|
||||||
channels = {}
|
channels = {}
|
||||||
|
|
||||||
|
consolePanel.onKeyPress = function(self, keyCode, keyboardModifiers)
|
||||||
|
if not (keyboardModifiers == KeyboardCtrlModifier and keyCode == KeyC) then return false end
|
||||||
|
|
||||||
|
local tab = consoleTabBar:getCurrentTab()
|
||||||
|
if not tab then return false end
|
||||||
|
|
||||||
|
local consoleBuffer = tab.tabPanel:getChildById('consoleBuffer')
|
||||||
|
if not consoleBuffer then return false end
|
||||||
|
|
||||||
|
local consoleLabel = consoleBuffer:getFocusedChild()
|
||||||
|
if not consoleLabel or not consoleLabel:hasSelection() then return false end
|
||||||
|
|
||||||
|
g_window.setClipboardText(consoleLabel:getSelection())
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
defaultTab = addTab(tr('Default'), true)
|
defaultTab = addTab(tr('Default'), true)
|
||||||
serverTab = addTab(tr('Server Log'), false)
|
serverTab = addTab(tr('Server Log'), false)
|
||||||
|
|
||||||
|
@ -355,16 +371,16 @@ function addTabText(text, speaktype, tab, creatureName)
|
||||||
local panel = consoleTabBar:getTabPanel(tab)
|
local panel = consoleTabBar:getTabPanel(tab)
|
||||||
local consoleBuffer = panel:getChildById('consoleBuffer')
|
local consoleBuffer = panel:getChildById('consoleBuffer')
|
||||||
local label = g_ui.createWidget('ConsoleLabel', consoleBuffer)
|
local label = g_ui.createWidget('ConsoleLabel', consoleBuffer)
|
||||||
label:setId('consoleLabel' .. panel:getChildCount())
|
label:setId('consoleLabel' .. consoleBuffer:getChildCount())
|
||||||
label:setText(text)
|
label:setText(text)
|
||||||
label:setColor(speaktype.color)
|
label:setColor(speaktype.color)
|
||||||
consoleTabBar:blinkTab(tab)
|
consoleTabBar:blinkTab(tab)
|
||||||
|
|
||||||
-- Overlay for consoleBuffer which shows highlighted words only
|
-- Overlay for consoleBuffer which shows highlighted words only
|
||||||
local consoleBufferHighlight = panel:getChildById('consoleBufferHighlight')
|
local consoleBufferHighlight = panel:getChildById('consoleBufferHighlight')
|
||||||
local labelHighlight = g_ui.createWidget('ConsoleLabel', consoleBufferHighlight)
|
local labelHighlight = g_ui.createWidget('ConsolePhantomLabel', consoleBufferHighlight)
|
||||||
|
|
||||||
labelHighlight:setId('consoleLabel' .. panel:getChildCount())
|
labelHighlight:setId('consoleLabel' .. consoleBufferHighlight:getChildCount())
|
||||||
labelHighlight:setColor("#1f9ffe")
|
labelHighlight:setColor("#1f9ffe")
|
||||||
|
|
||||||
local player = g_game.getLocalPlayer()
|
local player = g_game.getLocalPlayer()
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
ConsoleLabel < UILabel
|
ConsoleLabel < UITextEdit
|
||||||
font: verdana-11px-antialised
|
font: verdana-11px-antialised
|
||||||
height: 14
|
height: 14
|
||||||
color: yellow
|
color: yellow
|
||||||
margin-left: 2
|
margin-left: 2
|
||||||
text-wrap: true
|
text-wrap: true
|
||||||
text-auto-resize: true
|
text-auto-resize: true
|
||||||
|
selection-color: #111416
|
||||||
|
selection-background-color: #999999
|
||||||
|
|
||||||
|
ConsolePhantomLabel < UILabel
|
||||||
|
font: verdana-11px-antialised
|
||||||
|
height: 14
|
||||||
|
color: yellow
|
||||||
|
margin-left: 2
|
||||||
|
text-wrap: true
|
||||||
|
text-auto-resize: true
|
||||||
|
selection-color: #111416
|
||||||
|
selection-background-color: #999999
|
||||||
|
|
||||||
ConsoleTabBar < TabBar
|
ConsoleTabBar < TabBar
|
||||||
ConsoleTabBarPanel < TabBarPanel
|
ConsoleTabBarPanel < TabBarPanel
|
||||||
|
@ -168,3 +180,4 @@ Panel
|
||||||
margin-left: 6
|
margin-left: 6
|
||||||
margin-bottom: 6
|
margin-bottom: 6
|
||||||
shift-navigation: true
|
shift-navigation: true
|
||||||
|
max-length: 255
|
||||||
|
|
|
@ -40,7 +40,6 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
textEdit:setText(text)
|
textEdit:setText(text)
|
||||||
textEdit:setEditable(writeable)
|
textEdit:setEditable(writeable)
|
||||||
textEdit:setCursorVisible(writeable)
|
textEdit:setCursorVisible(writeable)
|
||||||
textEdit:wrapText()
|
|
||||||
|
|
||||||
local desc = ''
|
local desc = ''
|
||||||
if #writter > 0 then
|
if #writter > 0 then
|
||||||
|
|
|
@ -25,6 +25,7 @@ TextWindow < MainWindow
|
||||||
anchors.right: textScroll.left
|
anchors.right: textScroll.left
|
||||||
anchors.bottom: textScroll.bottom
|
anchors.bottom: textScroll.bottom
|
||||||
vertical-scrollbar: textScroll
|
vertical-scrollbar: textScroll
|
||||||
|
text-wrap: true
|
||||||
|
|
||||||
VerticalScrollBar
|
VerticalScrollBar
|
||||||
id: textScroll
|
id: textScroll
|
||||||
|
|
|
@ -360,8 +360,6 @@ if(FRAMEWORK_GRAPHICS)
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.h
|
${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.cpp
|
${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.h
|
${CMAKE_CURRENT_LIST_DIR}/ui/uiparticles.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uirichtext.cpp
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uirichtext.h
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.cpp
|
${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.h
|
${CMAKE_CURRENT_LIST_DIR}/ui/uitextedit.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp
|
${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "uirichtext.h"
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef UIRICHTEXT_H
|
|
||||||
#define UIRICHTEXT_H
|
|
||||||
|
|
||||||
#include <framework/ui/uiwidget.h>
|
|
||||||
|
|
||||||
|
|
||||||
class UIRichText : public UIWidget
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // UIRICHTEXT_H
|
|
|
@ -136,6 +136,17 @@ void UITextEdit::update(bool focusCursor)
|
||||||
const Size *glyphsSize = m_font->getGlyphsSize();
|
const Size *glyphsSize = m_font->getGlyphsSize();
|
||||||
int glyph;
|
int glyph;
|
||||||
|
|
||||||
|
// update rect size
|
||||||
|
if(!m_rect.isValid() || m_textAutoResize) {
|
||||||
|
textBoxSize += Size(m_padding.left + m_padding.right, m_padding.top + m_padding.bottom) + m_textOffset.toSize();
|
||||||
|
Size size = getSize();
|
||||||
|
if(size.width() <= 0 || (m_textAutoResize && !m_textWrap))
|
||||||
|
size.setWidth(textBoxSize.width());
|
||||||
|
if(size.height() <= 0 || m_textAutoResize)
|
||||||
|
size.setHeight(textBoxSize.height());
|
||||||
|
setSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
// resize just on demand
|
// resize just on demand
|
||||||
if(textLength > (int)m_glyphsCoords.size()) {
|
if(textLength > (int)m_glyphsCoords.size()) {
|
||||||
m_glyphsCoords.resize(textLength);
|
m_glyphsCoords.resize(textLength);
|
||||||
|
@ -144,6 +155,11 @@ void UITextEdit::update(bool focusCursor)
|
||||||
|
|
||||||
Point oldTextAreaOffset = m_textVirtualOffset;
|
Point oldTextAreaOffset = m_textVirtualOffset;
|
||||||
|
|
||||||
|
if(textBoxSize.width() <= getPaddingRect().width())
|
||||||
|
m_textVirtualOffset.x = 0;
|
||||||
|
if(textBoxSize.height() <= getPaddingRect().height())
|
||||||
|
m_textVirtualOffset.y = 0;
|
||||||
|
|
||||||
// readjust start view area based on cursor position
|
// readjust start view area based on cursor position
|
||||||
m_cursorInRange = false;
|
m_cursorInRange = false;
|
||||||
if(focusCursor) {
|
if(focusCursor) {
|
||||||
|
@ -331,8 +347,6 @@ void UITextEdit::setSelection(int start, int end)
|
||||||
|
|
||||||
m_selectionStart = std::min(std::max(start, 0), (int)m_text.length());
|
m_selectionStart = std::min(std::max(start, 0), (int)m_text.length());
|
||||||
m_selectionEnd = std::min(std::max(end, 0), (int)m_text.length());
|
m_selectionEnd = std::min(std::max(end, 0), (int)m_text.length());
|
||||||
|
|
||||||
onSelectionChange(getSelection(), m_selectionStart, m_selectionEnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITextEdit::setTextHidden(bool hidden)
|
void UITextEdit::setTextHidden(bool hidden)
|
||||||
|
@ -355,8 +369,9 @@ void UITextEdit::appendText(std::string text)
|
||||||
if(m_cursorPos >= 0) {
|
if(m_cursorPos >= 0) {
|
||||||
// replace characters that are now allowed
|
// replace characters that are now allowed
|
||||||
if(!m_multiline)
|
if(!m_multiline)
|
||||||
stdext::replace_all(text, "\n", "");
|
stdext::replace_all(text, "\n", " ");
|
||||||
stdext::replace_all(text, "\r", " ");
|
stdext::replace_all(text, "\r", "");
|
||||||
|
stdext::replace_all(text, "\t", " ");
|
||||||
|
|
||||||
if(text.length() > 0) {
|
if(text.length() > 0) {
|
||||||
// only add text if textedit can add it
|
// only add text if textedit can add it
|
||||||
|
@ -371,10 +386,10 @@ void UITextEdit::appendText(std::string text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string oldText = m_text;
|
std::string tmp = m_text;
|
||||||
m_text.insert(m_cursorPos, text);
|
tmp.insert(m_cursorPos, text);
|
||||||
m_cursorPos += text.length();
|
m_cursorPos += text.length();
|
||||||
onTextChange(m_text, oldText);
|
setText(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -396,26 +411,26 @@ void UITextEdit::appendCharacter(char c)
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
tmp = c;
|
tmp = c;
|
||||||
std::string oldText = m_text;
|
std::string tmp2 = m_text;
|
||||||
m_text.insert(m_cursorPos, tmp);
|
tmp2.insert(m_cursorPos, tmp);
|
||||||
m_cursorPos++;
|
m_cursorPos++;
|
||||||
onTextChange(m_text, oldText);
|
setText(tmp2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITextEdit::removeCharacter(bool right)
|
void UITextEdit::removeCharacter(bool right)
|
||||||
{
|
{
|
||||||
std::string oldText = m_text;
|
std::string tmp = m_text;
|
||||||
if(m_cursorPos >= 0 && m_text.length() > 0) {
|
if(m_cursorPos >= 0 && tmp.length() > 0) {
|
||||||
if((uint)m_cursorPos >= m_text.length()) {
|
if((uint)m_cursorPos >= tmp.length()) {
|
||||||
m_text.erase(m_text.begin() + (--m_cursorPos));
|
tmp.erase(tmp.begin() + (--m_cursorPos));
|
||||||
} else {
|
} else {
|
||||||
if(right)
|
if(right)
|
||||||
m_text.erase(m_text.begin() + m_cursorPos);
|
tmp.erase(tmp.begin() + m_cursorPos);
|
||||||
else if(m_cursorPos > 0)
|
else if(m_cursorPos > 0)
|
||||||
m_text.erase(m_text.begin() + --m_cursorPos);
|
tmp.erase(tmp.begin() + --m_cursorPos);
|
||||||
}
|
}
|
||||||
onTextChange(m_text, oldText);
|
setText(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,12 +443,12 @@ void UITextEdit::blinkCursor()
|
||||||
void UITextEdit::del(bool right)
|
void UITextEdit::del(bool right)
|
||||||
{
|
{
|
||||||
if(hasSelection()) {
|
if(hasSelection()) {
|
||||||
std::string oldText = m_text;
|
std::string tmp = m_text;
|
||||||
m_text.erase(m_selectionStart, m_selectionEnd - m_selectionStart);
|
tmp.erase(m_selectionStart, m_selectionEnd - m_selectionStart);
|
||||||
|
|
||||||
setCursorPos(m_selectionStart);
|
setCursorPos(m_selectionStart);
|
||||||
clearSelection();
|
clearSelection();
|
||||||
onTextChange(m_text, oldText);
|
setText(tmp);
|
||||||
} else
|
} else
|
||||||
removeCharacter(right);
|
removeCharacter(right);
|
||||||
}
|
}
|
||||||
|
@ -494,28 +509,51 @@ int UITextEdit::getTextPos(Point pos)
|
||||||
|
|
||||||
// find any glyph that is actually on the
|
// find any glyph that is actually on the
|
||||||
int candidatePos = -1;
|
int candidatePos = -1;
|
||||||
|
Rect firstGlyphRect, lastGlyphRect;
|
||||||
for(int i=0;i<textLength;++i) {
|
for(int i=0;i<textLength;++i) {
|
||||||
Rect clickGlyphRect = m_glyphsCoords[i];
|
Rect clickGlyphRect = m_glyphsCoords[i];
|
||||||
|
if(!clickGlyphRect.isValid())
|
||||||
|
continue;
|
||||||
|
if(!firstGlyphRect.isValid())
|
||||||
|
firstGlyphRect = clickGlyphRect;
|
||||||
|
lastGlyphRect = clickGlyphRect;
|
||||||
clickGlyphRect.expandTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
|
clickGlyphRect.expandTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
|
||||||
clickGlyphRect.expandLeft(m_font->getGlyphSpacing().width()+1);
|
clickGlyphRect.expandLeft(m_font->getGlyphSpacing().width()+1);
|
||||||
if(clickGlyphRect.contains(pos))
|
if(clickGlyphRect.contains(pos)) {
|
||||||
return i;
|
|
||||||
else if(pos.y >= clickGlyphRect.top() && pos.y <= clickGlyphRect.bottom()) {
|
|
||||||
if(pos.x <= clickGlyphRect.left())
|
|
||||||
candidatePos = i;
|
candidatePos = i;
|
||||||
else if(pos.x >= clickGlyphRect.right())
|
break;
|
||||||
|
}
|
||||||
|
else if(pos.y >= clickGlyphRect.top() && pos.y <= clickGlyphRect.bottom()) {
|
||||||
|
if(pos.x <= clickGlyphRect.left()) {
|
||||||
|
candidatePos = i;
|
||||||
|
break;
|
||||||
|
} else if(pos.x >= clickGlyphRect.right())
|
||||||
candidatePos = i+1;
|
candidatePos = i+1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(textLength > 0) {
|
||||||
|
if(pos.y < firstGlyphRect.top())
|
||||||
|
return 0;
|
||||||
|
else if(pos.y > lastGlyphRect.bottom())
|
||||||
|
return textLength;
|
||||||
|
}
|
||||||
|
|
||||||
return candidatePos;
|
return candidatePos;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UITextEdit::getDisplayedText()
|
std::string UITextEdit::getDisplayedText()
|
||||||
{
|
{
|
||||||
|
std::string text;
|
||||||
if(m_textHidden)
|
if(m_textHidden)
|
||||||
return std::string(m_text.length(), '*');
|
text = std::string(m_text.length(), '*');
|
||||||
else
|
else
|
||||||
return m_text;
|
text = m_text;
|
||||||
|
|
||||||
|
if(m_textWrap && m_rect.isValid())
|
||||||
|
text = m_font->wrapText(text, getWidth() - m_textOffset.x);
|
||||||
|
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UITextEdit::getSelection()
|
std::string UITextEdit::getSelection()
|
||||||
|
@ -525,6 +563,21 @@ std::string UITextEdit::getSelection()
|
||||||
return m_text.substr(m_selectionStart, m_selectionEnd - m_selectionStart);
|
return m_text.substr(m_selectionStart, m_selectionEnd - m_selectionStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UITextEdit::updateText()
|
||||||
|
{
|
||||||
|
if(m_cursorPos > (int)m_text.length())
|
||||||
|
m_cursorPos = m_text.length();
|
||||||
|
|
||||||
|
// any text changes reset the selection
|
||||||
|
if(m_selectable) {
|
||||||
|
m_selectionEnd = 0;
|
||||||
|
m_selectionStart = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
blinkCursor();
|
||||||
|
update(true);
|
||||||
|
}
|
||||||
|
|
||||||
void UITextEdit::onHoverChange(bool hovered)
|
void UITextEdit::onHoverChange(bool hovered)
|
||||||
{
|
{
|
||||||
if(hovered)
|
if(hovered)
|
||||||
|
@ -533,29 +586,6 @@ void UITextEdit::onHoverChange(bool hovered)
|
||||||
g_mouse.restoreCursor();
|
g_mouse.restoreCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITextEdit::onTextChange(const std::string& text, const std::string& oldText)
|
|
||||||
{
|
|
||||||
if(m_cursorPos > (int)text.length())
|
|
||||||
m_cursorPos = text.length();
|
|
||||||
|
|
||||||
// any text changes reset the selection
|
|
||||||
if(m_selectable) {
|
|
||||||
m_selectionEnd = 0;
|
|
||||||
m_selectionStart = 0;
|
|
||||||
onSelectionChange(std::string(), 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
blinkCursor();
|
|
||||||
update(true);
|
|
||||||
UIWidget::onTextChange(text, oldText);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UITextEdit::onFontChange(const std::string& font)
|
|
||||||
{
|
|
||||||
update(true);
|
|
||||||
UIWidget::onFontChange(font);
|
|
||||||
}
|
|
||||||
|
|
||||||
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||||
{
|
{
|
||||||
UIWidget::onStyleApply(styleName, styleNode);
|
UIWidget::onStyleApply(styleName, styleNode);
|
||||||
|
@ -615,11 +645,15 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
|
||||||
|
|
||||||
if(keyboardModifiers == Fw::KeyboardNoModifier) {
|
if(keyboardModifiers == Fw::KeyboardNoModifier) {
|
||||||
if(keyCode == Fw::KeyDelete && m_editable) { // erase right character
|
if(keyCode == Fw::KeyDelete && m_editable) { // erase right character
|
||||||
|
if(hasSelection() || !m_text.empty()) {
|
||||||
del(true);
|
del(true);
|
||||||
return true;
|
return true;
|
||||||
} else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character {
|
}
|
||||||
|
} else if(keyCode == Fw::KeyBackspace && m_editable) { // erase left character
|
||||||
|
if(hasSelection() || !m_text.empty()) {
|
||||||
del(false);
|
del(false);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
|
} else if(keyCode == Fw::KeyRight && !m_shiftNavigation) { // move cursor right
|
||||||
clearSelection();
|
clearSelection();
|
||||||
moveCursorHorizontally(true);
|
moveCursorHorizontally(true);
|
||||||
|
@ -629,13 +663,17 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
|
||||||
moveCursorHorizontally(false);
|
moveCursorHorizontally(false);
|
||||||
return true;
|
return true;
|
||||||
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
|
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
|
||||||
|
if(m_cursorPos != 0) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
setCursorPos(0);
|
setCursorPos(0);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
|
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
|
||||||
|
if(m_cursorPos != (int)m_text.length()) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
setCursorPos(m_text.length());
|
setCursorPos(m_text.length());
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
|
} else if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
if(UIWidgetPtr parent = getParent())
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
@ -656,15 +694,21 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
|
||||||
paste(g_window.getClipboardText());
|
paste(g_window.getClipboardText());
|
||||||
return true;
|
return true;
|
||||||
} else if(keyCode == Fw::KeyX && m_editable && m_selectable) {
|
} else if(keyCode == Fw::KeyX && m_editable && m_selectable) {
|
||||||
|
if(hasSelection()) {
|
||||||
cut();
|
cut();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else if(keyCode == Fw::KeyC && m_selectable) {
|
} else if(keyCode == Fw::KeyC && m_selectable) {
|
||||||
|
if(hasSelection()) {
|
||||||
copy();
|
copy();
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else if(keyCode == Fw::KeyA && m_selectable) {
|
} else if(keyCode == Fw::KeyA && m_selectable) {
|
||||||
|
if(m_text.length() > 0) {
|
||||||
selectAll();
|
selectAll();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
|
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
|
||||||
if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
|
if(keyCode == Fw::KeyTab && !m_shiftNavigation) {
|
||||||
if(UIWidgetPtr parent = getParent())
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
@ -708,6 +752,9 @@ bool UITextEdit::onKeyText(const std::string& keyText)
|
||||||
|
|
||||||
bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
{
|
{
|
||||||
|
if(UIWidget::onMousePress(mousePos, button))
|
||||||
|
return true;
|
||||||
|
|
||||||
if(button == Fw::MouseLeftButton) {
|
if(button == Fw::MouseLeftButton) {
|
||||||
int pos = getTextPos(mousePos);
|
int pos = getTextPos(mousePos);
|
||||||
if(pos >= 0) {
|
if(pos >= 0) {
|
||||||
|
@ -720,7 +767,8 @@ bool UITextEdit::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return UIWidget::onMousePress(mousePos, button);
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
bool UITextEdit::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
|
||||||
|
@ -741,13 +789,16 @@ bool UITextEdit::onMouseMove(const Point& mousePos, const Point& mouseMoved)
|
||||||
return UIWidget::onMouseMove(mousePos, mouseMoved);
|
return UIWidget::onMouseMove(mousePos, mouseMoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UITextEdit::onDoubleClick(const Point& mousePos)
|
||||||
|
{
|
||||||
|
if(m_selectable && m_text.length() > 0) {
|
||||||
|
selectAll();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return UIWidget::onDoubleClick(mousePos);
|
||||||
|
}
|
||||||
|
|
||||||
void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize)
|
void UITextEdit::onTextAreaUpdate(const Point& offset, const Size& visibleSize, const Size& totalSize)
|
||||||
{
|
{
|
||||||
callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize);
|
callLuaField("onTextAreaUpdate", offset, visibleSize, totalSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITextEdit::onSelectionChange(const std::string& text, int start, int end)
|
|
||||||
{
|
|
||||||
update(true);
|
|
||||||
callLuaField("onSelectionChange", text, start, end);
|
|
||||||
}
|
|
||||||
|
|
|
@ -88,9 +88,9 @@ public:
|
||||||
bool isSelectable() { return m_selectable; }
|
bool isSelectable() { return m_selectable; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void updateText();
|
||||||
|
|
||||||
virtual void onHoverChange(bool hovered);
|
virtual void onHoverChange(bool hovered);
|
||||||
virtual void onTextChange(const std::string& text, const std::string& oldText);
|
|
||||||
virtual void onFontChange(const std::string& font);
|
|
||||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||||
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
||||||
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
|
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
|
||||||
|
@ -99,8 +99,8 @@ protected:
|
||||||
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
||||||
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
||||||
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
||||||
|
virtual bool onDoubleClick(const Point& mousePos);
|
||||||
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
||||||
virtual void onSelectionChange(const std::string& text, int start, int end);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void disableUpdates() { m_updatesEnabled = false; }
|
void disableUpdates() { m_updatesEnabled = false; }
|
||||||
|
|
|
@ -1513,7 +1513,7 @@ bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
|
||||||
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||||
{
|
{
|
||||||
if(button == Fw::MouseLeftButton) {
|
if(button == Fw::MouseLeftButton) {
|
||||||
if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 500) {
|
if(m_clickTimer.running() && m_clickTimer.ticksElapsed() <= 200) {
|
||||||
if(onDoubleClick(mousePos))
|
if(onDoubleClick(mousePos))
|
||||||
return true;
|
return true;
|
||||||
m_clickTimer.stop();
|
m_clickTimer.stop();
|
||||||
|
|
|
@ -456,7 +456,6 @@ public:
|
||||||
// text related
|
// text related
|
||||||
private:
|
private:
|
||||||
void initText();
|
void initText();
|
||||||
void updateText();
|
|
||||||
void parseTextStyle(const OTMLNodePtr& styleNode);
|
void parseTextStyle(const OTMLNodePtr& styleNode);
|
||||||
|
|
||||||
stdext::boolean<true> m_textMustRecache;
|
stdext::boolean<true> m_textMustRecache;
|
||||||
|
@ -464,6 +463,7 @@ private:
|
||||||
Rect m_textCachedScreenCoords;
|
Rect m_textCachedScreenCoords;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual void updateText();
|
||||||
void drawText(const Rect& screenCoords);
|
void drawText(const Rect& screenCoords);
|
||||||
|
|
||||||
virtual void onTextChange(const std::string& text, const std::string& oldText);
|
virtual void onTextChange(const std::string& text, const std::string& oldText);
|
||||||
|
|
|
@ -120,6 +120,7 @@ void UIWidget::setText(std::string text)
|
||||||
m_text = text;
|
m_text = text;
|
||||||
updateText();
|
updateText();
|
||||||
|
|
||||||
|
text = m_text;
|
||||||
onTextChange(text, oldText);
|
onTextChange(text, oldText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue