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

Side by Side Diff: resources/slides.lua

Issue 643113005: parse outline to generate slides (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 2 months 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_content.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 function tostr(t)
2 local str = ""
3 for k, v in next, t do
4 if #str > 0 then
5 str = str .. ", "
6 end
7 if type(k) == "number" then
8 str = str .. "[" .. k .. "] = "
9 else
10 str = str .. tostring(k) .. " = "
11 end
12 if type(v) == "table" then
13 str = str .. "{ " .. tostr(v) .. " }"
14 elseif type(v) == "string" then
15 str = str .. '"' .. v .. '"'
16 else
17 str = str .. tostring(v)
18 end
19 end
20 return str
21 end
22
23
24 function trim_ws(s)
25 return s:match("^%s*(.*)")
26 end
27
28 function count_hypens(s)
29 local leftover = s:match("^-*(.*)")
30 return string.len(s) - string.len(leftover)
31 end
32
33 function parse_file(file)
34 local slides = {}
35 local block = {}
36
37 for line in file:lines() do
38 local s = trim_ws(line)
39 if #s == 0 then -- done with a block
40 if #block > 0 then
41 slides[#slides + 1] = block
42 block = {}
43 end
44 else
45 local n = count_hypens(s)
46 block[#block + 1] = {
47 indent = n,
48 text = trim_ws(s:sub(n + 1, -1))
49 }
50 end
51 end
52 return slides
53 end
54
55 function pretty_print_slide(slide)
56 io.write("{\n")
57 for i = 1, #slide do
58 local node = slide[i]
59 for j = 0, node.indent do
60 io.write(" ")
61 end
62 io.write("{ ")
63 io.write(tostr(node))
64 io.write(" },\n")
65 end
66 io.write("},\n")
67 end
68
69 function pretty_print_slides(slides)
70 io.write("gSlides = {\n")
71 for i = 1, #slides do
72 pretty_print_slide(slides[i])
73 end
74 io.write("}\n")
75 end
76
77 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r"))
1 78
2 function make_paint(size, color) 79 function make_paint(size, color)
3 local paint = Sk.newPaint(); 80 local paint = Sk.newPaint();
4 paint:setAntiAlias(true) 81 paint:setAntiAlias(true)
5 paint:setSubpixelText(true) 82 paint:setSubpixelText(true)
6 paint:setTextSize(size) 83 paint:setTextSize(size)
7 paint:setColor(color) 84 paint:setColor(color)
8 return paint 85 return paint
9 end 86 end
10 87
11 function find_paint(paints, style) 88 function drawSlide(canvas, slide, template, paints)
12 if not style then 89 local scale = 1.15
13 style = "child" 90 local y = 0
14 end 91 for i = 1, #slide do
15 local paint = paints[style] 92 local node = slide[i]
16 return paint 93 local temp = template[node.indent + 1]
17 end 94 local paint = paints[node.indent + 1]
18 95 local fm = paint:getFontMetrics()
19 function draw_node(canvas, node, x, y, paints) 96 y = y - fm.ascent * scale
20 if node.text then 97 canvas:drawText(node.text, temp.x, y, paint)
21 local paint = find_paint(paints, node.style) 98 y = y + fm.descent * scale
22 canvas:drawText(node.text, x, y, paint)
23 end
24 if node.draw then
25 node.draw(canvas)
26 end 99 end
27 end 100 end
28 101
29 function drawSlide(canvas, slide, template, paints)
30 draw_node(canvas, slide, template.title.x, template.title.y, paints)
31
32 if slide.children then
33 local x = template.child.x
34 local y = template.child.y
35 local dy = template.child.dy
36 for i = 1, #slide.children do
37 draw_node(canvas, slide.children[i], x, y, paints)
38 y = y + dy
39 end
40 end
41 end
42
43 function slide_transition(prev, next, is_forward) 102 function slide_transition(prev, next, is_forward)
44 local rec = { 103 local rec = {
45 proc = function(self, canvas, drawSlideProc) 104 proc = function(self, canvas, drawSlideProc)
46 if self:isDone() then 105 if self:isDone() then
47 drawSlideProc(canvas) 106 drawSlideProc(canvas)
48 return nil 107 return nil
49 end 108 end
50 self.prevDrawable:draw(canvas, self.curr_x, 0) 109 self.prevDrawable:draw(canvas, self.curr_x, 0)
51 self.nextDrawable:draw(canvas, self.curr_x + 640, 0) 110 self.nextDrawable:draw(canvas, self.curr_x + 640, 0)
52 self.curr_x = self.curr_x + self.step_x 111 self.curr_x = self.curr_x + self.step_x
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 self.prev_a = (640 - self.prev_x) / 640 165 self.prev_a = (640 - self.prev_x) / 640
107 self.next_a = 1 - self.prev_a 166 self.next_a = 1 - self.prev_a
108 end 167 end
109 end 168 end
110 return rec 169 return rec
111 end 170 end
112 171
113 -------------------------------------------------------------------------------- ------ 172 -------------------------------------------------------------------------------- ------
114 173
115 gTemplate = { 174 gTemplate = {
116 title = { x = 10, y = 64, textSize = 64 }, 175 { x = 10, textSize = 40, bullet = "" },
117 child = { x = 40, y = 120, dy = 50, textSize = 40 }, 176 { x = 40, textSize = 30, bullet = "\xE2\x80\xA2" },
177 { x = 70, textSize = 20, bullet = "\xE2\x97\xA6" },
118 } 178 }
119 179
120 gPaints = {} 180 gPaints = {
121 gPaints.title = make_paint(gTemplate.title.textSize, { a=1, r=0, g=0, b=0 } ) 181 make_paint(gTemplate[1].textSize, { a=1, r=0, g=0, b=0 } ),
122 gPaints.child = make_paint(gTemplate.child.textSize, { a=.75, r=0, g=0, b=0 } ) 182 make_paint(gTemplate[2].textSize, { a=1, r=1, g=0, b=0 } ),
183 make_paint(gTemplate[3].textSize, { a=1, r=0, g=1, b=0 } ),
184 }
123 185
124 gRedPaint = Sk.newPaint() 186 gRedPaint = Sk.newPaint()
125 gRedPaint:setAntiAlias(true) 187 gRedPaint:setAntiAlias(true)
126 gRedPaint:setColor{a=1, r=1, g=0, b=0 } 188 gRedPaint:setColor{a=1, r=1, g=0, b=0 }
127 189
128 gSlides = {
129 { text = "Title1", style="title", color = { a=1, r=1, g=0, b=0 },
130 children = {
131 { text = "bullet 1", style = "child" },
132 { text = "bullet 2", style = "child" },
133 { text = "bullet 3", style = "child" },
134 { draw = function (canvas)
135 canvas:drawOval({left=300, top=300, right=400, bottom=400}, gRedPaint)
136 end },
137 },
138 transition = fade_slide_transition
139 },
140 { text = "Title2", style="title", color = { a=1, r=0, g=1, b=0 },
141 children = {
142 { text = "bullet uno", style = "child" },
143 { text = "bullet 2", style = "child" },
144 { text = "bullet tres", style = "child" },
145 },
146 transition = slide_transition
147 },
148 { text = "Title3", style="title",
149 children = {
150 { text = "bullet 1", style = "child", },
151 { text = "bullet 2", style = "child", color = { r=0, g=0, b=1 } },
152 { text = "bullet 3", style = "child" },
153 }
154 }
155 }
156
157 -------------------------------------------------------------------------------- ------
158 function tostr(t)
159 local str = ""
160 for k, v in next, t do
161 if #str > 0 then
162 str = str .. ", "
163 end
164 if type(k) == "number" then
165 str = str .. "[" .. k .. "] = "
166 else
167 str = str .. tostring(k) .. " = "
168 end
169 if type(v) == "table" then
170 str = str .. "{ " .. tostr(v) .. " }"
171 else
172 str = str .. tostring(v)
173 end
174 end
175 return str
176 end
177
178 -- animation.proc is passed the canvas before drawing. 190 -- animation.proc is passed the canvas before drawing.
179 -- The animation.proc returns itself or another animation (which means keep anim ating) 191 -- The animation.proc returns itself or another animation (which means keep anim ating)
180 -- or it returns nil, which stops the animation. 192 -- or it returns nil, which stops the animation.
181 -- 193 --
182 local gCurrAnimation 194 local gCurrAnimation
183 195
184 gSlideIndex = 1 196 gSlideIndex = 1
185 197
186 function next_slide() 198 function next_slide()
187 local prev = gSlides[gSlideIndex] 199 local prev = gSlides[gSlideIndex]
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 241
230 function spawn_transition(prevSlide, nextSlide, is_forward) 242 function spawn_transition(prevSlide, nextSlide, is_forward)
231 local transition 243 local transition
232 if is_forward then 244 if is_forward then
233 transition = prevSlide.transition 245 transition = prevSlide.transition
234 else 246 else
235 transition = nextSlide.transition 247 transition = nextSlide.transition
236 end 248 end
237 249
238 if not transition then 250 if not transition then
239 return 251 transition = fade_slide_transition
240 end 252 end
241 253
242 local rec = Sk.newPictureRecorder() 254 local rec = Sk.newPictureRecorder()
243 255
244 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate, gPaints) 256 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate, gPaints)
245 local prevDrawable = new_drawable_picture(rec:endRecording()) 257 local prevDrawable = new_drawable_picture(rec:endRecording())
246 258
247 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate, gPaints) 259 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate, gPaints)
248 local nextDrawable = new_drawable_picture(rec:endRecording()) 260 local nextDrawable = new_drawable_picture(rec:endRecording())
249 261
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 339 }
328 340
329 function onCharHandler(uni) 341 function onCharHandler(uni)
330 local proc = keyProcs[uni] 342 local proc = keyProcs[uni]
331 if proc then 343 if proc then
332 proc() 344 proc()
333 return true 345 return true
334 end 346 end
335 return false 347 return false
336 end 348 end
OLDNEW
« no previous file with comments | « no previous file | resources/slides_content.lua » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698