2012-06-26 00:13:30 +02:00
|
|
|
-- @docvars @{
|
2011-08-26 17:06:52 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
-- root widget
|
|
|
|
rootWidget = g_ui.getRootWidget()
|
2012-07-24 07:30:08 +02:00
|
|
|
modules = package.loaded
|
2012-01-05 02:28:29 +01:00
|
|
|
|
2012-06-04 14:38:15 +02:00
|
|
|
-- G is used as a global table to save variables in memory between reloads
|
|
|
|
G = G or {}
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
-- @}
|
2012-01-03 01:42:53 +01:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
-- @docfuncs @{
|
2012-02-06 20:19:47 +01:00
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function scheduleEvent(callback, delay)
|
2012-06-26 00:13:30 +02:00
|
|
|
local event = g_dispatcher.scheduleEvent(callback, delay)
|
2012-02-20 03:27:08 +01:00
|
|
|
-- must hold a reference to the callback, otherwise it would be collected
|
|
|
|
event._callback = callback
|
|
|
|
return event
|
|
|
|
end
|
|
|
|
|
|
|
|
function addEvent(callback, front)
|
2012-06-26 00:13:30 +02:00
|
|
|
local event = g_dispatcher.addEvent(callback, front)
|
2012-02-20 03:27:08 +01:00
|
|
|
-- must hold a reference to the callback, otherwise it would be collected
|
|
|
|
event._callback = callback
|
|
|
|
return event
|
|
|
|
end
|
|
|
|
|
2013-02-05 22:08:32 +01:00
|
|
|
function cycleEvent(callback, interval)
|
|
|
|
local event = g_dispatcher.cycleEvent(callback, interval)
|
2012-06-06 22:14:53 +02:00
|
|
|
-- must hold a reference to the callback, otherwise it would be collected
|
|
|
|
event._callback = callback
|
|
|
|
return event
|
|
|
|
end
|
|
|
|
|
2012-07-10 19:36:18 +02:00
|
|
|
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
|
|
|
|
|
2012-02-20 03:27:08 +01:00
|
|
|
function removeEvent(event)
|
|
|
|
if event then
|
|
|
|
event:cancel()
|
|
|
|
event._callback = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
-- @}
|