diff --git a/modules/console/console.lua b/modules/console/console.lua index 73eb0d0c..99db32e8 100644 --- a/modules/console/console.lua +++ b/modules/console/console.lua @@ -30,6 +30,57 @@ local function navigateCommand(step) end end +local function completeCommand() + local cursorPos = commandLineEdit:getCursorPos() + if cursorPos == 0 then return end + + local commandBegin = string.sub(commandLineEdit:getText(), 1, cursorPos) + local possibleCommands = {} + + -- create a list containing all globals + local allVars = table.copy(_G) + table.merge(allVars, commandEnv) + + -- match commands + for k,v in pairs(allVars) do + if string.sub(k, 1, cursorPos) == commandBegin then + table.insert(possibleCommands, k) + end + end + + -- complete command with one match + if #possibleCommands == 1 then + commandLineEdit:setText(possibleCommands[1]) + -- show command matches + elseif #possibleCommands > 0 then + print('>> ' .. commandBegin) + + -- expand command + local expandedComplete = commandBegin + local done = false + while not done do + cursorPos = #commandBegin+1 + if #possibleCommands[1] < cursorPos then + break + end + expandedComplete = commandBegin .. string.sub(possibleCommands[1], cursorPos, cursorPos) + for i,v in ipairs(possibleCommands) do + if string.sub(v, 1, #expandedComplete) ~= expandedComplete then + done = true + end + end + if not done then + commandBegin = expandedComplete + end + end + commandLineEdit:setText(commandBegin) + + for i,v in ipairs(possibleCommands) do + print(v) + end + end +end + local function onKeyPress(widget, keyCode, keyChar, keyboardModifiers) if keyboardModifiers == KeyboardNoModifier then -- execute current command @@ -46,6 +97,10 @@ local function onKeyPress(widget, keyCode, keyChar, keyboardModifiers) elseif keyCode == KeyDown then navigateCommand(-1) return true + -- complete command + elseif keyCode == KeyTab then + completeCommand() + return true end end return false @@ -102,6 +157,18 @@ function Console.addLine(text, color) end function Console.executeCommand(command) + -- detect and convert commands with simple syntax + local realCommand + if commandEnv[command] then + if type(commandEnv[command]) == "function" then + realCommand = command .. '()' + else + realCommand = 'print(' .. command .. ')' + end + else + realCommand = command + end + -- reset current history index currentHistoryIndex = 0 @@ -112,7 +179,7 @@ function Console.executeCommand(command) Console.addLine(">> " .. command, "#ffffff") -- load command buffer - local func, err = loadstring(command, "@") + local func, err = loadstring(realCommand, "@") -- check for syntax errors if not func then diff --git a/modules/console/console.otui b/modules/console/console.otui index 66eb7597..94935c1f 100644 --- a/modules/console/console.otui +++ b/modules/console/console.otui @@ -33,4 +33,5 @@ RectPanel anchors.bottom: parent.bottom anchors.left: commandSymbolLabel.right anchors.right: parent.right + margin.left: 5 font: terminus-14px-bold diff --git a/modules/core/core.otmod b/modules/core/core.otmod index c1691759..291b0e64 100644 --- a/modules/core/core.otmod +++ b/modules/core/core.otmod @@ -10,6 +10,8 @@ Module - core_ui onLoad: | + require 'ext/table' + require 'ext/string' require 'constants' require 'util' require 'widget' diff --git a/modules/core/messagebox/messagebox.lua b/modules/core/messagebox/messagebox.lua index b47da380..6a213d64 100644 --- a/modules/core/messagebox/messagebox.lua +++ b/modules/core/messagebox/messagebox.lua @@ -19,7 +19,7 @@ function MessageBox.create(title, text, flags) label:resizeToText() -- set window size based on label size - window:setWidth(label:getWidth() + 48) + window:setWidth(math.max(label:getWidth() + 48, 120)) window:setHeight(label:getHeight() + 64) window:updateParentLayout() diff --git a/modules/core/util.lua b/modules/core/util.lua index bc60c00b..6db522b0 100644 --- a/modules/core/util.lua +++ b/modules/core/util.lua @@ -24,3 +24,9 @@ function connect(object, signalsAndSlots) end end end + +function dumpWidgets() + for i=1,UI.root:getChildCount() do + print(UI.root:getChildByIndex(i):getId()) + end +end diff --git a/modules/core_ui/styles/panels.otui b/modules/core_ui/styles/panels.otui index c88ea20a..365eb86e 100644 --- a/modules/core_ui/styles/panels.otui +++ b/modules/core_ui/styles/panels.otui @@ -8,9 +8,9 @@ FlatPanel < Panel TopPanel < Panel height: 34 - border-image: + image: source: /core_ui/images/top_panel.png - border-bottom: 3 + repeated: true RoundedPanel < Panel background-color: #ffffffdd diff --git a/modules/mainmenu/ui/mainmenu.otui b/modules/mainmenu/ui/mainmenu.otui index bbd64f8b..1e39566c 100644 --- a/modules/mainmenu/ui/mainmenu.otui +++ b/modules/mainmenu/ui/mainmenu.otui @@ -14,4 +14,5 @@ Panel anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom + margin.top: 1 focusable: false diff --git a/modules/topmenu/topmenu.otui b/modules/topmenu/topmenu.otui index 768ab16f..635b4644 100644 --- a/modules/topmenu/topmenu.otui +++ b/modules/topmenu/topmenu.otui @@ -34,17 +34,6 @@ TopPanel margin.top: 3 margin.right: 6 - UIWidget - size: 16 16 - image: /core_ui/icons/exit.png - anchors.centerIn: parent - phantom: true - - TopButton - anchors.top: prev.top - anchors.right: prev.left - margin.right: 6 - UIWidget size: 16 16 image: /core_ui/icons/logout.png diff --git a/src/framework/graphics/graphics.cpp b/src/framework/graphics/graphics.cpp index cadb10b5..20b8a04a 100644 --- a/src/framework/graphics/graphics.cpp +++ b/src/framework/graphics/graphics.cpp @@ -183,9 +183,11 @@ void Graphics::drawRepeatedTexturedRect(const Rect& screenCoords, if(screenCoords.isEmpty() || texture->getId() == 0 || textureCoords.isEmpty()) return; + bool mustStopDrawing = false; if(!m_drawing) { bindTexture(texture); startDrawing(); + mustStopDrawing = true; } // render many repeated texture rects @@ -212,7 +214,7 @@ void Graphics::drawRepeatedTexturedRect(const Rect& screenCoords, } } - if(!m_drawing) + if(mustStopDrawing) stopDrawing(); } diff --git a/src/framework/graphics/image.cpp b/src/framework/graphics/image.cpp index dec7d3ba..0eb4a003 100644 --- a/src/framework/graphics/image.cpp +++ b/src/framework/graphics/image.cpp @@ -30,6 +30,7 @@ Image::Image() { m_fixedRatio = false; + m_repeated = false; } void Image::loadFromOTML(const OTMLNodePtr& imageNode) @@ -37,13 +38,14 @@ void Image::loadFromOTML(const OTMLNodePtr& imageNode) // load configs from otml node std::string source = imageNode->hasValue() ? imageNode->value() : imageNode->valueAt("source"); bool smooth = imageNode->valueAt("smooth", false); - m_textureCoords = imageNode->valueAt("coords", Rect()); m_fixedRatio = imageNode->valueAt("fixed ratio", false); + m_repeated = imageNode->valueAt("repeated", false); // load texture m_texture = g_textures.getTexture(source); if(!m_texture) throw OTMLException(imageNode, "could not load image texture"); + m_textureCoords = imageNode->valueAt("coords", Rect(Point(0,0),m_texture->getSize())); // enable texture bilinear filter if(smooth) @@ -65,7 +67,10 @@ void Image::draw(const Rect& screenCoords) g_graphics.drawTexturedRect(screenCoords, m_texture, Rect(texCoordsOffset, texCoordsSize)); } else { - g_graphics.drawTexturedRect(screenCoords, m_texture, m_textureCoords); + if(m_repeated) + g_graphics.drawRepeatedTexturedRect(screenCoords, m_texture, m_textureCoords); + else + g_graphics.drawTexturedRect(screenCoords, m_texture, m_textureCoords); } } } diff --git a/src/framework/graphics/image.h b/src/framework/graphics/image.h index a63c0707..61b884d4 100644 --- a/src/framework/graphics/image.h +++ b/src/framework/graphics/image.h @@ -40,6 +40,7 @@ protected: TexturePtr m_texture; Rect m_textureCoords; bool m_fixedRatio; + bool m_repeated; }; #endif diff --git a/src/framework/luascript/luafunctions.cpp b/src/framework/luascript/luafunctions.cpp index 070dba3a..1a692275 100644 --- a/src/framework/luascript/luafunctions.cpp +++ b/src/framework/luascript/luafunctions.cpp @@ -108,6 +108,7 @@ void LuaInterface::registerFunctions() g_lua.bindClassMemberFunction("getText", &UILineEdit::getText); g_lua.bindClassMemberFunction("setText", &UILineEdit::setText); g_lua.bindClassMemberFunction("clearText", &UILineEdit::clearText); + g_lua.bindClassMemberFunction("getCursorPos", &UILineEdit::getCursorPos); // UIWindow g_lua.registerClass(); diff --git a/src/framework/luascript/luavaluecasts.cpp b/src/framework/luascript/luavaluecasts.cpp index ca679275..d759b060 100644 --- a/src/framework/luascript/luavaluecasts.cpp +++ b/src/framework/luascript/luavaluecasts.cpp @@ -92,7 +92,7 @@ void push_luavalue(const std::string& str) bool luavalue_cast(int index, std::string& str) { str = g_lua.toString(index); - if(str.empty() && !g_lua.isString(index)) + if(str.empty() && g_lua.isString(index) && !g_lua.isNil()) return false; return true; } diff --git a/src/framework/ui/uilineedit.h b/src/framework/ui/uilineedit.h index b1c42d18..e29eb391 100644 --- a/src/framework/ui/uilineedit.h +++ b/src/framework/ui/uilineedit.h @@ -50,6 +50,7 @@ public: std::string getText() const { return m_text; } std::string getDisplayedText(); int getTextPos(Point pos); + int getCursorPos() const { return m_cursorPos; } protected: virtual void onStyleApply(const OTMLNodePtr& styleNode); diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index e4129c8a..c46aeca9 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -105,7 +105,7 @@ void UIWidget::render() // debug draw box //g_graphics.bindColor(Fw::green); //g_graphics.drawBoundingRect(child->getRect()); - //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Color::red); + //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Fw::red); g_graphics.setOpacity(oldOpacity); }