OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 import 'dart:math' as math; | |
6 import 'dart:sky'; | |
7 | |
8 import 'package:sky/mojo/net/image_cache.dart' as image_cache; | |
9 | |
10 double timeBase = null; | |
11 | |
12 Image image = null; | |
13 String url1 = "https://www.dartlang.org/logos/dart-logo.png"; | |
14 String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg"
; | |
15 | |
16 void beginFrame(double timeStamp) { | |
17 if (timeBase == null) timeBase = timeStamp; | |
18 double delta = timeStamp - timeBase; | |
19 PictureRecorder recorder = new PictureRecorder(); | |
20 Canvas canvas = new Canvas(recorder, view.width, view.height); | |
21 canvas.translate(view.width / 2.0, view.height / 2.0); | |
22 canvas.rotate(math.PI * delta / 1800); | |
23 canvas.scale(0.2, 0.2); | |
24 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0); | |
25 | |
26 // Draw image | |
27 if (image != null) | |
28 canvas.drawImage(image, -image.width / 2.0, -image.height / 2.0, paint); | |
29 | |
30 // Draw cut out of image | |
31 canvas.rotate(math.PI * delta / 1800); | |
32 if (image != null) { | |
33 var w = image.width.toDouble(); | |
34 var h = image.width.toDouble(); | |
35 canvas.drawImageRect(image, | |
36 new Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75), | |
37 new Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0), | |
38 paint); | |
39 } | |
40 | |
41 view.picture = recorder.endRecording(); | |
42 view.scheduleFrame(); | |
43 } | |
44 | |
45 void handleImageLoad(result) { | |
46 if (result != image) { | |
47 print("${result.width}x${result.width} image loaded!"); | |
48 image = result; | |
49 view.scheduleFrame(); | |
50 } else { | |
51 print("Existing image was loaded again"); | |
52 } | |
53 } | |
54 | |
55 bool handleEvent(Event event) { | |
56 if (event.type == "pointerdown") { | |
57 return true; | |
58 } | |
59 | |
60 if (event.type == "pointerup") { | |
61 image_cache.load(url2, handleImageLoad); | |
62 return true; | |
63 } | |
64 | |
65 return false; | |
66 } | |
67 | |
68 void main() { | |
69 image_cache.load(url1, handleImageLoad); | |
70 image_cache.load(url1, handleImageLoad); | |
71 view.setEventCallback(handleEvent); | |
72 view.setBeginFrameCallback(beginFrame); | |
73 } | |
OLD | NEW |