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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/slidefield/animator.rb', line 23
def transform(obj)
raise "Can not animate outside a frame" unless @frame
tr_struct = Struct.new :skip_draw?, :x_offset, :y_offset, :scale, :opacity
tr = tr_struct.new false, 0, 0, 1.0, 1.0
anim = animation_for obj.ancestor(:animation)
return tr if anim.nil?
cur_direction = @frame.forward? ? @frame.current? : !@frame.current?
dir_enabled = cur_direction ? anim.enter : anim.leave
anim.enabled = false unless dir_enabled
elapsed = @frame.time - anim.start_time
position = elapsed / anim.duration
anim.enabled = false if position > 1.0
unless anim.enabled
tr[:skip_draw?] = !@frame.current? return tr
end
width, height = @layout_size
case anim.name
when "fade"
if @frame.current?
tr.opacity = position
else
tr.opacity = 1.0 - position
end
when "slide right"
tr.x_offset = slide_offset position, width, false
when "slide left"
tr.x_offset = slide_offset position, width, true
when "slide down"
tr.y_offset = slide_offset position, height, false
when "slide up"
tr.y_offset = slide_offset position, height, true
when "zoom"
if @frame.current?
tr.scale = position
else
tr.scale = 1.0 - position
end
else
raise SlideField::RuntimeError,
"Unsupported animation '#{anim.name}'"
end
tr
end
|