Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: resources/slides.lua

Issue 692543004: break transitions into separate file (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | resources/slides_content.lua » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 gPath = "/skia/trunk/resources/" 2 gPath = "/skia/trunk/resources/"
3 3
4 function load_file(file) 4 function load_file(file)
5 local prev_path = package.path
5 package.path = package.path .. ";" .. gPath .. file .. ".lua" 6 package.path = package.path .. ";" .. gPath .. file .. ".lua"
6 require(file) 7 require(file)
8 package.path = prev_path
7 end 9 end
8 10
9 load_file("slides_utils") 11 load_file("slides_utils")
10 12
11 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r")) 13 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r"))
12 14
13 function make_rect(l, t, r, b) 15 function make_rect(l, t, r, b)
14 return { left = l, top = t, right = r, bottom = b } 16 return { left = l, top = t, right = r, bottom = b }
15 end 17 end
16 18
(...skipping 20 matching lines...) Expand all
37 local extra_dy = template[node.indent + 1].extra_dy 39 local extra_dy = template[node.indent + 1].extra_dy
38 local fm = paint:getFontMetrics() 40 local fm = paint:getFontMetrics()
39 local x_offset = -fm.ascent * node.indent 41 local x_offset = -fm.ascent * node.indent
40 42
41 y = y - fm.ascent * scale 43 y = y - fm.ascent * scale
42 canvas:drawText(node.text, x + x_offset, y, paint) 44 canvas:drawText(node.text, x + x_offset, y, paint)
43 y = y + fm.descent * scale + extra_dy 45 y = y + fm.descent * scale + extra_dy
44 end 46 end
45 end 47 end
46 48
47 function scale_text_delta(template, delta)
48 template = template.slide
49 for i = 1, #template do
50 local paint = template[i].paint
51 paint:setTextSize(paint:getTextSize() + delta)
52 end
53 end
54
55 function slide_transition(prev, next, is_forward)
56 local rec = {
57 proc = function(self, canvas, drawSlideProc)
58 if self:isDone() then
59 drawSlideProc(canvas)
60 return nil
61 end
62 self.prevDrawable:draw(canvas, self.curr_x, 0)
63 self.nextDrawable:draw(canvas, self.curr_x + 640, 0)
64 self.curr_x = self.curr_x + self.step_x
65 return self
66 end
67 }
68 if is_forward then
69 rec.prevDrawable = prev
70 rec.nextDrawable = next
71 rec.curr_x = 0
72 rec.step_x = -15
73 rec.isDone = function (self) return self.curr_x <= -640 end
74 else
75 rec.prevDrawable = next
76 rec.nextDrawable = prev
77 rec.curr_x = -640
78 rec.step_x = 15
79 rec.isDone = function (self) return self.curr_x >= 0 end
80 end
81 return rec
82 end
83
84 function sqr(value) return value * value end
85
86 function set_blur(paint, alpha)
87 local sigma = sqr(1 - alpha) * 20
88 -- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma))
89 paint:setAlpha(alpha)
90 end
91
92 function fade_slide_transition(prev, next, is_forward)
93 local rec = {
94 paint = Sk.newPaint(),
95 prevDrawable = prev,
96 nextDrawable = next,
97 proc = function(self, canvas, drawSlideProc)
98 if self:isDone() then
99 drawSlideProc(canvas)
100 return nil
101 end
102
103 set_blur(self.paint, self.prev_a)
104 self.prevDrawable:draw(canvas, self.prev_x, 0, self.paint)
105
106 set_blur(self.paint, self.next_a)
107 self.nextDrawable:draw(canvas, self.next_x, 0, self.paint)
108 self:step()
109 return self
110 end
111 }
112 if is_forward then
113 rec.prev_x = 0
114 rec.prev_a = 1
115 rec.next_x = 640
116 rec.next_a = 0
117 rec.isDone = function (self) return self.next_x <= 0 end
118 rec.step = function (self)
119 self.next_x = self.next_x - 20
120 self.next_a = (640 - self.next_x) / 640
121 self.prev_a = 1 - self.next_a
122 end
123 else
124 rec.prev_x = 0
125 rec.prev_a = 1
126 rec.next_x = 0
127 rec.next_a = 0
128 rec.isDone = function (self) return self.prev_x >= 640 end
129 rec.step = function (self)
130 self.prev_x = self.prev_x + 20
131 self.prev_a = (640 - self.prev_x) / 640
132 self.next_a = 1 - self.prev_a
133 end
134 end
135 return rec
136 end
137
138 -------------------------------------------------------------------------------- ------ 49 -------------------------------------------------------------------------------- ------
139 function make_tmpl(paint, extra_dy) 50 function make_tmpl(paint, extra_dy)
140 return { paint = paint, extra_dy = extra_dy } 51 return { paint = paint, extra_dy = extra_dy }
141 end 52 end
142 53
143 function SkiaPoint_make_template() 54 function SkiaPoint_make_template()
144 local title = { 55 local title = {
145 margin_x = 30, 56 margin_x = 30,
146 margin_y = 100, 57 margin_y = 100,
147 } 58 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 157
247 function convert_to_image_drawable(slide) 158 function convert_to_image_drawable(slide)
248 local surf = Sk.newRasterSurface(640, 480) 159 local surf = Sk.newRasterSurface(640, 480)
249 drawSlide(surf:getCanvas(), slide, gTemplate) 160 drawSlide(surf:getCanvas(), slide, gTemplate)
250 return new_drawable_image(surf:newImageSnapshot()) 161 return new_drawable_image(surf:newImageSnapshot())
251 end 162 end
252 163
253 -- gMakeDrawable = convert_to_picture_drawable 164 -- gMakeDrawable = convert_to_picture_drawable
254 gMakeDrawable = new_drawable_slide 165 gMakeDrawable = new_drawable_slide
255 166
167 load_file("slides_transitions")
168
256 function spawn_transition(prevSlide, nextSlide, is_forward) 169 function spawn_transition(prevSlide, nextSlide, is_forward)
257 local transition 170 local transition
258 if is_forward then 171 if is_forward then
259 transition = prevSlide.transition 172 transition = gTransitionTable[nextSlide.transition]
260 else 173 else
261 transition = nextSlide.transition 174 transition = gTransitionTable[prevSlide.transition]
262 end 175 end
263 176
264 if not transition then 177 if not transition then
265 transition = fade_slide_transition 178 transition = fade_slide_transition
266 end 179 end
267 180
268 local prevDrawable = gMakeDrawable(prevSlide) 181 local prevDrawable = gMakeDrawable(prevSlide)
269 local nextDrawable = gMakeDrawable(nextSlide) 182 local nextDrawable = gMakeDrawable(nextSlide)
270 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) 183 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward)
271 end 184 end
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 281 }
369 282
370 function onCharHandler(uni) 283 function onCharHandler(uni)
371 local proc = keyProcs[uni] 284 local proc = keyProcs[uni]
372 if proc then 285 if proc then
373 proc() 286 proc()
374 return true 287 return true
375 end 288 end
376 return false 289 return false
377 end 290 end
OLDNEW
« no previous file with comments | « no previous file | resources/slides_content.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698