| 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:sky'; | 6 import 'dart:sky'; |
| 6 | 7 |
| 8 PaintingNode paintingNode = null; |
| 7 Picture draw(int a, int r, int g, int b) { | 9 Picture draw(int a, int r, int g, int b) { |
| 10 Rect bounds = new Rect.fromLTRB(0.0, 0.0, view.width, view.height); |
| 8 Size size = new Size(view.width, view.height); | 11 Size size = new Size(view.width, view.height); |
| 9 | 12 |
| 10 PictureRecorder recorder = new PictureRecorder(); | 13 PictureRecorder recorder = new PictureRecorder(); |
| 11 Canvas canvas = new Canvas(recorder, size); | 14 Canvas canvas = new Canvas(recorder, bounds); |
| 12 double radius = size.shortestSide * 0.45; | 15 double radius = size.shortestSide * 0.45; |
| 13 | 16 |
| 14 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); | 17 Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b); |
| 15 canvas.drawCircle(size.center(Point.origin), radius, paint); | 18 canvas.drawCircle(size.center(Point.origin), radius, paint); |
| 19 |
| 20 if (paintingNode == null) { |
| 21 paintingNode = new PaintingNode(); |
| 22 Paint innerPaint = new Paint()..color = new Color.fromARGB(a, 255 - r, 255 -
g, 255 - b); |
| 23 PictureRecorder innerRecorder = new PictureRecorder(); |
| 24 Canvas innerCanvas = new Canvas(innerRecorder, bounds); |
| 25 innerCanvas.drawCircle(size.center(Point.origin), radius * 0.5, innerPaint); |
| 26 |
| 27 paintingNode.setBackingDrawable(innerRecorder.endRecordingAsDrawable()); |
| 28 } |
| 29 canvas.drawPaintingNode(paintingNode); |
| 30 |
| 16 return recorder.endRecording(); | 31 return recorder.endRecording(); |
| 17 } | 32 } |
| 18 | 33 |
| 19 bool handleEvent(Event event) { | 34 bool handleEvent(Event event) { |
| 20 if (event.type == "pointerdown") { | 35 if (event.type == "pointerdown") { |
| 21 view.picture = draw(255, 0, 0, 255); | 36 view.picture = draw(255, 0, 0, 255); |
| 22 view.scheduleFrame(); | 37 view.scheduleFrame(); |
| 23 return true; | 38 return true; |
| 24 } | 39 } |
| 25 | 40 |
| 26 if (event.type == "pointerup") { | 41 if (event.type == "pointerup") { |
| 27 view.picture = draw(255, 0, 255, 0); | 42 view.picture = draw(255, 0, 255, 0); |
| 28 view.scheduleFrame(); | 43 view.scheduleFrame(); |
| 29 return true; | 44 return true; |
| 30 } | 45 } |
| 31 | 46 |
| 32 if (event.type == "back") { | |
| 33 print("Pressed back button."); | |
| 34 return true; | |
| 35 } | |
| 36 | |
| 37 return false; | 47 return false; |
| 38 } | 48 } |
| 39 | 49 |
| 40 void main() { | 50 void main() { |
| 41 print("Hello, world"); | |
| 42 view.picture = draw(255, 0, 255, 0); | 51 view.picture = draw(255, 0, 255, 0); |
| 43 view.scheduleFrame(); | 52 view.scheduleFrame(); |
| 44 | 53 |
| 45 view.setEventCallback(handleEvent); | 54 view.setEventCallback(handleEvent); |
| 46 } | 55 } |
| OLD | NEW |