aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorGravatar reed <reed@chromium.org>2014-10-11 13:13:11 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-11 13:13:11 -0700
commit09a1d6751c5c7c09d72ff8e195148509d2cb87ce (patch)
treed7ad0962f3bc243a9f99058fb19cf6d4b8b2d7cf /resources
parent18ea777638f1494b068ba4ca1a5d6725a0e80cf1 (diff)
add key handlers to lua
BUG=skia: TBR= Review URL: https://codereview.chromium.org/652473002
Diffstat (limited to 'resources')
-rw-r--r--resources/slides.lua100
1 files changed, 90 insertions, 10 deletions
diff --git a/resources/slides.lua b/resources/slides.lua
index 2f44e78e1b..2f774e0de2 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
-