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

Side by Side Diff: resources/slides.lua

Issue 652473002: add key handlers to 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') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 function make_paint(size, color) 2 function make_paint(size, color)
3 local paint = Sk.newPaint(); 3 local paint = Sk.newPaint();
4 paint:setAntiAlias(true) 4 paint:setAntiAlias(true)
5 paint:setSubpixelText(true)
5 paint:setTextSize(size) 6 paint:setTextSize(size)
6 paint:setColor(color) 7 paint:setColor(color)
7 return paint 8 return paint
8 end 9 end
9 10
10 function find_paint(paints, style) 11 function find_paint(paints, style)
11 if not style then 12 if not style then
12 style = "child" 13 style = "child"
13 end 14 end
14 local paint = paints[style] 15 local paint = paints[style]
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 }, 75 },
75 { text = "Title3", style="title", 76 { text = "Title3", style="title",
76 children = { 77 children = {
77 { text = "bullet 1", style = "child", }, 78 { text = "bullet 1", style = "child", },
78 { text = "bullet 2", style = "child", color = { r=0, g=0, b=1 } }, 79 { text = "bullet 2", style = "child", color = { r=0, g=0, b=1 } },
79 { text = "bullet 3", style = "child" }, 80 { text = "bullet 3", style = "child" },
80 } 81 }
81 } 82 }
82 } 83 }
83 84
85 -------------------------------------------------------------------------------- ------
86
84 gSlideIndex = 1 87 gSlideIndex = 1
85 88
86 -------------------------------------------------------------------------------- ------ 89 function next_slide()
87
88 function onDrawContent(canvas)
89 drawSlide(canvas, gSlides[gSlideIndex], gTemplate, gPaints)
90
91 return false -- we're not animating
92 end
93
94 function onClickHandler(x, y)
95 if x < 100 and y < 100 then
96 onNextSlide()
97 return true
98 end
99 return false
100 end
101
102 function onNextSlide()
103 gSlideIndex = gSlideIndex + 1 90 gSlideIndex = gSlideIndex + 1
104 if gSlideIndex > #gSlides then 91 if gSlideIndex > #gSlides then
105 gSlideIndex = 1 92 gSlideIndex = 1
106 end 93 end
107 end 94 end
108 95
96 function prev_slide()
97 gSlideIndex = gSlideIndex - 1
98 if gSlideIndex < 1 then
99 gSlideIndex = #gSlides
100 end
101 end
102
103 -------------------------------------------------------------------------------- ------
104
105 -- animation.proc is passed the canvas before drawing.
106 -- The animation.proc returns itself or another animation (which means keep anim ating)
107 -- or it returns nil, which stops the animation.
108 --
109 local gCurrAnimation
110
111 function spawn_rotate_animation()
112 gCurrAnimation = {
113 angle = 0,
114 angle_delta = 5,
115 pivot_x = 320,
116 pivot_y = 240,
117 proc = function (this, canvas)
118 if this.angle >= 360 then
119 return nil
120 end
121 canvas:translate(this.pivot_x, this.pivot_y)
122 canvas:rotate(this.angle)
123 canvas:translate(-this.pivot_x, -this.pivot_y)
124
125 this.angle = this.angle + this.angle_delta
126 return this
127 end
128 }
129 end
130
131 function spawn_scale_animation()
132 gCurrAnimation = {
133 scale = 1,
134 scale_delta = .95,
135 scale_limit = 0.2,
136 pivot_x = 320,
137 pivot_y = 240,
138 proc = function (this, canvas)
139 if this.scale < this.scale_limit then
140 this.scale = this.scale_limit
141 this.scale_delta = 1 / this.scale_delta
142 end
143 if this.scale > 1 then
144 return nil
145 end
146 canvas:translate(this.pivot_x, this.pivot_y)
147 canvas:scale(this.scale, this.scale)
148 canvas:translate(-this.pivot_x, -this.pivot_y)
149
150 this.scale = this.scale * this.scale_delta
151 return this
152 end
153 }
154 end
155
156 function onDrawContent(canvas)
157 if gCurrAnimation then
158 gCurrAnimation = gCurrAnimation:proc(canvas)
159 end
160
161 drawSlide(canvas, gSlides[gSlideIndex], gTemplate, gPaints)
162
163 if gCurrAnimation then
164 return true
165 else
166 return false
167 end
168 end
169
170 function onClickHandler(x, y)
171 return false
172 end
173
174 local keyProcs = {
175 n = next_slide,
176 p = prev_slide,
177 r = spawn_rotate_animation,
178 s = spawn_scale_animation,
179 }
180
181 function onCharHandler(uni)
182 local proc = keyProcs[uni]
183 if proc then
184 proc()
185 return true
186 end
187 return false
188 end
OLDNEW
« no previous file with comments | « no previous file | samplecode/SampleLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698