| 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_content2.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 draw_bullet(canvas, x, y, paint, indent) |
| 30 if 0 == indent then |
| 31 return |
| 32 end |
| 33 local ps = paint:getTextSize() |
| 34 local cx = x - ps * .8 |
| 35 local cy = y - ps * .4 |
| 36 local radius = ps * .2 |
| 37 canvas:drawCircle(cx, cy, radius, paint) |
| 38 end |
| 39 |
| 29 function drawSlide(canvas, slide, master_template) | 40 function drawSlide(canvas, slide, master_template) |
| 30 template = master_template.slide -- need to sniff the slide to know if we'
re title or slide | 41 template = master_template.slide -- need to sniff the slide to know if we'
re title or slide |
| 31 | 42 |
| 32 local x = template.margin_x | 43 local x = template.margin_x |
| 33 local y = template.margin_y | 44 local y = template.margin_y |
| 45 local scale = 1.25 |
| 34 | 46 |
| 35 if slide.blockstyle == "code" then | 47 if slide.blockstyle == "code" then |
| 36 local paint = master_template.codePaint | 48 local paint = master_template.codePaint |
| 37 local fm = paint:getFontMetrics() | 49 local fm = paint:getFontMetrics() |
| 38 local height = #slide * (fm.descent - fm.ascent) | 50 local height = #slide * (fm.descent - fm.ascent) |
| 39 y = (480 - height) / 2 | 51 y = (480 - height) / 2 |
| 40 for i = 1, #slide do | 52 for i = 1, #slide do |
| 41 local node = slide[i] | 53 local node = slide[i] |
| 42 y = y - fm.ascent | 54 y = y - fm.ascent * scale |
| 43 canvas:drawText(node.text, x, y, paint) | 55 canvas:drawText(node.text, x, y, paint) |
| 44 y = y + fm.descent | 56 y = y + fm.descent * scale |
| 45 end | 57 end |
| 46 return | 58 return |
| 47 end | 59 end |
| 48 | 60 |
| 49 local scale = 1.25 | |
| 50 for i = 1, #slide do | 61 for i = 1, #slide do |
| 51 local node = slide[i] | 62 local node = slide[i] |
| 52 local paint = template[node.indent + 1].paint | 63 local paint = template[node.indent + 1].paint |
| 53 local extra_dy = template[node.indent + 1].extra_dy | 64 local extra_dy = template[node.indent + 1].extra_dy |
| 54 local fm = paint:getFontMetrics() | 65 local fm = paint:getFontMetrics() |
| 55 local x_offset = -fm.ascent * node.indent | 66 local x_offset = -fm.ascent * node.indent * 1.25 |
| 56 | 67 |
| 57 y = y - fm.ascent * scale | 68 y = y - fm.ascent * scale |
| 69 draw_bullet(canvas, x + x_offset, y, paint, node.indent) |
| 58 canvas:drawText(node.text, x + x_offset, y, paint) | 70 canvas:drawText(node.text, x + x_offset, y, paint) |
| 59 y = y + fm.descent * scale + extra_dy | 71 y = y + fm.descent * scale + extra_dy |
| 60 end | 72 end |
| 61 end | 73 end |
| 62 | 74 |
| 63 --------------------------------------------------------------------------------
------ | 75 --------------------------------------------------------------------------------
------ |
| 64 function make_tmpl(paint, extra_dy) | 76 function make_tmpl(paint, extra_dy) |
| 65 return { paint = paint, extra_dy = extra_dy } | 77 return { paint = paint, extra_dy = extra_dy } |
| 66 end | 78 end |
| 67 | 79 |
| 68 function SkiaPoint_make_template() | 80 function SkiaPoint_make_template() |
| 69 local title = { | 81 local title = { |
| 70 margin_x = 30, | 82 margin_x = 30, |
| 71 margin_y = 100, | 83 margin_y = 100, |
| 72 } | 84 } |
| 73 title[1] = make_paint("Arial", 1, 50, { a=1, r=1, g=1, b=1 }) | 85 title[1] = make_paint("Arial", 1, 45, { a=1, r=1, g=1, b=1 }) |
| 74 title[1]:setTextAlign("center") | 86 title[1]:setTextAlign("center") |
| 75 title[2] = make_paint("Arial", 1, 25, { a=1, r=.75, g=.75, b=.75 }) | 87 title[2] = make_paint("Arial", 1, 25, { a=1, r=.75, g=.75, b=.75 }) |
| 76 title[2]:setTextAlign("center") | 88 title[2]:setTextAlign("center") |
| 77 | 89 |
| 78 local slide = { | 90 local slide = { |
| 79 margin_x = 20, | 91 margin_x = 20, |
| 80 margin_y = 25, | 92 margin_y = 25, |
| 81 } | 93 } |
| 82 slide[1] = make_tmpl(make_paint("Arial", 1, 36, { a=1, r=1, g=1, b=1 }), 18) | 94 slide[1] = make_tmpl(make_paint("Arial", 1, 35, { a=1, r=1, g=1, b=1 }), 18) |
| 83 slide[2] = make_tmpl(make_paint("Arial", 0, 30, { a=1, r=1, g=1, b=1 }), 0) | 95 slide[2] = make_tmpl(make_paint("Arial", 0, 25, { a=1, r=1, g=1, b=1 }), 0) |
| 84 slide[3] = make_tmpl(make_paint("Arial", 0, 24, { a=1, r=.8, g=.8, b=.8 }),
0) | 96 slide[3] = make_tmpl(make_paint("Arial", 0, 20, { a=1, r=.9, g=.9, b=.9 }),
0) |
| 85 | 97 |
| 86 return { | 98 return { |
| 87 title = title, | 99 title = title, |
| 88 slide = slide, | 100 slide = slide, |
| 89 codePaint = make_paint("Courier", 0, 24, { a=1, r=.9, g=.9, b=.9 }), | 101 codePaint = make_paint("Courier", 0, 20, { a=1, r=.9, g=.9, b=.9 }), |
| 90 } | 102 } |
| 91 end | 103 end |
| 92 | 104 |
| 93 gTemplate = SkiaPoint_make_template() | 105 gTemplate = SkiaPoint_make_template() |
| 94 | 106 |
| 95 gRedPaint = Sk.newPaint() | 107 gRedPaint = Sk.newPaint() |
| 96 gRedPaint:setAntiAlias(true) | 108 gRedPaint:setAntiAlias(true) |
| 97 gRedPaint:setColor{a=1, r=1, g=0, b=0 } | 109 gRedPaint:setColor{a=1, r=1, g=0, b=0 } |
| 98 | 110 |
| 99 -- animation.proc is passed the canvas before drawing. | 111 -- animation.proc is passed the canvas before drawing. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 308 } |
| 297 | 309 |
| 298 function onCharHandler(uni) | 310 function onCharHandler(uni) |
| 299 local proc = keyProcs[uni] | 311 local proc = keyProcs[uni] |
| 300 if proc then | 312 if proc then |
| 301 proc() | 313 proc() |
| 302 return true | 314 return true |
| 303 end | 315 end |
| 304 return false | 316 return false |
| 305 end | 317 end |
| OLD | NEW |