2011-12-07 01:31:55 +01:00
|
|
|
Effects = {}
|
2011-08-14 19:45:25 +02:00
|
|
|
|
2011-12-07 01:31:55 +01:00
|
|
|
function 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()
|
|
|
|
Effects.fadeIn(widget, time, elapsed + 30)
|
|
|
|
end, 30)
|
|
|
|
else
|
|
|
|
widget.fadeEvent = nil
|
|
|
|
end
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
|
|
|
|
2011-12-07 01:31:55 +01:00
|
|
|
function 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()
|
|
|
|
Effects.fadeOut(widget, time, elapsed + 30)
|
|
|
|
end, 30)
|
|
|
|
else
|
|
|
|
widget.fadeEvent = nil
|
|
|
|
end
|
2011-08-14 19:45:25 +02:00
|
|
|
end
|
|
|
|
|
2012-03-23 14:48:05 +01:00
|
|
|
function Effects.cancelFade(widget)
|
|
|
|
removeEvent(widget.fadeEvent)
|
2012-03-26 20:33:00 +02:00
|
|
|
widget.fadeEvent = nil
|
2012-03-23 14:48:05 +01:00
|
|
|
end
|