major UIWidget rewrite with new features

This commit is contained in:
Eduardo Bart 2012-01-10 20:13:40 -02:00
parent 044213c6cd
commit a1374baee1
83 changed files with 1990 additions and 2010 deletions

4
TODO
View File

@ -16,6 +16,7 @@
== Lua
[bart] make possible to bind non LuaObject derived classes on lua engine (for usage with Point,Rect,Color,Size)
[bart] bind every global lua function in static classes
[bart] review usage of x,y/width,height in lua instead of point/size
== Platform
[bart] port to MacOs and iphone
@ -102,3 +103,6 @@ game map text message boxes is not displayed like tibia
name/shields doesnt follow the creature when walking on parcels
hotkeys wont work with caps lock
hotkeys works while windows are locked, it shouldnt
-- current todo
allow usage of background width alone

View File

@ -2,13 +2,15 @@ MapEffects = {}
function MapEffects.init()
--[[
local box = createWidget('ComboBox')
box:moveTo({x=100, y=8})
local box = createWidget('ComboBox', 'leftButtonsPanel')
box:addAnchor(AnchorLeft, 'prev', AnchorRight)
box:addAnchor(AnchorTop, 'parent', AnchorTop)
box:setMargin(6, 6)
box:addOption('Normal')
box:addOption('Bloom')
box:addOption('TV')
displayUI(box)
]]--
]]--
end
function MapEffects.terminate()

View File

@ -21,7 +21,7 @@ end
-- hooked events
local function onGamePingUpdate(ping)
pingLabel:setText('Walk Ping: ' .. ping .. ' ms')
pingLabel:setText('Ping: ' .. ping .. ' ms')
end
connect(Game, { onWalkPingUpdate = onGamePingUpdate })

View File

@ -2,10 +2,10 @@ TerminalLabel < UILabel
font: terminus-14px-bold
height: 16
RectPanel
Panel
id: terminalPanel
background-color: #000000
opacity: 216
opacity: 0.85
anchors.fill: parent
@onEscape: Terminal.hide()

View File

@ -1,9 +1,8 @@
Panel
id: background
image:
source: /client_background/background.png
smooth: true
fixed ratio: true
image-source: /client_background/background.png
image-smooth: true
image-fixed-ratio: true
anchors.top: topMenu.bottom
anchors.left: parent.left
anchors.right: parent.right

View File

@ -1,12 +1,8 @@
CharacterListLabel < Label
image: /core_styles/images/empty_rect.png
font: verdana-11px-monochrome
background-color: #00000000
background-color: alpha
text-offset: 2 0
focusable: true
margin-left: 1
margin-right: 1
margin-top: 1
$focus:
background-color: #ffffff22

View File

@ -1,27 +1,22 @@
TopButton < UIButton
background-color: white
size: 26 26
text-translate: 0 0
border-image:
source: /core_styles/images/top_button.png
clip: 0 0 26 26
border: 3
image-color: white
image-source: /core_styles/images/top_button.png
image-clip: 0 0 26 26
image-border: 3
$hover:
border-image:
source: /core_styles/images/top_button.png
clip: 26 0 26 26
border: 3
image-source: /core_styles/images/top_button.png
image-clip: 26 0 26 26
image-border: 3
$pressed:
text-translate: 1 1
border-image:
source: /core_styles/images/top_button.png
clip: 52 0 26 26
border: 3
image-source: /core_styles/images/top_button.png
image-clip: 52 0 26 26
image-border: 3
$disabled:
background-color: #ffffff66
image-color: #ffffff66
TopLeftButton < TopButton
$first:

View File

@ -66,6 +66,9 @@ function createWidget(style, parent)
local widget = class.create()
if parent then
if type(parent) == 'string' then
parent = rootWidget:recursiveGetChildById(parent)
end
parent:addChild(widget)
end
widget:setStyle(style)

View File

@ -11,6 +11,7 @@ Module
importStyle 'styles/separators.otui'
importStyle 'styles/lineedits.otui'
importStyle 'styles/checkboxes.otui'
importStyle 'styles/progressbars.otui'
importStyle 'styles/windows.otui'
importStyle 'styles/listboxes.otui'
importStyle 'styles/items.otui'

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 B

View File

@ -1,26 +1,23 @@
Button < UIButton
font: verdana-11px-antialised
background-color: white
color: #f0ad4dff
size: 106 24
text-translate: 0 0
text-offset: 0 0
border-image:
source: /core_styles/images/button.png
border: 5
image-color: white
image-source: /core_styles/images/button.png
image-border: 5
$hover:
border-image:
source: /core_styles/images/button_hover.png
border: 5
image-source: /core_styles/images/button_hover.png
image-border: 5
$pressed:
text-translate: 1 1
border-image:
source: /core_styles/images/button_down.png
border: 5
text-offset: 1 1
image-source: /core_styles/images/button_down.png
image-border: 5
$disabled:
color: #f0ad4d88
background-color: #ffffff88
image-color: #ffffff88

View File

@ -2,41 +2,38 @@ CheckBox < UICheckBox
size: 12 12
box-size: 12 12
text-align: left
text-offset: 16 -1
text-offset: 16 0
color: #aaaaaa
background-color: #ffffffff
image-color: #ffffffff
image-rect: 0 0 12 12
$hover:
color: #cccccc
$!checked:
image:
source: /core_styles/images/checkbox.png
clip: 0 0 12 12
image-source: /core_styles/images/checkbox.png
image-clip: 0 0 12 12
$hover !checked:
image:
source: /core_styles/images/checkbox.png
clip: 0 12 12 12
image-source: /core_styles/images/checkbox.png
image-clip: 0 12 12 12
$checked:
image:
source: /core_styles/images/checkbox.png
clip: 0 24 12 12
image-source: /core_styles/images/checkbox.png
image-clip: 0 24 12 12
$hover checked:
image:
source: /core_styles/images/checkbox.png
clip: 0 36 12 12
image-source: /core_styles/images/checkbox.png
image-clip: 0 36 12 12
$disabled:
background-color: #ffffff88
image-color: #ffffff88
color: #aaaaaa88
ColorBox < UICheckBox
size: 16 16
box-size: 16 16
background-color: #ffffffff
image-color: #ffffffff
$checked:
image:
@ -50,28 +47,25 @@ ColorBox < UICheckBox
ButtonBox < UICheckBox
font: verdana-11px-antialised
background-color: white
color: #f0ad4dff
size: 106 24
box-size: 106 24
text-offset: 0 0
text-align: center
border-image:
source: /core_styles/images/button.png
border: 5
image-color: white
image-source: /core_styles/images/button.png
image-border: 5
$hover:
border-image:
source: /core_styles/images/button_hover.png
border: 5
image-source: /core_styles/images/button_hover.png
image-border: 5
$checked:
text-offset: 1 1
border-image:
source: /core_styles/images/button_down.png
border: 5
image-source: /core_styles/images/button_down.png
image-border: 5
$disabled:
color: #f0ad4d88
background-color: #ffffff88
image-color: #ffffff88

View File

@ -1,6 +1,6 @@
ComboBoxPopupMenuButton < UIButton
font: verdana-11px-antialised
background-color: alpha
image-color: alpha
text-align: left
text-offset: 2 0
color: #aaaaaa
@ -9,10 +9,7 @@ ComboBoxPopupMenuButton < UIButton
margin-right: 1
margin-top: 0
margin-bottom: 0
image:
source: /core_styles/images/empty_rect.png
repeated: true
background-color: white
$hover:
color: #ffffff
@ -30,19 +27,17 @@ ComboBoxPopupMenuButton < UIButton
ComboBoxPopupMenuSeparator < UIWidget
margin-left: 1
margin-right: 1
image:
source: /core_styles/images/combobox.png
repeated: true
image-source: /core_styles/images/combobox.png
image-repeated: true
clip: 1 59 89 1
height: 1
phantom: true
ComboBoxPopupMenu < UIPopupMenu
border-image:
source: /core_styles/images/combobox.png
clip: 0 60 89 20
border: 1
border.top: 0
image-source: /core_styles/images/combobox.png
image-clip: 0 60 89 20
image-border: 1
image-border-top: 0
ComboBox < UIComboBox
font: verdana-11px-antialised
@ -50,22 +45,19 @@ ComboBox < UIComboBox
size: 86 20
text-offset: 3 0
text-align: left
border-image:
source: /core_styles/images/combobox.png
border: 1
border.right: 17
size: 89 20
image-source: /core_styles/images/combobox.png
image-border: 1
image-border-right: 17
image-clip: 0 0 89 20
$hover:
border-image:
source: /core_styles/images/combobox.png
border: 1
border.right: 17
clip: 0 20 89 20
image-source: /core_styles/images/combobox.png
image-border: 1
image-border-right: 17
image-clip: 0 20 89 20
$on:
border-image:
source: /core_styles/images/combobox.png
border: 1
border.right: 17
clip: 0 40 89 20
image-source: /core_styles/images/combobox.png
image-border: 1
image-border-right: 17
image-clip: 0 40 89 20

View File

@ -1,6 +1,5 @@
Creature < UICreature
size: 66 66
padding: 1
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1

View File

@ -1,6 +1,5 @@
Item < UIItem
size: 34 34
padding: 1
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1

View File

@ -3,9 +3,8 @@ LineEdit < UILineEdit
color: #aaaaaa
size: 86 20
text-margin: 3
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1
$disabled:
color: #aaaaaa88

View File

@ -1,5 +1,5 @@
TextList < UIWidget
layout: verticalBox
border-image:
source: /core_styles/images/panel_flat.png
border: 4
border-width: 1
border-color: #1d222b
background-color: #222833

View File

@ -1,34 +1,26 @@
Panel < UIWidget
phantom: true
RectPanel < UIWidget
image: /core_styles/images/empty_rect.png
FlatPanel < Panel
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1
TopPanel < Panel
height: 36
image:
source: /core_styles/images/top_panel.png
repeated: true
image-source: /core_styles/images/top_panel.png
image-repeated: true
InterfacePanel < Panel
focusable: false
border-image:
source: /core_styles/images/interface_panel.png
border: 4
image-source: /core_styles/images/interface_panel.png
image-border: 4
InterfacePanel2 < Panel
focusable: false
border-image:
source: /core_styles/images/interface_panel2.png
border: 4
image-source: /core_styles/images/interface_panel2.png
image-border: 4
Map< UIMap
padding: 4
border-image:
source: /core_styles/images/map_panel.png
border: 4
image-source: /core_styles/images/map_panel.png
image-border: 4

View File

@ -1,16 +1,13 @@
PopupMenuButton < UIButton
font: verdana-11px-antialised
background-color: alpha
image-color: alpha
color: #aaaaaa
height: 18
margin-left: 3
margin-right: 3
margin-top: 0
margin-bottom: 0
image:
source: /core_styles/images/empty_rect.png
repeated: true
background-color: alpha
$hover:
color: #ffffff
@ -28,16 +25,15 @@ PopupMenuButton < UIButton
PopupMenuSeparator < UIWidget
margin-left: 2
margin-right: 2
border-image:
source: /core_styles/images/menubox.png
border.left: 1
border.right: 1
clip: 0 0 32 2
image-source: /core_styles/images/menubox.png
image-border-left: 1
image-border-right: 1
image-clip: 0 0 32 2
height: 2
phantom: true
PopupMenu < UIPopupMenu
width: 50
border-image:
source: /core_styles/images/menubox.png
border: 3
image-source: /core_styles/images/menubox.png
image-border: 3

View File

@ -0,0 +1,4 @@
ProgressBar < UIProgressBar
height: 15
background-color: red
border: 1 black

View File

@ -1,7 +1,6 @@
HorizontalSeparator < UIWidget
border-image:
source: /core_styles/images/horizontal_separator.png
border.top: 2
image-source: /core_styles/images/horizontal_separator.png
image-border.top: 2
height: 2
phantom: true
focusable: false

View File

@ -0,0 +1,5 @@
TabBar < UITabBar
TabBarTabButton < UIButton
TabBarCloseButton < UIButton
TabBarPrevButton < UIButton
TabBarNextButton < UIButton

View File

@ -1,20 +1,18 @@
Window < UIWindow
font: verdana-11px-antialised
size: 200 200
opacity: 255
opacity: 1
color: white
background-color: white
head-height: 20
head-text-align: center
move-policy: free
stackable: true
border-image:
source: /core_styles/images/window.png
border: 4
border.top: 20
image-source: /core_styles/images/window.png
image-border: 4
image-border-top: 20
$pressed:
opacity: 192
opacity: 0.75
$disabled:
color: #aaaaaa88
@ -28,10 +26,9 @@ MiniWindow < UIWindow
margin-left: 6
margin-right: 6
move-policy: free updated
border-image:
source: /core_styles/images/mini_window.png
border: 4
border.top: 25
image-source: /core_styles/images/mini_window.png
image-border: 4
image-border-top: 25
MainWindow < Window
anchors.centerIn: parent

View File

@ -5,10 +5,12 @@ Module
website: https://github.com/edubart/otclient
onLoad: |
require 'tooltip/tooltip'
require 'messagebox/messagebox'
require 'uiwidget'
require 'uibutton'
require 'uilabel'
require 'uicheckbox'
require 'uicombobox'
require 'uiprogressbar'
require 'uipopupmenu'
require 'tooltip/tooltip'
require 'messagebox/messagebox'

View File

@ -13,7 +13,7 @@ local function moveToolTip(tooltip)
else
pos.x = pos.x + 10
end
tooltip:moveTo(pos)
tooltip:setPos(pos)
end
-- public functions
@ -28,7 +28,7 @@ function ToolTip.display(text)
local size = label:getSize()
size.width = size.width + 4
size.height = size.height + 4
currentToolTip:resize(size)
currentToolTip:setSize(size)
moveToolTip(currentToolTip)
end
end

View File

@ -1,4 +1,4 @@
RectPanel
Panel
background-color: #111111bb
size: 200 200
id: toolTip

View File

@ -3,6 +3,12 @@ UICheckBox = extends(UIWidget)
function UICheckBox.create()
local checkbox = UICheckBox.internalCreate()
checkbox:setFocusable(false)
checkbox:setAlign(AlignLeft)
checkbox:setTextAlign(AlignLeft)
return checkbox
end
function UICheckBox:onMouseRelease(mousePos, mouseButton)
if self:isPressed() and self:containsPoint(mousePos) then
self:setChecked(not self:isChecked())
end
end

View File

@ -0,0 +1,19 @@
UIProgressBar = extends(UIWidget)
function UIProgressBar.create()
local progressbar = UIProgressBar.internalCreate()
progressbar:setFocusable(false)
progressbar:setPhantom(true)
progressbar.percent = 100
return progressbar
end
function UIProgressBar:setPercent(percent)
self:setBackgroundHeight(self:getHeight())
self:setBackgroundWidth((percent * self:getWidth())/100)
self.percent = percent
end
function UIProgressBar:getPercent()
return self.percent
end

View File

@ -0,0 +1 @@
UITabBar = extends(UIWidget)

View File

@ -1,19 +1,19 @@
function UIWidget:setMargin(...)
local params = {...}
if #params == 1 then
self:setMarginTop(params[1])
self:setMarginRight(params[1])
self:setMarginBottom(params[1])
self:setMarginLeft(params[1])
elseif #params == 2 then
self:setMarginTop(params[1])
self:setMarginRight(params[2])
self:setMarginBottom(params[1])
self:setMarginLeft(params[2])
elseif #params == 4 then
self:setMarginTop(params[1])
self:setMarginRight(params[2])
self:setMarginBottom(params[3])
self:setMarginLeft(params[4])
end
local params = {...}
if #params == 1 then
self:setMarginTop(params[1])
self:setMarginRight(params[1])
self:setMarginBottom(params[1])
self:setMarginLeft(params[1])
elseif #params == 2 then
self:setMarginTop(params[1])
self:setMarginRight(params[2])
self:setMarginBottom(params[1])
self:setMarginLeft(params[2])
elseif #params == 4 then
self:setMarginTop(params[1])
self:setMarginRight(params[2])
self:setMarginBottom(params[3])
self:setMarginLeft(params[4])
end
end

