-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_slide.lua
53 lines (43 loc) · 1.26 KB
/
image_slide.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local class = require '30log'
local json = require 'json'
local Slide = require 'slide'
local ImageSlide = Slide:extend("ImageSlide")
function ImageSlide:init(x, y, width, height, data_filename, font)
self.super:init()
self.x, self.y = x, y
self.padding = 0
self.width, self.height = width, height
self:reset()
self.image = nil
util.file_watch(data_filename, function(content)
local data = json.decode(content)
self.duration = data.duration
self.image = resource.load_image(data.file)
if data.padding then
self.padding = data.padding
end
end)
end
function ImageSlide:draw()
self.super:tick()
local padding = self.padding
local fade_duration = 0.2
local time = self.super.active_time
if time < fade_duration then
alpha = math.min(time / fade_duration, 1.0)
elseif time > (self.duration - fade_duration) then
alpha = math.max((self.duration - time) / fade_duration, 0.0)
else
alpha = 1.0
end
self.image:draw(self.width * padding, self.height * padding,
self.width * (1 - padding), self.height * (1 - padding),
alpha)
end
function ImageSlide:reset()
self.super:reset()
end
function ImageSlide:is_done()
return (self.super.active_time > self.duration)
end
return ImageSlide