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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 else | 131 else |
132 rec.prevDrawable = next | 132 rec.prevDrawable = next |
133 rec.nextDrawable = prev | 133 rec.nextDrawable = prev |
134 rec.curr_x = -640 | 134 rec.curr_x = -640 |
135 rec.step_x = 15 | 135 rec.step_x = 15 |
136 rec.isDone = function (self) return self.curr_x >= 0 end | 136 rec.isDone = function (self) return self.curr_x >= 0 end |
137 end | 137 end |
138 return rec | 138 return rec |
139 end | 139 end |
140 | 140 |
| 141 function sqr(value) return value * value end |
| 142 |
| 143 function ease(value) |
| 144 function set_blur(paint, alpha) |
| 145 local sigma = sqr(1 - alpha) * 20 |
| 146 -- paint:setImageFilter(Sk.newBlurImageFilter(sigma, sigma)) |
| 147 paint:setAlpha(alpha) |
| 148 end |
| 149 |
141 function fade_slide_transition(prev, next, is_forward) | 150 function fade_slide_transition(prev, next, is_forward) |
142 local rec = { | 151 local rec = { |
| 152 paint = Sk.newPaint(), |
143 prevDrawable = prev, | 153 prevDrawable = prev, |
144 nextDrawable = next, | 154 nextDrawable = next, |
145 proc = function(self, canvas, drawSlideProc) | 155 proc = function(self, canvas, drawSlideProc) |
146 if self:isDone() then | 156 if self:isDone() then |
147 drawSlideProc(canvas) | 157 drawSlideProc(canvas) |
148 return nil | 158 return nil |
149 end | 159 end |
150 self.prevDrawable:draw(canvas, self.prev_x, 0, self.prev_a) | 160 |
151 self.nextDrawable:draw(canvas, self.next_x, 0, self.next_a) | 161 set_blur(self.paint, self.prev_a) |
| 162 self.prevDrawable:draw(canvas, self.prev_x, 0, self.paint) |
| 163 |
| 164 set_blur(self.paint, self.next_a) |
| 165 self.nextDrawable:draw(canvas, self.next_x, 0, self.paint) |
152 self:step() | 166 self:step() |
153 return self | 167 return self |
154 end | 168 end |
155 } | 169 } |
156 if is_forward then | 170 if is_forward then |
157 rec.prev_x = 0 | 171 rec.prev_x = 0 |
158 rec.prev_a = 1 | 172 rec.prev_a = 1 |
159 rec.next_x = 640 | 173 rec.next_x = 640 |
160 rec.next_a = 0 | 174 rec.next_a = 0 |
161 rec.isDone = function (self) return self.next_x <= 0 end | 175 rec.isDone = function (self) return self.next_x <= 0 end |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 return { | 270 return { |
257 image = img, | 271 image = img, |
258 width = img:width(), | 272 width = img:width(), |
259 height = img:height(), | 273 height = img:height(), |
260 draw = function (self, canvas, x, y, paint) | 274 draw = function (self, canvas, x, y, paint) |
261 canvas:drawImage(self.image, x, y, paint) | 275 canvas:drawImage(self.image, x, y, paint) |
262 end | 276 end |
263 } | 277 } |
264 end | 278 end |
265 | 279 |
| 280 function convert_to_picture_drawable(slide) |
| 281 local rec = Sk.newPictureRecorder() |
| 282 drawSlide(rec:beginRecording(640, 480), slide, gTemplate) |
| 283 return new_drawable_picture(rec:endRecording()) |
| 284 end |
| 285 |
| 286 function convert_to_image_drawable(slide) |
| 287 local surf = Sk.newRasterSurface(640, 480) |
| 288 drawSlide(surf:getCanvas(), slide, gTemplate) |
| 289 return new_drawable_image(surf:newImageSnapshot()) |
| 290 end |
| 291 |
| 292 gMakeDrawable = convert_to_picture_drawable |
| 293 |
266 function spawn_transition(prevSlide, nextSlide, is_forward) | 294 function spawn_transition(prevSlide, nextSlide, is_forward) |
267 local transition | 295 local transition |
268 if is_forward then | 296 if is_forward then |
269 transition = prevSlide.transition | 297 transition = prevSlide.transition |
270 else | 298 else |
271 transition = nextSlide.transition | 299 transition = nextSlide.transition |
272 end | 300 end |
273 | 301 |
274 if not transition then | 302 if not transition then |
275 transition = fade_slide_transition | 303 transition = fade_slide_transition |
276 end | 304 end |
277 | 305 |
278 local rec = Sk.newPictureRecorder() | 306 local prevDrawable = gMakeDrawable(prevSlide) |
279 | 307 local nextDrawable = gMakeDrawable(nextSlide) |
280 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate) | |
281 local prevDrawable = new_drawable_picture(rec:endRecording()) | |
282 | |
283 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate) | |
284 local nextDrawable = new_drawable_picture(rec:endRecording()) | |
285 | |
286 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) | 308 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) |
287 end | 309 end |
288 | 310 |
289 --------------------------------------------------------------------------------
------ | 311 --------------------------------------------------------------------------------
------ |
290 | 312 |
291 function spawn_rotate_animation() | 313 function spawn_rotate_animation() |
292 gCurrAnimation = { | 314 gCurrAnimation = { |
293 angle = 0, | 315 angle = 0, |
294 angle_delta = 5, | 316 angle_delta = 5, |
295 pivot_x = 320, | 317 pivot_x = 320, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 } | 389 } |
368 | 390 |
369 function onCharHandler(uni) | 391 function onCharHandler(uni) |
370 local proc = keyProcs[uni] | 392 local proc = keyProcs[uni] |
371 if proc then | 393 if proc then |
372 proc() | 394 proc() |
373 return true | 395 return true |
374 end | 396 end |
375 return false | 397 return false |
376 end | 398 end |
OLD | NEW |