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"; | 5 import "dart:math"; |
6 import 'dart:sky'; | 6 import 'dart:sky'; |
7 | 7 |
8 import 'package:sky/rendering/object.dart'; | |
abarth-chromium
2015/06/23 02:28:45
This demo shouldn't depend on package:sky. It's m
iansf
2015/06/23 22:46:09
Done.
| |
9 | |
8 Picture draw(int a, int r, int g, int b) { | 10 Picture draw(int a, int r, int g, int b) { |
9 double width = view.width; | 11 double width = view.width; |
10 double height = view.height; | 12 double height = view.height; |
11 | 13 |
12 PictureRecorder recorder = new PictureRecorder(width, height); | 14 PictureRecorder recorder = new PictureRecorder(); |
15 RenderCanvas canvas = new RenderCanvas(recorder, width, height); | |
abarth-chromium
2015/06/23 02:28:45
You can just use regular Canvas here.
iansf
2015/06/23 22:46:09
Done.
| |
13 double radius = min(width, height) * 0.45; | 16 double radius = min(width, height) * 0.45; |
14 | 17 |
15 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); | 18 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); |
16 recorder.drawCircle(width / 2, height / 2, radius, paint); | 19 canvas.drawCircle(width / 2, height / 2, radius, paint); |
17 return recorder.endRecording(); | 20 return recorder.endRecording(); |
18 } | 21 } |
19 | 22 |
20 bool handleEvent(Event event) { | 23 bool handleEvent(Event event) { |
21 if (event.type == "pointerdown") { | 24 if (event.type == "pointerdown") { |
22 view.picture = draw(255, 0, 0, 255); | 25 view.picture = draw(255, 0, 0, 255); |
23 view.scheduleFrame(); | 26 view.scheduleFrame(); |
24 return true; | 27 return true; |
25 } | 28 } |
26 | 29 |
(...skipping 11 matching lines...) Expand all Loading... | |
38 return false; | 41 return false; |
39 } | 42 } |
40 | 43 |
41 void main() { | 44 void main() { |
42 print("Hello, world"); | 45 print("Hello, world"); |
43 view.picture = draw(255, 0, 255, 0); | 46 view.picture = draw(255, 0, 255, 0); |
44 view.scheduleFrame(); | 47 view.scheduleFrame(); |
45 | 48 |
46 view.setEventCallback(handleEvent); | 49 view.setEventCallback(handleEvent); |
47 } | 50 } |
OLD | NEW |