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/framework/shell.dart' as shell; | 8 import 'package:sky/framework/shell.dart' as shell; |
9 import 'package:mojom/intents/intents.mojom.dart'; | 9 import 'package:mojom/intents/intents.mojom.dart'; |
10 | 10 |
11 Picture draw(int a, int r, int g, int b) { | 11 Picture draw(int a, int r, int g, int b) { |
12 double width = view.width; | 12 Size size = new Size(view.width, view.height); |
13 double height = view.height; | |
14 | 13 |
15 PictureRecorder recorder = new PictureRecorder(); | 14 PictureRecorder recorder = new PictureRecorder(); |
16 Canvas canvas = new Canvas(recorder, width, height); | 15 Canvas canvas = new Canvas(recorder, size); |
17 double radius = min(width, height) * 0.45; | 16 double radius = size.shortestSide * 0.45; |
18 | 17 |
19 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); |
20 canvas.drawRect(new Rect.fromSize(new Size(width, height)), paint); | 19 canvas.drawRect(new Rect.fromSize(size), paint); |
21 return recorder.endRecording(); | 20 return recorder.endRecording(); |
22 } | 21 } |
23 | 22 |
24 bool handleEvent(Event event) { | 23 bool handleEvent(Event event) { |
25 if (event.type == "pointerdown") { | 24 if (event.type == "pointerdown") { |
26 view.picture = draw(255, 0, 0, 255); | 25 view.picture = draw(255, 0, 0, 255); |
27 view.scheduleFrame(); | 26 view.scheduleFrame(); |
28 return true; | 27 return true; |
29 } | 28 } |
30 | 29 |
(...skipping 18 matching lines...) Expand all Loading... |
49 return false; | 48 return false; |
50 } | 49 } |
51 | 50 |
52 void main() { | 51 void main() { |
53 print("Hello, world"); | 52 print("Hello, world"); |
54 view.picture = draw(255, 255, 255, 0); | 53 view.picture = draw(255, 255, 255, 0); |
55 view.scheduleFrame(); | 54 view.scheduleFrame(); |
56 | 55 |
57 view.setEventCallback(handleEvent); | 56 view.setEventCallback(handleEvent); |
58 } | 57 } |
OLD | NEW |