Textedit improvements

This commit is contained in:
Eduardo Bart 2013-01-25 09:44:15 -02:00
parent 95f79b45dc
commit 0a91fff82a
7 changed files with 36 additions and 5 deletions

View File

@ -25,6 +25,7 @@ local function navigateCommand(step)
if currentHistoryIndex > 0 then if currentHistoryIndex > 0 then
local command = commandHistory[numCommands - currentHistoryIndex + 1] local command = commandHistory[numCommands - currentHistoryIndex + 1]
commandTextEdit:setText(command) commandTextEdit:setText(command)
commandTextEdit:setCursorPos(-1)
else else
commandTextEdit:clearText() commandTextEdit:clearText()
end end
@ -52,6 +53,7 @@ local function completeCommand()
-- complete command with one match -- complete command with one match
if #possibleCommands == 1 then if #possibleCommands == 1 then
commandTextEdit:setText(possibleCommands[1]) commandTextEdit:setText(possibleCommands[1])
commandTextEdit:setCursorPos(-1)
-- show command matches -- show command matches
elseif #possibleCommands > 0 then elseif #possibleCommands > 0 then
print('>> ' .. commandBegin) print('>> ' .. commandBegin)
@ -75,6 +77,7 @@ local function completeCommand()
end end
end end
commandTextEdit:setText(commandBegin) commandTextEdit:setText(commandBegin)
commandTextEdit:setCursorPos(-1)
for i,v in ipairs(possibleCommands) do for i,v in ipairs(possibleCommands) do
print(v) print(v)

View File

@ -39,6 +39,8 @@ UIWindow
anchors.right: parent.right anchors.right: parent.right
margin-left: 5 margin-left: 5
font: terminus-14px-bold font: terminus-14px-bold
selection-color: black
selection-background-color: white
ResizeBorder ResizeBorder
id: bottomResizeBorder id: bottomResizeBorder

View File

@ -7,6 +7,7 @@ ConsoleLabel < UITextEdit
text-auto-resize: true text-auto-resize: true
selection-color: #111416 selection-color: #111416
selection-background-color: #999999 selection-background-color: #999999
change-cursor-image: false
ConsolePhantomLabel < UILabel ConsolePhantomLabel < UILabel
font: verdana-11px-antialised font: verdana-11px-antialised

View File

@ -219,7 +219,7 @@ void MapView::draw(const Rect& rect)
continue; continue;
PointF jumpOffset = creature->getJumpOffset() * scaleFactor; PointF jumpOffset = creature->getJumpOffset() * scaleFactor;
Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY()); Point creatureOffset = Point(16 - creature->getDisplacementX(), - creature->getDisplacementY() - 2);
Position pos = creature->getPosition(); Position pos = creature->getPosition();
Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p += (creature->getDrawOffset() + creatureOffset) * scaleFactor - Point(stdext::round(jumpOffset.x), stdext::round(jumpOffset.y)); p += (creature->getDrawOffset() + creatureOffset) * scaleFactor - Point(stdext::round(jumpOffset.x), stdext::round(jumpOffset.y));

View File

@ -652,6 +652,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UITextEdit>("setCursorPos", &UITextEdit::setCursorPos); g_lua.bindClassMemberFunction<UITextEdit>("setCursorPos", &UITextEdit::setCursorPos);
g_lua.bindClassMemberFunction<UITextEdit>("setSelection", &UITextEdit::setSelection); g_lua.bindClassMemberFunction<UITextEdit>("setSelection", &UITextEdit::setSelection);
g_lua.bindClassMemberFunction<UITextEdit>("setCursorVisible", &UITextEdit::setCursorVisible); g_lua.bindClassMemberFunction<UITextEdit>("setCursorVisible", &UITextEdit::setCursorVisible);
g_lua.bindClassMemberFunction<UITextEdit>("setChangeCursorImage", &UITextEdit::setChangeCursorImage);
g_lua.bindClassMemberFunction<UITextEdit>("setTextHidden", &UITextEdit::setTextHidden); g_lua.bindClassMemberFunction<UITextEdit>("setTextHidden", &UITextEdit::setTextHidden);
g_lua.bindClassMemberFunction<UITextEdit>("setValidCharacters", &UITextEdit::setValidCharacters); g_lua.bindClassMemberFunction<UITextEdit>("setValidCharacters", &UITextEdit::setValidCharacters);
g_lua.bindClassMemberFunction<UITextEdit>("setShiftNavigation", &UITextEdit::setShiftNavigation); g_lua.bindClassMemberFunction<UITextEdit>("setShiftNavigation", &UITextEdit::setShiftNavigation);
@ -690,6 +691,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UITextEdit>("isEditable", &UITextEdit::isEditable); g_lua.bindClassMemberFunction<UITextEdit>("isEditable", &UITextEdit::isEditable);
g_lua.bindClassMemberFunction<UITextEdit>("isSelectable", &UITextEdit::isSelectable); g_lua.bindClassMemberFunction<UITextEdit>("isSelectable", &UITextEdit::isSelectable);
g_lua.bindClassMemberFunction<UITextEdit>("isCursorVisible", &UITextEdit::isCursorVisible); g_lua.bindClassMemberFunction<UITextEdit>("isCursorVisible", &UITextEdit::isCursorVisible);
g_lua.bindClassMemberFunction<UITextEdit>("isChangingCursorImage", &UITextEdit::isChangingCursorImage);
g_lua.bindClassMemberFunction<UITextEdit>("isTextHidden", &UITextEdit::isTextHidden); g_lua.bindClassMemberFunction<UITextEdit>("isTextHidden", &UITextEdit::isTextHidden);
g_lua.bindClassMemberFunction<UITextEdit>("isShiftNavigation", &UITextEdit::isShiftNavigation); g_lua.bindClassMemberFunction<UITextEdit>("isShiftNavigation", &UITextEdit::isShiftNavigation);
g_lua.bindClassMemberFunction<UITextEdit>("isMultiline", &UITextEdit::isMultiline); g_lua.bindClassMemberFunction<UITextEdit>("isMultiline", &UITextEdit::isMultiline);

