Refactor for documentation

This commit is contained in:
Eduardo Bart
2012-06-25 19:13:30 -03:00
parent 2c7ae6e521
commit 98a1b611bf
106 changed files with 654 additions and 780 deletions

View File

@@ -1,3 +1,5 @@
-- @docconsts @{
AnchorNone = 0
AnchorTop = 1
AnchorBottom = 2
@@ -169,6 +171,31 @@ KeyNumpad7 = 148
KeyNumpad8 = 149
KeyNumpad9 = 150
SpeakSay = 1
SpeakWhisper = 2
SpeakYell = 3
SpeakBroadcast = 4
SpeakPrivate = 5
SpeakPrivateRed = 6
SpeakPrivatePlayerToNpc = 7
SpeakPrivateNpcToPlayer = 8
SpeakChannelYellow = 9
SpeakChannelWhite = 10
SpeakChannelRed = 11
SpeakChannelOrange = 12
SpeakMonsterSay = 13
SpeakMonsterYell = 14
FightOffensive = 1
FightBalanced = 2
FightDefensive = 3
DontChase = 0
ChaseOpponent = 1
-- @}
KeyCodeDescs = {
[KeyUnknown] = 'Unknown',
[KeyEscape] = 'Escape',
@@ -287,26 +314,3 @@ KeyCodeDescs = {
[KeyNumpad8] = 'Numpad8',
[KeyNumpad9] = 'Numpad9'
}
SpeakSay = 1
SpeakWhisper = 2
SpeakYell = 3
SpeakBroadcast = 4
SpeakPrivate = 5
SpeakPrivateRed = 6
SpeakPrivatePlayerToNpc = 7
SpeakPrivateNpcToPlayer = 8
SpeakChannelYellow = 9
SpeakChannelWhite = 10
SpeakChannelRed = 11
SpeakChannelOrange = 12
SpeakMonsterSay = 13
SpeakMonsterYell = 14
FightOffensive = 1
FightBalanced = 2
FightDefensive = 3
DontChase = 0
ChaseOpponent = 1

View File

@@ -6,8 +6,9 @@ Module
reloadable: false
@onLoad: |
dofiles 'ext'
dofiles 'math'
dofile 'math'
dofile 'string'
dofile 'table'
dofile 'const'
dofile 'util'
@@ -17,5 +18,3 @@ Module
dofile 'mouse'
dofiles 'ui'
dofiles 'widgets'

View File

@@ -1,6 +0,0 @@
function os.execute(command)
local f = assert(io.popen(command, 'r'))
local data = assert(f:read('*a'))
f:close()
print(data)
end

View File

@@ -1,45 +0,0 @@
function string.split(s, delim)
local start = 1
local results = {}
while true do
local pos = string.find(s, delim, start, true)
if not pos then
break
end
table.insert(results, string.sub(s, start, pos-1))
start = pos + string.len(delim)
end
table.insert(results, string.sub(s, start))
table.removevalue(results, '')
return results
end
function string.starts(s, start)
return string.sub(s, 1, #start) == start
end
function string.trim(s)
return string.match(s, '^%s*(.*%S)') or ''
end
function string.explode(str, sep, limit)
if(type(sep) ~= 'string' or tostring(str):len() == 0 or sep:len() == 0) then
return {}
end
local i, pos, tmp, t = 0, 1, "", {}
for s, e in function() return string.find(str, sep, pos) end do
tmp = str:sub(pos, s - 1):trim()
table.insert(t, tmp)
pos = e + 1
i = i + 1
if(limit ~= nil and i == limit) then
break
end
end
tmp = str:sub(pos):trim()
table.insert(t, tmp)
return t
end

View File

@@ -1,73 +1,36 @@
rootWidget = g_ui.getRootWidget()
-- @docvars @{
importStyle = g_ui.importStyle
importFont = g_fonts.importFont
setDefaultFont = g_fonts.setDefaultFont
-- root widget
rootWidget = g_ui.getRootWidget()
-- G is used as a global table to save variables in memory between reloads
G = G or {}
function loadUI(otui, parent)
local otuiFilePath = resolvepath(otui, 2)
return g_ui.loadUI(otuiFilePath, parent)
end
-- @}
function displayUI(otui, parent)
parent = parent or rootWidget
local otuiFilePath = resolvepath(otui, 2)
return g_ui.loadUI(otuiFilePath, parent)
end
function createWidget(stylename, parent)
if type(parent) == 'string' then
parent = rootWidget:recursiveGetChildById(parent)
end
local widget = g_ui.createWidgetFromStyle(stylename, parent)
return widget
end
-- @docfuncs @{
function scheduleEvent(callback, delay)
local event = g_eventDispatcher.scheduleEvent(callback, delay)
local event = g_dispatcher.scheduleEvent(callback, delay)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function addEvent(callback, front)
local event = g_eventDispatcher.addEvent(callback, front)
local event = g_dispatcher.addEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function cycleEvent(callback, front)
local event = g_eventDispatcher.cycleEvent(callback, front)
local event = g_dispatcher.cycleEvent(callback, front)
-- must hold a reference to the callback, otherwise it would be collected
event._callback = callback
return event
end
function periodicalEvent(eventFunc, conditionFunc, delay, autoRepeatDelay)
delay = delay or 30
autoRepeatDelay = autoRepeatDelay or delay
local func
func = function()
if conditionFunc and not conditionFunc() then
func = nil
return
end
eventFunc()
scheduleEvent(func, delay)
end
scheduleEvent(function()
func()
end, autoRepeatDelay)
end
function removeEvent(event)
if event then
event:cancel()
@@ -75,13 +38,4 @@ function removeEvent(event)
end
end
function reloadModule(name)
local module = g_modules.getModule(name)
if module then
module:reload()
end
end
function reloadModules()
g_modules.reloadModules()
end
-- @}

View File

@@ -1,4 +1,5 @@
Keyboard = {}
-- @docclass
g_keyboard = {}
-- private functions
function translateKeyCombo(keyCombo)
@@ -95,14 +96,14 @@ local function connectKeyPressEvent(widget)
end
-- public functions
function Keyboard.bindKeyDown(keyComboDesc, callback, widget)
function g_keyboard.bindKeyDown(keyComboDesc, callback, widget)
widget = widget or rootWidget
connectKeyDownEvent(widget)
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
widget.boundKeyDownCombos[keyComboDesc] = callback
end
function Keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
autoRepeatDelay = autoRepeatDelay or 500
widget = widget or rootWidget
connectKeyPressEvent(widget)
@@ -111,7 +112,7 @@ function Keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
end
function Keyboard.unbindKeyDown(keyComboDesc, widget)
function g_keyboard.unbindKeyDown(keyComboDesc, widget)
widget = widget or rootWidget
if widget.boundKeyDownCombos == nil then return end
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
@@ -120,7 +121,7 @@ function Keyboard.unbindKeyDown(keyComboDesc, widget)
end
end
function Keyboard.unbindKeyPress(keyComboDesc, widget)
function g_keyboard.unbindKeyPress(keyComboDesc, widget)
widget = widget or rootWidget
if widget.boundKeyPressCombos == nil then return end
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
@@ -129,18 +130,18 @@ function Keyboard.unbindKeyPress(keyComboDesc, widget)
end
end
function Keyboard.getModifiers()
function g_keyboard.getModifiers()
return g_window.getKeyboardModifiers()
end
function Keyboard.isCtrlPressed()
function g_keyboard.isCtrlPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardCtrlModifier) ~= 0
end
function Keyboard.isAltPressed()
function g_keyboard.isAltPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardAltModifier) ~= 0
end
function Keyboard.isShiftPressed()
function g_keyboard.isShiftPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardShiftModifier) ~= 0
end

