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:sky' as sky; | 5 import 'dart:sky' as sky; |
6 import 'dart:math' as math; | 6 import 'dart:math' as math; |
7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 | 8 |
9 import 'package:sky/rendering/object.dart'; | |
abarth-chromium
2015/06/23 02:28:45
Again, please don't add dependencies on package:sk
Hixie
2015/06/23 16:36:48
Specifically, nothing in examples/raw/ should have
iansf
2015/06/23 22:46:09
Done.
iansf
2015/06/23 22:46:09
Done.
| |
10 | |
9 void beginFrame(double timeStamp) { | 11 void beginFrame(double timeStamp) { |
10 sky.PictureRecorder context = new sky.PictureRecorder(sky.view.width, 200.0); | 12 sky.PictureRecorder recorder = new sky.PictureRecorder(); |
13 RenderCanvas canvas = new RenderCanvas(recorder, sky.view.width, 200.0); | |
11 | 14 |
12 sky.Paint paint = new sky.Paint(); | 15 sky.Paint paint = new sky.Paint(); |
13 sky.Point mid = new sky.Point(context.width / 2.0, context.height / 2.0); | 16 sky.Point mid = new sky.Point(sky.view.width / 2.0, sky.view.height / 2.0); |
14 double radius = math.min(mid.x, mid.y); | 17 double radius = math.min(mid.x, mid.y); |
15 | 18 |
16 context.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF)); | 19 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF)); |
17 | 20 |
18 context.save(); | 21 canvas.save(); |
19 | 22 |
20 context.translate(-mid.x/2.0, context.height*2.0); | 23 canvas.translate(-mid.x/2.0, sky.view.height*2.0); |
21 context.clipRect( | 24 canvas.clipRect( |
22 new sky.Rect.fromLTRB(0.0, -context.height, context.width, radius)); | 25 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius)); |
23 | 26 |
24 context.translate(mid.x, mid.y); | 27 canvas.translate(mid.x, mid.y); |
25 paint.color = const sky.Color.fromARGB(128, 255, 0, 255); | 28 paint.color = const sky.Color.fromARGB(128, 255, 0, 255); |
26 context.rotate(math.PI/4.0); | 29 canvas.rotate(math.PI/4.0); |
27 | 30 |
28 sky.Gradient yellowBlue = new sky.Gradient.linear( | 31 sky.Gradient yellowBlue = new sky.Gradient.linear( |
29 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)], | 32 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)], |
30 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]); | 33 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]); |
31 context.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius), | 34 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius), |
32 new sky.Paint()..setShader(yellowBlue)); | 35 new sky.Paint()..setShader(yellowBlue)); |
33 | 36 |
34 // Scale x and y by 0.5. | 37 // Scale x and y by 0.5. |
35 var scaleMatrix = new Float32List.fromList([ | 38 var scaleMatrix = new Float32List.fromList([ |
36 0.5, 0.0, 0.0, 0.0, | 39 0.5, 0.0, 0.0, 0.0, |
37 0.0, 0.5, 0.0, 0.0, | 40 0.0, 0.5, 0.0, 0.0, |
38 0.0, 0.0, 0.0, 0.0, | 41 0.0, 0.0, 0.0, 0.0, |
39 0.0, 0.0, 0.0, 1.0, | 42 0.0, 0.0, 0.0, 1.0, |
40 ]); | 43 ]); |
41 context.concat(scaleMatrix); | 44 canvas.concat(scaleMatrix); |
42 paint.color = const sky.Color.fromARGB(128, 0, 255, 0); | 45 paint.color = const sky.Color.fromARGB(128, 0, 255, 0); |
43 context.drawCircle(0.0, 0.0, radius, paint); | 46 canvas.drawCircle(0.0, 0.0, radius, paint); |
44 | 47 |
45 context.restore(); | 48 canvas.restore(); |
46 | 49 |
47 context.translate(0.0, 50.0); | 50 canvas.translate(0.0, 50.0); |
48 var builder = new sky.LayerDrawLooperBuilder() | 51 var builder = new sky.LayerDrawLooperBuilder() |
49 ..addLayerOnTop( | 52 ..addLayerOnTop( |
50 new sky.DrawLooperLayerInfo() | 53 new sky.DrawLooperLayerInfo() |
51 ..setOffset(const sky.Point(150.0, 0.0)) | 54 ..setOffset(const sky.Point(150.0, 0.0)) |
52 ..setColorMode(sky.TransferMode.src) | 55 ..setColorMode(sky.TransferMode.src) |
53 ..setPaintBits(sky.PaintBits.all), | 56 ..setPaintBits(sky.PaintBits.all), |
54 (sky.Paint layerPaint) { | 57 (sky.Paint layerPaint) { |
55 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0); | 58 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0); |
56 layerPaint.setColorFilter(new sky.ColorFilter.mode( | 59 layerPaint.setColorFilter(new sky.ColorFilter.mode( |
57 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)); | 60 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)); |
(...skipping 15 matching lines...) Expand all Loading... | |
73 layerPaint.setMaskFilter(new sky.MaskFilter.blur( | 76 layerPaint.setMaskFilter(new sky.MaskFilter.blur( |
74 sky.BlurStyle.normal, 50.0, highQuality: true)); | 77 sky.BlurStyle.normal, 50.0, highQuality: true)); |
75 }) | 78 }) |
76 ..addLayerOnTop( | 79 ..addLayerOnTop( |
77 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)) , | 80 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)) , |
78 (sky.Paint layerPaint) { | 81 (sky.Paint layerPaint) { |
79 // Since this layer uses a DST color mode, this has no effect. | 82 // Since this layer uses a DST color mode, this has no effect. |
80 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0); | 83 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0); |
81 }); | 84 }); |
82 paint.setDrawLooper(builder.build()); | 85 paint.setDrawLooper(builder.build()); |
83 context.drawCircle(0.0, 0.0, radius, paint); | 86 canvas.drawCircle(0.0, 0.0, radius, paint); |
84 | 87 |
85 sky.view.picture = context.endRecording(); | 88 sky.view.picture = recorder.endRecording(); |
86 } | 89 } |
87 | 90 |
88 void main() { | 91 void main() { |
89 sky.view.setBeginFrameCallback(beginFrame); | 92 sky.view.setBeginFrameCallback(beginFrame); |
90 sky.view.scheduleFrame(); | 93 sky.view.scheduleFrame(); |
91 } | 94 } |
OLD | NEW |