View File

@ -41,6 +41,7 @@ UITextEdit::UITextEdit()
m_maxLength = 0; m_maxLength = 0;
m_editable = true; m_editable = true;
m_selectable = true; m_selectable = true;
m_changeCursorImage = true;
m_selectionReference = 0; m_selectionReference = 0;
m_selectionStart = 0; m_selectionStart = 0;
m_selectionEnd = 0; m_selectionEnd = 0;
@ -349,6 +350,9 @@ void UITextEdit::setSelection(int start, int end)
if(start > end) if(start > end)
std::swap(start, end); std::swap(start, end);
if(end == -1)
end = m_text.length();
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());
} }
@ -584,10 +588,12 @@ void UITextEdit::updateText()
void UITextEdit::onHoverChange(bool hovered) void UITextEdit::onHoverChange(bool hovered)
{ {
if(m_changeCursorImage) {
if(hovered) if(hovered)
g_mouse.setTextCursor(); g_mouse.setTextCursor();
else else
g_mouse.restoreCursor(); g_mouse.restoreCursor();
}
} }
void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
@ -620,6 +626,8 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
} }
else if(node->tag() == "cursor-visible") else if(node->tag() == "cursor-visible")
setCursorVisible(node->value<bool>()); setCursorVisible(node->value<bool>());
else if(node->tag() == "change-cursor-image")
setChangeCursorImage(node->value<bool>());
} }
} }
@ -735,6 +743,18 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat
setSelection(m_selectionReference, m_cursorPos); setSelection(m_selectionReference, m_cursorPos);
} }
return true; return true;
} else if(keyCode == Fw::KeyHome) { // move cursor to first character
if(m_cursorPos != 0) {
setSelection(m_cursorPos, 0);
setCursorPos(0);
return true;
}
} else if(keyCode == Fw::KeyEnd) { // move cursor to last character
if(m_cursorPos != (int)m_text.length()) {
setSelection(m_cursorPos, m_text.length());
setCursorPos(m_text.length());
return true;
}
} }
} }

View File

@ -41,6 +41,7 @@ public:
void setCursorPos(int pos); void setCursorPos(int pos);
void setSelection(int start, int end); void setSelection(int start, int end);
void setCursorVisible(bool enable) { m_cursorVisible = enable; } void setCursorVisible(bool enable) { m_cursorVisible = enable; }
void setChangeCursorImage(bool enable) { m_changeCursorImage = enable; }
void setTextHidden(bool hidden); void setTextHidden(bool hidden);
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; } void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
@ -81,6 +82,7 @@ public:
Color getSelectionBackgroundColor() { return m_selectionBackgroundColor; } Color getSelectionBackgroundColor() { return m_selectionBackgroundColor; }
bool hasSelection() { return m_selectionEnd - m_selectionStart > 0; } bool hasSelection() { return m_selectionEnd - m_selectionStart > 0; }
bool isCursorVisible() { return m_cursorVisible; } bool isCursorVisible() { return m_cursorVisible; }
bool isChangingCursorImage() { return m_changeCursorImage; }
bool isTextHidden() { return m_textHidden; } bool isTextHidden() { return m_textHidden; }
bool isShiftNavigation() { return m_shiftNavigation; } bool isShiftNavigation() { return m_shiftNavigation; }
bool isMultiline() { return m_multiline; } bool isMultiline() { return m_multiline; }
@ -118,6 +120,7 @@ private:
bool m_cursorInRange; bool m_cursorInRange;
bool m_cursorVisible; bool m_cursorVisible;
bool m_editable; bool m_editable;
bool m_changeCursorImage;
std::string m_validCharacters; std::string m_validCharacters;
uint m_maxLength; uint m_maxLength;
bool m_updatesEnabled; bool m_updatesEnabled;