View File

@ -3,6 +3,27 @@ ConsoleLabel < UILabel
height: 14
color: yellow
SayModeButton < UIButton
size: 26 26
icon: /core_styles/icons/say.png
image-source: /core_styles/images/top_button.png
image-color: white
image-clip: 0 0 26 26
image-border: 3
$hover:
image-source: /core_styles/images/top_button.png
clip: 26 0 26 26
border: 3
$pressed:
image-source: /core_styles/images/top_button.png
image-clip: 52 0 26 26
image-border: 3
$disabled:
image-color: #ffffff66
Panel
id: consolePanel
anchors.fill: parent
@ -22,9 +43,17 @@ Panel
align-bottom: true
focusable: false
SayModeButton
id: sayModeButton
size: 20 20
anchors.left: parent.left
anchors.bottom: parent.bottom
margin-left: 6
margin-bottom: 6
LineEdit
id: consoleLineEdit
anchors.left: parent.left
anchors.left: sayModeButton.right
anchors.right: parent.right
anchors.bottom: parent.bottom
margin-right: 6

View File

@ -1,15 +1,13 @@
HealthBar < UIProgressBar
HealthBar < ProgressBar
id: healthBar
color: black
height: 15
background-color: red
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
ManaBar < UIProgressBar
ManaBar < ProgressBar
id: manaBar
color: black
height: 15
background-color: blue
anchors.bottom: parent.bottom

View File

@ -90,9 +90,8 @@ UIWindow
text-align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1
GameLabel
id: capacity
@ -104,7 +103,6 @@ UIWindow
text-align: center
border-image:
source: /core_styles/images/panel_flat.png
border: 1
image-source: /core_styles/images/panel_flat.png
image-border: 1

View File

@ -22,9 +22,8 @@ SkillValueLabel < GameLabel
anchors.bottom: parent.bottom
anchors.left: prev.left
SkillPercentPanel < UIProgressBar
SkillPercentPanel < ProgressBar
id: percent
color: black
background-color: green
height: 5
margin-top: 15
@ -36,7 +35,7 @@ SkillPercentPanel < UIProgressBar
MiniWindow
id: skillWindow
title: Skills
size: 200 400
size: 200 310
Panel
id: skillPanel
@ -60,7 +59,7 @@ MiniWindow
text: Level
SkillValueLabel
SkillPercentPanel
background-color: red
image-color: red
SkillButton
id: health
@ -103,7 +102,7 @@ MiniWindow
text: Magic Level
SkillValueLabel
SkillPercentPanel
background-color: red
image-color: red
SkillButton
id: skillId0

View File

@ -8,11 +8,11 @@ MiniWindow
id: vipWindow
title: VIP List
TextList
UIWidget
id: vipList
border-image: ~
layout: verticalBox
anchors.fill: parent
margin-top: 26
margin-top: 27
margin-bottom: 6
margin-left: 6
margin-right: 6

View File

@ -159,8 +159,6 @@ SET(framework_SOURCES ${framework_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/graphics/framebuffer.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/animatedtexture.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/texturemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/borderimage.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/image.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/particlemanager.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/particlesystem.cpp
${CMAKE_CURRENT_LIST_DIR}/graphics/particleemitter.cpp
@ -187,13 +185,14 @@ 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/uiwidgetimage.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiwidgettext.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiwidgetbasestyle.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uilineedit.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiwindow.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uianchorlayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiverticallayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uilayout.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiprogressbar.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uicheckbox.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uiframecounter.cpp
${CMAKE_CURRENT_LIST_DIR}/ui/uitranslator.cpp

View File

@ -1,201 +0,0 @@
/*
* Copyright (c) 2010-2012 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 "borderimage.h"
#include "graphics.h"
#include "texture.h"
#include "texturemanager.h"
#include <framework/otml/otml.h>
BorderImage::BorderImage(TexturePtr texture,
const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center)
{
m_texture = texture;
m_leftBorderTexCoords = left;
m_rightBorderTexCoords = right;
m_topBorderTexCoords = top;
m_bottomBorderTexCoords = bottom;
m_topLeftCornerTexCoords = topLeft;
m_topRightCornerTexCoords = topRight;
m_bottomLeftCornerTexCoords = bottomLeft;
m_bottomRightCornerTexCoords = bottomRight;
m_centerTexCoords = center;
m_bordersSize = Size(left.width() + right.width(),
top.height() + bottom.height());
m_defaultSize = Size(std::max(std::max(topLeft.width(), bottomLeft.width()), left.width()) +
std::max(std::max(topRight.width(), bottomRight.width()), right.width()) +
center.width(),
std::max(std::max(topLeft.height(), topRight.height()), top.height()) +
std::max(std::max(bottomLeft.height(), bottomRight.height()), bottom.height()) +
center.height());
}
BorderImagePtr BorderImage::loadFromOTML(const OTMLNodePtr& borderImageNode)
{
Rect leftBorder;
Rect rightBorder;
Rect topBorder;
Rect bottomBorder;
Rect topLeftCorner;
Rect topRightCorner;
Rect bottomLeftCorner;
Rect bottomRightCorner;
Rect center;
Rect clipRect;
int top, bottom, left, right, border;
Size size;
Point offset;
// load texture
std::string source = borderImageNode->at("source")->value();
TexturePtr texture = g_textures.getTexture(source);
// load basic border confs
border = borderImageNode->valueAt("border", 0);
clipRect = borderImageNode->valueAt("clip", Rect(0, 0, texture->getSize()));
// load border margins
top = bottom = left = right = border;
top = borderImageNode->valueAt("border.top", top);
bottom = borderImageNode->valueAt("border.bottom", bottom);
left = borderImageNode->valueAt("border.left", left);
right = borderImageNode->valueAt("border.right", right);
// calculates border coords
leftBorder = Rect(clipRect.left(), clipRect.top() + top, left, clipRect.height() - top - bottom);
rightBorder = Rect(clipRect.right() - right + 1, clipRect.top() + top, right, clipRect.height() - top - bottom);
topBorder = Rect(clipRect.left() + left, clipRect.top(), clipRect.width() - right - left, top);
bottomBorder = Rect(clipRect.left() + left, clipRect.bottom() - bottom + 1, clipRect.width() - right - left, bottom);
topLeftCorner = Rect(clipRect.left(), clipRect.top(), left, top);
topRightCorner = Rect(clipRect.right() - right + 1, clipRect.top(), right, top);
bottomLeftCorner = Rect(clipRect.left(), clipRect.bottom() - bottom + 1, left, bottom);
bottomRightCorner = Rect(clipRect.right() - right + 1, clipRect.bottom() - bottom + 1, right, bottom);
center = Rect(clipRect.left() + left, clipRect.top() + top, clipRect.width() - right - left, clipRect.height() - top - bottom);
// load individual border conf if supplied
/*
leftBorder = borderImageNode->valueAt("left border", leftBorder);
rightBorder = borderImageNode->valueAt("right border", rightBorder);
topBorder = borderImageNode->valueAt("top border", topBorder);
bottomBorder = borderImageNode->valueAt("bottom border", bottomBorder);
topLeftCorner = borderImageNode->valueAt("top left corner", topLeftCorner);
topRightCorner = borderImageNode->valueAt("top right corner", topRightCorner);
bottomLeftCorner = borderImageNode->valueAt("bottom left corner", bottomLeftCorner);
bottomRightCorner = borderImageNode->valueAt("bottom right corner", bottomRightCorner);
center = borderImageNode->valueAt("center", center);
*/
return BorderImagePtr(new BorderImage(texture,
leftBorder,
rightBorder,
topBorder,
bottomBorder,
topLeftCorner,
topRightCorner,
bottomLeftCorner,
bottomRightCorner,
center));
}
void BorderImage::draw(const Rect& screenCoords)
{
//TODO: borderimage drawing could be optimized by caching the render into a texture
if(screenCoords != m_cachedScreenCoords) {
m_cachedScreenCoords = screenCoords;
m_coordsBuffer.clear();
Rect rectCoords;
Size centerSize = screenCoords.size() - m_bordersSize;
// first the center
if(centerSize.area() > 0) {
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width(),
screenCoords.top() + m_topBorderTexCoords.height(),
centerSize);
m_coordsBuffer.addRepeatedRects(rectCoords, m_centerTexCoords);
}
// top left corner
rectCoords = Rect(screenCoords.topLeft(),
m_topLeftCornerTexCoords.size());
m_coordsBuffer.addRepeatedRects(rectCoords, m_topLeftCornerTexCoords);
// top
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width(),
screenCoords.topLeft().y,
centerSize.width(),
m_topBorderTexCoords.height());
m_coordsBuffer.addRepeatedRects(rectCoords, m_topBorderTexCoords);
// top right corner
rectCoords = Rect(screenCoords.left() + m_topLeftCornerTexCoords.width() + centerSize.width(),
screenCoords.top(),
m_topRightCornerTexCoords.size());
m_coordsBuffer.addRepeatedRects(rectCoords, m_topRightCornerTexCoords);
// left
rectCoords = Rect(screenCoords.left(),
screenCoords.top() + m_topLeftCornerTexCoords.height(),
m_leftBorderTexCoords.width(),
centerSize.height());
m_coordsBuffer.addRepeatedRects(rectCoords, m_leftBorderTexCoords);
// right
rectCoords = Rect(screenCoords.left() + m_leftBorderTexCoords.width() + centerSize.width(),
screenCoords.top() + m_topRightCornerTexCoords.height(),
m_rightBorderTexCoords.width(),
centerSize.height());
m_coordsBuffer.addRepeatedRects(rectCoords, m_rightBorderTexCoords);
// bottom left corner
rectCoords = Rect(screenCoords.left(),
screenCoords.top() + m_topLeftCornerTexCoords.height() + centerSize.height(),
m_bottomLeftCornerTexCoords.size());
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomLeftCornerTexCoords);
// bottom
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width(),
screenCoords.top() + m_topBorderTexCoords.height() + centerSize.height(),
centerSize.width(),
m_bottomBorderTexCoords.height());
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomBorderTexCoords);
// bottom right corner
rectCoords = Rect(screenCoords.left() + m_bottomLeftCornerTexCoords.width() + centerSize.width(),
screenCoords.top() + m_topRightCornerTexCoords.height() + centerSize.height(),
m_bottomRightCornerTexCoords.size());
m_coordsBuffer.addRepeatedRects(rectCoords, m_bottomRightCornerTexCoords);
}
g_painter.drawTextureCoords(m_coordsBuffer, m_texture);
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2010-2012 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 BORDERIMAGE_H
#define BORDERIMAGE_H
#include "image.h"
class BorderImage : public Image
{
public:
BorderImage(TexturePtr texture,
const Rect& left,
const Rect& right,
const Rect& top,
const Rect& bottom,
const Rect& topLeft,
const Rect& topRight,
const Rect& bottomLeft,
const Rect& bottomRight,
const Rect& center);
static BorderImagePtr loadFromOTML(const OTMLNodePtr& borderImageNode);
void draw(const Rect& screenCoords);
Size getDefaultSize() const { return m_defaultSize; }
private:
Rect m_leftBorderTexCoords;
Rect m_rightBorderTexCoords;
Rect m_topBorderTexCoords;
Rect m_bottomBorderTexCoords;
Rect m_topLeftCornerTexCoords;
Rect m_topRightCornerTexCoords;
Rect m_bottomLeftCornerTexCoords;
Rect m_bottomRightCornerTexCoords;
Rect m_centerTexCoords;
Size m_bordersSize;
Size m_defaultSize;
};
#endif

View File

@ -29,8 +29,6 @@
class Texture;
class AnimatedTexture;
class Font;
class Image;
class BorderImage;
class FrameBuffer;
class Shader;
class ShaderProgram;
@ -46,8 +44,6 @@ typedef std::weak_ptr<ParticleSystem> ParticleSystemWeakPtr;
typedef std::shared_ptr<Texture> TexturePtr;
typedef std::shared_ptr<AnimatedTexture> AnimatedTexturePtr;
typedef std::shared_ptr<Font> FontPtr;
typedef std::shared_ptr<Image> ImagePtr;
typedef std::shared_ptr<BorderImage> BorderImagePtr;
typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
typedef std::shared_ptr<Shader> ShaderPtr;
typedef std::shared_ptr<ShaderProgram> ShaderProgramPtr;

View File

@ -44,7 +44,7 @@ void FrameBuffer::resize(const Size& size)
{
internalBind();
m_texture = TexturePtr(new Texture(size.width(), size.height(), 4));
m_texture->enableBilinearFilter();
m_texture->setSmooth(true);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture->getId(), 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2010-2012 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 "image.h"
#include "texture.h"
#include "graphics.h"
#include "texturemanager.h"
#include <framework/otml/otml.h>
Image::Image()
{
m_fixedRatio = false;
m_repeated = false;
}
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_fixedRatio = imageNode->valueAt("fixed ratio", false);
m_repeated = imageNode->valueAt("repeated", false);
// load texture
m_texture = g_textures.getTexture(source);
m_textureCoords = imageNode->valueAt("clip", Rect(0, 0, m_texture->getSize()));
// enable texture bilinear filter
if(smooth)
m_texture->enableBilinearFilter();
}
void Image::draw(const Rect& screenCoords)
{
if(!m_texture)
return;
if(m_cachedScreenCoords != screenCoords) {
m_cachedScreenCoords = screenCoords;
m_coordsBuffer.clear();
if(m_fixedRatio) {
const Size& texSize = m_texture->getSize();
Size texCoordsSize = screenCoords.size();
texCoordsSize.scale(texSize, Fw::KeepAspectRatio);
Point texCoordsOffset;
if(texSize.height() > texCoordsSize.height())
texCoordsOffset.y = (texSize.height() - texCoordsSize.height())/2;
else if(texSize.width() > texCoordsSize.width())
texCoordsOffset.x = (texSize.width() - texCoordsSize.width())/2;
m_coordsBuffer.addRect(screenCoords, Rect(texCoordsOffset, texCoordsSize));
} else {
if(m_repeated)
m_coordsBuffer.addRepeatedRects(screenCoords, m_textureCoords);
else
m_coordsBuffer.addRect(screenCoords, m_textureCoords);
}
}
g_painter.drawTextureCoords(m_coordsBuffer, m_texture);
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2010-2012 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 IMAGE_H
#define IMAGE_H
#include "declarations.h"
#include "coordsbuffer.h"
#include <framework/otml/declarations.h>
class Image
{
public:
Image();
void loadFromOTML(const OTMLNodePtr& imageNode);
virtual void draw(const Rect& screenCoords);
protected:
TexturePtr m_texture;
Rect m_textureCoords;
bool m_fixedRatio;
bool m_repeated;
Rect m_cachedScreenCoords;
CoordsBuffer m_coordsBuffer;
};
#endif

View File

@ -51,8 +51,8 @@ public:
void setColor(const Color& color) { m_currentColor = color; }
Color getColor() { return m_currentColor; }
void setOpacity(int opacity) { m_currentOpacity = opacity / 255.0f; }
int getOpacity() { return m_currentOpacity * 255.0f; }
void setOpacity(float opacity) { m_currentOpacity = opacity; }
float getOpacity() { return m_currentOpacity; }
void setCustomProgram(PainterShaderProgramPtr program);
void releaseCustomProgram() { m_customProgram = nullptr; }

View File

@ -91,7 +91,7 @@ void Particle::updatePosition(double elapsedTime)
m_velocity += m_acceleration * elapsedTime;
}
m_rect.moveTo((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2);
m_rect.move((int)m_position.x - m_size.width() / 2, (int)m_position.y - m_size.height() / 2);
}
void Particle::updateSize()

