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

Side by Side Diff: resources/slides.lua

Issue 698563004: update slide content (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 2
3 gPath = "/skia/trunk/resources/" 3 gPath = "/skia/trunk/resources/"
4 4
5 function load_file(file) 5 function load_file(file)
6 local prev_path = package.path 6 local prev_path = package.path
7 package.path = package.path .. ";" .. gPath .. file .. ".lua" 7 package.path = package.path .. ";" .. gPath .. file .. ".lua"
8 require(file) 8 require(file)
9 package.path = prev_path 9 package.path = prev_path
10 end 10 end
11 11
12 load_file("slides_utils") 12 load_file("slides_utils")
13 13
14 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r")) 14 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r"))
15 15
16 function make_rect(l, t, r, b) 16 function make_rect(l, t, r, b)
17 return { left = l, top = t, right = r, bottom = b } 17 return { left = l, top = t, right = r, bottom = b }
18 end 18 end
19 19
20 function make_paint(typefacename, stylebits, size, color) 20 function make_paint(typefacename, stylebits, size, color)
21 local paint = Sk.newPaint(); 21 local paint = Sk.newPaint();
22 paint:setAntiAlias(true) 22 paint:setAntiAlias(true)
23 paint:setSubpixelText(true) 23 paint:setSubpixelText(true)
24 paint:setTypeface(Sk.newTypeface(typefacename, stylebits)) 24 paint:setTypeface(Sk.newTypeface(typefacename, stylebits))
25 paint:setTextSize(size) 25 paint:setTextSize(size)
26 paint:setColor(color) 26 paint:setColor(color)
27 return paint 27 return paint
28 end 28 end
29 29
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
30 function draw_bullet(canvas, x, y, paint, indent) 56 function draw_bullet(canvas, x, y, paint, indent)
31 if 0 == indent then 57 if 0 == indent then
32 return 58 return
33 end 59 end
34 local ps = paint:getTextSize() 60 local ps = paint:getTextSize()
35 local cx = x - ps * .8 61 local cx = x - ps * .8
36 local cy = y - ps * .4 62 local cy = y - ps * .4
37 local radius = ps * .2 63 local radius = ps * .2
38 canvas:drawCircle(cx, cy, radius, paint) 64 canvas:drawCircle(cx, cy, radius, paint)
39 end 65 end
40 66
41 function stroke_rect(canvas, rect, color) 67 function stroke_rect(canvas, rect, color)
42 local paint = Sk.newPaint() 68 local paint = Sk.newPaint()
43 paint:setStroke(true); 69 paint:setStroke(true);
44 paint:setColor(color) 70 paint:setColor(color)
45 canvas:drawRect(rect, paint) 71 canvas:drawRect(rect, paint)
46 end 72 end
47 73
48 function drawSlide(canvas, slide, master_template) 74 function drawSlide(canvas, slide, master_template)
49 template = master_template.slide -- need to sniff the slide to know if we' re title or slide 75
76 if #slide == 1 then
77 template = master_template.title
78 canvas:drawText(slide[1].text, 320, 240, template[1])
79 return
80 end
81
82 template = master_template.slide
50 83
51 local x = template.margin_x 84 local x = template.margin_x
52 local y = template.margin_y 85 local y = template.margin_y
53 local scale = 1.25 86 local scale = 1.25
54 87
55 if slide.blockstyle == "code" then 88 if slide.blockstyle == "code" then
56 local paint = master_template.codePaint 89 local paint = master_template.codePaint
57 local fm = paint:getFontMetrics() 90 local fm = paint:getFontMetrics()
58 local height = #slide * (fm.descent - fm.ascent) 91 local height = #slide * (fm.descent - fm.ascent)
59 y = (480 - height) / 2 92 y = (480 - height) / 2
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 canvas:translate(x, y) 199 canvas:translate(x, y)
167 drawSlide(canvas, self.slide, gTemplate) 200 drawSlide(canvas, self.slide, gTemplate)
168 canvas:restore() 201 canvas:restore()
169 end 202 end
170 } 203 }
171 end 204 end
172 205
173 function next_slide() 206 function next_slide()
174 local prev = gSlides[gSlideIndex] 207 local prev = gSlides[gSlideIndex]
175 208
176 gSlideIndex = gSlideIndex + 1 209 if gSlideIndex < #gSlides then
177 if gSlideIndex > #gSlides then 210 gSlideIndex = gSlideIndex + 1
178 gSlideIndex = 1 211 spawn_transition(prev, gSlides[gSlideIndex], true)
179 end 212 end
180
181 spawn_transition(prev, gSlides[gSlideIndex], true)
182 end 213 end
183 214
184 function prev_slide() 215 function prev_slide()
185 local prev = gSlides[gSlideIndex] 216 local prev = gSlides[gSlideIndex]
186 217
187 gSlideIndex = gSlideIndex - 1 218 if gSlideIndex > 1 then
188 if gSlideIndex < 1 then 219 gSlideIndex = gSlideIndex - 1
189 gSlideIndex = #gSlides 220 spawn_transition(prev, gSlides[gSlideIndex], false)
190 end 221 end
191
192 spawn_transition(prev, gSlides[gSlideIndex], false)
193 end 222 end
194 223
195 function convert_to_picture_drawable(slide) 224 function convert_to_picture_drawable(slide)
196 local rec = Sk.newPictureRecorder() 225 local rec = Sk.newPictureRecorder()
197 drawSlide(rec:beginRecording(640, 480), slide, gTemplate) 226 drawSlide(rec:beginRecording(640, 480), slide, gTemplate)
198 return new_drawable_picture(rec:endRecording()) 227 return new_drawable_picture(rec:endRecording())
199 end 228 end
200 229
201 function convert_to_image_drawable(slide) 230 function convert_to_image_drawable(slide)
202 local surf = Sk.newRasterSurface(640, 480) 231 local surf = Sk.newRasterSurface(640, 480)
203 drawSlide(surf:getCanvas(), slide, gTemplate) 232 drawSlide(surf:getCanvas(), slide, gTemplate)
204 return new_drawable_image(surf:newImageSnapshot()) 233 return new_drawable_image(surf:newImageSnapshot())
205 end 234 end
206 235
207 -- gMakeDrawable = convert_to_picture_drawable
208 gMakeDrawable = new_drawable_slide 236 gMakeDrawable = new_drawable_slide
209 237
210 load_file("slides_transitions") 238 load_file("slides_transitions")
211 239
212 function spawn_transition(prevSlide, nextSlide, is_forward) 240 function spawn_transition(prevSlide, nextSlide, is_forward)
213 local transition 241 local transition
214 if is_forward then 242 if is_forward then
215 transition = gTransitionTable[nextSlide.transition] 243 transition = gTransitionTable[nextSlide.transition]
216 else 244 else
217 transition = gTransitionTable[prevSlide.transition] 245 transition = gTransitionTable[prevSlide.transition]
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 end 306 end
279 307
280 local bgPaint = nil 308 local bgPaint = nil
281 309
282 function draw_bg(canvas) 310 function draw_bg(canvas)
283 if not bgPaint then 311 if not bgPaint then
284 bgPaint = Sk.newPaint() 312 bgPaint = Sk.newPaint()
285 local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 }, 313 local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 },
286 640, 480, { a=1, r=0, g=0, b=.8 }) 314 640, 480, { a=1, r=0, g=0, b=.8 })
287 bgPaint:setShader(grad) 315 bgPaint:setShader(grad)
316 bgPaint:setDither(true)
288 end 317 end
289 318
290 canvas:drawPaint(bgPaint) 319 canvas:drawPaint(bgPaint)
291 end 320 end
292 321
293 function onDrawContent(canvas, width, height) 322 function onDrawContent(canvas, width, height)
294 local matrix = Sk.newMatrix() 323 local matrix = Sk.newMatrix()
295 matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, heigh t), "center") 324 matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, heigh t), "center")
296 canvas:concat(matrix) 325 canvas:concat(matrix)
297 326
(...skipping 28 matching lines...) Expand all
326 } 355 }
327 356
328 function onCharHandler(uni) 357 function onCharHandler(uni)
329 local proc = keyProcs[uni] 358 local proc = keyProcs[uni]
330 if proc then 359 if proc then
331 proc() 360 proc()
332 return true 361 return true
333 end 362 end
334 return false 363 return false
335 end 364 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