OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 import 'dart:sky'; | 5 import 'dart:sky'; |
| 6 import 'package:sky/framework/net/image_cache.dart' as image_cache; |
6 | 7 |
7 double timeBase = null; | 8 double timeBase = null; |
8 | 9 |
9 Image image = null; | 10 Image image = null; |
| 11 String url1 = "https://www.dartlang.org/logos/dart-logo.png"; |
| 12 String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg"
; |
10 | 13 |
11 void beginFrame(double timeStamp) { | 14 void beginFrame(double timeStamp) { |
12 if (timeBase == null) timeBase = timeStamp; | 15 if (timeBase == null) timeBase = timeStamp; |
13 double delta = timeStamp - timeBase; | 16 double delta = timeStamp - timeBase; |
14 PictureRecorder canvas = new PictureRecorder(view.width, view.height); | 17 PictureRecorder canvas = new PictureRecorder(view.width, view.height); |
15 canvas.translate(view.width / 2.0, view.height / 2.0); | 18 canvas.translate(view.width / 2.0, view.height / 2.0); |
16 canvas.rotateDegrees(delta / 10); | 19 canvas.rotateDegrees(delta / 10); |
17 canvas.scale(0.2, 0.2); | 20 canvas.scale(0.2, 0.2); |
18 Paint paint = new Paint()..setARGB(255, 0, 255, 0); | 21 Paint paint = new Paint()..setARGB(255, 0, 255, 0); |
19 if (image != null) | 22 if (image != null) |
20 canvas.drawImage(image, -image.width / 2.0, -image.height / 2.0, paint); | 23 canvas.drawImage(image, -image.width / 2.0, -image.height / 2.0, paint); |
21 view.picture = canvas.endRecording(); | 24 view.picture = canvas.endRecording(); |
22 view.scheduleFrame(); | 25 view.scheduleFrame(); |
23 } | 26 } |
24 | 27 |
| 28 void handleImageLoad(result) { |
| 29 if (result != image) { |
| 30 print("${result.width}x${result.width} image loaded!"); |
| 31 image = result; |
| 32 view.scheduleFrame(); |
| 33 } else { |
| 34 print("Existing image was loaded again"); |
| 35 } |
| 36 } |
| 37 |
| 38 bool handleEvent(Event event) { |
| 39 if (event.type == "pointerdown") { |
| 40 return true; |
| 41 } |
| 42 |
| 43 if (event.type == "pointerup") { |
| 44 image_cache.load(url2, handleImageLoad); |
| 45 return true; |
| 46 } |
| 47 |
| 48 return false; |
| 49 } |
| 50 |
25 void main() { | 51 void main() { |
26 new ImageLoader("https://www.dartlang.org/logos/dart-logo.png", (result) { | 52 image_cache.load(url1, handleImageLoad); |
27 if (result != null) { | 53 image_cache.load(url1, handleImageLoad); |
28 print("${result.width}x${result.width} image loaded!"); | 54 view.setEventCallback(handleEvent); |
29 image = result; | |
30 view.scheduleFrame(); | |
31 } else { | |
32 print("Image failed to load"); | |
33 } | |
34 }).load(); | |
35 view.setBeginFrameCallback(beginFrame); | 55 view.setBeginFrameCallback(beginFrame); |
36 } | 56 } |
OLD | NEW |