blob: 2f44e78e1bad87fb16538bf5ac8920fa23f9ab68 [file] [log] [blame]
reed18ea7772014-10-11 11:28:07 -07001
2function make_paint(size, color)
3 local paint = Sk.newPaint();
4 paint:setAntiAlias(true)
5 paint:setTextSize(size)
6 paint:setColor(color)
7 return paint
8end
9
10function find_paint(paints, style)
11 if not style then
12 style = "child"
13 end
14 local paint = paints[style]
15 return paint
16end
17
18function draw_node(canvas, node, x, y, paints)
19 if node.text then
20 local paint = find_paint(paints, node.style)
21 canvas:drawText(node.text, x, y, paint)
22 end
23 if node.draw then
24 node.draw(canvas)
25 end
26end
27
28function drawSlide(canvas, slide, template, paints)
29 draw_node(canvas, slide, template.title.x, template.title.y, paints)
30
31 if slide.children then
32 local x = template.child.x
33 local y = template.child.y
34 local dy = template.child.dy
35 for i = 1, #slide.children do
36 draw_node(canvas, slide.children[i], x, y, paints)
37 y = y + dy
38 end
39 end
40end
41
42--------------------------------------------------------------------------------------
43
44gTemplate = {
45 title = { x = 10, y = 64, textSize = 64 },
46 child = { x = 40, y = 120, dy = 50, textSize = 40 },
47}
48
49gPaints = {}
50gPaints.title = make_paint(gTemplate.title.textSize, { a=1, r=0, g=0, b=0 } )
51gPaints.child = make_paint(gTemplate.child.textSize, { a=.75, r=0, g=0, b=0 } )
52
53gRedPaint = Sk.newPaint()
54gRedPaint:setAntiAlias(true)
55gRedPaint:setColor{a=1, r=1, g=0, b=0 }
56
57gSlides = {
58 { text = "Title1", style="title", color = { a=1, r=1, g=0, b=0 },
59 children = {
60 { text = "bullet 1", style = "child" },
61 { text = "bullet 2", style = "child" },
62 { text = "bullet 3", style = "child" },
63 { draw = function (canvas)
64 canvas:drawOval({left=300, top=300, right=400, bottom=400}, gRedPaint)
65 end },
66 },
67 },
68 { text = "Title2", style="title", color = { a=1, r=0, g=1, b=0 },
69 children = {
70 { text = "bullet uno", style = "child" },
71 { text = "bullet 2", style = "child" },
72 { text = "bullet tres", style = "child" },
73 }
74 },
75 { text = "Title3", style="title",
76 children = {
77 { text = "bullet 1", style = "child", },
78 { text = "bullet 2", style = "child", color = { r=0, g=0, b=1 } },
79 { text = "bullet 3", style = "child" },
80 }
81 }
82}
83
84gSlideIndex = 1
85
86--------------------------------------------------------------------------------------
87
88function onDrawContent(canvas)
89 drawSlide(canvas, gSlides[gSlideIndex], gTemplate, gPaints)
90
91 return false -- we're not animating
92end
93
94function onClickHandler(x, y)
95 if x < 100 and y < 100 then
96 onNextSlide()
97 return true
98 end
99 return false
100end
101
102function onNextSlide()
103 gSlideIndex = gSlideIndex + 1
104 if gSlideIndex > #gSlides then
105 gSlideIndex = 1
106 end
107end
108