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

Side by Side Diff: resources/slides.lua

Issue 686853005: update slides (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_content2.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 gShowBounds = false 1 gShowBounds = false
2 gUseBlurInTransitions = false
2 3
3 gPath = "/skia/trunk/resources/" 4 gPath = "/skia/trunk/resources/"
4 5
5 function load_file(file) 6 function load_file(file)
6 local prev_path = package.path 7 local prev_path = package.path
7 package.path = package.path .. ";" .. gPath .. file .. ".lua" 8 package.path = package.path .. ";" .. gPath .. file .. ".lua"
8 require(file) 9 require(file)
9 package.path = prev_path 10 package.path = prev_path
10 end 11 end
11 12
12 load_file("slides_utils") 13 load_file("slides_utils")
13 14
14 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r")) 15 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r"))
15 16
16 function make_rect(l, t, r, b) 17 function make_rect(l, t, r, b)
17 return { left = l, top = t, right = r, bottom = b } 18 return { left = l, top = t, right = r, bottom = b }
18 end 19 end
19 20
20 function make_paint(typefacename, stylebits, size, color) 21 function make_paint(typefacename, stylebits, size, color)
21 local paint = Sk.newPaint(); 22 local paint = Sk.newPaint();
22 paint:setAntiAlias(true) 23 paint:setAntiAlias(true)
23 paint:setSubpixelText(true) 24 paint:setSubpixelText(true)
24 paint:setTypeface(Sk.newTypeface(typefacename, stylebits)) 25 paint:setTypeface(Sk.newTypeface(typefacename, stylebits))
25 paint:setTextSize(size) 26 paint:setTextSize(size)
26 paint:setColor(color) 27 paint:setColor(color)
27 return paint 28 return paint
28 end 29 end
29 30
30 function center_rect(sw, sh, dst)
31 local dw = dst.right - dst.left
32 local dh = dst.bottom - dst.top
33
34 local rw, rh
35
36 if sw / sh > dw / dh then
37 rw = dw
38 rh = sh * dw / sw
39 else
40 rh = dh
41 rw = sw * dh / sh
42 end
43
44 local x = dst.left + ((sw - rw) / 2)
45 local y = dst.top + ((sh - rh) / 2)
46 return make_rect(x, y, x + rw, y + rh)
47 end
48
49 function draw_image_centered(canvas, image)
50 local sw = image:width()
51 local sh = image:height()
52 local dstR = center_rect(image:width(), image:height(), make_rect(20, 20, 62 0, 460))
53 canvas:drawImageRect(image, nil, dstR)
54 end
55
56 function draw_bullet(canvas, x, y, paint, indent) 31 function draw_bullet(canvas, x, y, paint, indent)
57 if 0 == indent then 32 if 0 == indent then
58 return 33 return
59 end 34 end
60 local ps = paint:getTextSize() 35 local ps = paint:getTextSize()
61 local cx = x - ps * .8 36 local cx = x - ps * .8
62 local cy = y - ps * .4 37 local cy = y - ps * .4
63 local radius = ps * .2 38 local radius = ps * .2
64 canvas:drawCircle(cx, cy, radius, paint) 39 canvas:drawCircle(cx, cy, radius, paint)
65 end 40 end
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 gRedPaint:setColor{a=1, r=1, g=0, b=0 } 133 gRedPaint:setColor{a=1, r=1, g=0, b=0 }
159 134
160 -- animation.proc is passed the canvas before drawing. 135 -- animation.proc is passed the canvas before drawing.
161 -- The animation.proc returns itself or another animation (which means keep anim ating) 136 -- The animation.proc returns itself or another animation (which means keep anim ating)
162 -- or it returns nil, which stops the animation. 137 -- or it returns nil, which stops the animation.
163 -- 138 --
164 local gCurrAnimation 139 local gCurrAnimation
165 140
166 gSlideIndex = 1 141 gSlideIndex = 1
167 142
143 -----------------------------------------------------------------------------
144
168 function new_drawable_picture(pic) 145 function new_drawable_picture(pic)
169 return { 146 return {
170 picture = pic, 147 picture = pic,
171 width = pic:width(), 148 width = pic:width(),
172 height = pic:height(), 149 height = pic:height(),
173 draw = function (self, canvas, x, y, paint) 150 draw = function (self, canvas, x, y, paint)
174 canvas:drawPicture(self.picture, x, y, paint) 151 canvas:drawPicture(self.picture, x, y, paint)
175 end 152 end
176 } 153 }
177 end 154 end
178 155
179 function new_drawable_image(img) 156 function new_drawable_image(img)
180 return { 157 return {
181 image = img, 158 image = img,
182 width = img:width(), 159 width = img:width(),
183 height = img:height(), 160 height = img:height(),
184 draw = function (self, canvas, x, y, paint) 161 draw = function (self, canvas, x, y, paint)
185 canvas:drawImage(self.image, x, y, paint) 162 canvas:drawImage(self.image, x, y, paint)
186 end 163 end
187 } 164 }
188 end 165 end
189 166
167 function convert_to_picture_drawable(slide)
168 local rec = Sk.newPictureRecorder()
169 drawSlide(rec:beginRecording(640, 480), slide, gTemplate)
170 return new_drawable_picture(rec:endRecording())
171 end
172
173 function convert_to_image_drawable(slide)
174 local surf = Sk.newRasterSurface(640, 480)
175 drawSlide(surf:getCanvas(), slide, gTemplate)
176 return new_drawable_image(surf:newImageSnapshot())
177 end
178
190 function new_drawable_slide(slide) 179 function new_drawable_slide(slide)
191 return { 180 return {
192 slide = slide, 181 slide = slide,
193 draw = function (self, canvas, x, y, paint) 182 draw = function (self, canvas, x, y, paint)
194 if (nil == paint or ("number" == type(paint) and (1 == paint))) then 183 if (nil == paint or ("number" == type(paint) and (1 == paint))) then
195 canvas:save() 184 canvas:save()
196 else 185 else
197 canvas:saveLayer(paint) 186 canvas:saveLayer(paint)
198 end 187 end
199 canvas:translate(x, y) 188 canvas:translate(x, y)
200 drawSlide(canvas, self.slide, gTemplate) 189 drawSlide(canvas, self.slide, gTemplate)
201 canvas:restore() 190 canvas:restore()
202 end 191 end
203 } 192 }
204 end 193 end
205 194
195 gNewDrawableFactory = {
196 default = new_drawable_slide,
197 picture = convert_to_picture_drawable,
198 image = convert_to_image_drawable,
199 }
200
201 -----------------------------------------------------------------------------
202
206 function next_slide() 203 function next_slide()
207 local prev = gSlides[gSlideIndex] 204 local prev = gSlides[gSlideIndex]
208 205
209 if gSlideIndex < #gSlides then 206 if gSlideIndex < #gSlides then
210 gSlideIndex = gSlideIndex + 1 207 gSlideIndex = gSlideIndex + 1
211 spawn_transition(prev, gSlides[gSlideIndex], true) 208 spawn_transition(prev, gSlides[gSlideIndex], true)
212 end 209 end
213 end 210 end
214 211
215 function prev_slide() 212 function prev_slide()
216 local prev = gSlides[gSlideIndex] 213 local prev = gSlides[gSlideIndex]
217 214
218 if gSlideIndex > 1 then 215 if gSlideIndex > 1 then
219 gSlideIndex = gSlideIndex - 1 216 gSlideIndex = gSlideIndex - 1
220 spawn_transition(prev, gSlides[gSlideIndex], false) 217 spawn_transition(prev, gSlides[gSlideIndex], false)
221 end 218 end
222 end 219 end
223 220
224 function convert_to_picture_drawable(slide) 221 gDrawableType = "default"
225 local rec = Sk.newPictureRecorder()
226 drawSlide(rec:beginRecording(640, 480), slide, gTemplate)
227 return new_drawable_picture(rec:endRecording())
228 end
229
230 function convert_to_image_drawable(slide)
231 local surf = Sk.newRasterSurface(640, 480)
232 drawSlide(surf:getCanvas(), slide, gTemplate)
233 return new_drawable_image(surf:newImageSnapshot())
234 end
235
236 gMakeDrawable = new_drawable_slide
237 222
238 load_file("slides_transitions") 223 load_file("slides_transitions")
239 224
240 function spawn_transition(prevSlide, nextSlide, is_forward) 225 function spawn_transition(prevSlide, nextSlide, is_forward)
241 local transition 226 local transition
242 if is_forward then 227 if is_forward then
243 transition = gTransitionTable[nextSlide.transition] 228 transition = gTransitionTable[nextSlide.transition]
244 else 229 else
245 transition = gTransitionTable[prevSlide.transition] 230 transition = gTransitionTable[prevSlide.transition]
246 end 231 end
247 232
248 if not transition then 233 if not transition then
249 transition = fade_slide_transition 234 transition = fade_slide_transition
250 end 235 end
251 236
252 local prevDrawable = gMakeDrawable(prevSlide) 237 local prevDrawable = gNewDrawableFactory[gDrawableType](prevSlide)
253 local nextDrawable = gMakeDrawable(nextSlide) 238 local nextDrawable = gNewDrawableFactory[gDrawableType](nextSlide)
254 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) 239 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward)
255 end 240 end
256 241
257 -------------------------------------------------------------------------------- ------ 242 -------------------------------------------------------------------------------- ------
258 243
259 function spawn_rotate_animation() 244 function spawn_rotate_animation()
260 gCurrAnimation = { 245 gCurrAnimation = {
261 angle = 0, 246 angle = 0,
262 angle_delta = 5, 247 angle_delta = 5,
263 pivot_x = 320, 248 pivot_x = 320,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 330
346 local keyProcs = { 331 local keyProcs = {
347 n = next_slide, 332 n = next_slide,
348 p = prev_slide, 333 p = prev_slide,
349 r = spawn_rotate_animation, 334 r = spawn_rotate_animation,
350 s = spawn_scale_animation, 335 s = spawn_scale_animation,
351 ["="] = function () scale_text_delta(gTemplate, 1) end, 336 ["="] = function () scale_text_delta(gTemplate, 1) end,
352 ["-"] = function () scale_text_delta(gTemplate, -1) end, 337 ["-"] = function () scale_text_delta(gTemplate, -1) end,
353 338
354 b = function () gShowBounds = not gShowBounds end, 339 b = function () gShowBounds = not gShowBounds end,
340 B = function () gUseBlurInTransitions = not gUseBlurInTransitions end,
341
342 ["1"] = function () gDrawableType = "default" end,
343 ["2"] = function () gDrawableType = "picture" end,
344 ["3"] = function () gDrawableType = "image" end,
355 } 345 }
356 346
357 function onCharHandler(uni) 347 function onCharHandler(uni)
358 local proc = keyProcs[uni] 348 local proc = keyProcs[uni]
359 if proc then 349 if proc then
360 proc() 350 proc()
361 return true 351 return true
362 end 352 end
363 return false 353 return false
364 end 354 end
OLDNEW
« no previous file with comments | « no previous file | resources/slides_content2.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698