From b8150d160e35591519a9dafc7c0f30befd5f97c8 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 4 Jan 2012 08:26:58 -0200 Subject: [PATCH] implement combobox and do some ui rework --- LICENSE | 2 +- modules/addon_playground/playground.lua | 2 + modules/core_scripts/const.lua | 17 +++ modules/core_styles/styles/checkboxes.otui | 1 + modules/core_styles/styles/comboboxes.otui | 3 +- modules/core_widgets/core_widgets.otmod | 2 + modules/core_widgets/tooltip/tooltip.lua | 6 +- modules/core_widgets/uibutton.lua | 7 + modules/core_widgets/uicombobox.lua | 40 ++++++ modules/core_widgets/uilabel.lua | 9 ++ modules/core_widgets/uipopupmenu.lua | 38 +++--- src/framework/CMakeLists.txt | 2 - src/framework/const.h | 18 +-- src/framework/graphics/particle.h | 2 +- src/framework/graphics/particleaffector.cpp | 2 +- src/framework/luafunctions.cpp | 52 ++++---- src/framework/ui/ui.h | 2 - src/framework/ui/uibutton.cpp | 72 ---------- src/framework/ui/uibutton.h | 49 ------- src/framework/ui/uicheckbox.cpp | 4 +- src/framework/ui/uicheckbox.h | 2 +- src/framework/ui/uiframecounter.cpp | 4 +- src/framework/ui/uiframecounter.h | 2 +- src/framework/ui/uilabel.cpp | 75 ----------- src/framework/ui/uilabel.h | 53 -------- src/framework/ui/uilineedit.cpp | 97 +++++++------- src/framework/ui/uilineedit.h | 27 ++-- src/framework/ui/uiverticallayout.cpp | 2 +- src/framework/ui/uiwidget.cpp | 137 +++++++++++++++++-- src/framework/ui/uiwidget.h | 52 +++++--- src/framework/ui/uiwindow.cpp | 6 +- src/framework/ui/uiwindow.h | 2 +- src/otclient/core/game.cpp | 16 +-- src/otclient/core/item.cpp | 4 +- src/otclient/core/item.h | 2 +- src/otclient/core/localplayer.cpp | 6 +- src/otclient/core/map.cpp | 20 +-- src/otclient/core/thing.h | 4 +- src/otclient/core/tile.h | 2 +- src/otclient/net/protocolgameparse.cpp | 4 +- src/otclient/ui/uicreature.cpp | 4 +- src/otclient/ui/uicreature.h | 2 +- src/otclient/ui/uiitem.cpp | 4 +- src/otclient/ui/uiitem.h | 2 +- src/otclient/ui/uimap.cpp | 4 +- src/otclient/ui/uimap.h | 2 +- src/otclient/util/position.h | 2 +- tools/katepart-syntax/lua.xml | 138 -------------------- 48 files changed, 413 insertions(+), 592 deletions(-) create mode 100644 modules/core_widgets/uibutton.lua create mode 100644 modules/core_widgets/uilabel.lua delete mode 100644 src/framework/ui/uibutton.cpp delete mode 100644 src/framework/ui/uibutton.h delete mode 100644 src/framework/ui/uilabel.cpp delete mode 100644 src/framework/ui/uilabel.h diff --git a/LICENSE b/LICENSE index 2c4b7d21..813a2a15 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ OTClient is made available under the MIT License -Copyright (c) 2010-2011 OTClient +Copyright (c) 2010-2012 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 diff --git a/modules/addon_playground/playground.lua b/modules/addon_playground/playground.lua index c6c5dac0..b300e634 100644 --- a/modules/addon_playground/playground.lua +++ b/modules/addon_playground/playground.lua @@ -3,6 +3,8 @@ function init() local box = createWidget('ComboBox') box:moveTo({x=100, y=8}) + box:addOption('Option 1') + box:addOption('Option 2') displayUI(box) end diff --git a/modules/core_scripts/const.lua b/modules/core_scripts/const.lua index 47fed839..0d18d8bf 100644 --- a/modules/core_scripts/const.lua +++ b/modules/core_scripts/const.lua @@ -132,3 +132,20 @@ MouseNoButton = 0 MouseLeftButton = 1 MouseRightButton = 2 MouseMidButton = 3 + +AlignNone = 0 +AlignLeft = 1 +AlignRight = 2 +AlignTop = 4 +AlignBottom = 8 +AlignHorizontalCenter = 16 +AlignVerticalCenter = 32 +AlignTopLeft = 5 +AlignTopRight = 6 +AlignBottomLeft = 9 +AlignBottomRight = 10 +AlignLeftCenter = 33 +AlignRightCenter = 34 +AlignTopCenter = 20 +AlignBottomCenter = 24 +AlignCenter = 48 diff --git a/modules/core_styles/styles/checkboxes.otui b/modules/core_styles/styles/checkboxes.otui index 0d098bcb..67552384 100644 --- a/modules/core_styles/styles/checkboxes.otui +++ b/modules/core_styles/styles/checkboxes.otui @@ -1,6 +1,7 @@ CheckBox < UICheckBox size: 12 12 box-size: 12 12 + text-align: left text-offset: 16 -1 color: #aaaaaa background-color: #ffffffff diff --git a/modules/core_styles/styles/comboboxes.otui b/modules/core_styles/styles/comboboxes.otui index 1e709ebf..fa423c90 100644 --- a/modules/core_styles/styles/comboboxes.otui +++ b/modules/core_styles/styles/comboboxes.otui @@ -2,7 +2,8 @@ ComboBox < UIComboBox font: verdana-11px-antialised color: #aaaaaa size: 86 20 - text-margin: 3 + text-offset: 3 0 + text-align: left border-image: source: /core_styles/images/combobox.png border: 1 diff --git a/modules/core_widgets/core_widgets.otmod b/modules/core_widgets/core_widgets.otmod index 654d6e80..1a096d49 100644 --- a/modules/core_widgets/core_widgets.otmod +++ b/modules/core_widgets/core_widgets.otmod @@ -7,6 +7,8 @@ Module onLoad: | require 'tooltip/tooltip' require 'messagebox/messagebox' + require 'uibutton' + require 'uilabel' require 'uicombobox' require 'uipopupmenu' return true \ No newline at end of file diff --git a/modules/core_widgets/tooltip/tooltip.lua b/modules/core_widgets/tooltip/tooltip.lua index 118ed624..7bfb3d17 100644 --- a/modules/core_widgets/tooltip/tooltip.lua +++ b/modules/core_widgets/tooltip/tooltip.lua @@ -49,9 +49,9 @@ local function onWidgetHoverChange(widget, hovered) end end -local function onWidgetStyleApply(widget, style) - if style and style.tooltip then - widget.tooltip = style.tooltip +local function onWidgetStyleApply(widget, styleName, styleNode) + if styleNode.tooltip then + widget.tooltip = styleNode.tooltip end end diff --git a/modules/core_widgets/uibutton.lua b/modules/core_widgets/uibutton.lua new file mode 100644 index 00000000..ebac55d3 --- /dev/null +++ b/modules/core_widgets/uibutton.lua @@ -0,0 +1,7 @@ +UIButton = extends(UIWidget) + +function UIButton.create() + local button = UIButton.internalCreate() + button:setFocusable(false) + return button +end diff --git a/modules/core_widgets/uicombobox.lua b/modules/core_widgets/uicombobox.lua index 613c15bc..1319a09e 100644 --- a/modules/core_widgets/uicombobox.lua +++ b/modules/core_widgets/uicombobox.lua @@ -1 +1,41 @@ UIComboBox = extends(UIWidget) + +function UIComboBox.create() + local combobox = UIComboBox.internalCreate() + combobox.options = {} + combobox.currentIndex = -1 + return combobox +end + +function UIComboBox:setCurrentOption(text) + if not self.options then return end + for i,v in ipairs(self.options) do + if v.text == text and self.currentIndex ~= i then + self.currentIndex = i + self:setText(text) + self:onOptionChange(text, data) + return + end + end +end + +function UIComboBox:addOption(text, data) + table.insert(self.options, { text = text, data = data }) + local index = #self.options + if index == 1 then self:setCurrentOption(text) end + return index +end + +function UIComboBox:onMousePress(mousePos, mouseButton) + local menu = createWidget('PopupMenu', self) + for i,v in ipairs(self.options) do + menu:addOption(v.text, function() self:setCurrentOption(v.text) end) + end + menu:setWidth(self:getWidth()) + menu:display({ x = self:getX(), y = self:getY() + self:getHeight() }) + return true +end + +function UIComboBox:onOptionChange(optionText, optionData) + -- nothing todo +end diff --git a/modules/core_widgets/uilabel.lua b/modules/core_widgets/uilabel.lua new file mode 100644 index 00000000..1eed41ed --- /dev/null +++ b/modules/core_widgets/uilabel.lua @@ -0,0 +1,9 @@ +UILabel = extends(UIWidget) + +function UILabel.create() + local label = UILabel.internalCreate() + label:setPhantom(true) + label:setFocusable(false) + label:setTextAlign(AlignLeft) + return label +end diff --git a/modules/core_widgets/uipopupmenu.lua b/modules/core_widgets/uipopupmenu.lua index 65453764..29b2c838 100644 --- a/modules/core_widgets/uipopupmenu.lua +++ b/modules/core_widgets/uipopupmenu.lua @@ -1,7 +1,5 @@ --- extends UIWidget UIPopupMenu = extends(UIWidget) --- public functions function UIPopupMenu.create() local menu = UIPopupMenu.internalCreate() local layout = UIVerticalLayout.create(menu) @@ -10,41 +8,39 @@ function UIPopupMenu.create() return menu end -function UIPopupMenu.display(menu, pos) - displayUI(menu, {x = pos.x, y = pos.y}) - menu:bindRectToParent() - menu:grabMouse() - menu:grabKeyboard() - return menu +function UIPopupMenu:display(pos) + displayUI(self, {x = pos.x, y = pos.y}) + self:bindRectToParent() + self:grabMouse() + self:grabKeyboard() end -function UIPopupMenu.addOption(menu, optionName, optionCallback) - local optionWidget = createWidget(menu:getStyleName() .. 'Button', menu) - local lastOptionWidget = menu:getLastChild() +function UIPopupMenu:addOption(optionName, optionCallback) + local optionWidget = createWidget(self:getStyleName() .. 'Button', self) + local lastOptionWidget = self:getLastChild() optionWidget.onClick = function() optionCallback() - menu:destroy() + self:destroy() end optionWidget:setText(optionName) end -function UIPopupMenu.addSeparator(menu) - local separatorWidget = createWidget(menu:getStyleName() .. 'Separator', menu) +function UIPopupMenu:addSeparator() + createWidget(self:getStyleName() .. 'Separator', self) end --- hooked events -function UIPopupMenu.onMousePress(menu, mousePos, mouseButton) - -- clicks outside menu area destroys the menu - if not menu:containsPoint(mousePos) then - menu:destroy() +function UIPopupMenu:onMousePress(mousePos, mouseButton) + -- clicks outside self area destroys the self + if not self:containsPoint(mousePos) then + self:destroy() return true end return false end -function UIPopupMenu.onKeyPress(menu, keyCode, keyText, keyboardModifiers) +function UIPopupMenu:onKeyPress(keyCode, keyText, keyboardModifiers) if keyCode == KeyEscape then - menu:destroy() + self:destroy() return true end return false diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt index 1a2f3170..fc65aa43 100644 --- a/src/framework/CMakeLists.txt +++ b/src/framework/CMakeLists.txt @@ -187,8 +187,6 @@ SET(framework_SOURCES ${framework_SOURCES} # framework ui ${CMAKE_CURRENT_LIST_DIR}/ui/uimanager.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uiwidget.cpp - ${CMAKE_CURRENT_LIST_DIR}/ui/uilabel.cpp - ${CMAKE_CURRENT_LIST_DIR}/ui/uibutton.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uilineedit.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uiwindow.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp diff --git a/src/framework/const.h b/src/framework/const.h index a6c20f80..283541bc 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -198,15 +198,15 @@ namespace Fw AlignBottom = 8, AlignHorizontalCenter = 16, AlignVerticalCenter = 32, - AlignTopLeft = AlignTop | AlignLeft, - AlignTopRight = AlignTop | AlignRight, - AlignBottomLeft = AlignBottom | AlignLeft, - AlignBottomRight = AlignBottom | AlignRight, - AlignLeftCenter = AlignLeft | AlignVerticalCenter, - AlignRightCenter = AlignRight | AlignVerticalCenter, - AlignTopCenter = AlignTop | AlignHorizontalCenter, - AlignBottomCenter = AlignBottom | AlignHorizontalCenter, - AlignCenter = AlignVerticalCenter | AlignHorizontalCenter + AlignTopLeft = AlignTop | AlignLeft, // 5 + AlignTopRight = AlignTop | AlignRight, // 6 + AlignBottomLeft = AlignBottom | AlignLeft, // 9 + AlignBottomRight = AlignBottom | AlignRight, // 10 + AlignLeftCenter = AlignLeft | AlignVerticalCenter, // 33 + AlignRightCenter = AlignRight | AlignVerticalCenter, // 34 + AlignTopCenter = AlignTop | AlignHorizontalCenter, // 20 + AlignBottomCenter = AlignBottom | AlignHorizontalCenter, // 24 + AlignCenter = AlignVerticalCenter | AlignHorizontalCenter // 48 }; enum AnchorEdge { diff --git a/src/framework/graphics/particle.h b/src/framework/graphics/particle.h index a37f23e2..f7929785 100644 --- a/src/framework/graphics/particle.h +++ b/src/framework/graphics/particle.h @@ -36,7 +36,7 @@ public: bool hasFinished() { return m_finished; } - PointF getPosition() { return m_position; } + PointF getPos() { return m_position; } PointF getVelocity() { return m_velocity; } void setPos(const PointF& position) { m_position = position; } diff --git a/src/framework/graphics/particleaffector.cpp b/src/framework/graphics/particleaffector.cpp index 0596e6a2..b818945a 100644 --- a/src/framework/graphics/particleaffector.cpp +++ b/src/framework/graphics/particleaffector.cpp @@ -131,7 +131,7 @@ void AttractionAffector::updateParticle(const ParticlePtr& particle, double elap if(!m_active) return; - PointF pPosition = particle->getPosition(); + PointF pPosition = particle->getPos(); PointF d = PointF(m_position.x - pPosition.x, pPosition.y - m_position.y); if(d.length() == 0) return; diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index b3e869b6..edd9110c 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -37,6 +37,9 @@ void Application::registerLuaFunctions() g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); g_lua.bindClassMemberFunction("destroy", &UIWidget::destroy); + g_lua.bindClassMemberFunction("render", &UIWidget::render); + g_lua.bindClassMemberFunction("renderSelf", &UIWidget::renderSelf); + g_lua.bindClassMemberFunction("renderChildren", &UIWidget::renderChildren); g_lua.bindClassMemberFunction("setVisible", &UIWidget::setVisible); g_lua.bindClassMemberFunction("setEnabled", &UIWidget::setEnabled); g_lua.bindClassMemberFunction("setPressed", &UIWidget::setPressed); @@ -53,7 +56,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setWidth", &UIWidget::setWidth); g_lua.bindClassMemberFunction("setHeight", &UIWidget::setHeight); //g_lua.bindClassMemberFunction("setImage", &UIWidget::setImage); - //g_lua.bindClassMemberFunction("setFont", &UIWidget::setFont); + g_lua.bindClassMemberFunction("setIcon", &UIWidget::setIcon); g_lua.bindClassMemberFunction("setOpacity", &UIWidget::setOpacity); g_lua.bindClassMemberFunction("setBackgroundColor", &UIWidget::setBackgroundColor); g_lua.bindClassMemberFunction("setForegroundColor", &UIWidget::setForegroundColor); @@ -61,10 +64,15 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("setMarginRight", &UIWidget::setMarginRight); g_lua.bindClassMemberFunction("setMarginBottom", &UIWidget::setMarginBottom); g_lua.bindClassMemberFunction("setMarginLeft", &UIWidget::setMarginLeft); + g_lua.bindClassMemberFunction("setText", &UIWidget::setText); + g_lua.bindClassMemberFunction("setTextAlign", &UIWidget::setTextAlign); + g_lua.bindClassMemberFunction("setTextOffset", &UIWidget::setTextOffset); + g_lua.bindClassMemberFunction("setFont", &UIWidget::setFont); g_lua.bindClassMemberFunction("setSizeFixed", &UIWidget::setSizeFixed); g_lua.bindClassMemberFunction("setLastFocusReason", &UIWidget::setLastFocusReason); g_lua.bindClassMemberFunction("bindRectToParent", &UIWidget::bindRectToParent); g_lua.bindClassMemberFunction("resize", &UIWidget::resize); + g_lua.bindClassMemberFunction("resizeToText", &UIWidget::resizeToText); g_lua.bindClassMemberFunction("moveTo", &UIWidget::moveTo); g_lua.bindClassMemberFunction("hide", &UIWidget::hide); g_lua.bindClassMemberFunction("show", &UIWidget::show); @@ -102,15 +110,13 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getLayout", &UIWidget::getLayout); g_lua.bindClassMemberFunction("getParent", &UIWidget::getParent); g_lua.bindClassMemberFunction("getRootParent", &UIWidget::getRootParent); - g_lua.bindClassMemberFunction("getPosition", &UIWidget::getPosition); + g_lua.bindClassMemberFunction("getPos", &UIWidget::getPos); g_lua.bindClassMemberFunction("getSize", &UIWidget::getSize); g_lua.bindClassMemberFunction("getRect", &UIWidget::getRect); g_lua.bindClassMemberFunction("getX", &UIWidget::getX); g_lua.bindClassMemberFunction("getY", &UIWidget::getY); g_lua.bindClassMemberFunction("getWidth", &UIWidget::getWidth); g_lua.bindClassMemberFunction("getHeight", &UIWidget::getHeight); - //g_lua.bindClassMemberFunction("getImage", &UIWidget::getImage); - //g_lua.bindClassMemberFunction("getFont", &UIWidget::getFont); g_lua.bindClassMemberFunction("getForegroundColor", &UIWidget::getForegroundColor); g_lua.bindClassMemberFunction("getBackgroundColor", &UIWidget::getBackgroundColor); g_lua.bindClassMemberFunction("getOpacity", &UIWidget::getOpacity); @@ -118,6 +124,11 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getMarginRight", &UIWidget::getMarginRight); g_lua.bindClassMemberFunction("getMarginBottom", &UIWidget::getMarginBottom); g_lua.bindClassMemberFunction("getMarginLeft", &UIWidget::getMarginLeft); + g_lua.bindClassMemberFunction("getText", &UIWidget::getText); + g_lua.bindClassMemberFunction("getTextAlign", &UIWidget::getTextAlign); + g_lua.bindClassMemberFunction("getTextOffset", &UIWidget::getTextOffset); + g_lua.bindClassMemberFunction("getFont", &UIWidget::getFont); + g_lua.bindClassMemberFunction("getTextSize", &UIWidget::getTextSize); g_lua.bindClassMemberFunction("getLastFocusReason", &UIWidget::getLastFocusReason); g_lua.bindClassMemberFunction("getStyle", &UIWidget::getStyle); g_lua.bindClassMemberFunction("getStyleName", &UIWidget::getStyleName); @@ -169,32 +180,30 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("centerIn", &UIAnchorLayout::centerIn); g_lua.bindClassMemberFunction("fill", &UIAnchorLayout::fill); - // UILabel - g_lua.registerClass(); - g_lua.bindClassStaticFunction("create", &UIWidget::create); - g_lua.bindClassMemberFunction("getText", &UILabel::getText); - g_lua.bindClassMemberFunction("setText", &UILabel::setText); - g_lua.bindClassMemberFunction("resizeToText", &UILabel::resizeToText); - - // UILabel + // UIProgressBar g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); g_lua.bindClassMemberFunction("getPercent", &UIProgressBar::getPercent); g_lua.bindClassMemberFunction("setPercent", &UIProgressBar::setPercent); - // UIButton - g_lua.registerClass(); - g_lua.bindClassStaticFunction("create", &UIWidget::create); - g_lua.bindClassMemberFunction("getText", &UIButton::getText); - g_lua.bindClassMemberFunction("setText", &UIButton::setText); - // UILineEdit g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); - g_lua.bindClassMemberFunction("getText", &UILineEdit::getText); - g_lua.bindClassMemberFunction("setText", &UILineEdit::setText); - g_lua.bindClassMemberFunction("clearText", &UILineEdit::clearText); + g_lua.bindClassMemberFunction("setTextHorizontalMargin", &UILineEdit::setTextHorizontalMargin); + g_lua.bindClassMemberFunction("setCursorPos", &UILineEdit::setCursorPos); + g_lua.bindClassMemberFunction("setCursorEnabled", &UILineEdit::setCursorEnabled); + g_lua.bindClassMemberFunction("setTextHidden", &UILineEdit::setTextHidden); + g_lua.bindClassMemberFunction("setAlwaysActive", &UILineEdit::setAlwaysActive); + g_lua.bindClassMemberFunction("moveCursor", &UILineEdit::moveCursor); + g_lua.bindClassMemberFunction("appendText", &UILineEdit::appendText); + g_lua.bindClassMemberFunction("removeCharacter", &UILineEdit::removeCharacter); + g_lua.bindClassMemberFunction("getDisplayedText", &UILineEdit::getDisplayedText); + g_lua.bindClassMemberFunction("getTextPos", &UILineEdit::getTextPos); + g_lua.bindClassMemberFunction("getTextHorizontalMargin", &UILineEdit::getTextHorizontalMargin); g_lua.bindClassMemberFunction("getCursorPos", &UILineEdit::getCursorPos); + g_lua.bindClassMemberFunction("isCursorEnabled", &UILineEdit::isCursorEnabled); + g_lua.bindClassMemberFunction("isAlwaysActive", &UILineEdit::isAlwaysActive); + g_lua.bindClassMemberFunction("isTextHidden", &UILineEdit::isTextHidden); // UICheckBox g_lua.registerClass(); @@ -202,7 +211,6 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("isChecked", &UICheckBox::isChecked); g_lua.bindClassMemberFunction("setChecked", &UICheckBox::setChecked); - // UIWindow g_lua.registerClass(); g_lua.bindClassStaticFunction("create", &UIWidget::create); diff --git a/src/framework/ui/ui.h b/src/framework/ui/ui.h index 07e60ee9..6316c91f 100644 --- a/src/framework/ui/ui.h +++ b/src/framework/ui/ui.h @@ -25,8 +25,6 @@ #include "uimanager.h" #include "uiwidget.h" -#include "uibutton.h" -#include "uilabel.h" #include "uilineedit.h" #include "uiwindow.h" #include "uiframecounter.h" diff --git a/src/framework/ui/uibutton.cpp b/src/framework/ui/uibutton.cpp deleted file mode 100644 index 392268b0..00000000 --- a/src/framework/ui/uibutton.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2010-2012 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 "uibutton.h" -#include -#include -#include -#include -#include -#include -#include - -UIButton::UIButton() -{ - m_focusable = false; -} - -void UIButton::render() -{ - UIWidget::render(); - - if(m_icon) { - Rect iconRect; - iconRect.resize(m_icon->getSize()); - iconRect.moveCenter(m_rect.center()); - g_painter.drawTexturedRect(iconRect, m_icon); - } - - Rect textRect = m_rect; - textRect.translate(m_textOffset); - m_font->renderText(m_text, textRect, Fw::AlignCenter, m_foregroundColor); -} - -void UIButton::onStyleApply(const OTMLNodePtr& styleNode) -{ - UIWidget::onStyleApply(styleNode); - - for(OTMLNodePtr node : styleNode->children()) { - if(node->tag() == "text-offset") - m_textOffset = node->value(); - else if(node->tag() == "text") - m_text = node->value(); - else if(node->tag() == "icon") - m_icon = g_textures.getTexture(node->value()); - } -} - -void UIButton::onMouseRelease(const Point& mousePos, Fw::MouseButton button) -{ - if(isPressed() && getRect().contains(mousePos)) { - callLuaField("onClick"); - } -} diff --git a/src/framework/ui/uibutton.h b/src/framework/ui/uibutton.h deleted file mode 100644 index 4979792d..00000000 --- a/src/framework/ui/uibutton.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2010-2012 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 UIBUTTON_H -#define UIBUTTON_H - -#include "uiwidget.h" - -class UIButton : public UIWidget -{ -public: - UIButton(); - - virtual void render(); - - void setText(const std::string& text) { m_text = text; } - std::string getText() const { return m_text; } - - UIButtonPtr asUIButton() { return std::static_pointer_cast(shared_from_this()); } - -protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); - virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); - - Point m_textOffset; - TexturePtr m_icon; - std::string m_text; -}; - -#endif diff --git a/src/framework/ui/uicheckbox.cpp b/src/framework/ui/uicheckbox.cpp index a78a241e..94e4e446 100644 --- a/src/framework/ui/uicheckbox.cpp +++ b/src/framework/ui/uicheckbox.cpp @@ -58,9 +58,9 @@ void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button) setChecked(!isChecked()); } -void UICheckBox::onStyleApply(const OTMLNodePtr& styleNode) +void UICheckBox::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "text-offset") diff --git a/src/framework/ui/uicheckbox.h b/src/framework/ui/uicheckbox.h index 8c3751ac..aed81e61 100644 --- a/src/framework/ui/uicheckbox.h +++ b/src/framework/ui/uicheckbox.h @@ -40,7 +40,7 @@ public: UICheckBoxPtr asUICheckBox() { return std::static_pointer_cast(shared_from_this()); } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); std::string m_text; diff --git a/src/framework/ui/uiframecounter.cpp b/src/framework/ui/uiframecounter.cpp index 8967cf88..cbfa41b9 100644 --- a/src/framework/ui/uiframecounter.cpp +++ b/src/framework/ui/uiframecounter.cpp @@ -50,9 +50,9 @@ void UIFrameCounter::render() m_font->renderText(m_fpsText, m_rect, m_align, Fw::white); } -void UIFrameCounter::onStyleApply(const OTMLNodePtr& styleNode) +void UIFrameCounter::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "align") diff --git a/src/framework/ui/uiframecounter.h b/src/framework/ui/uiframecounter.h index 1158eefb..97035215 100644 --- a/src/framework/ui/uiframecounter.h +++ b/src/framework/ui/uiframecounter.h @@ -36,7 +36,7 @@ public: int getFrameCount() { return m_frameCount; } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); private: Fw::AlignmentFlag m_align; diff --git a/src/framework/ui/uilabel.cpp b/src/framework/ui/uilabel.cpp deleted file mode 100644 index 2520606e..00000000 --- a/src/framework/ui/uilabel.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2010-2012 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 "uilabel.h" -#include "uitranslator.h" -#include -#include - -UILabel::UILabel() -{ - m_focusable = false; - m_phantom = true; - m_textAlign = Fw::AlignLeft; -} - -void UILabel::render() -{ - UIWidget::render(); - Rect textRect = m_rect; - textRect.setTopLeft(textRect.topLeft() + m_textOffset); - m_font->renderText(m_text, textRect, m_textAlign, m_foregroundColor); -} - -void UILabel::setText(const std::string& text) -{ - m_text = text; - - // auto resize - if(!m_fixedSize && !m_rect.isValid()) { - Size textSize = m_font->calculateTextRectSize(m_text); - if(m_rect.width() <= 0) - m_rect.setWidth(textSize.width()); - if(m_rect.height() <= 0) - m_rect.setHeight(textSize.height()); - } -} - -void UILabel::resizeToText() -{ - resize(m_font->calculateTextRectSize(m_text)); -} - -void UILabel::onStyleApply(const OTMLNodePtr& styleNode) -{ - UIWidget::onStyleApply(styleNode); - - for(const OTMLNodePtr& node : styleNode->children()) { - if(node->tag() == "text") - setText(node->value()); - else if(node->tag() == "text-align") - setTextAlign(Fw::translateAlignment(node->value())); - else if(node->tag() == "text-offset") { - setTextOffset(node->value()); - } - } -} diff --git a/src/framework/ui/uilabel.h b/src/framework/ui/uilabel.h deleted file mode 100644 index 8f705752..00000000 --- a/src/framework/ui/uilabel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2010-2012 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 UILABEL_H -#define UILABEL_H - -#include "uiwidget.h" - -class UILabel : public UIWidget -{ -public: - UILabel(); - virtual void render(); - - void resizeToText(); - - void setText(const std::string& text); - void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; } - void setTextOffset(const Point& offset) { m_textOffset = offset; } - - std::string getText() const { return m_text; } - Fw::AlignmentFlag getTextAlign() const { return m_textAlign; } - Point getTextOffset() const { return m_textOffset; } - -protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); - -private: - std::string m_text; - Point m_textOffset; - Fw::AlignmentFlag m_textAlign; -}; - -#endif diff --git a/src/framework/ui/uilineedit.cpp b/src/framework/ui/uilineedit.cpp index bd04dd21..7d67bbfb 100644 --- a/src/framework/ui/uilineedit.cpp +++ b/src/framework/ui/uilineedit.cpp @@ -29,8 +29,8 @@ UILineEdit::UILineEdit() { - m_align = Fw::AlignLeftCenter; m_cursorPos = 0; + m_textAlign = Fw::AlignLeftCenter; m_startRenderPos = 0; m_textHorizontalMargin = 0; m_textHidden = false; @@ -38,9 +38,12 @@ UILineEdit::UILineEdit() blinkCursor(); } -void UILineEdit::render() +void UILineEdit::renderSelf() { - UIWidget::render(); + drawBackground(m_rect); + drawBorder(m_rect); + drawImage(m_rect); + drawIcon(m_rect); //TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture @@ -81,7 +84,7 @@ void UILineEdit::update() // map glyphs positions Size textBoxSize; - const std::vector& glyphsPositions = m_font->calculateGlyphsPositions(text, m_align, &textBoxSize); + const std::vector& glyphsPositions = m_font->calculateGlyphsPositions(text, m_textAlign, &textBoxSize); const Rect *glyphsTextureCoords = m_font->getGlyphsTextureCoords(); const Size *glyphsSize = m_font->getGlyphsSize(); int glyph; @@ -141,16 +144,16 @@ void UILineEdit::update() textScreenCoords.addRight(-m_textHorizontalMargin); m_drawArea = textScreenCoords; - if(m_align & Fw::AlignBottom) { + if(m_textAlign & Fw::AlignBottom) { m_drawArea.translate(0, textScreenCoords.height() - textBoxSize.height()); - } else if(m_align & Fw::AlignVerticalCenter) { + } else if(m_textAlign & Fw::AlignVerticalCenter) { m_drawArea.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2); } else { // AlignTop } - if(m_align & Fw::AlignRight) { + if(m_textAlign & Fw::AlignRight) { m_drawArea.translate(textScreenCoords.width() - textBoxSize.width(), 0); - } else if(m_align & Fw::AlignHorizontalCenter) { + } else if(m_textAlign & Fw::AlignHorizontalCenter) { m_drawArea.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0); } else { // AlignLeft @@ -169,17 +172,17 @@ void UILineEdit::update() Rect glyphTextureCoords = glyphsTextureCoords[glyph]; // first translate to align position - if(m_align & Fw::AlignBottom) { + if(m_textAlign & Fw::AlignBottom) { glyphScreenCoords.translate(0, textScreenCoords.height() - textBoxSize.height()); - } else if(m_align & Fw::AlignVerticalCenter) { + } else if(m_textAlign & Fw::AlignVerticalCenter) { glyphScreenCoords.translate(0, (textScreenCoords.height() - textBoxSize.height()) / 2); } else { // AlignTop // nothing to do } - if(m_align & Fw::AlignRight) { + if(m_textAlign & Fw::AlignRight) { glyphScreenCoords.translate(textScreenCoords.width() - textBoxSize.width(), 0); - } else if(m_align & Fw::AlignHorizontalCenter) { + } else if(m_textAlign & Fw::AlignHorizontalCenter) { glyphScreenCoords.translate((textScreenCoords.width() - textBoxSize.width()) / 2, 0); } else { // AlignLeft // nothing to do @@ -225,38 +228,12 @@ void UILineEdit::update() } } -void UILineEdit::setFont(const FontPtr& font) +void UILineEdit::setTextHorizontalMargin(int margin) { - if(m_font != font) { - m_font = font; - update(); - } -} - -void UILineEdit::setText(const std::string& text) -{ - if(m_text != text) { - m_text = text; - m_cursorPos = text.length(); - blinkCursor(); - update(); - } -} - -void UILineEdit::setTextHidden(bool hidden) -{ - m_textHidden = true; + m_textHorizontalMargin = margin; update(); } -void UILineEdit::setAlign(Fw::AlignmentFlag align) -{ - if(m_align != align) { - m_align = align; - update(); - } -} - void UILineEdit::setCursorPos(int pos) { if(pos != m_cursorPos) { @@ -280,6 +257,17 @@ void UILineEdit::setCursorEnabled(bool enable) update(); } +void UILineEdit::setTextHidden(bool hidden) +{ + m_textHidden = true; + update(); +} + +void UILineEdit::setAlwaysActive(bool enable) +{ + m_alwaysActive = enable; +} + void UILineEdit::appendText(std::string text) { if(m_cursorPos >= 0) { @@ -373,21 +361,34 @@ std::string UILineEdit::getDisplayedText() return m_text; } -void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode) +void UILineEdit::onTextChange(const std::string& text) +{ + m_cursorPos = text.length(); + blinkCursor(); + update(); + UIWidget::onTextChange(text); +} + +void UILineEdit::onFontChange(const std::string& font) { - UIWidget::onStyleApply(styleNode); + update(); + UIWidget::onFontChange(font); +} + +void UILineEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) +{ + UIWidget::onStyleApply(styleName, styleNode); for(const OTMLNodePtr& node : styleNode->children()) { if(node->tag() == "text") { setText(node->value()); setCursorPos(m_text.length()); - } else if(node->tag() == "text-hidden") { + } else if(node->tag() == "text-hidden") setTextHidden(node->value()); - } else if(node->tag() == "text-margin") { - m_textHorizontalMargin = node->value(); - } else if(node->tag() == "always-active") { - m_alwaysActive = true; - } + else if(node->tag() == "text-margin") + setTextHorizontalMargin(node->value()); + else if(node->tag() == "always-active") + setAlwaysActive(node->value()); } } diff --git a/src/framework/ui/uilineedit.h b/src/framework/ui/uilineedit.h index ce57c368..bad865a5 100644 --- a/src/framework/ui/uilineedit.h +++ b/src/framework/ui/uilineedit.h @@ -30,30 +30,35 @@ class UILineEdit : public UIWidget public: UILineEdit(); - virtual void render(); + virtual void renderSelf(); +private: void update(); - void setText(const std::string& text); - void setTextHidden(bool hidden); - void setAlign(Fw::AlignmentFlag align); +public: + void setTextHorizontalMargin(int margin); void setCursorPos(int pos); - void setCursorEnabled(bool enable = true); + void setCursorEnabled(bool enable); + void setTextHidden(bool hidden); + void setAlwaysActive(bool enable); - void clearText() { setText(""); } void moveCursor(bool right); void appendText(std::string text); void appendCharacter(char c); void removeCharacter(bool right); - void setFont(const FontPtr& font); - std::string getText() const { return m_text; } std::string getDisplayedText(); int getTextPos(Point pos); - int getCursorPos() const { return m_cursorPos; } + int getTextHorizontalMargin() { return m_textHorizontalMargin; } + int getCursorPos() { return m_cursorPos; } + bool isCursorEnabled() { return m_cursorPos != -1; } + bool isAlwaysActive() { return m_alwaysActive; } + bool isTextHidden() { return m_textHidden; } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onTextChange(const std::string& text); + virtual void onFontChange(const std::string& font); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); virtual void onFocusChange(bool focused, Fw::FocusReason reason); virtual bool onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers); @@ -62,9 +67,7 @@ protected: private: void blinkCursor(); - std::string m_text; Rect m_drawArea; - Fw::AlignmentFlag m_align; int m_cursorPos; Point m_startInternalPos; int m_startRenderPos; diff --git a/src/framework/ui/uiverticallayout.cpp b/src/framework/ui/uiverticallayout.cpp index d75e3cca..084e9752 100644 --- a/src/framework/ui/uiverticallayout.cpp +++ b/src/framework/ui/uiverticallayout.cpp @@ -54,7 +54,7 @@ void UIVerticalLayout::update() if(m_alignBottom) std::reverse(widgets.begin(), widgets.end()); - Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPosition(); + Point pos = (m_alignBottom) ? parentWidget->getRect().bottomLeft() : parentWidget->getPos(); int prefferedHeight = 0; int gap; diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 883d9705..e3fc4ec7 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -33,6 +33,7 @@ #include #include #include +#include UIWidget::UIWidget() { @@ -41,6 +42,10 @@ UIWidget::UIWidget() m_font = g_fonts.getDefaultFont(); m_opacity = 255; m_marginTop = m_marginRight = m_marginBottom = m_marginLeft = 0; + //m_backgroundColor = Fw::alpha; + m_backgroundColor = Fw::white; + m_foregroundColor = Fw::white; + m_textAlign = Fw::AlignCenter; // generate an unique id, this is need because anchored layouts find widgets by id static unsigned long id = 1; @@ -74,11 +79,12 @@ void UIWidget::render() void UIWidget::renderSelf() { - // draw background - if(m_image) { - g_painter.setColor(m_backgroundColor); - m_image->draw(m_rect); - } + // draw style components in order + drawBackground(m_rect); + drawBorder(m_rect); + drawImage(m_rect); + drawIcon(m_rect); + drawText(m_rect); } void UIWidget::renderChildren() @@ -86,7 +92,10 @@ void UIWidget::renderChildren() // draw children for(const UIWidgetPtr& child : m_children) { // render only visible children with a valid rect inside our rect - if(child->isExplicitlyVisible() && child->getRect().isValid() && child->getRect().intersects(m_rect)) { + if(child->isExplicitlyVisible() && + child->getRect().isValid() && + child->getRect().intersects(m_rect) && + child->getOpacity() > 0) { // store current graphics opacity int oldOpacity = g_painter.getOpacity(); @@ -99,13 +108,63 @@ void UIWidget::renderChildren() // debug draw box //g_painter.setColor(Fw::green); //g_painter.drawBoundingRect(child->getRect()); - //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Fw::red); + //g_fonts.getDefaultFont()->renderText(child->getId(), child->getPos() + Point(2, 0), Fw::red); g_painter.setOpacity(oldOpacity); } } } +void UIWidget::drawBackground(const Rect& screenCoords) +{ + /* + if(m_backgroundColor.a() > 0) { + g_painter.setColor(m_backgroundColor); + g_painter.drawFilledRect(screenCoords); + //g_painter.drawFilledRect(screenCoords.expanded(-m_borderWidth)); + } + */ +} + +void UIWidget::drawBorder(const Rect& screenCoords) +{ + /* + if(m_borderWidth > 0 && m_borderColor.a() > 0) { + g_painter.bindColor(m_borderColor); + g_painter.drawBoundingRect(screenCoords, m_borderWidth); + } + */ +} + +void UIWidget::drawImage(const Rect& screenCoords) +{ + if(m_image) { + g_painter.setColor(m_backgroundColor); + m_image->draw(screenCoords); + } +} + +void UIWidget::drawIcon(const Rect& screenCoords) +{ + if(m_icon) { + Rect iconRect; + iconRect.resize(m_icon->getSize()); + iconRect.moveCenter(screenCoords.center()); + g_painter.setColor(Fw::white); + g_painter.drawTexturedRect(iconRect, m_icon); + } +} + +void UIWidget::drawText(const Rect& screenCoords) +{ + g_painter.setColor(m_foregroundColor); + if(m_text.length() > 0 && m_foregroundColor.a() > 0) { + Rect textRect = screenCoords; + textRect.translate(m_textOffset); + m_font->renderText(m_text, textRect, m_textAlign, m_foregroundColor); + } +} + void UIWidget::setEnabled(bool enabled) { if(enabled != m_enabled) { @@ -215,6 +274,36 @@ void UIWidget::setRect(const Rect& rect) m_updateEventScheduled = true; } +void UIWidget::setIcon(const std::string& iconFile) +{ + m_icon = g_textures.getTexture(iconFile); +} + +void UIWidget::setText(const std::string& text) +{ + if(m_text != text) { + m_text = text; + + // update rect size + if(!m_rect.isValid()) { + Size textSize = m_font->calculateTextRectSize(m_text); + Size newSize = getSize(); + if(newSize.width() <= 0) + newSize.setWidth(textSize.width()); + if(newSize.height() <= 0) + newSize.setHeight(textSize.height()); + resize(newSize); + } + + onTextChange(text); + } +} + +void UIWidget::setFont(const std::string& fontName) +{ + m_font = g_fonts.getFont(fontName); +} + void UIWidget::bindRectToParent() { Rect boundRect = m_rect; @@ -672,8 +761,8 @@ void UIWidget::updateLayout() void UIWidget::applyStyle(const OTMLNodePtr& styleNode) { try { - onStyleApply(styleNode); - callLuaField("onStyleApply", styleNode); + onStyleApply(styleNode->tag(), styleNode); + callLuaField("onStyleApply", styleNode->tag(), styleNode); } catch(Exception& e) { logError("Failed to apply style to widget '", m_id, "' style: ", e.what()); } @@ -862,7 +951,7 @@ void UIWidget::updateStyle() m_stateStyle = newStateStyle; } -void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) +void UIWidget::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { // first set id if(const OTMLNodePtr& node = styleNode->get("id")) @@ -878,8 +967,16 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) } else if(node->tag() == "border-image") setImage(BorderImage::loadFromOTML(node)); + if(node->tag() == "icon") + setIcon(node->value()); + else if(node->tag() == "text") + setText(node->value()); + else if(node->tag() == "text-align") + setTextAlign(Fw::translateAlignment(node->value())); + else if(node->tag() == "text-offset") + setTextOffset(node->value()); else if(node->tag() == "font") - setFont(g_fonts.getFont(node->value())); + setFont(node->value()); else if(node->tag() == "color") setForegroundColor(node->value()); else if(node->tag() == "background-color") @@ -902,7 +999,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) setHeight(node->value()); else if(node->tag() == "fixed-size") setSizeFixed(node->value()); - else if(node->tag() == "position") + else if(node->tag() == "pos") moveTo(node->value()); else if(node->tag() == "x") setX(node->value()); @@ -1007,7 +1104,7 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) } // lua functions } else if(boost::starts_with(node->tag(), "@")) { - // on load once + // load once if(m_firstOnStyle) { std::string funcName = node->tag().substr(1); std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]"; @@ -1051,6 +1148,17 @@ void UIWidget::onHoverChange(bool hovered) g_ui.getRootWidget()->updateState(Fw::HoverState); } + +void UIWidget::onTextChange(const std::string& text) +{ + callLuaField("onTextChange", text); +} + +void UIWidget::onFontChange(const std::string& font) +{ + callLuaField("onFontChange", font); +} + bool UIWidget::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers) { if(callLuaField("onKeyPress", keyCode, keyText, keyboardModifiers)) @@ -1140,6 +1248,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button) void UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button) { + if(isPressed() && getRect().contains(mousePos)) + callLuaField("onClick"); + callLuaField("onMouseRelease", mousePos, button); // do a backup of children list, because it may change while looping it diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 42bbc5bc..ab3d4071 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -27,6 +27,7 @@ #include #include #include +#include class UIWidget : public LuaObject { @@ -40,9 +41,17 @@ public: void destroy(); virtual void render(); - void renderSelf(); - void renderChildren(); + virtual void renderSelf(); + virtual void renderChildren(); +protected: + void drawBackground(const Rect& screenCoords); + void drawBorder(const Rect& screenCoords); + void drawImage(const Rect& screenCoords); + void drawIcon(const Rect& screenCoords); + void drawText(const Rect& screenCoords); + +public: void setVisible(bool visible); void setEnabled(bool enabled); void setPressed(bool pressed) { m_pressed = pressed; updateState(Fw::PressedState); } @@ -59,7 +68,7 @@ public: void setWidth(int width) { resize(Size(width, getHeight())); } void setHeight(int height) { resize(Size(getWidth(), height)); } void setImage(const ImagePtr& image) { m_image = image; } - virtual void setFont(const FontPtr& font) { m_font = font; } + void setIcon(const std::string& iconFile); void setOpacity(int opacity) { m_opacity = opacity; } void setBackgroundColor(const Color& color) { m_backgroundColor = color; } void setForegroundColor(const Color& color) { m_foregroundColor = color; } @@ -67,11 +76,16 @@ public: void setMarginRight(int margin) { m_marginRight = margin; updateParentLayout(); } void setMarginBottom(int margin) { m_marginBottom = margin; updateParentLayout(); } void setMarginLeft(int margin) { m_marginLeft = margin; updateParentLayout(); } + void setText(const std::string& text); + void setTextAlign(Fw::AlignmentFlag align) { m_textAlign = align; } + void setTextOffset(const Point& offset) { m_textOffset = offset; } + void setFont(const std::string& fontName); void setSizeFixed(bool fixed) { m_fixedSize = fixed; updateParentLayout(); } void setLastFocusReason(Fw::FocusReason reason) { m_lastFocusReason = reason; } void bindRectToParent(); - void resize(const Size& size) { setRect(Rect(getPosition(), size)); } + void resize(const Size& size) { setRect(Rect(getPos(), size)); } + void resizeToText() { resize(getTextSize()); } void moveTo(const Point& pos) { setRect(Rect(pos, getSize())); } void hide() { setVisible(false); } void show() { setVisible(true); } @@ -84,6 +98,7 @@ public: void ungrabMouse(); void grabKeyboard(); void ungrabKeyboard(); + void clearText() { setText(""); } bool isActive() { return hasState(Fw::ActiveState); } bool isEnabled() { return !hasState(Fw::DisabledState); } @@ -111,15 +126,13 @@ public: UILayoutPtr getLayout() { return m_layout; } UIWidgetPtr getParent() { return m_parent.lock(); } UIWidgetPtr getRootParent(); - Point getPosition() { return m_rect.topLeft(); } + Point getPos() { return m_rect.topLeft(); } Size getSize() { return m_rect.size(); } Rect getRect() { return m_rect; } int getX() { return m_rect.x(); } int getY() { return m_rect.y(); } int getWidth() { return m_rect.width(); } int getHeight() { return m_rect.height(); } - ImagePtr getImage() { return m_image; } - FontPtr getFont() { return m_font; } Color getForegroundColor() { return m_foregroundColor; } Color getBackgroundColor() { return m_backgroundColor; } int getOpacity() { return m_opacity; } @@ -127,6 +140,12 @@ public: int getMarginRight() { return m_marginRight; } int getMarginBottom() { return m_marginBottom; } int getMarginLeft() { return m_marginLeft; } + std::string getText() { return m_text; } + Fw::AlignmentFlag getTextAlign() { return m_textAlign; } + Point getTextOffset() { return m_textOffset; } + std::string getFont() { return m_font->getName(); } + Size getTextSize() { return m_font->calculateTextRectSize(m_text); } + Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; } OTMLNodePtr getStyle() { return m_style; } std::string getStyleName() { return m_style->tag(); } @@ -175,27 +194,18 @@ private: void updateStyle(); protected: - /// Triggered when widget style is changed - virtual void onStyleApply(const OTMLNodePtr& styleNode); - /// Triggered when widget is moved or resized + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); - /// Triggered when widget gets or loses focus virtual void onFocusChange(bool focused, Fw::FocusReason reason); - /// Triggered when the mouse enters or leaves widget area virtual void onHoverChange(bool hovered); - /// Triggered when user presses key while widget has focus + virtual void onTextChange(const std::string& text); + virtual void onFontChange(const std::string& font); virtual bool onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers); - /// Triggered when user releases key while widget has focus virtual bool onKeyRelease(uchar keyCode, std::string keyText, int keyboardModifiers); - /// Triggered when a mouse button is pressed down while mouse pointer is inside widget area virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); - /// Triggered when a mouse button is released virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); - /// Triggered when mouse moves (even when the mouse is outside widget area) virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); - /// Triggered when mouse middle button wheels inside widget area virtual bool onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction); - friend class UIManager; protected: @@ -218,6 +228,7 @@ protected: OTMLNodePtr m_style; OTMLNodePtr m_stateStyle; ImagePtr m_image; + TexturePtr m_icon; FontPtr m_font; Color m_backgroundColor; Color m_foregroundColor; @@ -227,6 +238,9 @@ protected: int m_marginRight; int m_marginBottom; int m_marginLeft; + std::string m_text; + Point m_textOffset; + Fw::AlignmentFlag m_textAlign; }; #endif diff --git a/src/framework/ui/uiwindow.cpp b/src/framework/ui/uiwindow.cpp index d637fecc..ed981e51 100644 --- a/src/framework/ui/uiwindow.cpp +++ b/src/framework/ui/uiwindow.cpp @@ -56,9 +56,9 @@ void UIWindow::render() m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor); } -void UIWindow::onStyleApply(const OTMLNodePtr& styleNode) +void UIWindow::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "head-height") @@ -94,7 +94,7 @@ bool UIWindow::onMousePress(const Point& mousePos, Fw::MouseButton button) m_moving = true; m_movingReference = mousePos - getRect().topLeft(); m_oldIndex = getParent()->getChildIndex(asUIWidget()); - m_oldPos = getPosition(); + m_oldPos = getPos(); getParent()->moveChildToTop(asUIWidget()); } } diff --git a/src/framework/ui/uiwindow.h b/src/framework/ui/uiwindow.h index 6e2b8f80..99c972a6 100644 --- a/src/framework/ui/uiwindow.h +++ b/src/framework/ui/uiwindow.h @@ -41,7 +41,7 @@ public: std::string getTitle() const { return m_title; } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index b77daa09..b8db523d 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -98,7 +98,7 @@ void Game::processTextMessage(int type, const std::string& message) void Game::processInventoryChange(int slot, const ItemPtr& item) { if(item) - item->setPosition(Position(65535, slot, 0)); + item->setPos(Position(65535, slot, 0)); g_lua.callGlobalField("Game","onInventoryChange", slot, item); } @@ -162,8 +162,8 @@ void Game::turn(Otc::Direction direction) void Game::look(const ThingPtr& thing) { // thing is at map - if(thing->getPosition().x != 65535) { - Position tilePos = thing->getPosition(); + if(thing->getPos().x != 65535) { + Position tilePos = thing->getPos(); TilePtr tile = nullptr; int stackpos = -1; @@ -182,21 +182,21 @@ void Game::look(const ThingPtr& thing) } // thing is at inventory else - m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), 0); + m_protocolGame->sendLookAt(thing->getPos(), thing->getId(), 0); } void Game::use(const ThingPtr& thing) { // thing is at map - if(thing->getPosition().x != 65535) { - TilePtr tile = g_map.getTile(thing->getPosition()); + if(thing->getPos().x != 65535) { + TilePtr tile = g_map.getTile(thing->getPos()); int stackpos = tile->getThingStackpos(thing); if(stackpos != -1) - m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, 0); + m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0); } // thing is at inventory else - m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), 0, 0); // last 0 has something to do with container + m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), 0, 0); // last 0 has something to do with container } void Game::talkChannel(int channelType, int channelId, const std::string& message) diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 326354ce..a66d6b19 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -41,7 +41,7 @@ void Item::draw(const Point& p) internalDraw(p, b); } -void Item::setPosition(const Position& position) +void Item::setPos(const Position& position) { if(m_type->properties[ThingType::IsGround]) { m_xPattern = position.x % m_type->dimensions[ThingType::PatternX]; @@ -49,7 +49,7 @@ void Item::setPosition(const Position& position) m_zPattern = position.z % m_type->dimensions[ThingType::PatternZ]; } - Thing::setPosition(position); + Thing::setPos(position); } void Item::setData(int data) diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index c1f0a0bf..92fa6552 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -37,7 +37,7 @@ public: void draw(const Point& p); - void setPosition(const Position &position); + void setPos(const Position &position); void setData(int data); int getData() { return m_data; } diff --git a/src/otclient/core/localplayer.cpp b/src/otclient/core/localplayer.cpp index e6ee150e..b1eb5a4b 100644 --- a/src/otclient/core/localplayer.cpp +++ b/src/otclient/core/localplayer.cpp @@ -35,7 +35,7 @@ void LocalPlayer::clientWalk(Otc::Direction direction) { // We're not walking, so start a client walk. if(!m_walking) { - Position newPos = m_position + Position::getPositionFromDirection(direction); + Position newPos = m_position + Position::getPosFromDirection(direction); Creature::walk(newPos, false); m_clientWalking = true; } @@ -49,7 +49,7 @@ void LocalPlayer::walk(const Position& position, bool inverse) if(m_clientWalking) { m_clientWalking = false; - Position pos = Position::getPositionFromDirection(m_direction); + Position pos = Position::getPosFromDirection(m_direction); Point walkOffset = Point(m_walkOffset.x - pos.x * 32, m_walkOffset.y - pos.y * 32); @@ -97,7 +97,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction) return false; } - Position newPos = m_position + Position::getPositionFromDirection(direction); + Position newPos = m_position + Position::getPosFromDirection(direction); TilePtr tile = g_map.getTile(newPos); if(!tile->isWalkable()) { // TODO: create enum for 17, white message on screen bottom and console. diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index 1a7ebd66..45fb55ba 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -88,7 +88,7 @@ void Map::draw(const Rect& rect) // after drawing all tiles, draw shots for(const MissilePtr& shot : m_missilesAtFloor[iz]) { - Position missilePos = shot->getPosition(); + Position missilePos = shot->getPos(); shot->draw(positionTo2D(missilePos) - m_drawOffset); } } @@ -132,7 +132,7 @@ void Map::draw(const Rect& rect) // draw animated text for(auto it = m_animatedTexts.begin(), end = m_animatedTexts.end(); it != end; ++it) { - Point pos = positionTo2D((*it)->getPosition()) - m_drawOffset; + Point pos = positionTo2D((*it)->getPos()) - m_drawOffset; pos.x *= horizontalStretchFactor; pos.y *= verticalStretchFactor; (*it)->draw(rect.topLeft() + pos); @@ -140,7 +140,7 @@ void Map::draw(const Rect& rect) // draw static text for(auto it = m_staticTexts.begin(), end = m_staticTexts.end(); it != end; ++it) { - Point pos = positionTo2D((*it)->getPosition()) - m_drawOffset; + Point pos = positionTo2D((*it)->getPos()) - m_drawOffset; pos.x *= horizontalStretchFactor; pos.y *= verticalStretchFactor; (*it)->draw(rect.topLeft() + pos); @@ -246,7 +246,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos) m_creatures[creature->getId()] = creature; } else if(MissilePtr shot = thing->asMissile()) { - m_missilesAtFloor[shot->getPosition().z].push_back(shot); + m_missilesAtFloor[shot->getPos().z].push_back(shot); } else if(AnimatedTextPtr animatedText = thing->asAnimatedText()) { m_animatedTexts.push_back(animatedText); @@ -255,7 +255,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos) bool mustAdd = true; for(auto it = m_staticTexts.begin(), end = m_staticTexts.end(); it != end; ++it) { StaticTextPtr cStaticText = *it; - if(cStaticText->getPosition() == pos) { + if(cStaticText->getPos() == pos) { // try to combine messages if(cStaticText->addMessage(staticText->getName(), staticText->getMessageType(), staticText->getFirstMessage())) { mustAdd = false; @@ -276,7 +276,7 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos) } thing->start(); - thing->setPosition(pos); + thing->setPos(pos); } ThingPtr Map::getThing(const Position& pos, int stackPos) @@ -298,9 +298,9 @@ void Map::removeThing(const ThingPtr& thing) return; if(MissilePtr shot = thing->asMissile()) { - auto it = std::find(m_missilesAtFloor[shot->getPosition().z].begin(), m_missilesAtFloor[shot->getPosition().z].end(), shot); - if(it != m_missilesAtFloor[shot->getPosition().z].end()) { - m_missilesAtFloor[shot->getPosition().z].erase(it); + auto it = std::find(m_missilesAtFloor[shot->getPos().z].begin(), m_missilesAtFloor[shot->getPos().z].end(), shot); + if(it != m_missilesAtFloor[shot->getPos().z].end()) { + m_missilesAtFloor[shot->getPos().z].erase(it); } return; } @@ -317,7 +317,7 @@ void Map::removeThing(const ThingPtr& thing) return; } - if(TilePtr& tile = m_tiles[thing->getPosition()]) + if(TilePtr& tile = m_tiles[thing->getPos()]) tile->removeThing(thing); } diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index a5c8dc8e..d1213a58 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -44,10 +44,10 @@ public: virtual void draw(const Point& p) = 0; void setId(int id); - virtual void setPosition(const Position& position) { m_position = position; } + virtual void setPos(const Position& position) { m_position = position; } int getId() const { return m_id; } - Position getPosition() const { return m_position; } + Position getPos() const { return m_position; } int getStackPriority(); virtual ThingType *getType(); int getAnimationPhases() { return m_type->dimensions[ThingType::AnimationPhases]; } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index f243009e..5cc94615 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -44,7 +44,7 @@ public: ThingPtr removeThing(int stackPos); ThingPtr removeThing(const ThingPtr& thing); - const Position& getPosition() { return m_position; } + const Position& getPos() { return m_position; } int getDrawElevation() { return m_drawElevation; } std::vector getCreatures(); ItemPtr getGround(); diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index eb10ff75..3421d53c 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -535,7 +535,7 @@ void ProtocolGame::parseMagicEffect(InputMessage& msg) EffectPtr effect = EffectPtr(new Effect()); effect->setId(effectId); - effect->setPosition(pos); + effect->setPos(pos); g_map.addThing(effect, pos); } @@ -547,7 +547,7 @@ void ProtocolGame::parseAnimatedText(InputMessage& msg) std::string text = msg.getString(); AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setPosition(position); + animatedText->setPos(position); animatedText->setColor(color); animatedText->setText(text); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index 6338e5f6..f6eb0fb5 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -41,12 +41,12 @@ void UICreature::render() renderChildren(); } -void UICreature::onStyleApply(const OTMLNodePtr& styleNode) +void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "creature-margin") m_creatureMargin = node->value(); } - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); } diff --git a/src/otclient/ui/uicreature.h b/src/otclient/ui/uicreature.h index 2ca9278e..fe73627d 100644 --- a/src/otclient/ui/uicreature.h +++ b/src/otclient/ui/uicreature.h @@ -38,7 +38,7 @@ public: CreaturePtr getCreature() { return m_creature; } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); private: CreaturePtr m_creature; diff --git a/src/otclient/ui/uiitem.cpp b/src/otclient/ui/uiitem.cpp index 11388a27..4167f52a 100644 --- a/src/otclient/ui/uiitem.cpp +++ b/src/otclient/ui/uiitem.cpp @@ -41,12 +41,12 @@ void UIItem::render() renderChildren(); } -void UIItem::onStyleApply(const OTMLNodePtr& styleNode) +void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "item margin") m_itemMargin = node->value(); } - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); } diff --git a/src/otclient/ui/uiitem.h b/src/otclient/ui/uiitem.h index 4b906c4b..55dcd45e 100644 --- a/src/otclient/ui/uiitem.h +++ b/src/otclient/ui/uiitem.h @@ -37,7 +37,7 @@ public: ItemPtr getItem() { return m_item; } protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); private: ItemPtr m_item; diff --git a/src/otclient/ui/uimap.cpp b/src/otclient/ui/uimap.cpp index f04fce51..bca0541f 100644 --- a/src/otclient/ui/uimap.cpp +++ b/src/otclient/ui/uimap.cpp @@ -46,14 +46,14 @@ void UIMap::render() renderChildren(); } -void UIMap::onStyleApply(const OTMLNodePtr& styleNode) +void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode) { for(OTMLNodePtr node : styleNode->children()) { if(node->tag() == "map margin") m_mapMargin = node->value(); } - UIWidget::onStyleApply(styleNode); + UIWidget::onStyleApply(styleName, styleNode); } bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) diff --git a/src/otclient/ui/uimap.h b/src/otclient/ui/uimap.h index cc3145ab..44316985 100644 --- a/src/otclient/ui/uimap.h +++ b/src/otclient/ui/uimap.h @@ -33,7 +33,7 @@ public: void render(); protected: - virtual void onStyleApply(const OTMLNodePtr& styleNode); + virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect); diff --git a/src/otclient/util/position.h b/src/otclient/util/position.h index a39dba44..2e63df10 100644 --- a/src/otclient/util/position.h +++ b/src/otclient/util/position.h @@ -33,7 +33,7 @@ public: Position() : x(-1), y(-1), z(-1) { } Position(int x, int y, int z) : x(x), y(y), z(z) { } - static Position getPositionFromDirection(Otc::Direction direction) { + static Position getPosFromDirection(Otc::Direction direction) { switch(direction) { case Otc::North: return Position( 0, -1, 0); diff --git a/tools/katepart-syntax/lua.xml b/tools/katepart-syntax/lua.xml index 038362db..66415ca3 100644 --- a/tools/katepart-syntax/lua.xml +++ b/tools/katepart-syntax/lua.xml @@ -136,142 +136,6 @@ displayUI createWidget - - AnchorNone - AnchorTop - AnchorBottom - AnchorLeft - AnchorRight - AnchorVerticalCenter - AnchorHorizontalCenter - - LogDebug - LogInfo - LogWarning - LogError - LogFatal - - ActiveFocusReason - - KeyUnknown - KeyEscape - KeyTab - KeyBackspace - KeyReturn - KeyEnter - KeyInsert - KeyDelete - KeyPause - KeyPrintScreen - KeyHome - KeyEnd - KeyPageUp - KeyPageDown - KeyUp - KeyDown - KeyLeft - KeyRight - KeyNumLock - KeyScrollLock - KeyCapsLock - KeyCtrl - KeyShift - KeyAlt - KeyAltGr - KeyMeta - KeyMenu - KeySpace - KeyExclamation - KeyQuote - KeyNumberSign - KeyDollar - KeyPercent - KeyAmpersand - KeyApostrophe - KeyLeftParen - KeyRightParen - KeyAsterisk - KeyPlus - KeyComma - KeyMinus - KeyPeriod - KeySlash - Key0 - Key1 - Key2 - Key3 - Key4 - Key5 - Key6 - Key7 - Key8 - Key9 - KeyColon - KeySemicolon - KeyLess - KeyEqual - KeyGreater - KeyQuestion - KeyAtSign - KeyA - KeyB - KeyC - KeyD - KeyE - KeyF - KeyG - KeyH - KeyI - KeyJ - KeyK - KeyL - KeyM - KeyN - KeyO - KeyP - KeyQ - KeyR - KeyS - KeyT - KeyU - KeyV - KeyW - KeyX - KeyY - KeyZ - KeyLeftBracket - KeyBackslash - KeyRightBracket - KeyCaret - KeyUnderscore - KeyGrave - KeyLeftCurly - KeyBar - KeyRightCurly - KeyTilde - KeyF1 - KeyF2 - KeyF3 - KeyF4 - KeyF5 - KeyF6 - KeyF7 - KeyF8 - KeyF9 - KeyF10 - KeyF11 - KeyF12 - - KeyboardNoModifier - KeyboardCtrlModifier - KeyboardAltModifier - KeyboardShiftModifier - - MouseNoButton - MouseLeftButton - MouseRightButton - MouseMidButton - TODO FIXME @@ -302,7 +166,6 @@ - @@ -358,7 +221,6 @@ -