10
modules/corelib/math.lua Normal file
View File

@@ -0,0 +1,10 @@
-- @docclass math
function math.round(num, idp)
local mult = 10^(idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end
end

View File

@@ -1 +0,0 @@
Color = {}

View File

@@ -1,8 +0,0 @@
function math.round(num, idp)
local mult = 10^(idp or 0)
if num >= 0 then
return math.floor(num * mult + 0.5) / mult
else
return math.ceil(num * mult - 0.5) / mult
end
end

View File

@@ -1 +0,0 @@
Point = {}

View File

@@ -1 +0,0 @@
Rect = {}

View File

@@ -1 +0,0 @@
Size = {}

View File

@@ -1,37 +1,38 @@
Mouse = {}
-- @docclass
g_mouse = {}
local cursorChanged = false
function Mouse.setTargetCursor()
function g_mouse.setTargetCursor()
g_window.setMouseCursor('/cursors/targetcursor.png', {x=9,y=9})
cursorChanged = true
end
function Mouse.setHorizontalCursor()
function g_mouse.setHorizontalCursor()
g_window.setMouseCursor('/cursors/horizontal.png', {x=9,y=4})
cursorChanged = true
end
function Mouse.setVerticalCursor()
function g_mouse.setVerticalCursor()
g_window.setMouseCursor('/cursors/vertical.png', {x=4,y=9})
cursorChanged = true
end
function Mouse.restoreCursor()
function g_mouse.restoreCursor()
g_window.restoreMouseCursor()
cursorChanged = false
end
function Mouse.isCursorChanged()
function g_mouse.isCursorChanged()
return cursorChanged
end
function Mouse.isPressed(button)
function g_mouse.isPressed(button)
if not button then button = MouseLeftButton end
return g_window.isMouseButtonPressed(button)
end
function Mouse.bindAutoPress(widget, callback)
function g_mouse.bindAutoPress(widget, callback)
connect(widget, { onMousePress = function(widget, mousePos, mouseButton)
callback()
periodicalEvent(function()
@@ -43,7 +44,7 @@ function Mouse.bindAutoPress(widget, callback)
end })
end
function Mouse.bindPressMove(widget, callback)
function g_mouse.bindPressMove(widget, callback)
connect(widget, { onMouseMove = function(widget, mousePos, mouseMoved)
if widget:isPressed() then
callback(mousePos, mouseMoved)

View File

@@ -1,12 +1,13 @@
Settings = {}
-- @docclass
g_settings = {}
Settings.exists = g_configs.exists
Settings.setNode = g_configs.setNode
Settings.mergeNode = g_configs.mergeNode
Settings.getNode = g_configs.getNode
Settings.remove = g_configs.remove
Settings.setList = g_configs.setList
Settings.getList = g_configs.getList
g_settings.exists = g_configs.exists
g_settings.setNode = g_configs.setNode
g_settings.mergeNode = g_configs.mergeNode
g_settings.getNode = g_configs.getNode
g_settings.remove = g_configs.remove
g_settings.setList = g_configs.setList
g_settings.getList = g_configs.getList
local function convertSettingValue(value)
if type(value) == 'table' then
@@ -28,55 +29,55 @@ local function convertSettingValue(value)
end
end
function Settings.set(key, value)
function g_settings.set(key, value)
g_configs.set(key, convertSettingValue(value))
end
function Settings.setDefault(key, value)
if Settings.exists(key) then return false end
Settings.set(key, value)
function g_settings.setDefault(key, value)
if g_settings.exists(key) then return false end
g_settings.set(key, value)
return true
end
function Settings.get(key, default)
if not Settings.exists(key) and default ~= nil then
Settings.set(key, default)
function g_settings.get(key, default)
if not g_settings.exists(key) and default ~= nil then
g_settings.set(key, default)
end
return g_configs.get(key)
end
function Settings.getString(key, default)
return Settings.get(key, default)
function g_settings.getString(key, default)
return g_settings.get(key, default)
end
function Settings.getInteger(key, default)
return tonumber(Settings.get(key, default))
function g_settings.getInteger(key, default)
return tonumber(g_settings.get(key, default))
end
function Settings.getNumber(key, default)
return tonumber(Settings.get(key, default))
function g_settings.getNumber(key, default)
return tonumber(g_settings.get(key, default))
end
function Settings.getBoolean(key, default)
return toboolean(Settings.get(key, default))
function g_settings.getBoolean(key, default)
return toboolean(g_settings.get(key, default))
end
function Settings.getPoint(key, default)
return topoint(Settings.get(key, default))
function g_settings.getPoint(key, default)
return topoint(g_settings.get(key, default))
end
function Settings.getRect(key, default)
return torect(Settings.get(key, default))
function g_settings.getRect(key, default)
return torect(g_settings.get(key, default))
end
function Settings.getSize(key, default)
return tosize(Settings.get(key, default))
function g_settings.getSize(key, default)
return tosize(g_settings.get(key, default))
end
function Settings.getColor(key, default)
return tocolor(Settings.get(key, default))
function g_settings.getColor(key, default)
return tocolor(g_settings.get(key, default))
end
function Settings.getColor(key, default)
return tocolor(Settings.get(key, default))
function g_settings.getColor(key, default)
return tocolor(g_settings.get(key, default))
end

View File

@@ -0,0 +1,47 @@
-- @docclass string
function string:split(delim)
local start = 1
local results = {}
while true do
local pos = string.find(self, delim, start, true)
if not pos then
break
end
table.insert(results, string.sub(self, start, pos-1))
start = pos + string.len(delim)
end
table.insert(results, string.sub(self, start))
table.removevalue(results, '')
return results
end
function string:starts(start)
return string.sub(self, 1, #start) == start
end
function string:trim()
return string.match(self, '^%s*(.*%S)') or ''
end
function string:explode(sep, limit)
if(type(sep) ~= 'string' or tostring(self):len() == 0 or sep:len() == 0) then
return {}
end
local i, pos, tmp, t = 0, 1, "", {}
for s, e in function() return string.find(self, sep, pos) end do
tmp = self:sub(pos, s - 1):trim()
table.insert(t, tmp)
pos = e + 1
i = i + 1
if(limit ~= nil and i == limit) then
break
end
end
tmp = self:sub(pos):trim()
table.insert(t, tmp)
return t
end

View File

@@ -1,3 +1,5 @@
-- @docclass table
function table.dump(t, depth)
if not depth then depth = 0 end
for k,v in pairs(t) do

View File

@@ -1,6 +1,7 @@
Effects = {}
-- @docclass
g_effects = {}
function Effects.fadeIn(widget, time, elapsed)
function g_effects.fadeIn(widget, time, elapsed)
if not elapsed then elapsed = 0 end
if not time then time = 300 end
widget:setOpacity(math.min(elapsed/time, 1))
@@ -8,14 +9,14 @@ function Effects.fadeIn(widget, time, elapsed)
if elapsed < time then
removeEvent(widget.fadeEvent)
widget.fadeEvent = scheduleEvent(function()
Effects.fadeIn(widget, time, elapsed + 30)
g_effects.fadeIn(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
function Effects.fadeOut(widget, time, elapsed)
function g_effects.fadeOut(widget, time, elapsed)
if not elapsed then elapsed = 0 end
if not time then time = 300 end
elapsed = math.max((1 - widget:getOpacity()) * time, elapsed)
@@ -23,14 +24,14 @@ function Effects.fadeOut(widget, time, elapsed)
widget:setOpacity(math.max((time - elapsed)/time, 0))
if elapsed < time then
widget.fadeEvent = scheduleEvent(function()
Effects.fadeOut(widget, time, elapsed + 30)
g_effects.fadeOut(widget, time, elapsed + 30)
end, 30)
else
widget.fadeEvent = nil
end
end
function Effects.cancelFade(widget)
function g_effects.cancelFade(widget)
removeEvent(widget.fadeEvent)
widget.fadeEvent = nil
end

View File

@@ -1,4 +1,5 @@
ToolTip = {}
-- @docclass
g_tooltip = {}
-- private variables
local toolTipLabel
@@ -21,13 +22,13 @@ end
local function onWidgetHoverChange(widget, hovered)
if hovered then
if widget.tooltip and not Mouse.isPressed() then
ToolTip.display(widget.tooltip)
if widget.tooltip and not g_mouse.isPressed() then
g_tooltip.display(widget.tooltip)
currentHoveredWidget = widget
end
else
if widget == currentHoveredWidget then
ToolTip:hide()
g_tooltip.hide()
currentHoveredWidget = nil
end
end
@@ -40,12 +41,12 @@ local function onWidgetStyleApply(widget, styleName, styleNode)
end
-- public functions
function ToolTip.init()
function g_tooltip.init()
connect(UIWidget, { onStyleApply = onWidgetStyleApply,
onHoverChange = onWidgetHoverChange})
addEvent(function()
toolTipLabel = createWidget('UILabel', rootWidget)
toolTipLabel = g_ui.createWidget('UILabel', rootWidget)
toolTipLabel:setId('toolTip')
toolTipLabel:setBackgroundColor('#111111cc')
toolTipLabel:setTextAlign(AlignCenter)
@@ -54,7 +55,7 @@ function ToolTip.init()
end)
end
function ToolTip.terminate()
function g_tooltip.terminate()
disconnect(UIWidget, { onStyleApply = onWidgetStyleApply,
onHoverChange = onWidgetHoverChange })
@@ -62,10 +63,10 @@ function ToolTip.terminate()
toolTipLabel:destroy()
toolTipLabel = nil
ToolTip = nil
g_tooltip = nil
end
function ToolTip.display(text)
function g_tooltip.display(text)
if text == nil then return end
if not toolTipLabel then return end
@@ -75,14 +76,17 @@ function ToolTip.display(text)
toolTipLabel:show()
toolTipLabel:raise()
toolTipLabel:enable()
Effects.fadeIn(toolTipLabel, 100)
g_effects.fadeIn(toolTipLabel, 100)
moveToolTip(toolTipLabel)
end
function ToolTip.hide()
Effects.fadeOut(toolTipLabel, 100)
function g_tooltip.hide()
g_effects.fadeOut(toolTipLabel, 100)
end
-- @docclass UIWidget @{
-- UIWidget extensions
function UIWidget:setTooltip(text)
self.tooltip = text
@@ -92,5 +96,7 @@ function UIWidget:getTooltip()
return self.tooltip
end
ToolTip.init()
connect(g_app, { onTerminate = ToolTip.terminate })
-- @}
g_tooltip.init()
connect(g_app, { onTerminate = g_tooltip.terminate })

View File

@@ -1,3 +1,4 @@
-- @docclass
UIButton = extends(UIWidget)
function UIButton.create()

View File

@@ -1,3 +1,4 @@
-- @docclass
UICheckBox = extends(UIWidget)
function UICheckBox.create()

View File

@@ -1,3 +1,4 @@
-- @docclass
UIComboBox = extends(UIWidget)
function UIComboBox.create()
@@ -36,7 +37,7 @@ function UIComboBox:addOption(text, data)
end
function UIComboBox:onMousePress(mousePos, mouseButton)
local menu = createWidget(self:getStyleName() .. 'PopupMenu')
local menu = g_ui.createWidget(self:getStyleName() .. 'PopupMenu')
menu:setId(self:getId() .. 'PopupMenu')
for i,v in ipairs(self.options) do
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)

View File

@@ -1,3 +1,4 @@
-- @docclass
UILabel = extends(UIWidget)
function UILabel.create()

View File

@@ -1,5 +1,6 @@
if not UIWindow then dofile 'uiwindow' end
-- @docclass
UIMessageBox = extends(UIWindow)
MessageBoxOk = 1
@@ -15,7 +16,7 @@ function UIMessageBox.display(title, message, flags)
messagebox:setStyle('MessageBoxWindow')
messagebox:setText(title)
local messageLabel = createWidget('MessageBoxLabel', messagebox)
local messageLabel = g_ui.createWidget('MessageBoxLabel', messagebox)
messageLabel:setText(message)
messageLabel:resizeToText()
@@ -23,7 +24,7 @@ function UIMessageBox.display(title, message, flags)
messagebox:setHeight(math.max(messageLabel:getHeight() + 64, messagebox:getHeight()))
-- setup messagebox first button
local buttonRight = createWidget('MessageBoxRightButton', messagebox)
local buttonRight = g_ui.createWidget('MessageBoxRightButton', messagebox)
if flags == MessageBoxOk then
buttonRight:setText('Ok')

View File

@@ -1,3 +1,4 @@
-- @docclass
UIMiniWindow = extends(UIWindow)
function UIMiniWindow.create()
@@ -77,7 +78,7 @@ function UIMiniWindow:onSetup()
local oldParent = self:getParent()
local settings = Settings.getNode('MiniWindows')
local settings = g_settings.getNode('MiniWindows')
if settings then
local selfSettings = settings[self:getId()]
if selfSettings then
@@ -215,7 +216,7 @@ end
function UIMiniWindow:setSettings(data)
if not self.save then return end
local settings = Settings.getNode('MiniWindows')
local settings = g_settings.getNode('MiniWindows')
if not settings then
settings = {}
end
@@ -229,7 +230,7 @@ function UIMiniWindow:setSettings(data)
settings[id][key] = value
end
Settings.setNode('MiniWindows', settings)
g_settings.setNode('MiniWindows', settings)
end
function UIMiniWindow:saveParentPosition(parentId, position)

View File

@@ -1,3 +1,4 @@
-- @docclass
UIMiniWindowContainer = extends(UIWidget)
function UIMiniWindowContainer.create()
@@ -25,7 +26,7 @@ function UIMiniWindowContainer:onDrop(widget, mousePos)
else
self:addChild(widget)
end
return true
end
end

View File

@@ -1,3 +1,4 @@
-- @docclass
UIPopupMenu = extends(UIWidget)
local currentMenu
@@ -33,7 +34,7 @@ function UIPopupMenu:onGeometryChange()
end
function UIPopupMenu:addOption(optionName, optionCallback)
local optionWidget = createWidget(self:getStyleName() .. 'Button', self)
local optionWidget = g_ui.createWidget(self:getStyleName() .. 'Button', self)
local lastOptionWidget = self:getLastChild()
optionWidget.onClick = function(self)
optionCallback()
@@ -45,7 +46,7 @@ function UIPopupMenu:addOption(optionName, optionCallback)
end
function UIPopupMenu:addSeparator()
createWidget(self:getStyleName() .. 'Separator', self)
g_ui.createWidget(self:getStyleName() .. 'Separator', self)
end
function UIPopupMenu:onDestroy()

View File

@@ -1,3 +1,4 @@
-- @docclass
UIProgressBar = extends(UIWidget)
function UIProgressBar.create()

View File

@@ -1,24 +1,25 @@
RadioGroup = newclass()
-- @docclass
UIRadioGroup = newclass()
function RadioGroup.create()
local radiogroup = RadioGroup.internalCreate()
function UIRadioGroup.create()
local radiogroup = UIRadioGroup.internalCreate()
radiogroup.widgets = {}
return radiogroup
end
function RadioGroup:destroy()
function UIRadioGroup:destroy()
for k,widget in pairs(self.widgets) do
widget.onClick = nil
end
self.widgets = {}
end
function RadioGroup:addWidget(widget)
function UIRadioGroup:addWidget(widget)
table.insert(self.widgets, widget)
widget.onClick = function(widget) self:selectWidget(widget) end
end
function RadioGroup:removeWidget(widget)
function UIRadioGroup:removeWidget(widget)
if self.selectedWidget == widget then
self:selectWidget(nil)
end
@@ -26,7 +27,7 @@ function RadioGroup:removeWidget(widget)
table.removevalue(self.widgets, widget)
end
function RadioGroup:selectWidget(selectedWidget)
function UIRadioGroup:selectWidget(selectedWidget)
if selectedWidget == self.selectedWidget then return end
local previousSelectedWidget = self.selectedWidget

View File

@@ -1,3 +1,4 @@
-- @docclass
UIResizeBorder = extends(UIWidget)
function UIResizeBorder.create()
@@ -10,22 +11,22 @@ end
function UIResizeBorder:onHoverChange(hovered)
if hovered then
if Mouse.isCursorChanged() or Mouse.isPressed() then return end
if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end
if self:getWidth() > self:getHeight() then
Mouse.setVerticalCursor()
g_mouse.setVerticalCursor()
self.vertical = true
else
Mouse.setHorizontalCursor()
g_mouse.setHorizontalCursor()
self.vertical = false
end
self.hovering = true
if not self:isPressed() then
Effects.fadeIn(self)
g_effects.fadeIn(self)
end
else
if not self:isPressed() and self.hovering then
Mouse.restoreCursor()
Effects.fadeOut(self)
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
end
end
@@ -64,8 +65,8 @@ end
function UIResizeBorder:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then
Mouse.restoreCursor()
Effects.fadeOut(self)
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
end
end

View File

@@ -1,3 +1,4 @@
-- @docclass
UIScrollArea = extends(UIWidget)
-- public functions

View File

@@ -1,3 +1,4 @@
-- @docclass
UIScrollBar = extends(UIWidget)
-- private functions
@@ -101,9 +102,9 @@ end
function UIScrollBar:onSetup()
self.setupDone = true
signalcall(self.onValueChange, self, self.value)
Mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end)
Mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end)
Mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end)
g_mouse.bindAutoPress(self:getChildById('decrementButton'), function() self:decrement() end)
g_mouse.bindAutoPress(self:getChildById('incrementButton'), function() self:increment() end)
g_mouse.bindPressMove(self:getChildById('sliderButton'), function(mousePos, mouseMoved) parseSliderPos(self, mousePos) end)
updateSlider(self)
end

View File

@@ -1,3 +1,4 @@
-- @docclass
UISpinBox = extends(UITextEdit)
function UISpinBox.create()
@@ -30,7 +31,7 @@ function UISpinBox:onTextChange(text, oldText)
self:setText(oldText)
return
end
self:setValue(number)
end

View File

@@ -1,3 +1,4 @@
-- @docclass
UISplitter = extends(UIWidget)
function UISplitter.create()
@@ -9,22 +10,22 @@ end
function UISplitter:onHoverChange(hovered)
if hovered then
if Mouse.isCursorChanged() or Mouse.isPressed() then return end
if g_mouse.isCursorChanged() or g_mouse.isPressed() then return end
if self:getWidth() > self:getHeight() then
Mouse.setVerticalCursor()
g_mouse.setVerticalCursor()
self.vertical = true
else
Mouse.setHorizontalCursor()
g_mouse.setHorizontalCursor()
self.vertical = false
end
self.hovering = true
if not self:isPressed() then
Effects.fadeIn(self)
g_effects.fadeIn(self)
end
else
if not self:isPressed() and self.hovering then
Mouse.restoreCursor()
Effects.fadeOut(self)
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
end
end
@@ -64,8 +65,8 @@ end
function UISplitter:onMouseRelease(mousePos, mouseButton)
if not self:isHovered() then
Mouse.restoreCursor()
Effects.fadeOut(self)
g_mouse.restoreCursor()
g_effects.fadeOut(self)
self.hovering = false
end
end

View File

@@ -1,3 +1,4 @@
-- @docclass
UITabBar = extends(UIWidget)
-- private functions
@@ -28,11 +29,11 @@ end
function UITabBar:addTab(text, panel)
if panel == nil then
panel = createWidget(self:getStyleName() .. 'Panel')
panel = g_ui.createWidget(self:getStyleName() .. 'Panel')
panel:setId('tabPanel')
end
local tab = createWidget(self:getStyleName() .. 'Button', self)
local tab = g_ui.createWidget(self:getStyleName() .. 'Button', self)
panel.isTab = true
tab.tabPanel = panel
tab.tabBar = self

View File

@@ -1,3 +1,5 @@
-- @docclass UIWidget
function UIWidget:setMargin(...)
local params = {...}
if #params == 1 then

View File

@@ -1,3 +1,4 @@
-- @docclass
UIWindow = extends(UIWidget)
function UIWindow.create()

View File

@@ -1,3 +1,5 @@
-- @docfuncs @{
function print(...)
local msg = ""
for i,v in ipairs({...}) do
@@ -26,9 +28,13 @@ function fatal(msg)
g_logger.log(LogFatal, msg)
end
function exit()
g_app.exit()
end
exit = g_app.exit
quit = g_app.exit
function quit()
g_app.quit()
end
function connect(object, signalsAndSlots, pushFront)
for signal,slot in pairs(signalsAndSlots) do
@@ -151,6 +157,7 @@ function toboolean(str)
end
local oldtonumber = tonumber
function tonumber(v)
if v == nil then return 0 end
return oldtonumber(v)
@@ -174,3 +181,5 @@ end
function tr(s)
return s
end
-- @}