2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
|
|
|
g_effects = {}
|
2011-08-14 19:45:25 +02:00
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_effects.fadeIn(widget, time, elapsed)
|
2012-03-23 14:48:05 +01:00
|
|
|
if not elapsed then elapsed = 0 end
|
2012-03-26 20:33:00 +02:00
|
|
|
if not time then time = 300 end
|
2012-03-23 14:48:05 +01:00
|
|
|
widget:setOpacity(math.min(elapsed/time, 1))
|
2012-03-26 20:33:00 +02:00
|
|
|
removeEvent(widget.fadeEvent)
|
2012-03-23 14:48:05 +01:00
|
|
|
if elapsed < time then
|
|
|
|
removeEvent(widget.fadeEvent)
|
|
|
|
widget.fadeEvent = scheduleEvent(function()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_effects.fadeIn(widget, time, elapsed + 30)
|
2012-03-23 14:48:05 +01:00
|
|
|
end, 30)
|
|
|
|
else
|
|
|
|
widget.fadeEvent = nil
|
|
|
|
end
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_effects.fadeOut(widget, time, elapsed)
|
2012-03-23 14:48:05 +01:00
|
|
|
if not elapsed then elapsed = 0 end
|
2012-03-26 20:33:00 +02:00
|
|
|
if not time then time = 300 end
|
|
|
|
elapsed = math.max((1 - widget:getOpacity()) * time, elapsed)
|
|
|
|
removeEvent(widget.fadeEvent)
|
2012-03-23 14:48:05 +01:00
|
|
|
widget:setOpacity(math.max((time - elapsed)/time, 0))
|
|
|
|
if elapsed < time then
|
|
|
|
widget.fadeEvent = scheduleEvent(function()
|
2012-06-26 00:13:30 +02:00
|
|
|
g_effects.fadeOut(widget, time, elapsed + 30)
|
2012-03-23 14:48:05 +01:00
|
|
|
end, 30)
|
|
|
|
else
|
|
|
|
widget.fadeEvent = nil
|
|
|
|
end
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function g_effects.cancelFade(widget)
|
2012-03-23 14:48:05 +01:00
|
|
|
removeEvent(widget.fadeEvent)
|
2012-03-26 20:33:00 +02:00
|
|
|
widget.fadeEvent = nil
|
2012-03-23 14:48:05 +01:00
|
|
|
end
|
2013-02-05 22:08:32 +01:00
|
|
|
|
|
|
|
function g_effects.startBlink(widget, duration, interval, clickCancel)
|
|
|
|
duration = duration or 0 -- until stop is called
|
|
|
|
interval = interval or 500
|
|
|
|
clickCancel = clickCancel or true
|
|
|
|
|
|
|
|
removeEvent(widget.blinkEvent)
|
|
|
|
removeEvent(widget.blinkStopEvent)
|
|
|
|
|
|
|
|
widget.blinkEvent = cycleEvent(function()
|
|
|
|
widget:setOn(not widget:isOn())
|
|
|
|
end, interval)
|
|
|
|
|
|
|
|
if duration > 0 then
|
|
|
|
widget.blinkStopEvent = scheduleEvent(function()
|
|
|
|
g_effects.stopBlink(widget)
|
|
|
|
end, duration)
|
|
|
|
end
|
|
|
|
|
|
|
|
connect(widget, { onClick = g_effects.stopBlink })
|
|
|
|
end
|
|
|
|
|
|
|
|
function g_effects.stopBlink(widget)
|
|
|
|
disconnect(widget, { onClick = g_effects.stopBlink })
|
|
|
|
removeEvent(widget.blinkEvent)
|
|
|
|
removeEvent(widget.blinkStopEvent)
|
|
|
|
widget.blinkEvent = nil
|
|
|
|
widget.blinkStopEvent = nil
|
|
|
|
widget:setOn(false)
|
|
|
|
end
|