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

Side by Side Diff: resources/slides.lua

Issue 651823004: create and modify matrices in lua (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | samplecode/SampleLua.cpp » ('j') | src/utils/SkLua.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 function tostr(t) 1 function tostr(t)
2 local str = "" 2 local str = ""
3 for k, v in next, t do 3 for k, v in next, t do
4 if #str > 0 then 4 if #str > 0 then
5 str = str .. ", " 5 str = str .. ", "
6 end 6 end
7 if type(k) == "number" then 7 if type(k) == "number" then
8 str = str .. "[" .. k .. "] = " 8 str = str .. "[" .. k .. "] = "
9 else 9 else
10 str = str .. tostring(k) .. " = " 10 str = str .. tostring(k) .. " = "
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 function pretty_print_slides(slides) 69 function pretty_print_slides(slides)
70 io.write("gSlides = {\n") 70 io.write("gSlides = {\n")
71 for i = 1, #slides do 71 for i = 1, #slides do
72 pretty_print_slide(slides[i]) 72 pretty_print_slide(slides[i])
73 end 73 end
74 io.write("}\n") 74 io.write("}\n")
75 end 75 end
76 76
77 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r")) 77 gSlides = parse_file(io.open("/skia/trunk/resources/slides_content.lua", "r"))
78 78
79 function make_paint(size, color) 79 function make_rect(l, t, r, b)
80 return { left = l, top = t, right = r, bottom = b }
81 end
82
83 function make_paint(typefacename, stylebits, size, color)
80 local paint = Sk.newPaint(); 84 local paint = Sk.newPaint();
81 paint:setAntiAlias(true) 85 paint:setAntiAlias(true)
82 paint:setSubpixelText(true) 86 paint:setSubpixelText(true)
87 paint:setTypeface(Sk.newTypeface(typefacename, stylebits))
83 paint:setTextSize(size) 88 paint:setTextSize(size)
84 paint:setColor(color) 89 paint:setColor(color)
85 return paint 90 return paint
86 end 91 end
87 92
88 function drawSlide(canvas, slide, template, paints) 93 function drawSlide(canvas, slide, template)
94 template = template.slide -- need to sniff the slide to know if we're titl e or slide
95
96 local x = template.margin_x
97 local y = template.margin_y
98
89 local scale = 1.15 99 local scale = 1.15
90 local y = 0
91 for i = 1, #slide do 100 for i = 1, #slide do
92 local node = slide[i] 101 local node = slide[i]
93 local temp = template[node.indent + 1] 102 local paint = template[node.indent + 1]
94 local paint = paints[node.indent + 1]
95 local fm = paint:getFontMetrics() 103 local fm = paint:getFontMetrics()
104 local x_offset = -fm.ascent * node.indent
105
96 y = y - fm.ascent * scale 106 y = y - fm.ascent * scale
97 canvas:drawText(node.text, temp.x, y, paint) 107 canvas:drawText(node.text, x + x_offset, y, paint)
98 y = y + fm.descent * scale 108 y = y + fm.descent * scale
99 end 109 end
100 end 110 end
101 111
102 function slide_transition(prev, next, is_forward) 112 function slide_transition(prev, next, is_forward)
103 local rec = { 113 local rec = {
104 proc = function(self, canvas, drawSlideProc) 114 proc = function(self, canvas, drawSlideProc)
105 if self:isDone() then 115 if self:isDone() then
106 drawSlideProc(canvas) 116 drawSlideProc(canvas)
107 return nil 117 return nil
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 self.prev_x = self.prev_x + 20 174 self.prev_x = self.prev_x + 20
165 self.prev_a = (640 - self.prev_x) / 640 175 self.prev_a = (640 - self.prev_x) / 640
166 self.next_a = 1 - self.prev_a 176 self.next_a = 1 - self.prev_a
167 end 177 end
168 end 178 end
169 return rec 179 return rec
170 end 180 end
171 181
172 -------------------------------------------------------------------------------- ------ 182 -------------------------------------------------------------------------------- ------
173 183
174 gTemplate = { 184 function SkiaPoint_make_template()
175 { x = 10, textSize = 40, bullet = "" }, 185 local title = {
176 { x = 40, textSize = 30, bullet = "\xE2\x80\xA2" }, 186 margin_x = 30,
177 { x = 70, textSize = 20, bullet = "\xE2\x97\xA6" }, 187 margin_y = 100,
178 } 188 }
189 title[1] = make_paint("Arial", 1, 50, { a=1, r=0, g=0, b=0 })
190 title[1]:setTextAlign("center")
191 title[2] = make_paint("Arial", 1, 25, { a=1, r=.3, g=.3, b=.3 })
192 title[2]:setTextAlign("center")
179 193
180 gPaints = { 194 local slide = {
181 make_paint(gTemplate[1].textSize, { a=1, r=0, g=0, b=0 } ), 195 margin_x = 20,
182 make_paint(gTemplate[2].textSize, { a=1, r=1, g=0, b=0 } ), 196 margin_y = 30,
183 make_paint(gTemplate[3].textSize, { a=1, r=0, g=1, b=0 } ), 197 }
184 } 198 slide[1] = make_paint("Arial", 1, 36, { a=1, r=0, g=0, b=0 })
199 slide[2] = make_paint("Arial", 0, 30, { a=1, r=0, g=0, b=0 })
200 slide[3] = make_paint("Arial", 0, 24, { a=1, r=.2, g=.2, b=.2 })
201
202 return {
203 title = title,
204 slide = slide,
205 }
206 end
207
208 gTemplate = SkiaPoint_make_template()
185 209
186 gRedPaint = Sk.newPaint() 210 gRedPaint = Sk.newPaint()
187 gRedPaint:setAntiAlias(true) 211 gRedPaint:setAntiAlias(true)
188 gRedPaint:setColor{a=1, r=1, g=0, b=0 } 212 gRedPaint:setColor{a=1, r=1, g=0, b=0 }
189 213
190 -- animation.proc is passed the canvas before drawing. 214 -- animation.proc is passed the canvas before drawing.
191 -- The animation.proc returns itself or another animation (which means keep anim ating) 215 -- The animation.proc returns itself or another animation (which means keep anim ating)
192 -- or it returns nil, which stops the animation. 216 -- or it returns nil, which stops the animation.
193 -- 217 --
194 local gCurrAnimation 218 local gCurrAnimation
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 else 270 else
247 transition = nextSlide.transition 271 transition = nextSlide.transition
248 end 272 end
249 273
250 if not transition then 274 if not transition then
251 transition = fade_slide_transition 275 transition = fade_slide_transition
252 end 276 end
253 277
254 local rec = Sk.newPictureRecorder() 278 local rec = Sk.newPictureRecorder()
255 279
256 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate, gPaints) 280 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate)
257 local prevDrawable = new_drawable_picture(rec:endRecording()) 281 local prevDrawable = new_drawable_picture(rec:endRecording())
258 282
259 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate, gPaints) 283 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate)
260 local nextDrawable = new_drawable_picture(rec:endRecording()) 284 local nextDrawable = new_drawable_picture(rec:endRecording())
261 285
262 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) 286 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward)
263 end 287 end
264 288
265 -------------------------------------------------------------------------------- ------ 289 -------------------------------------------------------------------------------- ------
266 290
267 function spawn_rotate_animation() 291 function spawn_rotate_animation()
268 gCurrAnimation = { 292 gCurrAnimation = {
269 angle = 0, 293 angle = 0,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 canvas:scale(self.scale, self.scale) 330 canvas:scale(self.scale, self.scale)
307 canvas:translate(-self.pivot_x, -self.pivot_y) 331 canvas:translate(-self.pivot_x, -self.pivot_y)
308 drawSlideProc(canvas) 332 drawSlideProc(canvas)
309 333
310 self.scale = self.scale * self.scale_delta 334 self.scale = self.scale * self.scale_delta
311 return self 335 return self
312 end 336 end
313 } 337 }
314 end 338 end
315 339
316 function onDrawContent(canvas) 340 function onDrawContent(canvas, width, height)
341 local matrix = Sk.newMatrix()
342 matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, heigh t), "center")
343 canvas:concat(matrix)
344
317 local drawSlideProc = function(canvas) 345 local drawSlideProc = function(canvas)
318 drawSlide(canvas, gSlides[gSlideIndex], gTemplate, gPaints) 346 drawSlide(canvas, gSlides[gSlideIndex], gTemplate)
319 end 347 end
320 348
321 if gCurrAnimation then 349 if gCurrAnimation then
322 gCurrAnimation = gCurrAnimation:proc(canvas, drawSlideProc) 350 gCurrAnimation = gCurrAnimation:proc(canvas, drawSlideProc)
323 return true 351 return true
324 else 352 else
325 drawSlideProc(canvas) 353 drawSlideProc(canvas)
326 return false 354 return false
327 end 355 end
328 end 356 end
(...skipping 10 matching lines...) Expand all
339 } 367 }
340 368
341 function onCharHandler(uni) 369 function onCharHandler(uni)
342 local proc = keyProcs[uni] 370 local proc = keyProcs[uni]
343 if proc then 371 if proc then
344 proc() 372 proc()
345 return true 373 return true
346 end 374 end
347 return false 375 return false
348 end 376 end
OLDNEW
« no previous file with comments | « no previous file | samplecode/SampleLua.cpp » ('j') | src/utils/SkLua.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698