View File

@ -95,12 +95,23 @@ uint Texture::internalLoadGLTexture(uchar *pixels, int channels, int width, int
return id;
}
void Texture::enableBilinearFilter()
void Texture::setSmooth(bool smooth)
{
// enable smooth texture
glBindTexture(GL_TEXTURE_2D, m_textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(smooth == m_smooth)
return;
if(smooth) {
// enable smooth texture
glBindTexture(GL_TEXTURE_2D, m_textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
// nearest filtering (non smooth)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
m_smooth = true;
}
std::vector<uint8> Texture::getPixels()

View File

@ -32,7 +32,7 @@ public:
Texture(int width, int height, int channels, uchar* pixels = NULL);
virtual ~Texture();
virtual void enableBilinearFilter();
virtual void setSmooth(bool smooth);
GLuint getId() { return m_textureId; }
std::vector<uint8> getPixels();
@ -48,6 +48,7 @@ protected:
GLuint m_textureId;
Size m_size;
Boolean<false> m_smooth;
};
#endif

View File

@ -45,116 +45,7 @@ void Application::registerLuaFunctions()
// UIWidget
g_lua.registerClass<UIWidget>();
g_lua.bindClassStaticFunction<UIWidget>("create", []{ return UIWidgetPtr(new UIWidget); } );
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible);
g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled);
g_lua.bindClassMemberFunction<UIWidget>("setChecked", &UICheckBox::setChecked);
g_lua.bindClassMemberFunction<UIWidget>("setOn", &UICheckBox::setOn);
g_lua.bindClassMemberFunction<UIWidget>("setPressed", &UIWidget::setPressed);
g_lua.bindClassMemberFunction<UIWidget>("setId", &UIWidget::setId);
g_lua.bindClassMemberFunction<UIWidget>("setFocusable", &UIWidget::setFocusable);
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
g_lua.bindClassMemberFunction<UIWidget>("setStyleFromNode", &UIWidget::setStyleFromNode);
g_lua.bindClassMemberFunction<UIWidget>("setLayout", &UIWidget::setLayout);
g_lua.bindClassMemberFunction<UIWidget>("setParent", &UIWidget::setParent);
g_lua.bindClassMemberFunction<UIWidget>("setRect", &UIWidget::setRect);
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY);
g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth);
g_lua.bindClassMemberFunction<UIWidget>("setHeight", &UIWidget::setHeight);
g_lua.bindClassMemberFunction<UIWidget>("setIcon", &UIWidget::setIcon);
g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundColor", &UIWidget::setBackgroundColor);
g_lua.bindClassMemberFunction<UIWidget>("setColor", &UIWidget::setColor);
g_lua.bindClassMemberFunction<UIWidget>("setMarginTop", &UIWidget::setMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
g_lua.bindClassMemberFunction<UIWidget>("setMarginBottom", &UIWidget::setMarginBottom);
g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
g_lua.bindClassMemberFunction<UIWidget>("setTextAlign", &UIWidget::setTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("setTextOffset", &UIWidget::setTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont);
g_lua.bindClassMemberFunction<UIWidget>("setSizeFixed", &UIWidget::setSizeFixed);
g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("bindRectToParent", &UIWidget::bindRectToParent);
g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
g_lua.bindClassMemberFunction<UIWidget>("resizeToText", &UIWidget::resizeToText);
g_lua.bindClassMemberFunction<UIWidget>("moveTo", &UIWidget::moveTo);
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
g_lua.bindClassMemberFunction<UIWidget>("disable", &UIWidget::disable);
g_lua.bindClassMemberFunction<UIWidget>("enable", &UIWidget::enable);
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus);
g_lua.bindClassMemberFunction<UIWidget>("grabMouse", &UIWidget::grabMouse);
g_lua.bindClassMemberFunction<UIWidget>("ungrabMouse", &UIWidget::ungrabMouse);
g_lua.bindClassMemberFunction<UIWidget>("grabKeyboard", &UIWidget::grabKeyboard);
g_lua.bindClassMemberFunction<UIWidget>("ungrabKeyboard", &UIWidget::ungrabKeyboard);
g_lua.bindClassMemberFunction<UIWidget>("clearText", &UIWidget::clearText);
g_lua.bindClassMemberFunction<UIWidget>("isActive", &UIWidget::isActive);
g_lua.bindClassMemberFunction<UIWidget>("isEnabled", &UIWidget::isEnabled);
g_lua.bindClassMemberFunction<UIWidget>("isDisabled", &UIWidget::isDisabled);
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
g_lua.bindClassMemberFunction<UIWidget>("isFirst", &UIWidget::isFirst);
g_lua.bindClassMemberFunction<UIWidget>("isMiddle", &UIWidget::isMiddle);
g_lua.bindClassMemberFunction<UIWidget>("isLast", &UIWidget::isLast);
g_lua.bindClassMemberFunction<UIWidget>("isAlternate", &UIWidget::isAlternate);
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
g_lua.bindClassMemberFunction<UIWidget>("isOn", &UICheckBox::isOn);
g_lua.bindClassMemberFunction<UIWidget>("isChecked", &UICheckBox::isChecked);
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyEnabled", &UIWidget::isExplicitlyEnabled);
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyVisible", &UIWidget::isExplicitlyVisible);
g_lua.bindClassMemberFunction<UIWidget>("isFocusable", &UIWidget::isFocusable);
g_lua.bindClassMemberFunction<UIWidget>("isPhantom", &UIWidget::isPhantom);
g_lua.bindClassMemberFunction<UIWidget>("isSizeFixed", &UIWidget::isSizeFixed);
g_lua.bindClassMemberFunction<UIWidget>("containsPoint", &UIWidget::containsPoint);
g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren);
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId);
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
g_lua.bindClassMemberFunction<UIWidget>("getLayout", &UIWidget::getLayout);
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
g_lua.bindClassMemberFunction<UIWidget>("getPos", &UIWidget::getPos);
g_lua.bindClassMemberFunction<UIWidget>("getSize", &UIWidget::getSize);
g_lua.bindClassMemberFunction<UIWidget>("getRect", &UIWidget::getRect);
g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
g_lua.bindClassMemberFunction<UIWidget>("getWidth", &UIWidget::getWidth);
g_lua.bindClassMemberFunction<UIWidget>("getHeight", &UIWidget::getHeight);
g_lua.bindClassMemberFunction<UIWidget>("getColor", &UIWidget::getColor);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundColor", &UIWidget::getBackgroundColor);
g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
g_lua.bindClassMemberFunction<UIWidget>("getMarginTop", &UIWidget::getMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
g_lua.bindClassMemberFunction<UIWidget>("getMarginBottom", &UIWidget::getMarginBottom);
g_lua.bindClassMemberFunction<UIWidget>("getMarginLeft", &UIWidget::getMarginLeft);
g_lua.bindClassMemberFunction<UIWidget>("getText", &UIWidget::getText);
g_lua.bindClassMemberFunction<UIWidget>("getTextAlign", &UIWidget::getTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("getTextOffset", &UIWidget::getTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("getFont", &UIWidget::getFont);
g_lua.bindClassMemberFunction<UIWidget>("getTextSize", &UIWidget::getTextSize);
g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
g_lua.bindClassMemberFunction<UIWidget>("getChildren", &UIWidget::getChildren);
g_lua.bindClassMemberFunction<UIWidget>("getFocusedChild", &UIWidget::getFocusedChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildAfter", &UIWidget::getChildAfter);
g_lua.bindClassMemberFunction<UIWidget>("getChildBefore", &UIWidget::getChildBefore);
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
g_lua.bindClassMemberFunction<UIWidget>("getChildByPos", &UIWidget::getChildByPos);
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
g_lua.bindClassMemberFunction<UIWidget>("getFirstChild", &UIWidget::getFirstChild);
g_lua.bindClassMemberFunction<UIWidget>("getLastChild", &UIWidget::getLastChild);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos);
g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById);
g_lua.bindClassStaticFunction<UIWidget>("create", []{ return UIWidgetPtr(new UIWidget); });
g_lua.bindClassMemberFunction<UIWidget>("addChild", &UIWidget::addChild);
g_lua.bindClassMemberFunction<UIWidget>("insertChild", &UIWidget::insertChild);
g_lua.bindClassMemberFunction<UIWidget>("removeChild", &UIWidget::removeChild);
@ -165,11 +56,217 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("moveChildToIndex", &UIWidget::moveChildToIndex);
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
g_lua.bindClassMemberFunction<UIWidget>("addAnchor", &UIWidget::addAnchor);
g_lua.bindClassMemberFunction<UIWidget>("fill", &UIWidget::fill);
g_lua.bindClassMemberFunction<UIWidget>("centerIn", &UIWidget::centerIn);
g_lua.bindClassMemberFunction<UIWidget>("breakAnchors", &UIWidget::breakAnchors);
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
g_lua.bindClassMemberFunction<UIWidget>("applyStyle", &UIWidget::applyStyle);
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus);
g_lua.bindClassMemberFunction<UIWidget>("grabMouse", &UIWidget::grabMouse);
g_lua.bindClassMemberFunction<UIWidget>("ungrabMouse", &UIWidget::ungrabMouse);
g_lua.bindClassMemberFunction<UIWidget>("grabKeyboard", &UIWidget::grabKeyboard);
g_lua.bindClassMemberFunction<UIWidget>("ungrabKeyboard", &UIWidget::ungrabKeyboard);
g_lua.bindClassMemberFunction<UIWidget>("bindRectToParent", &UIWidget::bindRectToParent);
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
g_lua.bindClassMemberFunction<UIWidget>("setId", &UIWidget::setId);
g_lua.bindClassMemberFunction<UIWidget>("setParent", &UIWidget::setParent);
g_lua.bindClassMemberFunction<UIWidget>("setLayout", &UIWidget::setLayout);
g_lua.bindClassMemberFunction<UIWidget>("setRect", &UIWidget::setRect);
g_lua.bindClassMemberFunction<UIWidget>("setStyle", &UIWidget::setStyle);
g_lua.bindClassMemberFunction<UIWidget>("setStyleFromNode", &UIWidget::setStyleFromNode);
g_lua.bindClassMemberFunction<UIWidget>("setEnabled", &UIWidget::setEnabled);
g_lua.bindClassMemberFunction<UIWidget>("setVisible", &UIWidget::setVisible);
g_lua.bindClassMemberFunction<UIWidget>("setPressed", &UIWidget::setPressed);
g_lua.bindClassMemberFunction<UIWidget>("setOn", &UIWidget::setOn);
g_lua.bindClassMemberFunction<UIWidget>("setChecked", &UIWidget::setChecked);
g_lua.bindClassMemberFunction<UIWidget>("setFocusable", &UIWidget::setFocusable);
g_lua.bindClassMemberFunction<UIWidget>("setPhantom", &UIWidget::setPhantom);
g_lua.bindClassMemberFunction<UIWidget>("setFixedSize", &UIWidget::setFixedSize);
g_lua.bindClassMemberFunction<UIWidget>("setLastFocusReason", &UIWidget::setLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
g_lua.bindClassMemberFunction<UIWidget>("isChildLocked", &UIWidget::isChildLocked);
g_lua.bindClassMemberFunction<UIWidget>("hasChild", &UIWidget::hasChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildIndex", &UIWidget::getChildIndex);
g_lua.bindClassMemberFunction<UIWidget>("getChildrenRect", &UIWidget::getChildrenRect);
g_lua.bindClassMemberFunction<UIWidget>("getAnchoredLayout", &UIWidget::getAnchoredLayout);
g_lua.bindClassMemberFunction<UIWidget>("getRootParent", &UIWidget::getRootParent);
g_lua.bindClassMemberFunction<UIWidget>("getChildAfter", &UIWidget::getChildAfter);
g_lua.bindClassMemberFunction<UIWidget>("getChildBefore", &UIWidget::getChildBefore);
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
g_lua.bindClassMemberFunction<UIWidget>("getChildByPos", &UIWidget::getChildByPos);
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildById", &UIWidget::recursiveGetChildById);
g_lua.bindClassMemberFunction<UIWidget>("recursiveGetChildByPos", &UIWidget::recursiveGetChildByPos);
g_lua.bindClassMemberFunction<UIWidget>("backwardsGetWidgetById", &UIWidget::backwardsGetWidgetById);
g_lua.bindClassMemberFunction<UIWidget>("asUIWidget", &UIWidget::asUIWidget);
g_lua.bindClassMemberFunction<UIWidget>("resize", &UIWidget::resize);
g_lua.bindClassMemberFunction<UIWidget>("move", &UIWidget::move);
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
g_lua.bindClassMemberFunction<UIWidget>("disable", &UIWidget::disable);
g_lua.bindClassMemberFunction<UIWidget>("enable", &UIWidget::enable);
g_lua.bindClassMemberFunction<UIWidget>("isActive", &UIWidget::isActive);
g_lua.bindClassMemberFunction<UIWidget>("isEnabled", &UIWidget::isEnabled);
g_lua.bindClassMemberFunction<UIWidget>("isDisabled", &UIWidget::isDisabled);
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
g_lua.bindClassMemberFunction<UIWidget>("isFirst", &UIWidget::isFirst);
g_lua.bindClassMemberFunction<UIWidget>("isMiddle", &UIWidget::isMiddle);
g_lua.bindClassMemberFunction<UIWidget>("isLast", &UIWidget::isLast);
g_lua.bindClassMemberFunction<UIWidget>("isAlternate", &UIWidget::isAlternate);
g_lua.bindClassMemberFunction<UIWidget>("isChecked", &UIWidget::isChecked);
g_lua.bindClassMemberFunction<UIWidget>("isOn", &UIWidget::isOn);
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyEnabled", &UIWidget::isExplicitlyEnabled);
g_lua.bindClassMemberFunction<UIWidget>("isExplicitlyVisible", &UIWidget::isExplicitlyVisible);
g_lua.bindClassMemberFunction<UIWidget>("isFocusable", &UIWidget::isFocusable);
g_lua.bindClassMemberFunction<UIWidget>("isPhantom", &UIWidget::isPhantom);
g_lua.bindClassMemberFunction<UIWidget>("isFixedSize", &UIWidget::isFixedSize);
g_lua.bindClassMemberFunction<UIWidget>("isDestroyed", &UIWidget::isDestroyed);
g_lua.bindClassMemberFunction<UIWidget>("hasChildren", &UIWidget::hasChildren);
g_lua.bindClassMemberFunction<UIWidget>("containsPoint", &UIWidget::containsPoint);
g_lua.bindClassMemberFunction<UIWidget>("getId", &UIWidget::getId);
g_lua.bindClassMemberFunction<UIWidget>("getParent", &UIWidget::getParent);
g_lua.bindClassMemberFunction<UIWidget>("getFocusedChild", &UIWidget::getFocusedChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildren", &UIWidget::getChildren);
g_lua.bindClassMemberFunction<UIWidget>("getFirstChild", &UIWidget::getFirstChild);
g_lua.bindClassMemberFunction<UIWidget>("getLastChild", &UIWidget::getLastChild);
g_lua.bindClassMemberFunction<UIWidget>("getLayout", &UIWidget::getLayout);
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
g_lua.bindClassMemberFunction<UIWidget>("setX", &UIWidget::setX);
g_lua.bindClassMemberFunction<UIWidget>("setY", &UIWidget::setY);
g_lua.bindClassMemberFunction<UIWidget>("setWidth", &UIWidget::setWidth);
g_lua.bindClassMemberFunction<UIWidget>("setHeight", &UIWidget::setHeight);
g_lua.bindClassMemberFunction<UIWidget>("setSize", &UIWidget::setSize);
g_lua.bindClassMemberFunction<UIWidget>("setPos", &UIWidget::setPos);
g_lua.bindClassMemberFunction<UIWidget>("setColor", &UIWidget::setColor);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundColor", &UIWidget::setBackgroundColor);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundOffsetX", &UIWidget::setBackgroundOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundOffsetY", &UIWidget::setBackgroundOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundOffset", &UIWidget::setBackgroundOffset);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundWidth", &UIWidget::setBackgroundWidth);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundHeight", &UIWidget::setBackgroundHeight);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundSize", &UIWidget::setBackgroundSize);
g_lua.bindClassMemberFunction<UIWidget>("setBackgroundRect", &UIWidget::setBackgroundRect);
g_lua.bindClassMemberFunction<UIWidget>("setIcon", &UIWidget::setIcon);
g_lua.bindClassMemberFunction<UIWidget>("setIconColor", &UIWidget::setIconColor);
g_lua.bindClassMemberFunction<UIWidget>("setIconOffsetX", &UIWidget::setIconOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("setIconOffsetY", &UIWidget::setIconOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("setIconOffset", &UIWidget::setIconOffset);
g_lua.bindClassMemberFunction<UIWidget>("setIconWidth", &UIWidget::setIconWidth);
g_lua.bindClassMemberFunction<UIWidget>("setIconHeight", &UIWidget::setIconHeight);
g_lua.bindClassMemberFunction<UIWidget>("setIconSize", &UIWidget::setIconSize);
g_lua.bindClassMemberFunction<UIWidget>("setIconRect", &UIWidget::setIconRect);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidth", &UIWidget::setBorderWidth);
g_lua.bindClassMemberFunction<UIWidget>("setBorderColor", &UIWidget::setBorderColor);
g_lua.bindClassMemberFunction<UIWidget>("setMargin", &UIWidget::setMargin);
g_lua.bindClassMemberFunction<UIWidget>("setMarginHorizontal", &UIWidget::setMarginHorizontal);
g_lua.bindClassMemberFunction<UIWidget>("setMarginVertical", &UIWidget::setMarginVertical);
g_lua.bindClassMemberFunction<UIWidget>("setMarginTop", &UIWidget::setMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
g_lua.bindClassMemberFunction<UIWidget>("setMarginBottom", &UIWidget::setMarginBottom);
g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
g_lua.bindClassMemberFunction<UIWidget>("setPadding", &UIWidget::setPadding);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingHorizontal", &UIWidget::setPaddingHorizontal);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingVertical", &UIWidget::setPaddingVertical);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingTop", &UIWidget::setPaddingTop);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingRight", &UIWidget::setPaddingRight);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingBottom", &UIWidget::setPaddingBottom);
g_lua.bindClassMemberFunction<UIWidget>("setPaddingLeft", &UIWidget::setPaddingLeft);
g_lua.bindClassMemberFunction<UIWidget>("setOpacity", &UIWidget::setOpacity);
g_lua.bindClassMemberFunction<UIWidget>("getX", &UIWidget::getX);
g_lua.bindClassMemberFunction<UIWidget>("getY", &UIWidget::getY);
g_lua.bindClassMemberFunction<UIWidget>("getPos", &UIWidget::getPos);
g_lua.bindClassMemberFunction<UIWidget>("getWidth", &UIWidget::getWidth);
g_lua.bindClassMemberFunction<UIWidget>("getHeight", &UIWidget::getHeight);
g_lua.bindClassMemberFunction<UIWidget>("getSize", &UIWidget::getSize);
g_lua.bindClassMemberFunction<UIWidget>("getRect", &UIWidget::getRect);
g_lua.bindClassMemberFunction<UIWidget>("getColor", &UIWidget::getColor);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundColor", &UIWidget::getBackgroundColor);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundOffsetX", &UIWidget::getBackgroundOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundOffsetY", &UIWidget::getBackgroundOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundOffset", &UIWidget::getBackgroundOffset);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundWidth", &UIWidget::getBackgroundWidth);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundHeight", &UIWidget::getBackgroundHeight);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundSize", &UIWidget::getBackgroundSize);
g_lua.bindClassMemberFunction<UIWidget>("getBackgroundRect", &UIWidget::getBackgroundRect);
g_lua.bindClassMemberFunction<UIWidget>("getIconColor", &UIWidget::getIconColor);
g_lua.bindClassMemberFunction<UIWidget>("getIconOffsetX", &UIWidget::getIconOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("getIconOffsetY", &UIWidget::getIconOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("getIconOffset", &UIWidget::getIconOffset);
g_lua.bindClassMemberFunction<UIWidget>("getIconWidth", &UIWidget::getIconWidth);
g_lua.bindClassMemberFunction<UIWidget>("getIconHeight", &UIWidget::getIconHeight);
g_lua.bindClassMemberFunction<UIWidget>("getIconSize", &UIWidget::getIconSize);
g_lua.bindClassMemberFunction<UIWidget>("getIconRect", &UIWidget::getIconRect);
g_lua.bindClassMemberFunction<UIWidget>("getBorderTopColor", &UIWidget::getBorderTopColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderRightColor", &UIWidget::getBorderRightColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderBottomColor", &UIWidget::getBorderBottomColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderLeftColor", &UIWidget::getBorderLeftColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderTopWidth", &UIWidget::getBorderTopWidth);
g_lua.bindClassMemberFunction<UIWidget>("getBorderRightWidth", &UIWidget::getBorderRightWidth);
g_lua.bindClassMemberFunction<UIWidget>("getBorderBottomWidth", &UIWidget::getBorderBottomWidth);
g_lua.bindClassMemberFunction<UIWidget>("getBorderLeftWidth", &UIWidget::getBorderLeftWidth);
g_lua.bindClassMemberFunction<UIWidget>("getMarginTop", &UIWidget::getMarginTop);
g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
g_lua.bindClassMemberFunction<UIWidget>("getMarginBottom", &UIWidget::getMarginBottom);
g_lua.bindClassMemberFunction<UIWidget>("getMarginLeft", &UIWidget::getMarginLeft);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingTop", &UIWidget::getPaddingTop);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingRight", &UIWidget::getPaddingRight);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingBottom", &UIWidget::getPaddingBottom);
g_lua.bindClassMemberFunction<UIWidget>("getPaddingLeft", &UIWidget::getPaddingLeft);
g_lua.bindClassMemberFunction<UIWidget>("getOpacity", &UIWidget::getOpacity);
g_lua.bindClassMemberFunction<UIWidget>("setImageSource", &UIWidget::setImageSource);
g_lua.bindClassMemberFunction<UIWidget>("setImageClip", &UIWidget::setImageClip);
g_lua.bindClassMemberFunction<UIWidget>("setImageOffsetX", &UIWidget::setImageOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("setImageOffsetY", &UIWidget::setImageOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("setImageOffset", &UIWidget::setImageOffset);
g_lua.bindClassMemberFunction<UIWidget>("setImageWidth", &UIWidget::setImageWidth);
g_lua.bindClassMemberFunction<UIWidget>("setImageHeight", &UIWidget::setImageHeight);
g_lua.bindClassMemberFunction<UIWidget>("setImageSize", &UIWidget::setImageSize);
g_lua.bindClassMemberFunction<UIWidget>("setImageRect", &UIWidget::setImageRect);
g_lua.bindClassMemberFunction<UIWidget>("setImageColor", &UIWidget::setImageColor);
g_lua.bindClassMemberFunction<UIWidget>("setImageFixedRatio", &UIWidget::setImageFixedRatio);
g_lua.bindClassMemberFunction<UIWidget>("setImageRepeated", &UIWidget::setImageRepeated);
g_lua.bindClassMemberFunction<UIWidget>("setImageSmooth", &UIWidget::setImageSmooth);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderTop", &UIWidget::setImageBorderTop);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderRight", &UIWidget::setImageBorderRight);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderBottom", &UIWidget::setImageBorderBottom);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderLeft", &UIWidget::setImageBorderLeft);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorder", &UIWidget::setImageBorder);
g_lua.bindClassMemberFunction<UIWidget>("getImageClip", &UIWidget::getImageClip);
g_lua.bindClassMemberFunction<UIWidget>("getImageOffsetX", &UIWidget::getImageOffsetX);
g_lua.bindClassMemberFunction<UIWidget>("getImageOffsetY", &UIWidget::getImageOffsetY);
g_lua.bindClassMemberFunction<UIWidget>("getImageOffset", &UIWidget::getImageOffset);
g_lua.bindClassMemberFunction<UIWidget>("getImageWidth", &UIWidget::getImageWidth);
g_lua.bindClassMemberFunction<UIWidget>("getImageHeight", &UIWidget::getImageHeight);
g_lua.bindClassMemberFunction<UIWidget>("getImageSize", &UIWidget::getImageSize);
g_lua.bindClassMemberFunction<UIWidget>("getImageRect", &UIWidget::getImageRect);
g_lua.bindClassMemberFunction<UIWidget>("getImageColor", &UIWidget::getImageColor);
g_lua.bindClassMemberFunction<UIWidget>("isImageFixedRatio", &UIWidget::isImageFixedRatio);
g_lua.bindClassMemberFunction<UIWidget>("isImageSmooth", &UIWidget::isImageSmooth);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderTop", &UIWidget::getImageBorderTop);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderRight", &UIWidget::getImageBorderRight);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderBottom", &UIWidget::getImageBorderBottom);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderLeft", &UIWidget::getImageBorderLeft);
g_lua.bindClassMemberFunction<UIWidget>("resizeToText", &UIWidget::resizeToText);
g_lua.bindClassMemberFunction<UIWidget>("clearText", &UIWidget::clearText);
g_lua.bindClassMemberFunction<UIWidget>("setText", &UIWidget::setText);
g_lua.bindClassMemberFunction<UIWidget>("setTextAlign", &UIWidget::setTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("setTextOffset", &UIWidget::setTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("setFont", &UIWidget::setFont);
g_lua.bindClassMemberFunction<UIWidget>("getText", &UIWidget::getText);
g_lua.bindClassMemberFunction<UIWidget>("getTextAlign", &UIWidget::getTextAlign);
g_lua.bindClassMemberFunction<UIWidget>("getTextOffset", &UIWidget::getTextOffset);
g_lua.bindClassMemberFunction<UIWidget>("getFont", &UIWidget::getFont);
g_lua.bindClassMemberFunction<UIWidget>("getTextSize", &UIWidget::getTextSize);
// UILayout
g_lua.registerClass<UILayout>();
@ -191,12 +288,6 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIAnchorLayout>("centerIn", &UIAnchorLayout::centerIn);
g_lua.bindClassMemberFunction<UIAnchorLayout>("fill", &UIAnchorLayout::fill);
// UIProgressBar
g_lua.registerClass<UIProgressBar, UIWidget>();
g_lua.bindClassStaticFunction<UIProgressBar>("create", []{ return UIProgressBarPtr(new UIProgressBar); } );
g_lua.bindClassMemberFunction<UIProgressBar>("getPercent", &UIProgressBar::getPercent);
g_lua.bindClassMemberFunction<UIProgressBar>("setPercent", &UIProgressBar::setPercent);
// UILineEdit
g_lua.registerClass<UILineEdit, UIWidget>();
g_lua.bindClassStaticFunction<UILineEdit>("create", []{ return UILineEditPtr(new UILineEdit); } );
@ -216,10 +307,6 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UILineEdit>("isAlwaysActive", &UILineEdit::isAlwaysActive);
g_lua.bindClassMemberFunction<UILineEdit>("isTextHidden", &UILineEdit::isTextHidden);
// UICheckBox
g_lua.registerClass<UICheckBox, UIWidget>();
g_lua.bindClassStaticFunction<UICheckBox>("create", []{ return UICheckBoxPtr(new UICheckBox); } );
// UIWindow
g_lua.registerClass<UIWindow, UIWidget>();
g_lua.bindClassStaticFunction<UIWindow>("create", []{ return UIWindowPtr(new UIWindow); } );

View File

@ -40,6 +40,10 @@ bool luavalue_cast(int index, int& i);
void push_luavalue(double d);
bool luavalue_cast(int index, double& d);
// float
inline void push_luavalue(float f) { push_luavalue((double)f); }
inline bool luavalue_cast(int index, float& f) { double d; bool r = luavalue_cast(index, d); f = d; return r; }
// int8
inline void push_luavalue(int8 v) { push_luavalue((int)v); }
inline bool luavalue_cast(int index, int8& v) { int i; bool r = luavalue_cast(index, i); v = i; return r; }

View File

@ -42,6 +42,7 @@ public:
TRect(const TRect<T>& other) : x1(other.x1), y1(other.y1), x2(other.x2), y2(other.y2) { }
TRect(T x, T y, const TSize<T>& size) : x1(x), y1(y), x2(x+size.width()-1), y2(y+size.height()-1) { }
TRect(const TPoint<T>& topLeft, const TSize<T>& size) : x1(topLeft.x), y1(topLeft.y), x2(x1+size.width()-1), y2(y1+size.height()-1) { }
TRect(const TPoint<T>& topLeft, int width, int height) : x1(topLeft.x), y1(topLeft.y), x2(x1+width-1), y2(y1+height-1) { }
bool isNull() const { return x2 == x1 - 1 && y2 == y1 - 1; }
bool isEmpty() const { return x1 > x2 || y1 > y2; }
@ -78,21 +79,23 @@ public:
void setBottomLeft(const TPoint<T> &p) { x1 = p.x; y2 = p.y; }
void setWidth(T width) { x2 = x1 + width - 1; }
void setHeight(T height) { y2 = y1 + height- 1; }
void resize(T width, T height) { x2 = x1 + width - 1; y2 = y1 + height - 1; }
void resize(const TSize<T>& size) { x2 = x1 + size.width() - 1; y2 = y1 + size.height() - 1; }
void setSize(const TSize<T>& size) { x2 = x1 + size.width() - 1; y2 = y1 + size.height() - 1; }
void setRect(T x, T y, T width, T height) { x1 = x; y1 = y; x2 = (x + width - 1); y2 = (y + height - 1); }
void setCoords(int left, int top, int right, int bottom) { x1 = left; y1 = top; x2 = right; y2 = bottom; }
void addLeft(T add) { x1 -= add; }
void addTop(T add) { y1 -= add; }
void addRight(T add) { x2 += add; }
void addBottom(T add) { y2 += add; }
void add(T top, T right, T bottom, T left) { x1 -= left; y1 -= top; x2 += right; y2 += bottom; }
void expandLeft(T add) { x1 -= add; }
void expandTop(T add) { y1 -= add; }
void expandRight(T add) { x2 += add; }
void expandBottom(T add) { y2 += add; }
void expand(T top, T right, T bottom, T left) { x1 -= left; y1 -= top; x2 += right; y2 += bottom; }
void expand(T add) { x1 -= add; y1 -= add; x2 += add; y2 += add; }
void translate(T x, T y) { x1 += x; y1 += y; x2 += x; y2 += y; }
void translate(const TPoint<T> &p) { x1 += p.x; y1 += p.y; x2 += p.x; y2 += p.y; }
void moveTo(T x, T y) { x2 += x - x1; y2 += y - y1; x1 = x; y1 = y; }
void moveTo(const TPoint<T> &p) { x2 += p.x - x1; y2 += p.y - y1; x1 = p.x; y1 = p.y; }
void resize(const TSize<T>& size) { x2 = x1 + size.width() - 1; y2 = y1 + size.height() - 1; }
void resize(T width, T height) { x2 = x1 + width - 1; y2 = y1 + height - 1; }
void move(T x, T y) { x2 += x - x1; y2 += y - y1; x1 = x; y1 = y; }
void move(const TPoint<T> &p) { x2 += p.x - x1; y2 += p.y - y1; x1 = p.x; y1 = p.y; }
void moveLeft(T pos) { x2 += (pos - x1); x1 = pos; }
void moveTop(T pos) { y2 += (pos - y1); y1 = pos; }
void moveRight(T pos) { x1 += (pos - x2); x2 = pos; }
@ -105,7 +108,7 @@ public:
TRect<T> translated(int x, int y) const { return TRect<T>(TPoint<T>(x1 + x, y1 + y), TPoint<T>(x2 + x, y2 + y)); }
TRect<T> translated(const TPoint<T> &p) const { return TRect<T>(TPoint<T>(x1 + p.x, y1 + p.y), TPoint<T>(x2 + p.x, y2 + p.y)); }
TRect<T> expanded(T pixels) const { return TRect<T>(TPoint<T>(x1 - pixels, y1 - pixels), TPoint<T>(x2 + pixels, y2 + pixels)); }
TRect<T> expanded(T add) const { return TRect<T>(TPoint<T>(x1 - add, y1 - add), TPoint<T>(x2 + add, y2 + add)); }
void moveCenter(const TPoint<T> &p) {
T w = x2 - x1;

View File

@ -27,11 +27,7 @@
class UIManager;
class UIWidget;
class UILabel;
class UIButton;
class UILineEdit;
class UICheckBox;
class UIProgressBar;
class UIFrameCounter;
class UIWindow;
class UILayout;
@ -41,11 +37,7 @@ class UIAnchorLayout;
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
typedef std::shared_ptr<UILabel> UILabelPtr;
typedef std::shared_ptr<UIButton> UIButtonPtr;
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
typedef std::shared_ptr<UICheckBox> UICheckBoxPtr;
typedef std::shared_ptr<UIProgressBar> UIProgressBarPtr;
typedef std::shared_ptr<UIFrameCounter> UIFrameCounterPtr;
typedef std::shared_ptr<UIWindow> UIWindowPtr;
typedef std::shared_ptr<UILayout> UILayoutPtr;

View File

@ -28,8 +28,6 @@
#include "uilineedit.h"
#include "uiwindow.h"
#include "uiframecounter.h"
#include "uiprogressbar.h"
#include "uicheckbox.h"
#include "uilayout.h"
#include "uiverticallayout.h"
#include "uianchorlayout.h"

View File

@ -1,79 +0,0 @@
/*
* Copyright (c) 2010-2012 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 "uicheckbox.h"
#include "uitranslator.h"
#include <framework/otml/otmlnode.h>
#include <framework/graphics/image.h>
#include <framework/graphics/font.h>
#include <framework/graphics/graphics.h>
#include <framework/core/eventdispatcher.h>
UICheckBox::UICheckBox()
{
m_focusable = false;
m_textAlign = Fw::AlignLeft;
}
void UICheckBox::render()
{
if(m_image) {
Rect boxRect;
boxRect.resize(m_boxSize);
boxRect.moveLeft(m_rect.left());
boxRect.moveVerticalCenter(m_rect.verticalCenter());
g_painter.setColor(m_backgroundColor);
m_image->draw(boxRect);
}
if(m_text.length()) {
Rect textRect(m_rect);
textRect.setTopLeft(textRect.topLeft() + m_textOffset);
m_font->renderText(m_text, textRect, m_textAlign, m_color);
}
}
void UICheckBox::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
if(isPressed() && getRect().contains(mousePos))
setChecked(!isChecked());
}
void UICheckBox::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
{
UIWidget::onStyleApply(styleName, styleNode);
for(OTMLNodePtr node : styleNode->children()) {
if(node->tag() == "text-offset")
m_textOffset = node->value<Point>();
else if(node->tag() == "text")
m_text = node->value();
else if(node->tag() == "box-size")
m_boxSize = node->value<Size>();
else if(node->tag() == "text-align")
m_textAlign = Fw::translateAlignment(node->value());
else if(node->tag() == "checked") {
// must be scheduled because setChecked can change the style again
g_dispatcher.addEvent(std::bind(&UICheckBox::setChecked, asUICheckBox(), node->value<bool>()));
}
}
}

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2010-2012 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 UICHECKBOX_H
#define UICHECKBOX_H
#include "uiwidget.h"
class UICheckBox : public UIWidget
{
public:
UICheckBox();
void render();
void setText(const std::string& text) { m_text = text; }
std::string getText() { return m_text; }
UICheckBoxPtr asUICheckBox() { return std::static_pointer_cast<UICheckBox>(shared_from_this()); }
protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
std::string m_text;
Size m_boxSize;
Point m_textOffset;
Fw::AlignmentFlag m_textAlign;
};
#endif

View File

@ -36,9 +36,9 @@ UIFrameCounter::UIFrameCounter()
m_frameCount = 0;
}
void UIFrameCounter::render()
void UIFrameCounter::draw()
{
UIWidget::render();
UIWidget::draw();
if(g_clock.ticksElapsed(m_lastFrameTicks) >= 1000) {
m_fpsText = Fw::mkstr("FPS: ", m_frameCount);

View File

@ -29,7 +29,7 @@ class UIFrameCounter : public UIWidget
{
public:
UIFrameCounter();
virtual void render();
virtual void draw();
void setAlign(Fw::AlignmentFlag align) { m_align = align; }
Fw::AlignmentFlag getAlign() { return m_align; }

View File

@ -1,41 +0,0 @@
#include "uiimage.h"
#include <framework/otml/otmlnode.h>
void UIImage::draw(const Rect& screenCoords)
{
}
void UIImage::applyStyle(const OTMLNodePtr& styleNode)
{
/*
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "image-source")
setImageSource(node->value());
else if(node->tag() == "image-clip")
setImageClip(node->value<Rect>());
else if(node->tag() == "image-rect")
setImageRect(node->value<Rect>());
else if(node->tag() == "image-fixed-ratio")
setImageFixedRatio(node->value<bool>());
else if(node->tag() == "image-repeated")
setImageRepeated(node->value<bool>());
else if(node->tag() == "image-smooth")
setImageSmooth(node->value<bool>());
else if(node->tag() == "image-color")
setImageColor(node->value<Color>());
else if(node->tag() == "image-border-top")
setImageBorderTop(node->value<int>());
else if(node->tag() == "image-border-right")
setImageBorderRight(node->value<int>());
else if(node->tag() == "image-border-bottom")
setImageBorderBottom(node->value<int>());
else if(node->tag() == "image-border-left")
setImageBorderLeft(node->value<int>());
else if(node->tag() == "image-border") {
}
}
*/
}

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2010-2012 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 UIIMAGE_H
#define UIIMAGE_H
#include <framework/graphics/declarations.h>
#include <framework/otml/declarations.h>
#include "declarations.h"
class UIImage
{
public:
void draw(const Rect& screenCoords);
void applyStyle(const OTMLNodePtr& styleNode);
void setImageSource(const std::string& source);
void setImageClip(const Rect& clipRect);
void setImageRect(const Rect& rect);
void setImageFixedRatio(bool fixedRatio);
void setImageRepeated(bool repeated);
void setImageSmooth(bool smooth);
void setImageColor(const Color& color);
void setImageBorderTop(int border);
void setImageBorderRight(int border);
void setImageBorderBottom(int border);
void setImageBorderLeft(int border);
protected:
TexturePtr m_imageTexture;
Rect m_imageClipRect;
Rect m_imageRect;
Boolean<false> m_imageFixedRatio;
Boolean<false> m_imageRepeated;
Color m_imageColor;
// border image coords
Rect m_leftBorderTexCoords;
Rect m_rightBorderTexCoords;
Rect m_topBorderTexCoords;
Rect m_bottomBorderTexCoords;
Rect m_topLeftCornerTexCoords;
Rect m_topRightCornerTexCoords;
Rect m_bottomLeftCornerTexCoords;
Rect m_bottomRightCornerTexCoords;
Rect m_centerTexCoords;
Size m_bordersSize;
};
#endif

View File

@ -26,6 +26,9 @@
void UILayout::update()
{
if(m_updateDisabled)
return;
assert(!m_updating);
m_updating = true;
internalUpdate();
@ -34,7 +37,7 @@ void UILayout::update()
void UILayout::updateLater()
{
if(m_updateScheduled)
if(m_updateDisabled || m_updateScheduled)
return;
if(!getParentWidget())

View File

@ -38,9 +38,13 @@ public:
virtual void applyStyle(const OTMLNodePtr& styleNode) { }
virtual void addWidget(const UIWidgetPtr& widget) = 0;
virtual void removeWidget(const UIWidgetPtr& widget) = 0;
void disableUpdates() { m_updateDisabled = true; }
void enableUpdates() { m_updateDisabled = false; }
void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; }
UIWidgetPtr getParentWidget() { return m_parentWidget.lock(); }
bool isUpdateDisabled() { return m_updateDisabled; }
bool isUpdating() { return m_updating; }
virtual bool needsUpdatesOnChildChange() { return false; }
@ -51,6 +55,7 @@ public:
protected:
virtual void internalUpdate() = 0;
Boolean<false> m_updateDisabled;
Boolean<false> m_updating;
Boolean<false> m_updateScheduled;
UIWidgetWeakPtr m_parentWidget;

View File

@ -38,7 +38,7 @@ UILineEdit::UILineEdit()
blinkCursor();
}
void UILineEdit::renderSelf()
void UILineEdit::drawSelf()
{
drawBackground(m_rect);
drawBorder(m_rect);
@ -140,8 +140,8 @@ void UILineEdit::update()
}
Rect textScreenCoords = m_rect;
textScreenCoords.addLeft(-m_textHorizontalMargin);
textScreenCoords.addRight(-m_textHorizontalMargin);
textScreenCoords.expandLeft(-m_textHorizontalMargin);
textScreenCoords.expandRight(-m_textHorizontalMargin);
m_drawArea = textScreenCoords;
if(m_textAlign & Fw::AlignBottom) {
@ -339,8 +339,8 @@ int UILineEdit::getTextPos(Point pos)
int candidatePos = -1;
for(int i=0;i<textLength;++i) {
Rect clickGlyphRect = m_glyphsCoords[i];
clickGlyphRect.addTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
clickGlyphRect.addLeft(m_font->getGlyphSpacing().width()+1);
clickGlyphRect.expandTop(m_font->getYOffset() + m_font->getGlyphSpacing().height());
clickGlyphRect.expandLeft(m_font->getGlyphSpacing().width()+1);
if(clickGlyphRect.contains(pos))
return i;
else if(pos.y >= clickGlyphRect.top() && pos.y <= clickGlyphRect.bottom()) {

View File

@ -30,7 +30,7 @@ class UILineEdit : public UIWidget
public:
UILineEdit();
virtual void renderSelf();
virtual void drawSelf();
private:
void update();

View File

@ -47,12 +47,12 @@ void UIManager::terminate()
void UIManager::render()
{
m_rootWidget->render();
m_rootWidget->draw();
}
void UIManager::resize(const Size& size)
{
m_rootWidget->resize(g_window.getSize());
m_rootWidget->setSize(g_window.getSize());
}
void UIManager::inputEvent(const InputEvent& event)

View File

@ -1,53 +0,0 @@
/*
* Copyright (c) 2010-2012 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 "uiprogressbar.h"
#include <framework/graphics/graphics.h>
#include <framework/otml/otmlnode.h>
UIProgressBar::UIProgressBar()
{
m_phantom = false;
m_focusable = false;
m_percent = 0;
}
void UIProgressBar::render()
{
UIWidget::render();
g_painter.setColor(m_color);
g_painter.drawBoundingRect(m_rect, 1);
Rect fillRect = m_rect.expanded(-1);
fillRect.setWidth(fillRect.width() * m_percent / 100.0);
g_painter.setColor(m_backgroundColor);
g_painter.drawFilledRect(fillRect);
}
void UIProgressBar::setPercent(double percent)
{
if(percent == NAN)
percent = 0;
m_percent = std::min(std::max(percent, 0.0), 100.0);
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2010-2012 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 UIPROGRESSBAR_H
#define UIPROGRESSBAR_H
#include "uiwidget.h"
class UIProgressBar : public UIWidget
{
public:
UIProgressBar();
virtual void render();
void setPercent(double percent);
double getPercent() { return m_percent; }
private:
double m_percent;
};
#endif

View File

@ -97,7 +97,7 @@ void UIVerticalLayout::internalUpdate()
pos.y += gap;
prefferedHeight += gap;
if(widget->isSizeFixed()) {
if(widget->isFixedSize()) {
// center it
pos.x = childrenRect.left() + (childrenRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
pos.x = std::max(pos.x, parentWidget->getX());

File diff suppressed because it is too large Load Diff

View File

@ -28,154 +28,50 @@
#include <framework/graphics/declarations.h>
#include <framework/otml/otmlnode.h>
#include <framework/graphics/font.h>
#include <framework/graphics/coordsbuffer.h>
template<typename T = int>
struct EdgeGroup {
EdgeGroup() { top = right = bottom = left = T(0); }
void set(T value) { top = right = bottom = left = value; }
T top;
T right;
T bottom;
T left;
};
class UIWidget : public LuaObject
{
// widget core
public:
UIWidget();
virtual ~UIWidget() { }
void destroy();
virtual ~UIWidget();
protected:
virtual void render();
virtual void renderSelf();
virtual void renderChildren();
virtual void draw();
virtual void drawSelf();
virtual void drawChildren();
friend class UIManager;
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);
std::string m_id;
Rect m_rect;
Boolean<true> m_enabled;
Boolean<true> m_visible;
Boolean<true> m_focusable;
Boolean<false> m_fixedSize;
Boolean<false> m_pressed;
Boolean<false> m_phantom;
Boolean<false> m_destroyed;
UILayoutPtr m_layout;
UIWidgetWeakPtr m_parent;
UIWidgetList m_children;
UIWidgetList m_lockedChildren;
UIWidgetPtr m_focusedChild;
OTMLNodePtr m_style;
Fw::FocusReason m_lastFocusReason;
public:
void setVisible(bool visible);
void setEnabled(bool enabled);
void setPressed(bool pressed);
void setOn(bool on);
void setChecked(bool checked);
void setId(const std::string& id) { m_id = id; }
void setFocusable(bool focusable);
void setPhantom(bool phantom) { m_phantom = phantom; }
void setStyle(const std::string& styleName);
void setStyleFromNode(const OTMLNodePtr& styleNode);
void setLayout(const UILayoutPtr& layout) { m_layout = layout; }
void setParent(const UIWidgetPtr& parent);
void setRect(const Rect& rect);
void setX(int x) { moveTo(Point(x, getY())); }
void setY(int y) { moveTo(Point(getX(), y)); }
void setWidth(int width) { resize(Size(width, getHeight())); }
void setHeight(int height) { resize(Size(getWidth(), height)); }
void setImage(const ImagePtr& image) { m_image = image; }
void setIcon(const std::string& iconFile);
void setOpacity(int opacity) { m_opacity = opacity; }
void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
void setColor(const Color& color) { m_color = color; }
void setMarginTop(int margin) { m_marginTop = margin; updateParentLayout(); }
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 setPaddingTop(int padding) { m_paddingTop = padding; updateLayout(); }
void setPaddingRight(int padding) { m_paddingRight = padding; updateLayout(); }
void setPaddingBottom(int padding) { m_paddingBottom = padding; updateLayout(); }
void setPaddingLeft(int padding) { m_paddingLeft = padding; updateLayout(); }
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(getPos(), size)); }
void resizeToText() { resize(getTextSize()); }
void moveTo(const Point& pos) { setRect(Rect(pos, getSize())); }
void hide() { setVisible(false); }
void show() { setVisible(true); }
void disable() { setEnabled(false); }
void enable() { setEnabled(true); }
void lock();
void unlock();
void focus();
void grabMouse();
void ungrabMouse();
void grabKeyboard();
void ungrabKeyboard();
void clearText() { setText(""); }
bool isActive() { return hasState(Fw::ActiveState); }
bool isEnabled() { return !hasState(Fw::DisabledState); }
bool isDisabled() { return hasState(Fw::DisabledState); }
bool isFocused() { return hasState(Fw::FocusState); }
bool isHovered() { return hasState(Fw::HoverState); }
bool isPressed() { return hasState(Fw::PressedState); }
bool isFirst() { return hasState(Fw::FirstState); }
bool isMiddle() { return hasState(Fw::MiddleState); }
bool isLast() { return hasState(Fw::LastState); }
bool isAlternate() { return hasState(Fw::AlternateState); }
bool isChecked() { return hasState(Fw::CheckedState); }
bool isOn() { return hasState(Fw::OnState); }
bool isVisible();
bool isHidden() { return !isVisible(); }
bool isExplicitlyEnabled() { return m_enabled; }
bool isExplicitlyVisible() { return m_visible; }
bool isFocusable() { return m_focusable; }
bool isPhantom() { return m_phantom; }
bool isSizeFixed() { return m_fixedSize; }
bool isDestroyed() { return m_destroyed; }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
bool hasChildren() { return m_children.size() > 0; }
bool hasChild(const UIWidgetPtr& child);
std::string getId() { return m_id; }
int getChildCount() { return m_children.size(); }
UILayoutPtr getLayout() { return m_layout; }
UIWidgetPtr getParent() { return m_parent.lock(); }
UIWidgetPtr getRootParent();
Point getPos() { return m_rect.topLeft(); }
Size getSize() { return m_rect.size(); }
Rect getRect() { return m_rect; }
Rect getChildrenRect();
int getX() { return m_rect.x(); }
int getY() { return m_rect.y(); }
int getWidth() { return m_rect.width(); }
int getHeight() { return m_rect.height(); }
Color getColor() { return m_color; }
Color getBackgroundColor() { return m_backgroundColor; }
int getOpacity() { return m_opacity; }
int getMarginTop() { return m_marginTop; }
int getMarginRight() { return m_marginRight; }
int getMarginBottom() { return m_marginBottom; }
int getMarginLeft() { return m_marginLeft; }
int getPaddingTop() { return m_paddingTop; }
int getPaddingRight() { return m_paddingRight; }
int getPaddingBottom() { return m_paddingBottom; }
int getPaddingLeft() { return m_paddingLeft; }
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(); }
UIWidgetList getChildren() { return m_children; }
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
UIWidgetPtr getChildById(const std::string& childId);
UIWidgetPtr getChildByPos(const Point& childPos);
UIWidgetPtr getChildByIndex(int index);
UIWidgetPtr getFirstChild() { return getChildByIndex(1); }
UIWidgetPtr getLastChild() { return getChildByIndex(-1); }
UIWidgetPtr recursiveGetChildById(const std::string& id);
UIWidgetPtr recursiveGetChildByPos(const Point& childPos);
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
void addChild(const UIWidgetPtr& child);
void insertChild(int index, const UIWidgetPtr& child);
void removeChild(const UIWidgetPtr& child);
@ -186,15 +82,63 @@ public:
void moveChildToIndex(const UIWidgetPtr& child, int index);
void lockChild(const UIWidgetPtr& child);
void unlockChild(const UIWidgetPtr& child);
bool isChildLocked(const UIWidgetPtr& child);
int getChildIndex(const UIWidgetPtr& child);
void applyStyle(const OTMLNodePtr& styleNode);
void addAnchor(Fw::AnchorEdge anchoredEdge, const std::string& hookedWidgetId, Fw::AnchorEdge hookedEdge);
void fill(const std::string& hookedWidgetId);
void centerIn(const std::string& hookedWidgetId);
void breakAnchors();
void updateParentLayout();
void updateLayout();
void applyStyle(const OTMLNodePtr& styleNode);
void lock();
void unlock();
void focus();
void grabMouse();
void ungrabMouse();
void grabKeyboard();
void ungrabKeyboard();
void bindRectToParent();
void destroy();
void setId(const std::string& id);
void setParent(const UIWidgetPtr& parent);
void setLayout(const UILayoutPtr& layout);
void setRect(const Rect& rect);
void setStyle(const std::string& styleName);
void setStyleFromNode(const OTMLNodePtr& styleNode);
void setEnabled(bool enabled);
void setVisible(bool visible);
void setPressed(bool pressed);
void setOn(bool on);
void setChecked(bool checked);
void setFocusable(bool focusable);
void setPhantom(bool phantom);
void setFixedSize(bool fixed);
void setLastFocusReason(Fw::FocusReason reason);
bool isVisible();
bool isChildLocked(const UIWidgetPtr& child);
bool hasChild(const UIWidgetPtr& child);
int getChildIndex(const UIWidgetPtr& child);
Rect getChildrenRect();
UIAnchorLayoutPtr getAnchoredLayout();
UIWidgetPtr getRootParent();
UIWidgetPtr getChildAfter(const UIWidgetPtr& relativeChild);
UIWidgetPtr getChildBefore(const UIWidgetPtr& relativeChild);
UIWidgetPtr getChildById(const std::string& childId);
UIWidgetPtr getChildByPos(const Point& childPos);
UIWidgetPtr getChildByIndex(int index);
UIWidgetPtr recursiveGetChildById(const std::string& id);
UIWidgetPtr recursiveGetChildByPos(const Point& childPos);
UIWidgetPtr backwardsGetWidgetById(const std::string& id);
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
private:
Boolean<false> m_updateEventScheduled;
Boolean<false> m_loadingStyle;
// state managment
protected:
bool setState(Fw::WidgetState state, bool on);
bool hasState(Fw::WidgetState state);
@ -203,16 +147,20 @@ private:
void updateState(Fw::WidgetState state);
void updateStates();
void updateChildrenIndexStates();
void updateStyle();
Boolean<false> m_updateStyleScheduled;
Boolean<true> m_firstOnStyle;
OTMLNodePtr m_stateStyle;
int m_states;
// event processing
protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
virtual void onHoverChange(bool hovered);
virtual void onTextChange(const std::string& text);
virtual void onFontChange(const std::string& font);
virtual bool onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers);
virtual bool onKeyRelease(uchar keyCode, std::string keyText, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
@ -227,46 +175,259 @@ protected:
bool propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved);
bool propagateOnMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction);
// function shortcuts
public:
void resize(int width, int height) { setRect(Rect(getPos(), Size(width, height))); }
void move(int x, int y) { setRect(Rect(x, y, getSize())); }
void hide() { setVisible(false); }
void show() { setVisible(true); }
void disable() { setEnabled(false); }
void enable() { setEnabled(true); }
bool isActive() { return hasState(Fw::ActiveState); }
bool isEnabled() { return !hasState(Fw::DisabledState); }
bool isDisabled() { return hasState(Fw::DisabledState); }
bool isFocused() { return hasState(Fw::FocusState); }
bool isHovered() { return hasState(Fw::HoverState); }
bool isPressed() { return hasState(Fw::PressedState); }
bool isFirst() { return hasState(Fw::FirstState); }
bool isMiddle() { return hasState(Fw::MiddleState); }
bool isLast() { return hasState(Fw::LastState); }
bool isAlternate() { return hasState(Fw::AlternateState); }
bool isChecked() { return hasState(Fw::CheckedState); }
bool isOn() { return hasState(Fw::OnState); }
bool isHidden() { return !isVisible(); }
bool isExplicitlyEnabled() { return m_enabled; }
bool isExplicitlyVisible() { return m_visible; }
bool isFocusable() { return m_focusable; }
bool isPhantom() { return m_phantom; }
bool isFixedSize() { return m_fixedSize; }
bool isDestroyed() { return m_destroyed; }
bool hasChildren() { return m_children.size() > 0; }
bool containsPoint(const Point& point) { return m_rect.contains(point); }
std::string getId() { return m_id; }
UIWidgetPtr getParent() { return m_parent.lock(); }
UIWidgetPtr getFocusedChild() { return m_focusedChild; }
UIWidgetList getChildren() { return m_children; }
UIWidgetPtr getFirstChild() { return getChildByIndex(1); }
UIWidgetPtr getLastChild() { return getChildByIndex(-1); }
UILayoutPtr getLayout() { return m_layout; }
OTMLNodePtr getStyle() { return m_style; }
int getChildCount() { return m_children.size(); }
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
std::string getStyleName() { return m_style->tag(); }
// base style
private:
void initBaseStyle();
void parseBaseStyle(const OTMLNodePtr& styleNode);
protected:
std::string m_id;
Fw::FocusReason m_lastFocusReason;
Boolean<true> m_enabled;
Boolean<true> m_visible;
Boolean<true> m_focusable;
Boolean<false> m_fixedSize;
Boolean<false> m_pressed;
Boolean<false> m_phantom;
Boolean<false> m_updateEventScheduled;
Boolean<false> m_loadingStyle;
Boolean<false> m_updateStyleScheduled;
Boolean<true> m_firstOnStyle;
Boolean<false> m_destroyed;
Rect m_rect;
UILayoutPtr m_layout;
UIWidgetWeakPtr m_parent;
UIWidgetList m_children;
UIWidgetList m_lockedChildren;
UIWidgetPtr m_focusedChild;
OTMLNodePtr m_style;
OTMLNodePtr m_stateStyle;
ImagePtr m_image;
TexturePtr m_icon;
FontPtr m_font;
Color m_backgroundColor;
void drawBackground(const Rect& screenCoords);
void drawBorder(const Rect& screenCoords);
void drawIcon(const Rect& screenCoords);
Color m_color;
int m_states;
int m_opacity;
int m_marginTop;
int m_marginRight;
int m_marginBottom;
int m_marginLeft;
int m_paddingTop;
int m_paddingRight;
int m_paddingBottom;
int m_paddingLeft;
Color m_backgroundColor;
Rect m_backgroundRect;
TexturePtr m_icon;
Color m_iconColor;
Rect m_iconRect;
EdgeGroup<Color> m_borderColor;
EdgeGroup<int> m_borderWidth;
EdgeGroup<int> m_margin;
EdgeGroup<int> m_padding;
float m_opacity;
public:
void setX(int x) { move(x, getY()); }
void setY(int y) { move(getX(), y); }
void setWidth(int width) { resize(width, getHeight()); }
void setHeight(int height) { resize(getWidth(), height); }
void setSize(const Size& size) { resize(size.width(), size.height()); }
void setPos(const Point& pos) { move(pos.x, pos.y); }
void setColor(const Color& color) { m_color = color; }
void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
void setBackgroundOffsetX(int x) { m_backgroundRect.setX(x); }
void setBackgroundOffsetY(int y) { m_backgroundRect.setX(y); }
void setBackgroundOffset(const Point& pos) { m_backgroundRect.move(pos); }
void setBackgroundWidth(int width) { m_backgroundRect.setWidth(width); }
void setBackgroundHeight(int height) { m_backgroundRect.setHeight(height); }
void setBackgroundSize(const Size& size) { m_backgroundRect.resize(size); }
void setBackgroundRect(const Rect& rect) { m_backgroundRect = rect; }
void setIcon(const std::string& iconFile);
void setIconColor(const Color& color) { m_iconColor = color; }
void setIconOffsetX(int x) { m_iconRect.setX(x); }
void setIconOffsetY(int y) { m_iconRect.setX(y); }
void setIconOffset(const Point& pos) { m_iconRect.move(pos); }
void setIconWidth(int width) { m_iconRect.setWidth(width); }
void setIconHeight(int height) { m_iconRect.setHeight(height); }
void setIconSize(const Size& size) { m_iconRect.resize(size); }
void setIconRect(const Rect& rect) { m_iconRect = rect; }
void setBorderWidth(int width) { m_borderWidth.set(width); updateLayout(); }
void setBorderWidthTop(int width) { m_borderWidth.top = width; }
void setBorderWidthRight(int width) { m_borderWidth.right = width; }
void setBorderWidthBottom(int width) { m_borderWidth.bottom = width; }
void setBorderWidthLeft(int width) { m_borderWidth.left = width; }
void setBorderColor(const Color& color) { m_borderColor.set(color); updateLayout(); }
void setBorderColorTop(const Color& color) { m_borderColor.top = color; }
void setBorderColorRight(const Color& color) { m_borderColor.right = color; }
void setBorderColorBottom(const Color& color) { m_borderColor.bottom = color; }
void setBorderColorLeft(const Color& color) { m_borderColor.left = color; }
void setMargin(int margin) { m_margin.set(margin); updateParentLayout(); }
void setMarginHorizontal(int margin) { m_margin.right = m_margin.left = margin; updateParentLayout(); }
void setMarginVertical(int margin) { m_margin.bottom = m_margin.top = margin; updateParentLayout(); }
void setMarginTop(int margin) { m_margin.top = margin; updateParentLayout(); }
void setMarginRight(int margin) { m_margin.right = margin; updateParentLayout(); }
void setMarginBottom(int margin) { m_margin.bottom = margin; updateParentLayout(); }
void setMarginLeft(int margin) { m_margin.left = margin; updateParentLayout(); }
void setPadding(int padding) { m_padding.top = m_padding.right = m_padding.bottom = m_padding.left = padding; updateLayout(); }
void setPaddingHorizontal(int padding) { m_padding.right = m_padding.left = padding; updateLayout(); }
void setPaddingVertical(int padding) { m_padding.bottom = m_padding.top = padding; updateLayout(); }
void setPaddingTop(int padding) { m_padding.top = padding; updateLayout(); }
void setPaddingRight(int padding) { m_padding.right = padding; updateLayout(); }
void setPaddingBottom(int padding) { m_padding.bottom = padding; updateLayout(); }
void setPaddingLeft(int padding) { m_padding.left = padding; updateLayout(); }
void setOpacity(float opacity) { m_opacity = opacity; }
int getX() { return m_rect.x(); }
int getY() { return m_rect.y(); }
Point getPos() { return m_rect.topLeft(); }
int getWidth() { return m_rect.width(); }
int getHeight() { return m_rect.height(); }
Size getSize() { return m_rect.size(); }
Rect getRect() { return m_rect; }
Color getColor() { return m_color; }
Color getBackgroundColor() { return m_backgroundColor; }
int getBackgroundOffsetX() { return m_backgroundRect.x(); }
int getBackgroundOffsetY() { return m_backgroundRect.y(); }
Point getBackgroundOffset() { return m_backgroundRect.topLeft(); }
int getBackgroundWidth() { return m_backgroundRect.width(); }
int getBackgroundHeight() { return m_backgroundRect.height(); }
Size getBackgroundSize() { return m_backgroundRect.size(); }
Rect getBackgroundRect() { return m_backgroundRect; }
Color getIconColor() { return m_iconColor; }
int getIconOffsetX() { return m_iconRect.x(); }
int getIconOffsetY() { return m_iconRect.y(); }
Point getIconOffset() { return m_iconRect.topLeft(); }
int getIconWidth() { return m_iconRect.width(); }
int getIconHeight() { return m_iconRect.height(); }
Size getIconSize() { return m_iconRect.size(); }
Rect getIconRect() { return m_iconRect; }
Color getBorderTopColor() { return m_borderColor.top; }
Color getBorderRightColor() { return m_borderColor.right; }
Color getBorderBottomColor() { return m_borderColor.bottom; }
Color getBorderLeftColor() { return m_borderColor.left; }
int getBorderTopWidth() { return m_borderWidth.top; }
int getBorderRightWidth() { return m_borderWidth.right; }
int getBorderBottomWidth() { return m_borderWidth.bottom; }
int getBorderLeftWidth() { return m_borderWidth.left; }
int getMarginTop() { return m_margin.top; }
int getMarginRight() { return m_margin.right; }
int getMarginBottom() { return m_margin.bottom; }
int getMarginLeft() { return m_margin.left; }
int getPaddingTop() { return m_padding.top; }
int getPaddingRight() { return m_padding.right; }
int getPaddingBottom() { return m_padding.bottom; }
int getPaddingLeft() { return m_padding.left; }
float getOpacity() { return m_opacity; }
// image
private:
void initImage() { }
void parseImageStyle(const OTMLNodePtr& styleNode);
void updateImageCache() { m_imageMustRecache = true; }
void configureBorderImage() { m_imageBordered = true; updateImageCache(); }
CoordsBuffer m_imageCoordsBuffer;
Rect m_imageCachedScreenCoords;
Boolean<true> m_imageMustRecache;
Boolean<false> m_imageBordered;
protected:
void drawImage(const Rect& screenCoords);
TexturePtr m_imageTexture;
Rect m_imageClipRect;
Rect m_imageRect;
Color m_imageColor;
Boolean<false> m_imageFixedRatio;
Boolean<false> m_imageRepeated;
Boolean<false> m_imageSmooth;
EdgeGroup<int> m_imageBorder;
public:
void setImageSource(const std::string& source);
void setImageClip(const Rect& clipRect) { m_imageClipRect = clipRect; updateImageCache(); }
void setImageOffsetX(int x) { m_imageRect.setX(x); updateImageCache(); }
void setImageOffsetY(int y) { m_imageRect.setX(y); updateImageCache(); }
void setImageOffset(const Point& pos) { m_imageRect.move(pos); updateImageCache(); }
void setImageWidth(int width) { m_imageRect.setWidth(width); updateImageCache(); }
void setImageHeight(int height) { m_imageRect.setHeight(height); updateImageCache(); }
void setImageSize(const Size& size) { m_imageRect.resize(size); updateImageCache(); }
void setImageRect(const Rect& rect) { m_imageRect = rect; updateImageCache(); }
void setImageColor(const Color& color) { m_imageColor = color; updateImageCache(); }
void setImageFixedRatio(bool fixedRatio) { m_imageFixedRatio = fixedRatio; updateImageCache(); }
void setImageRepeated(bool repeated) { m_imageRepeated = repeated; updateImageCache(); }
void setImageSmooth(bool smooth) { m_imageSmooth = smooth; }
void setImageBorderTop(int border) { m_imageBorder.top = border; configureBorderImage(); }
void setImageBorderRight(int border) { m_imageBorder.right = border; configureBorderImage(); }
void setImageBorderBottom(int border) { m_imageBorder.bottom = border; configureBorderImage(); }
void setImageBorderLeft(int border) { m_imageBorder.left = border; configureBorderImage(); }
void setImageBorder(int border) { m_imageBorder.set(border); configureBorderImage(); }
Rect getImageClip() { return m_imageClipRect; }
int getImageOffsetX() { return m_imageRect.x(); }
int getImageOffsetY() { return m_imageRect.y(); }
Point getImageOffset() { return m_imageRect.topLeft(); }
int getImageWidth() { return m_imageRect.width(); }
int getImageHeight() { return m_imageRect.height(); }
Size getImageSize() { return m_imageRect.size(); }
Rect getImageRect() { return m_imageRect; }
Color getImageColor() { return m_imageColor; }
bool isImageFixedRatio() { return m_imageFixedRatio; }
bool isImageSmooth() { return m_imageSmooth; }
int getImageBorderTop() { return m_imageBorder.top; }
int getImageBorderRight() { return m_imageBorder.right; }
int getImageBorderBottom() { return m_imageBorder.bottom; }
int getImageBorderLeft() { return m_imageBorder.left; }
// text related
private:
void initText();
void parseTextStyle(const OTMLNodePtr& styleNode);
protected:
void drawText(const Rect& screenCoords);
virtual void onTextChange(const std::string& text);
virtual void onFontChange(const std::string& font);
std::string m_text;
Point m_textOffset;
Fw::AlignmentFlag m_textAlign;
Point m_textOffset;
FontPtr m_font;
public:
void resizeToText() { setSize(getTextSize()); }
void clearText() { setText(""); }
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);
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); }
};
#endif

View File

@ -0,0 +1,366 @@
/*
* Copyright (c) 2010-2012 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 "uiwidget.h"
#include "uianchorlayout.h"
#include "uiverticallayout.h"
#include "uitranslator.h"
#include <framework/graphics/painter.h>
#include <framework/graphics/texture.h>
#include <framework/graphics/texturemanager.h>
void UIWidget::initBaseStyle()
{
m_backgroundColor = Fw::alpha;
m_borderColor.set(Fw::black);
m_iconColor = Fw::white;
m_color = Fw::white;
m_opacity = 1.0f;
// generate an unique id, this is need because anchored layouts find widgets by id
static unsigned long id = 1;
m_id = Fw::mkstr("widget", id++);
}
void UIWidget::parseBaseStyle(const OTMLNodePtr& styleNode)
{
// load styles used by all widgets
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "color")
setColor(node->value<Color>());
else if(node->tag() == "x")
setX(node->value<int>());
else if(node->tag() == "y")
setY(node->value<int>());
else if(node->tag() == "pos")
setPos(node->value<Point>());
else if(node->tag() == "width")
setWidth(node->value<int>());
else if(node->tag() == "height")
setHeight(node->value<int>());
else if(node->tag() == "rect")
setRect(node->value<Rect>());
else if(node->tag() == "background")
setBackgroundColor(node->value<Color>());
else if(node->tag() == "background-color")
setBackgroundColor(node->value<Color>());
else if(node->tag() == "background-offset-x")
setBackgroundOffsetX(node->value<int>());
else if(node->tag() == "background-offset-y")
setBackgroundOffsetY(node->value<int>());
else if(node->tag() == "background-offset")
setBackgroundOffset(node->value<Point>());
else if(node->tag() == "background-width")
setBackgroundWidth(node->value<int>());
else if(node->tag() == "background-height")
setBackgroundHeight(node->value<int>());
else if(node->tag() == "background-size")
setBackgroundSize(node->value<Size>());
else if(node->tag() == "background-rect")
setBackgroundRect(node->value<Rect>());
else if(node->tag() == "icon")
setIcon(node->value());
else if(node->tag() == "icon-source")
setIcon(node->value());
else if(node->tag() == "icon-color")
setIconColor(node->value<Color>());
else if(node->tag() == "icon-offset-x")
setIconOffsetX(node->value<int>());
else if(node->tag() == "icon-offset-y")
setIconOffsetY(node->value<int>());
else if(node->tag() == "icon-offset")
setIconOffset(node->value<Point>());
else if(node->tag() == "icon-width")
setIconWidth(node->value<int>());
else if(node->tag() == "icon-height")
setIconHeight(node->value<int>());
else if(node->tag() == "icon-size")
setIconSize(node->value<Size>());
else if(node->tag() == "icon-rect")
setIconRect(node->value<Rect>());
else if(node->tag() == "opacity")
setOpacity(node->value<float>());
else if(node->tag() == "enabled")
setEnabled(node->value<bool>());
else if(node->tag() == "visible")
setVisible(node->value<bool>());
else if(node->tag() == "checked")
setChecked(node->value<bool>());
else if(node->tag() == "on")
setOn(node->value<bool>());
else if(node->tag() == "focusable")
setFocusable(node->value<bool>());
else if(node->tag() == "phantom")
setPhantom(node->value<bool>());
else if(node->tag() == "size")
setSize(node->value<Size>());
else if(node->tag() == "fixed-size")
setFixedSize(node->value<bool>());
else if(node->tag() == "border") {
auto split = Fw::split(node->value(), " ");
setBorderWidth(Fw::safeCast<int>(split[0]));
setBorderColor(Fw::safeCast<Color>(split[1]));
}
else if(node->tag() == "border-width")
setBorderWidth(node->value<int>());
else if(node->tag() == "border-width-top")
setBorderWidthTop(node->value<int>());
else if(node->tag() == "border-width-right")
setBorderWidthRight(node->value<int>());
else if(node->tag() == "border-width-bottom")
setBorderWidthBottom(node->value<int>());
else if(node->tag() == "border-width-left")
setBorderWidthLeft(node->value<int>());
else if(node->tag() == "border-color")
setBorderColor(node->value<Color>());
else if(node->tag() == "border-color-top")
setBorderColorTop(node->value<Color>());
else if(node->tag() == "border-color-right")
setBorderColorRight(node->value<Color>());
else if(node->tag() == "border-color-bottom")
setBorderColorBottom(node->value<Color>());
else if(node->tag() == "border-color-left")
setBorderColorLeft(node->value<Color>());
else if(node->tag() == "margin-top")
setMarginTop(node->value<int>());
else if(node->tag() == "margin-right")
setMarginRight(node->value<int>());
else if(node->tag() == "margin-bottom")
setMarginBottom(node->value<int>());
else if(node->tag() == "margin-left")
setMarginLeft(node->value<int>());
else if(node->tag() == "margin") {
std::string marginDesc = node->value();
std::vector<std::string> split;
boost::split(split, marginDesc, boost::is_any_of(std::string(" ")));
if(split.size() == 4) {
setMarginTop(Fw::safeCast<int>(split[0]));
setMarginRight(Fw::safeCast<int>(split[1]));
setMarginBottom(Fw::safeCast<int>(split[2]));
setMarginLeft(Fw::safeCast<int>(split[3]));
} else if(split.size() == 3) {
int marginTop = Fw::safeCast<int>(split[0]);
int marginHorizontal = Fw::safeCast<int>(split[1]);
int marginBottom = Fw::safeCast<int>(split[2]);
setMarginTop(marginTop);
setMarginRight(marginHorizontal);
setMarginBottom(marginBottom);
setMarginLeft(marginHorizontal);
} else if(split.size() == 2) {
int marginVertical = Fw::safeCast<int>(split[0]);
int marginHorizontal = Fw::safeCast<int>(split[1]);
setMarginTop(marginVertical);
setMarginRight(marginHorizontal);
setMarginBottom(marginVertical);
setMarginLeft(marginHorizontal);
} else if(split.size() == 1) {
int margin = Fw::safeCast<int>(split[0]);
setMarginTop(margin);
setMarginRight(margin);
setMarginBottom(margin);
setMarginLeft(margin);
}
}
else if(node->tag() == "padding-top")
setPaddingTop(node->value<int>());
else if(node->tag() == "padding-right")
setPaddingRight(node->value<int>());
else if(node->tag() == "padding-bottom")
setPaddingBottom(node->value<int>());
else if(node->tag() == "padding-left")
setPaddingLeft(node->value<int>());
else if(node->tag() == "padding") {
std::string paddingDesc = node->value();
std::vector<std::string> split;
boost::split(split, paddingDesc, boost::is_any_of(std::string(" ")));
if(split.size() == 4) {
setPaddingTop(Fw::safeCast<int>(split[0]));
setPaddingRight(Fw::safeCast<int>(split[1]));
setPaddingBottom(Fw::safeCast<int>(split[2]));
setPaddingLeft(Fw::safeCast<int>(split[3]));
} else if(split.size() == 3) {
int paddingTop = Fw::safeCast<int>(split[0]);
int paddingHorizontal = Fw::safeCast<int>(split[1]);
int paddingBottom = Fw::safeCast<int>(split[2]);
setPaddingTop(paddingTop);
setPaddingRight(paddingHorizontal);
setPaddingBottom(paddingBottom);
setPaddingLeft(paddingHorizontal);
} else if(split.size() == 2) {
int paddingVertical = Fw::safeCast<int>(split[0]);
int paddingHorizontal = Fw::safeCast<int>(split[1]);
setPaddingTop(paddingVertical);
setPaddingRight(paddingHorizontal);
setPaddingBottom(paddingVertical);
setPaddingLeft(paddingHorizontal);
} else if(split.size() == 1) {
int padding = Fw::safeCast<int>(split[0]);
setPaddingTop(padding);
setPaddingRight(padding);
setPaddingBottom(padding);
setPaddingLeft(padding);
}
}
// layouts
else if(node->tag() == "layout") {
std::string layoutType;
if(node->hasValue())
layoutType = node->value();
else
layoutType = node->valueAt<std::string>("type", "");
if(!layoutType.empty()) {
UILayoutPtr layout;
if(layoutType == "verticalBox")
layout = UIVerticalLayoutPtr(new UIVerticalLayout(asUIWidget()));
else if(layoutType == "anchor")
layout = UIAnchorLayoutPtr(new UIAnchorLayout(asUIWidget()));
else
throw OTMLException(node, "cannot determine layout type");
setLayout(layout);
}
if(node->hasChildren())
m_layout->applyStyle(node);
}
// anchors
else if(boost::starts_with(node->tag(), "anchors.")) {
UIWidgetPtr parent = getParent();
if(!parent) {
if(m_firstOnStyle)
throw OTMLException(node, "cannot create anchor, there is no parent widget!");
else
continue;
}
UIAnchorLayoutPtr anchorLayout = parent->getLayout()->asUIAnchorLayout();
if(!anchorLayout)
throw OTMLException(node, "cannot create anchor, the parent widget doesn't use anchor layout!");
std::string what = node->tag().substr(8);
if(what == "fill") {
fill(node->value());
} else if(what == "centerIn") {
centerIn(node->value());
} else {
Fw::AnchorEdge anchoredEdge = Fw::translateAnchorEdge(what);
std::vector<std::string> split = Fw::split(node->value(), ".");
if(split.size() != 2)
throw OTMLException(node, "invalid anchor description");
std::string hookedWidgetId = split[0];
Fw::AnchorEdge hookedEdge = Fw::translateAnchorEdge(split[1]);
if(anchoredEdge == Fw::AnchorNone)
throw OTMLException(node, "invalid anchor edge");
if(hookedEdge == Fw::AnchorNone)
throw OTMLException(node, "invalid anchor target edge");
addAnchor(anchoredEdge, hookedWidgetId, hookedEdge);
}
// lua functions
} else if(boost::starts_with(node->tag(), "@")) {
// load once
if(m_firstOnStyle) {
std::string funcName = node->tag().substr(1);
std::string funcOrigin = "@" + node->source() + "[" + node->tag() + "]";
g_lua.loadFunction(node->value(), funcOrigin);
luaSetField(funcName);
}
// lua fields value
} else if(boost::starts_with(node->tag(), "&")) {
std::string fieldName = node->tag().substr(1);
std::string fieldOrigin = "@" + node->source() + "[" + node->tag() + "]";
g_lua.evaluateExpression(node->value(), fieldOrigin);
luaSetField(fieldName);
}
}
}
void UIWidget::drawBackground(const Rect& screenCoords)
{
if(m_backgroundColor.a() > 0) {
Rect drawRect = screenCoords;
drawRect.translate(m_backgroundRect.topLeft());
if(m_backgroundRect.isValid())
drawRect.resize(m_backgroundRect.size());
g_painter.setColor(m_backgroundColor);
g_painter.drawFilledRect(drawRect);
}
}
void UIWidget::drawBorder(const Rect& screenCoords)
{
// top
if(m_borderWidth.top > 0 && m_borderColor.top.a() > 0) {
g_painter.setColor(m_borderColor.top);
Rect borderRect(screenCoords.topLeft(), screenCoords.width(), m_borderWidth.top);
g_painter.drawFilledRect(borderRect);
}
// right
if(m_borderWidth.right > 0 && m_borderColor.top.a() > 0) {
g_painter.setColor(m_borderColor.top);
Rect borderRect(screenCoords.topRight() - Point(m_borderWidth.right - 1, 0), m_borderWidth.right, screenCoords.height());
g_painter.drawFilledRect(borderRect);
}
// bottom
if(m_borderWidth.bottom > 0 && m_borderColor.top.a() > 0) {
g_painter.setColor(m_borderColor.top);
Rect borderRect(screenCoords.bottomLeft() - Point(0, m_borderWidth.bottom - 1), screenCoords.width(), m_borderWidth.bottom);
g_painter.drawFilledRect(borderRect);
}
// left
if(m_borderWidth.top > 0 && m_borderColor.top.a() > 0) {
g_painter.setColor(m_borderColor.top);
Rect borderRect(screenCoords.topLeft(), m_borderWidth.left, screenCoords.height());
g_painter.drawFilledRect(borderRect);
}
}
void UIWidget::drawIcon(const Rect& screenCoords)
{
if(m_icon && m_iconColor.a() > 0) {
Rect drawRect;
if(m_iconRect.isValid()) {
drawRect = screenCoords;
drawRect.translate(m_iconRect.topLeft());
drawRect.resize(m_iconRect.size());
} else {
drawRect.resize(m_icon->getSize());
drawRect.moveCenter(screenCoords.center());
}
g_painter.setColor(m_iconColor);
g_painter.drawTexturedRect(drawRect, m_icon);
}
}
void UIWidget::setIcon(const std::string& iconFile)
{
m_icon = g_textures.getTexture(iconFile);
}

View File

@ -0,0 +1,175 @@
/*
* Copyright (c) 2010-2012 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 "uiwidget.h"
#include <framework/graphics/painter.h>
#include <framework/graphics/texture.h>
#include <framework/graphics/texturemanager.h>
void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode)
{
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "image")
setImageSource(node->value());
else if(node->tag() == "image-source")
setImageSource(node->value());
else if(node->tag() == "image-offset-x")
setImageOffsetX(node->value<int>());
else if(node->tag() == "image-offset-y")
setImageOffsetY(node->value<int>());
else if(node->tag() == "image-offset")
setImageOffset(node->value<Point>());
else if(node->tag() == "image-width")
setImageWidth(node->value<int>());
else if(node->tag() == "image-height")
setImageHeight(node->value<int>());
else if(node->tag() == "image-size")
setImageSize(node->value<Size>());
else if(node->tag() == "image-rect")
setImageRect(node->value<Rect>());
else if(node->tag() == "image-clip")
setImageClip(node->value<Rect>());
else if(node->tag() == "image-fixed-ratio")
setImageFixedRatio(node->value<bool>());
else if(node->tag() == "image-repeated")
setImageRepeated(node->value<bool>());
else if(node->tag() == "image-smooth")
setImageSmooth(node->value<bool>());
else if(node->tag() == "image-color")
setImageColor(node->value<Color>());
else if(node->tag() == "image-border-top")
setImageBorderTop(node->value<int>());
else if(node->tag() == "image-border-right")
setImageBorderRight(node->value<int>());
else if(node->tag() == "image-border-bottom")
setImageBorderBottom(node->value<int>());
else if(node->tag() == "image-border-left")
setImageBorderLeft(node->value<int>());
else if(node->tag() == "image-border") {
setImageBorder(node->value<int>());
}
}
}
void UIWidget::drawImage(const Rect& screenCoords)
{
if(!m_imageTexture || m_imageColor.a() == 0 || !screenCoords.isValid())
return;
// cache vertex buffers
if(m_imageCachedScreenCoords != screenCoords || m_imageMustRecache) {
m_imageCoordsBuffer.clear();
m_imageCachedScreenCoords = screenCoords;
m_imageMustRecache = false;
Rect drawRect = screenCoords;
drawRect.translate(m_imageRect.topLeft());
if(m_imageRect.isValid())
drawRect.resize(m_imageRect.size());
if(!m_imageBordered) {
if(m_imageFixedRatio) {
Size textureSize = m_imageTexture->getSize();
Size textureClipSize = drawRect.size();
textureClipSize.scale(textureSize, Fw::KeepAspectRatio);
Point texCoordsOffset;
if(textureSize.height() > textureClipSize.height())
texCoordsOffset.y = (textureSize.height() - textureClipSize.height())/2;
else if(textureSize.width() > textureClipSize.width())
texCoordsOffset.x = (textureSize.width() - textureClipSize.width())/2;
Rect textureClipRect(texCoordsOffset, textureClipSize);
m_imageCoordsBuffer.addRect(drawRect, textureClipRect);
} else {
if(m_imageRepeated)
m_imageCoordsBuffer.addRepeatedRects(drawRect, m_imageClipRect);
else
m_imageCoordsBuffer.addRect(drawRect, m_imageClipRect);
}
} else {
int top = m_imageBorder.top;
int bottom = m_imageBorder.bottom;
int left = m_imageBorder.left;
int right = m_imageBorder.right;
// calculates border coords
const Rect clip = m_imageClipRect;
Rect leftBorder(clip.left(), clip.top() + top, left, clip.height() - top - bottom);
Rect rightBorder(clip.right() - right + 1, clip.top() + top, right, clip.height() - top - bottom);
Rect topBorder(clip.left() + left, clip.top(), clip.width() - right - left, top);
Rect bottomBorder(clip.left() + left, clip.bottom() - bottom + 1, clip.width() - right - left, bottom);
Rect topLeftCorner(clip.left(), clip.top(), left, top);
Rect topRightCorner(clip.right() - right + 1, clip.top(), right, top);
Rect bottomLeftCorner(clip.left(), clip.bottom() - bottom + 1, left, bottom);
Rect bottomRightCorner(clip.right() - right + 1, clip.bottom() - bottom + 1, right, bottom);
Rect center(clip.left() + left, clip.top() + top, clip.width() - right - left, clip.height() - top - bottom);
Size bordersSize(leftBorder.width() + rightBorder.width(), topBorder.height() + bottomBorder.height());
Size centerSize = drawRect.size() - bordersSize;
Rect rectCoords;
// first the center
if(centerSize.area() > 0) {
rectCoords = Rect(drawRect.left() + leftBorder.width(), drawRect.top() + topBorder.height(), centerSize);
m_imageCoordsBuffer.addRepeatedRects(rectCoords, center);
}
// top left corner
rectCoords = Rect(drawRect.topLeft(), topLeftCorner.size());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, topLeftCorner);
// top
rectCoords = Rect(drawRect.left() + topLeftCorner.width(), drawRect.topLeft().y, centerSize.width(), topBorder.height());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, topBorder);
// top right corner
rectCoords = Rect(drawRect.left() + topLeftCorner.width() + centerSize.width(), drawRect.top(), topRightCorner.size());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, topRightCorner);
// left
rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height(), leftBorder.width(), centerSize.height());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, leftBorder);
// right
rectCoords = Rect(drawRect.left() + leftBorder.width() + centerSize.width(), drawRect.top() + topRightCorner.height(), rightBorder.width(), centerSize.height());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, rightBorder);
// bottom left corner
rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height() + centerSize.height(), bottomLeftCorner.size());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomLeftCorner);
// bottom
rectCoords = Rect(drawRect.left() + bottomLeftCorner.width(), drawRect.top() + topBorder.height() + centerSize.height(), centerSize.width(), bottomBorder.height());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomBorder);
// bottom right corner
rectCoords = Rect(drawRect.left() + bottomLeftCorner.width() + centerSize.width(), drawRect.top() + topRightCorner.height() + centerSize.height(), bottomRightCorner.size());
m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomRightCorner);
}
}
m_imageTexture->setSmooth(m_imageSmooth);
g_painter.setColor(m_imageColor);
g_painter.drawTextureCoords(m_imageCoordsBuffer, m_imageTexture);
}
void UIWidget::setImageSource(const std::string& source)
{
m_imageTexture = g_textures.getTexture(source);
if(!m_imageClipRect.isValid())
m_imageClipRect = Rect(0, 0, m_imageTexture->getSize());
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2010-2012 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 "uiwidget.h"
#include "uitranslator.h"
#include <framework/graphics/fontmanager.h>
#include <framework/graphics/painter.h>
void UIWidget::initText()
{
m_font = g_fonts.getDefaultFont();
m_textAlign = Fw::AlignCenter;
}
void UIWidget::parseTextStyle(const OTMLNodePtr& styleNode)
{
for(const OTMLNodePtr& node : styleNode->children()) {
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<Point>());
else if(node->tag() == "font")
setFont(node->value());
}
}
void UIWidget::drawText(const Rect& screenCoords)
{
g_painter.setColor(m_color);
if(m_text.length() > 0 && m_color.a() > 0) {
Rect textRect = screenCoords;
textRect.translate(m_textOffset);
m_font->renderText(m_text, textRect, m_textAlign, m_color);
}
}
void UIWidget::onTextChange(const std::string& text)
{
callLuaField("onTextChange", text);
}
void UIWidget::onFontChange(const std::string& font)
{
callLuaField("onFontChange", font);
}
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());
setSize(newSize);
}
onTextChange(text);
}
}
void UIWidget::setFont(const std::string& fontName)
{
m_font = g_fonts.getFont(fontName);
onFontChange(fontName);
}

View File

@ -22,7 +22,6 @@
#include "uiwindow.h"
#include "uitranslator.h"
#include <framework/graphics/borderimage.h>
#include <framework/graphics/font.h>
#include <framework/graphics/graphics.h>
#include <framework/otml/otml.h>
@ -36,22 +35,22 @@ UIWindow::UIWindow()
m_oldIndex = -1;
}
void UIWindow::render()
void UIWindow::draw()
{
// render children
UIWidget::render();
UIWidget::draw();
// draw window head text
Rect headTextRect = m_rect;
headTextRect.addTop(-m_headTextOffset.y);
headTextRect.expandTop(-m_headTextOffset.y);
headTextRect.setHeight(m_headHeight);
if(m_titleAlign & Fw::AlignLeft)
headTextRect.addLeft(-m_headTextOffset.x);
headTextRect.expandLeft(-m_headTextOffset.x);
else if(m_titleAlign & Fw::AlignRight)
headTextRect.addRight(-m_headTextOffset.x);
headTextRect.expandRight(-m_headTextOffset.x);
else {
headTextRect.addLeft(-m_headTextOffset.x);
headTextRect.addRight(-m_headTextOffset.x);
headTextRect.expandLeft(-m_headTextOffset.x);
headTextRect.expandRight(-m_headTextOffset.x);
}
m_font->renderText(m_title, headTextRect, m_titleAlign, m_color);
}
@ -111,7 +110,7 @@ void UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
// restore position before move
parent->moveChildToIndex(asUIWidget(), m_oldIndex);
moveTo(m_oldPos);
setPos(m_oldPos);
// calculate new index
int newIndex;
@ -133,7 +132,7 @@ void UIWindow::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
bool UIWindow::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{
if(m_moving) {
moveTo(mousePos - m_movingReference);
setPos(mousePos - m_movingReference);
return true;
}
return UIWidget::onMouseMove(mousePos, mouseMoved);

View File

@ -35,7 +35,7 @@ class UIWindow : public UIWidget
public:
UIWindow();
virtual void render();
virtual void draw();
void setTitle(const std::string& title) { m_title = title; }
std::string getTitle() const { return m_title; }

View File

@ -24,14 +24,14 @@
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
void UICreature::render()
void UICreature::draw()
{
renderSelf();
drawSelf();
if(m_creature) {
g_painter.setColor(Fw::white);
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop), m_rect);
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + Point(m_padding.left, m_padding.top), m_rect);
}
renderChildren();
drawChildren();
}

View File

@ -30,7 +30,7 @@
class UICreature : public UIWidget
{
public:
void render();
void draw();
void setCreature(const CreaturePtr& creature) { m_creature = creature; }

View File

@ -30,12 +30,12 @@ UIItem::UIItem()
m_font = g_fonts.getFont("verdana-11px-rounded");
}
void UIItem::render()
void UIItem::draw()
{
renderSelf();
drawSelf();
if(m_item) {
Point topLeft = m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop);
Point topLeft = m_rect.bottomRight() - Point(32, 32) + Point(m_padding.left, m_padding.top);
g_painter.setColor(Fw::white);
m_item->draw(topLeft, m_rect);
@ -46,5 +46,5 @@ void UIItem::render()
}
}
renderChildren();
drawChildren();
}

View File

@ -31,7 +31,7 @@ class UIItem : public UIWidget
{
public:
UIItem();
void render();
void draw();
void setItem(const ItemPtr& item) { m_item = item; }
ItemPtr getItem() { return m_item; }

View File

@ -27,15 +27,15 @@
#include <framework/graphics/graphics.h>
#include <otclient/core/localplayer.h>
void UIMap::render()
void UIMap::draw()
{
renderSelf();
drawSelf();
g_painter.setColor(Fw::black);
g_painter.drawBoundingRect(m_mapRect.expanded(1));
g_map.draw(m_mapRect);
renderChildren();
drawChildren();
}
TilePtr UIMap::getTile(const Point& mousePos)
@ -81,8 +81,7 @@ TilePtr UIMap::getTile(const Point& mousePos)
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
{
Rect mapRect = newRect.expanded(-1);
mapRect.add(-m_paddingTop, -m_paddingLeft, -m_paddingBottom, -m_paddingRight);
Rect mapRect = getChildrenRect().expanded(-1);
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);

View File

@ -30,7 +30,7 @@
class UIMap : public UIWidget
{
public:
void render();
void draw();
TilePtr getTile(const Point& mousePos);

View File

@ -44,10 +44,10 @@ for line in io.lines(cppclassheader) do
publicmethods = false
if cppclassinstance then
print('g_lua.registerStaticClass("' .. luaclassname .. '");')
print(' g_lua.registerStaticClass("' .. luaclassname .. '");')
else
baseclassname = line:match(': public ([%w_]+)')
bindline = 'g_lua.registerClass<' .. cppclassname
bindline = ' g_lua.registerClass<' .. cppclassname
if baseclassname and baseclassname ~= 'LuaObject' then
bindline = bindline .. ', ' .. baseclassname
@ -56,7 +56,7 @@ for line in io.lines(cppclassheader) do
bindline = bindline .. '>();'
print(bindline)
bindline = 'g_lua.bindClassStaticFunction<' .. cppclassname .. '>("create", []{ return ' .. cppclassname .. 'Ptr(new ' .. cppclassname .. '); });'
bindline = ' g_lua.bindClassStaticFunction<' .. cppclassname .. '>("create", []{ return ' .. cppclassname .. 'Ptr(new ' .. cppclassname .. '); });'
print(bindline)
end
elseif classfound then
@ -75,14 +75,14 @@ for line in io.lines(cppclassheader) do
numargs = args:matchcount('[^,)]+[,)]')
if cppclassinstance then
bindline = 'g_lua.bindClassStaticFunction("' .. luaclassname .. '", "' .. funcname .. '", ' ..
bindline = ' g_lua.bindClassStaticFunction("' .. luaclassname .. '", "' .. funcname .. '", ' ..
'std::bind(&' .. cppclassname .. "::" .. funcname .. ', &' .. cppclassinstance
for i=1,numargs do
bindline = bindline .. ', _' .. i
end
bindline = bindline .. '));'
else
bindline = 'g_lua.bindClassMemberFunction<' .. cppclassname .. '>("' .. funcname .. '", &' ..
bindline = ' g_lua.bindClassMemberFunction<' .. cppclassname .. '>("' .. funcname .. '", &' ..
cppclassname .. '::' .. funcname .. ');'
end
print(bindline)