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:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky'; | 6 import 'dart:sky'; |
7 | 7 |
8 import 'package:sky/mojo/net/image_cache.dart' as image_cache; | 8 import 'package:sky/mojo/net/image_cache.dart' as image_cache; |
9 | 9 |
10 double timeBase = null; | 10 double timeBase = null; |
11 | 11 |
12 Image image = null; | 12 Image image = null; |
13 String url1 = "https://www.dartlang.org/logos/dart-logo.png"; | 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"
; | 14 String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg"
; |
15 | 15 |
16 void beginFrame(double timeStamp) { | 16 void beginFrame(double timeStamp) { |
17 if (timeBase == null) timeBase = timeStamp; | 17 if (timeBase == null) timeBase = timeStamp; |
18 double delta = timeStamp - timeBase; | 18 double delta = timeStamp - timeBase; |
19 PictureRecorder recorder = new PictureRecorder(); | 19 PictureRecorder recorder = new PictureRecorder(); |
20 Canvas canvas = new Canvas(recorder, view.width, view.height); | 20 Canvas canvas = new Canvas(recorder, new Size(view.width, view.height)); |
21 canvas.translate(view.width / 2.0, view.height / 2.0); | 21 canvas.translate(view.width / 2.0, view.height / 2.0); |
22 canvas.rotate(math.PI * delta / 1800); | 22 canvas.rotate(math.PI * delta / 1800); |
23 canvas.scale(0.2, 0.2); | 23 canvas.scale(0.2, 0.2); |
24 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0); | 24 Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0); |
25 | 25 |
26 // Draw image | 26 // Draw image |
27 if (image != null) | 27 if (image != null) |
28 canvas.drawImage(image, -image.width / 2.0, -image.height / 2.0, paint); | 28 canvas.drawImage(image, new Point(-image.width / 2.0, -image.height / 2.0),
paint); |
29 | 29 |
30 // Draw cut out of image | 30 // Draw cut out of image |
31 canvas.rotate(math.PI * delta / 1800); | 31 canvas.rotate(math.PI * delta / 1800); |
32 if (image != null) { | 32 if (image != null) { |
33 var w = image.width.toDouble(); | 33 var w = image.width.toDouble(); |
34 var h = image.width.toDouble(); | 34 var h = image.width.toDouble(); |
35 canvas.drawImageRect(image, | 35 canvas.drawImageRect(image, |
36 new Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75), | 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), | 37 new Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0), |
38 paint); | 38 paint); |
(...skipping 25 matching lines...) Expand all Loading... |
64 | 64 |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 void main() { | 68 void main() { |
69 image_cache.load(url1, handleImageLoad); | 69 image_cache.load(url1, handleImageLoad); |
70 image_cache.load(url1, handleImageLoad); | 70 image_cache.load(url1, handleImageLoad); |
71 view.setEventCallback(handleEvent); | 71 view.setEventCallback(handleEvent); |
72 view.setBeginFrameCallback(beginFrame); | 72 view.setBeginFrameCallback(beginFrame); |
73 } | 73 } |
OLD | NEW |