OLD | NEW |
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 paint:setColor(color) | 89 paint:setColor(color) |
90 return paint | 90 return paint |
91 end | 91 end |
92 | 92 |
93 function drawSlide(canvas, slide, template) | 93 function drawSlide(canvas, slide, template) |
94 template = template.slide -- need to sniff the slide to know if we're titl
e or slide | 94 template = template.slide -- need to sniff the slide to know if we're titl
e or slide |
95 | 95 |
96 local x = template.margin_x | 96 local x = template.margin_x |
97 local y = template.margin_y | 97 local y = template.margin_y |
98 | 98 |
99 local scale = 1.15 | 99 local scale = 1.25 |
100 for i = 1, #slide do | 100 for i = 1, #slide do |
101 local node = slide[i] | 101 local node = slide[i] |
102 local paint = template[node.indent + 1] | 102 local paint = template[node.indent + 1].paint |
| 103 local extra_dy = template[node.indent + 1].extra_dy |
103 local fm = paint:getFontMetrics() | 104 local fm = paint:getFontMetrics() |
104 local x_offset = -fm.ascent * node.indent | 105 local x_offset = -fm.ascent * node.indent |
105 | 106 |
106 y = y - fm.ascent * scale | 107 y = y - fm.ascent * scale |
107 canvas:drawText(node.text, x + x_offset, y, paint) | 108 canvas:drawText(node.text, x + x_offset, y, paint) |
108 y = y + fm.descent * scale | 109 y = y + fm.descent * scale + extra_dy |
109 end | 110 end |
110 end | 111 end |
111 | 112 |
| 113 function scale_text_delta(template, delta) |
| 114 template = template.slide |
| 115 for i = 1, #template do |
| 116 local paint = template[i].paint |
| 117 paint:setTextSize(paint:getTextSize() + delta) |
| 118 end |
| 119 end |
| 120 |
112 function slide_transition(prev, next, is_forward) | 121 function slide_transition(prev, next, is_forward) |
113 local rec = { | 122 local rec = { |
114 proc = function(self, canvas, drawSlideProc) | 123 proc = function(self, canvas, drawSlideProc) |
115 if self:isDone() then | 124 if self:isDone() then |
116 drawSlideProc(canvas) | 125 drawSlideProc(canvas) |
117 return nil | 126 return nil |
118 end | 127 end |
119 self.prevDrawable:draw(canvas, self.curr_x, 0) | 128 self.prevDrawable:draw(canvas, self.curr_x, 0) |
120 self.nextDrawable:draw(canvas, self.curr_x + 640, 0) | 129 self.nextDrawable:draw(canvas, self.curr_x + 640, 0) |
121 self.curr_x = self.curr_x + self.step_x | 130 self.curr_x = self.curr_x + self.step_x |
(...skipping 11 matching lines...) Expand all Loading... |
133 rec.nextDrawable = prev | 142 rec.nextDrawable = prev |
134 rec.curr_x = -640 | 143 rec.curr_x = -640 |
135 rec.step_x = 15 | 144 rec.step_x = 15 |
136 rec.isDone = function (self) return self.curr_x >= 0 end | 145 rec.isDone = function (self) return self.curr_x >= 0 end |
137 end | 146 end |
138 return rec | 147 return rec |
139 end | 148 end |
140 | 149 |
141 function sqr(value) return value * value end | 150 function sqr(value) return value * value end |
142 | 151 |
143 function ease(value) | |
144 function set_blur(paint, alpha) | 152 function set_blur(paint, alpha) |
145 local sigma = sqr(1 - alpha) * 20 | 153 local sigma = sqr(1 - alpha) * 20 |
146 -- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma)) | 154 paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma)) |
147 paint:setAlpha(alpha) | 155 paint:setAlpha(alpha) |
148 end | 156 end |
149 | 157 |
150 function fade_slide_transition(prev, next, is_forward) | 158 function fade_slide_transition(prev, next, is_forward) |
151 local rec = { | 159 local rec = { |
152 paint = Sk.newPaint(), | 160 paint = Sk.newPaint(), |
153 prevDrawable = prev, | 161 prevDrawable = prev, |
154 nextDrawable = next, | 162 nextDrawable = next, |
155 proc = function(self, canvas, drawSlideProc) | 163 proc = function(self, canvas, drawSlideProc) |
156 if self:isDone() then | 164 if self:isDone() then |
(...skipping 30 matching lines...) Expand all Loading... |
187 rec.step = function (self) | 195 rec.step = function (self) |
188 self.prev_x = self.prev_x + 20 | 196 self.prev_x = self.prev_x + 20 |
189 self.prev_a = (640 - self.prev_x) / 640 | 197 self.prev_a = (640 - self.prev_x) / 640 |
190 self.next_a = 1 - self.prev_a | 198 self.next_a = 1 - self.prev_a |
191 end | 199 end |
192 end | 200 end |
193 return rec | 201 return rec |
194 end | 202 end |
195 | 203 |
196 --------------------------------------------------------------------------------
------ | 204 --------------------------------------------------------------------------------
------ |
| 205 function make_tmpl(paint, extra_dy) |
| 206 return { paint = paint, extra_dy = extra_dy } |
| 207 end |
197 | 208 |
198 function SkiaPoint_make_template() | 209 function SkiaPoint_make_template() |
199 local title = { | 210 local title = { |
200 margin_x = 30, | 211 margin_x = 30, |
201 margin_y = 100, | 212 margin_y = 100, |
202 } | 213 } |
203 title[1] = make_paint("Arial", 1, 50, { a=1, r=0, g=0, b=0 }) | 214 title[1] = make_paint("Arial", 1, 50, { a=1, r=1, g=1, b=1 }) |
204 title[1]:setTextAlign("center") | 215 title[1]:setTextAlign("center") |
205 title[2] = make_paint("Arial", 1, 25, { a=1, r=.3, g=.3, b=.3 }) | 216 title[2] = make_paint("Arial", 1, 25, { a=1, r=.75, g=.75, b=.75 }) |
206 title[2]:setTextAlign("center") | 217 title[2]:setTextAlign("center") |
207 | 218 |
208 local slide = { | 219 local slide = { |
209 margin_x = 20, | 220 margin_x = 20, |
210 margin_y = 30, | 221 margin_y = 25, |
211 } | 222 } |
212 slide[1] = make_paint("Arial", 1, 36, { a=1, r=0, g=0, b=0 }) | 223 slide[1] = make_tmpl(make_paint("Arial", 1, 36, { a=1, r=1, g=1, b=1 }), 18) |
213 slide[2] = make_paint("Arial", 0, 30, { a=1, r=0, g=0, b=0 }) | 224 slide[2] = make_tmpl(make_paint("Arial", 0, 30, { a=1, r=1, g=1, b=1 }), 0) |
214 slide[3] = make_paint("Arial", 0, 24, { a=1, r=.2, g=.2, b=.2 }) | 225 slide[3] = make_tmpl(make_paint("Arial", 0, 24, { a=1, r=.8, g=.8, b=.8 }),
0) |
215 | 226 |
216 return { | 227 return { |
217 title = title, | 228 title = title, |
218 slide = slide, | 229 slide = slide, |
219 } | 230 } |
220 end | 231 end |
221 | 232 |
222 gTemplate = SkiaPoint_make_template() | 233 gTemplate = SkiaPoint_make_template() |
223 | 234 |
224 gRedPaint = Sk.newPaint() | 235 gRedPaint = Sk.newPaint() |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 canvas:scale(self.scale, self.scale) | 363 canvas:scale(self.scale, self.scale) |
353 canvas:translate(-self.pivot_x, -self.pivot_y) | 364 canvas:translate(-self.pivot_x, -self.pivot_y) |
354 drawSlideProc(canvas) | 365 drawSlideProc(canvas) |
355 | 366 |
356 self.scale = self.scale * self.scale_delta | 367 self.scale = self.scale * self.scale_delta |
357 return self | 368 return self |
358 end | 369 end |
359 } | 370 } |
360 end | 371 end |
361 | 372 |
| 373 local bgPaint = nil |
| 374 |
| 375 function draw_bg(canvas) |
| 376 if not bgPaint then |
| 377 bgPaint = Sk.newPaint() |
| 378 local grad = Sk.newLinearGradient( 0, 0, { a=1, r=0, g=0, b=.3 }, |
| 379 640, 480, { a=1, r=0, g=0, b=.8 }) |
| 380 bgPaint:setShader(grad) |
| 381 end |
| 382 |
| 383 canvas:drawPaint(bgPaint) |
| 384 end |
| 385 |
362 function onDrawContent(canvas, width, height) | 386 function onDrawContent(canvas, width, height) |
363 local matrix = Sk.newMatrix() | 387 local matrix = Sk.newMatrix() |
364 matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, heigh
t), "center") | 388 matrix:setRectToRect(make_rect(0, 0, 640, 480), make_rect(0, 0, width, heigh
t), "center") |
365 canvas:concat(matrix) | 389 canvas:concat(matrix) |
366 | 390 |
| 391 draw_bg(canvas) |
| 392 |
367 local drawSlideProc = function(canvas) | 393 local drawSlideProc = function(canvas) |
368 drawSlide(canvas, gSlides[gSlideIndex], gTemplate) | 394 drawSlide(canvas, gSlides[gSlideIndex], gTemplate) |
369 end | 395 end |
370 | 396 |
371 if gCurrAnimation then | 397 if gCurrAnimation then |
372 gCurrAnimation = gCurrAnimation:proc(canvas, drawSlideProc) | 398 gCurrAnimation = gCurrAnimation:proc(canvas, drawSlideProc) |
373 return true | 399 return true |
374 else | 400 else |
375 drawSlideProc(canvas) | 401 drawSlideProc(canvas) |
376 return false | 402 return false |
377 end | 403 end |
378 end | 404 end |
379 | 405 |
380 function onClickHandler(x, y) | 406 function onClickHandler(x, y) |
381 return false | 407 return false |
382 end | 408 end |
383 | 409 |
384 local keyProcs = { | 410 local keyProcs = { |
385 n = next_slide, | 411 n = next_slide, |
386 p = prev_slide, | 412 p = prev_slide, |
387 r = spawn_rotate_animation, | 413 r = spawn_rotate_animation, |
388 s = spawn_scale_animation, | 414 s = spawn_scale_animation, |
| 415 u = function () scale_text_delta(gTemplate, 1) end, |
| 416 d = function () scale_text_delta(gTemplate, -1) end, |
389 } | 417 } |
390 | 418 |
391 function onCharHandler(uni) | 419 function onCharHandler(uni) |
392 local proc = keyProcs[uni] | 420 local proc = keyProcs[uni] |
393 if proc then | 421 if proc then |
394 proc() | 422 proc() |
395 return true | 423 return true |
396 end | 424 end |
397 return false | 425 return false |
398 end | 426 end |
OLD | NEW |