OLD | NEW |
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:setSubpixelText(true) |
6 paint:setTextSize(size) | 6 paint:setTextSize(size) |
7 paint:setColor(color) | 7 paint:setColor(color) |
8 return paint | 8 return paint |
9 end | 9 end |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 end | 40 end |
41 end | 41 end |
42 | 42 |
43 function slide_transition(prev, next, is_forward) | 43 function slide_transition(prev, next, is_forward) |
44 local rec = { | 44 local rec = { |
45 proc = function(self, canvas, drawSlideProc) | 45 proc = function(self, canvas, drawSlideProc) |
46 if self:isDone() then | 46 if self:isDone() then |
47 drawSlideProc(canvas) | 47 drawSlideProc(canvas) |
48 return nil | 48 return nil |
49 end | 49 end |
50 canvas:drawImage(self.prevImage, self.curr_x, 0) | 50 self.prevDrawable:draw(canvas, self.curr_x, 0) |
51 canvas:drawImage(self.nextImage, self.curr_x + 640, 0) | 51 self.nextDrawable:draw(canvas, self.curr_x + 640, 0) |
52 self.curr_x = self.curr_x + self.step_x | 52 self.curr_x = self.curr_x + self.step_x |
53 return self | 53 return self |
54 end | 54 end |
55 } | 55 } |
56 if is_forward then | 56 if is_forward then |
57 rec.prevImage = prev | 57 rec.prevDrawable = prev |
58 rec.nextImage = next | 58 rec.nextDrawable = next |
59 rec.curr_x = 0 | 59 rec.curr_x = 0 |
60 rec.step_x = -15 | 60 rec.step_x = -15 |
61 rec.isDone = function (self) return self.curr_x <= -640 end | 61 rec.isDone = function (self) return self.curr_x <= -640 end |
62 else | 62 else |
63 rec.prevImage = next | 63 rec.prevDrawable = next |
64 rec.nextImage = prev | 64 rec.nextDrawable = prev |
65 rec.curr_x = -640 | 65 rec.curr_x = -640 |
66 rec.step_x = 15 | 66 rec.step_x = 15 |
67 rec.isDone = function (self) return self.curr_x >= 0 end | 67 rec.isDone = function (self) return self.curr_x >= 0 end |
68 end | 68 end |
69 return rec | 69 return rec |
70 end | 70 end |
71 | 71 |
72 function fade_slide_transition(prev, next, is_forward) | 72 function fade_slide_transition(prev, next, is_forward) |
73 local rec = { | 73 local rec = { |
74 prevImage = prev, | 74 prevDrawable = prev, |
75 nextImage = next, | 75 nextDrawable = next, |
76 proc = function(self, canvas, drawSlideProc) | 76 proc = function(self, canvas, drawSlideProc) |
77 if self:isDone() then | 77 if self:isDone() then |
78 drawSlideProc(canvas) | 78 drawSlideProc(canvas) |
79 return nil | 79 return nil |
80 end | 80 end |
81 canvas:drawImage(self.prevImage, self.prev_x, 0, self.prev_a) | 81 self.prevDrawable:draw(canvas, self.prev_x, 0, self.prev_a) |
82 canvas:drawImage(self.nextImage, self.next_x, 0, self.next_a) | 82 self.nextDrawable:draw(canvas, self.next_x, 0, self.next_a) |
83 self:step() | 83 self:step() |
84 return self | 84 return self |
85 end | 85 end |
86 } | 86 } |
87 if is_forward then | 87 if is_forward then |
88 rec.prev_x = 0 | 88 rec.prev_x = 0 |
89 rec.prev_a = 1 | 89 rec.prev_a = 1 |
90 rec.next_x = 640 | 90 rec.next_x = 640 |
91 rec.next_a = 0 | 91 rec.next_a = 0 |
92 rec.isDone = function (self) return self.next_x <= 0 end | 92 rec.isDone = function (self) return self.next_x <= 0 end |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 local prev = gSlides[gSlideIndex] | 198 local prev = gSlides[gSlideIndex] |
199 | 199 |
200 gSlideIndex = gSlideIndex - 1 | 200 gSlideIndex = gSlideIndex - 1 |
201 if gSlideIndex < 1 then | 201 if gSlideIndex < 1 then |
202 gSlideIndex = #gSlides | 202 gSlideIndex = #gSlides |
203 end | 203 end |
204 | 204 |
205 spawn_transition(prev, gSlides[gSlideIndex], false) | 205 spawn_transition(prev, gSlides[gSlideIndex], false) |
206 end | 206 end |
207 | 207 |
208 gSurfaceFactory = function (w, h) return Sk.newRasterSurface(w, h) end | 208 function new_drawable_picture(pic) |
| 209 return { |
| 210 picture = pic, |
| 211 width = pic:width(), |
| 212 height = pic:height(), |
| 213 draw = function (self, canvas, x, y, paint) |
| 214 canvas:drawPicture(self.picture, x, y, paint) |
| 215 end |
| 216 } |
| 217 end |
| 218 |
| 219 function new_drawable_image(img) |
| 220 return { |
| 221 image = img, |
| 222 width = img:width(), |
| 223 height = img:height(), |
| 224 draw = function (self, canvas, x, y, paint) |
| 225 canvas:drawImage(self.image, x, y, paint) |
| 226 end |
| 227 } |
| 228 end |
209 | 229 |
210 function spawn_transition(prevSlide, nextSlide, is_forward) | 230 function spawn_transition(prevSlide, nextSlide, is_forward) |
211 local transition | 231 local transition |
212 if is_forward then | 232 if is_forward then |
213 transition = prevSlide.transition | 233 transition = prevSlide.transition |
214 else | 234 else |
215 transition = nextSlide.transition | 235 transition = nextSlide.transition |
216 end | 236 end |
217 | 237 |
218 if not transition then | 238 if not transition then |
219 return | 239 return |
220 end | 240 end |
221 | 241 |
222 local surf = gSurfaceFactory(640, 480) | 242 local rec = Sk.newPictureRecorder() |
223 local canvas = surf:getCanvas() | |
224 | 243 |
225 canvas:clear() | 244 drawSlide(rec:beginRecording(640, 480), prevSlide, gTemplate, gPaints) |
226 drawSlide(canvas, prevSlide, gTemplate, gPaints) | 245 local prevDrawable = new_drawable_picture(rec:endRecording()) |
227 local prevImage = surf:newImageSnapshot() | |
228 | 246 |
229 canvas:clear() | 247 drawSlide(rec:beginRecording(640, 480), nextSlide, gTemplate, gPaints) |
230 drawSlide(canvas, nextSlide, gTemplate, gPaints) | 248 local nextDrawable = new_drawable_picture(rec:endRecording()) |
231 local nextImage = surf:newImageSnapshot() | |
232 | 249 |
233 gCurrAnimation = transition(prevImage, nextImage, is_forward) | 250 gCurrAnimation = transition(prevDrawable, nextDrawable, is_forward) |
234 end | 251 end |
235 | 252 |
236 --------------------------------------------------------------------------------
------ | 253 --------------------------------------------------------------------------------
------ |
237 | 254 |
238 function spawn_rotate_animation() | 255 function spawn_rotate_animation() |
239 gCurrAnimation = { | 256 gCurrAnimation = { |
240 angle = 0, | 257 angle = 0, |
241 angle_delta = 5, | 258 angle_delta = 5, |
242 pivot_x = 320, | 259 pivot_x = 320, |
243 pivot_y = 240, | 260 pivot_y = 240, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 327 } |
311 | 328 |
312 function onCharHandler(uni) | 329 function onCharHandler(uni) |
313 local proc = keyProcs[uni] | 330 local proc = keyProcs[uni] |
314 if proc then | 331 if proc then |
315 proc() | 332 proc() |
316 return true | 333 return true |
317 end | 334 end |
318 return false | 335 return false |
319 end | 336 end |
OLD | NEW |