| OLD | NEW |
| 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 local prev_path = package.path |
| 6 package.path = package.path .. ";" .. gPath .. file .. ".lua" | 6 package.path = package.path .. ";" .. gPath .. file .. ".lua" |
| 7 require(file) | 7 require(file) |
| 8 package.path = prev_path | 8 package.path = prev_path |
| 9 end | 9 end |
| 10 | 10 |
| 11 load_file("slides_utils") | 11 load_file("slides_utils") |
| 12 | 12 |
| 13 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r")) | 13 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content2.lua", "r")) |
| 14 | 14 |
| 15 function make_rect(l, t, r, b) | 15 function make_rect(l, t, r, b) |
| 16 return { left = l, top = t, right = r, bottom = b } | 16 return { left = l, top = t, right = r, bottom = b } |
| 17 end | 17 end |
| 18 | 18 |
| 19 function make_paint(typefacename, stylebits, size, color) | 19 function make_paint(typefacename, stylebits, size, color) |
| 20 local paint = Sk.newPaint(); | 20 local paint = Sk.newPaint(); |
| 21 paint:setAntiAlias(true) | 21 paint:setAntiAlias(true) |
| 22 paint:setSubpixelText(true) | 22 paint:setSubpixelText(true) |
| 23 paint:setTypeface(Sk.newTypeface(typefacename, stylebits)) | 23 paint:setTypeface(Sk.newTypeface(typefacename, stylebits)) |
| 24 paint:setTextSize(size) | 24 paint:setTextSize(size) |
| 25 paint:setColor(color) | 25 paint:setColor(color) |
| 26 return paint | 26 return paint |
| 27 end | 27 end |
| 28 | 28 |
| 29 function drawSlide(canvas, slide, template) | 29 function drawSlide(canvas, slide, master_template) |
| 30 template = template.slide -- need to sniff the slide to know if we're titl
e or slide | 30 template = master_template.slide -- need to sniff the slide to know if we'
re title or slide |
| 31 | 31 |
| 32 local x = template.margin_x | 32 local x = template.margin_x |
| 33 local y = template.margin_y | 33 local y = template.margin_y |
| 34 | 34 |
| 35 if slide.blockstyle == "code" then |
| 36 local paint = master_template.codePaint |
| 37 local fm = paint:getFontMetrics() |
| 38 local height = #slide * (fm.descent - fm.ascent) |
| 39 y = (480 - height) / 2 |
| 40 for i = 1, #slide do |
| 41 local node = slide[i] |
| 42 y = y - fm.ascent |
| 43 canvas:drawText(node.text, x, y, paint) |
| 44 y = y + fm.descent |
| 45 end |
| 46 return |
| 47 end |
| 48 |
| 35 local scale = 1.25 | 49 local scale = 1.25 |
| 36 for i = 1, #slide do | 50 for i = 1, #slide do |
| 37 local node = slide[i] | 51 local node = slide[i] |
| 38 local paint = template[node.indent + 1].paint | 52 local paint = template[node.indent + 1].paint |
| 39 local extra_dy = template[node.indent + 1].extra_dy | 53 local extra_dy = template[node.indent + 1].extra_dy |
| 40 local fm = paint:getFontMetrics() | 54 local fm = paint:getFontMetrics() |
| 41 local x_offset = -fm.ascent * node.indent | 55 local x_offset = -fm.ascent * node.indent |
| 42 | 56 |
| 43 y = y - fm.ascent * scale | 57 y = y - fm.ascent * scale |
| 44 canvas:drawText(node.text, x + x_offset, y, paint) | 58 canvas:drawText(node.text, x + x_offset, y, paint) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 65 margin_x = 20, | 79 margin_x = 20, |
| 66 margin_y = 25, | 80 margin_y = 25, |
| 67 } | 81 } |
| 68 slide[1] = make_tmpl(make_paint("Arial", 1, 36, { a=1, r=1, g=1, b=1 }), 18) | 82 slide[1] = make_tmpl(make_paint("Arial", 1, 36, { a=1, r=1, g=1, b=1 }), 18) |
| 69 slide[2] = make_tmpl(make_paint("Arial", 0, 30, { a=1, r=1, g=1, b=1 }), 0) | 83 slide[2] = make_tmpl(make_paint("Arial", 0, 30, { a=1, r=1, g=1, b=1 }), 0) |
| 70 slide[3] = make_tmpl(make_paint("Arial", 0, 24, { a=1, r=.8, g=.8, b=.8 }),
0) | 84 slide[3] = make_tmpl(make_paint("Arial", 0, 24, { a=1, r=.8, g=.8, b=.8 }),
0) |
| 71 | 85 |
| 72 return { | 86 return { |
| 73 title = title, | 87 title = title, |
| 74 slide = slide, | 88 slide = slide, |
| 89 codePaint = make_paint("Courier", 0, 24, { a=1, r=.9, g=.9, b=.9 }), |
| 75 } | 90 } |
| 76 end | 91 end |
| 77 | 92 |
| 78 gTemplate = SkiaPoint_make_template() | 93 gTemplate = SkiaPoint_make_template() |
| 79 | 94 |
| 80 gRedPaint = Sk.newPaint() | 95 gRedPaint = Sk.newPaint() |
| 81 gRedPaint:setAntiAlias(true) | 96 gRedPaint:setAntiAlias(true) |
| 82 gRedPaint:setColor{a=1, r=1, g=0, b=0 } | 97 gRedPaint:setColor{a=1, r=1, g=0, b=0 } |
| 83 | 98 |
| 84 -- animation.proc is passed the canvas before drawing. | 99 -- animation.proc is passed the canvas before drawing. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 296 } |
| 282 | 297 |
| 283 function onCharHandler(uni) | 298 function onCharHandler(uni) |
| 284 local proc = keyProcs[uni] | 299 local proc = keyProcs[uni] |
| 285 if proc then | 300 if proc then |
| 286 proc() | 301 proc() |
| 287 return true | 302 return true |
| 288 end | 303 end |
| 289 return false | 304 return false |
| 290 end | 305 end |
| OLD | NEW |