| Index: resources/slides.lua
|
| diff --git a/resources/slides.lua b/resources/slides.lua
|
| index 2f44e78e1bad87fb16538bf5ac8920fa23f9ab68..2f774e0de266312739b37bd971fd3b7c5e50bd77 100644
|
| --- a/resources/slides.lua
|
| +++ b/resources/slides.lua
|
| @@ -2,6 +2,7 @@
|
| function make_paint(size, color)
|
| local paint = Sk.newPaint();
|
| paint:setAntiAlias(true)
|
| + paint:setSubpixelText(true)
|
| paint:setTextSize(size)
|
| paint:setColor(color)
|
| return paint
|
| @@ -81,28 +82,107 @@ gSlides = {
|
| }
|
| }
|
|
|
| +--------------------------------------------------------------------------------------
|
| +
|
| gSlideIndex = 1
|
|
|
| +function next_slide()
|
| + gSlideIndex = gSlideIndex + 1
|
| + if gSlideIndex > #gSlides then
|
| + gSlideIndex = 1
|
| + end
|
| +end
|
| +
|
| +function prev_slide()
|
| + gSlideIndex = gSlideIndex - 1
|
| + if gSlideIndex < 1 then
|
| + gSlideIndex = #gSlides
|
| + end
|
| +end
|
| +
|
| --------------------------------------------------------------------------------------
|
|
|
| +-- animation.proc is passed the canvas before drawing.
|
| +-- The animation.proc returns itself or another animation (which means keep animating)
|
| +-- or it returns nil, which stops the animation.
|
| +--
|
| +local gCurrAnimation
|
| +
|
| +function spawn_rotate_animation()
|
| + gCurrAnimation = {
|
| + angle = 0,
|
| + angle_delta = 5,
|
| + pivot_x = 320,
|
| + pivot_y = 240,
|
| + proc = function (this, canvas)
|
| + if this.angle >= 360 then
|
| + return nil
|
| + end
|
| + canvas:translate(this.pivot_x, this.pivot_y)
|
| + canvas:rotate(this.angle)
|
| + canvas:translate(-this.pivot_x, -this.pivot_y)
|
| +
|
| + this.angle = this.angle + this.angle_delta
|
| + return this
|
| + end
|
| + }
|
| +end
|
| +
|
| +function spawn_scale_animation()
|
| + gCurrAnimation = {
|
| + scale = 1,
|
| + scale_delta = .95,
|
| + scale_limit = 0.2,
|
| + pivot_x = 320,
|
| + pivot_y = 240,
|
| + proc = function (this, canvas)
|
| + if this.scale < this.scale_limit then
|
| + this.scale = this.scale_limit
|
| + this.scale_delta = 1 / this.scale_delta
|
| + end
|
| + if this.scale > 1 then
|
| + return nil
|
| + end
|
| + canvas:translate(this.pivot_x, this.pivot_y)
|
| + canvas:scale(this.scale, this.scale)
|
| + canvas:translate(-this.pivot_x, -this.pivot_y)
|
| +
|
| + this.scale = this.scale * this.scale_delta
|
| + return this
|
| + end
|
| + }
|
| +end
|
| +
|
| function onDrawContent(canvas)
|
| + if gCurrAnimation then
|
| + gCurrAnimation = gCurrAnimation:proc(canvas)
|
| + end
|
| +
|
| drawSlide(canvas, gSlides[gSlideIndex], gTemplate, gPaints)
|
|
|
| - return false -- we're not animating
|
| + if gCurrAnimation then
|
| + return true
|
| + else
|
| + return false
|
| + end
|
| end
|
|
|
| function onClickHandler(x, y)
|
| - if x < 100 and y < 100 then
|
| - onNextSlide()
|
| - return true
|
| - end
|
| return false
|
| end
|
|
|
| -function onNextSlide()
|
| - gSlideIndex = gSlideIndex + 1
|
| - if gSlideIndex > #gSlides then
|
| - gSlideIndex = 1
|
| +local keyProcs = {
|
| + n = next_slide,
|
| + p = prev_slide,
|
| + r = spawn_rotate_animation,
|
| + s = spawn_scale_animation,
|
| +}
|
| +
|
| +function onCharHandler(uni)
|
| + local proc = keyProcs[uni]
|
| + if proc then
|
| + proc()
|
| + return true
|
| end
|
| + return false
|
| end
|
| -
|
|
|