Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: sky/sdk/example/raw/painting_node.dart

Issue 1233673003: Fix bugs found by Dart analyzer (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: typo Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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";
6 import 'dart:sky'; 5 import 'dart:sky';
7 6
8 PaintingNode paintingNode = null; 7 PaintingNode paintingNode = null;
9 Picture draw(int a, int r, int g, int b) { 8 Picture draw(int a, int r, int g, int b) {
10 Rect bounds = new Rect.fromLTRB(0.0, 0.0, view.width, view.height); 9 Rect bounds = new Rect.fromLTRB(0.0, 0.0, view.width, view.height);
11 Size size = new Size(view.width, view.height); 10 Size size = new Size(view.width, view.height);
12 11
13 PictureRecorder recorder = new PictureRecorder(); 12 PictureRecorder recorder = new PictureRecorder();
14 Canvas canvas = new Canvas(recorder, bounds); 13 Canvas canvas = new Canvas(recorder, bounds);
15 double radius = size.shortestSide * 0.45; 14 double radius = size.shortestSide * 0.45;
16 15
17 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); 16 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b);
18 canvas.drawCircle(size.center(Point.origin), radius, paint); 17 canvas.drawCircle(size.center(Point.origin), radius, paint);
19 18
20 if (paintingNode == null) { 19 if (paintingNode == null) {
21 paintingNode = new PaintingNode(); 20 paintingNode = new PaintingNode();
22 Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 - g, 255 - b); 21 Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 - g, 255 - b);
23 PictureRecorder innerRecorder = new PictureRecorder(); 22 PictureRecorder innerRecorder = new PictureRecorder();
24 Canvas innerCanvas = new Canvas(innerRecorder, bounds); 23 Canvas innerCanvas = new Canvas(innerRecorder, bounds);
25 innerCanvas.drawCircle(size.center(Point.origin), radius * 0.5, innerPaint); 24 innerCanvas.drawCircle(size.center(Point.origin), radius * 0.5, innerPaint);
26 25
27 paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable()); 26 paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable());
28 } 27 }
29 canvas.drawPaintingNode(paintingNode); 28 canvas.drawPaintingNode(paintingNode, Point.origin);
30 29
31 return recorder.endRecording(); 30 return recorder.endRecording();
32 } 31 }
33 32
34 bool handleEvent(Event event) { 33 bool handleEvent(Event event) {
35 if (event.type == "pointerdown") { 34 if (event.type == "pointerdown") {
36 view.picture = draw(255, 0, 0, 255); 35 view.picture = draw(255, 0, 0, 255);
37 view.scheduleFrame(); 36 view.scheduleFrame();
38 return true; 37 return true;
39 } 38 }
40 39
41 if (event.type == "pointerup") { 40 if (event.type == "pointerup") {
42 view.picture = draw(255, 0, 255, 0); 41 view.picture = draw(255, 0, 255, 0);
43 view.scheduleFrame(); 42 view.scheduleFrame();
44 return true; 43 return true;
45 } 44 }
46 45
47 return false; 46 return false;
48 } 47 }
49 48
50 void main() { 49 void main() {
51 view.picture = draw(255, 0, 255, 0); 50 view.picture = draw(255, 0, 255, 0);
52 view.scheduleFrame(); 51 view.scheduleFrame();
53 52
54 view.setEventCallback(handleEvent); 53 view.setEventCallback(handleEvent);
55 } 54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698