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

Side by Side Diff: sky/sdk/lib/example/raw/painting.dart

Issue 1214833004: Split Size into Size and Offset. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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
« no previous file with comments | « sky/sdk/lib/example/raw/launcher.dart ('k') | sky/sdk/lib/example/raw/shadow.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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: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 void beginFrame(double timeStamp) { 9 void beginFrame(double timeStamp) {
10 sky.Size size = new sky.Size(sky.view.width, sky.view.height);
10 sky.PictureRecorder recorder = new sky.PictureRecorder(); 11 sky.PictureRecorder recorder = new sky.PictureRecorder();
11 Canvas canvas = new Canvas(recorder, sky.view.width, 200.0); 12 sky.Canvas canvas = new sky.Canvas(recorder, size);
12 13
13 sky.Paint paint = new sky.Paint(); 14 sky.Paint paint = new sky.Paint();
14 sky.Point mid = new sky.Point(sky.view.width / 2.0, sky.view.height / 2.0); 15 sky.Point mid = size.center(sky.Point.origin);
15 double radius = math.min(mid.x, mid.y); 16 double radius = size.shortestSide / 2.0;
16 17
17 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF)); 18 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
18 19
19 canvas.save(); 20 canvas.save();
20 21
21 canvas.translate(-mid.x/2.0, sky.view.height*2.0); 22 canvas.translate(-mid.x/2.0, sky.view.height*2.0);
22 canvas.clipRect( 23 canvas.clipRect(
23 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius)); 24 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
24 25
25 canvas.translate(mid.x, mid.y); 26 canvas.translate(mid.x, mid.y);
26 paint.color = const sky.Color.fromARGB(128, 255, 0, 255); 27 paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
27 canvas.rotate(math.PI/4.0); 28 canvas.rotate(math.PI/4.0);
28 29
29 sky.Gradient yellowBlue = new sky.Gradient.linear( 30 sky.Gradient yellowBlue = new sky.Gradient.linear(
30 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)], 31 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
31 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]); 32 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
32 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius), 33 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
33 new sky.Paint()..setShader(yellowBlue)); 34 new sky.Paint()..setShader(yellowBlue));
34 35
35 // Scale x and y by 0.5. 36 // Scale x and y by 0.5.
36 var scaleMatrix = new Float32List.fromList([ 37 var scaleMatrix = new Float32List.fromList([
37 0.5, 0.0, 0.0, 0.0, 38 0.5, 0.0, 0.0, 0.0,
38 0.0, 0.5, 0.0, 0.0, 39 0.0, 0.5, 0.0, 0.0,
39 0.0, 0.0, 0.0, 0.0, 40 0.0, 0.0, 0.0, 0.0,
40 0.0, 0.0, 0.0, 1.0, 41 0.0, 0.0, 0.0, 1.0,
41 ]); 42 ]);
42 canvas.concat(scaleMatrix); 43 canvas.concat(scaleMatrix);
43 paint.color = const sky.Color.fromARGB(128, 0, 255, 0); 44 paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
44 canvas.drawCircle(0.0, 0.0, radius, paint); 45 canvas.drawCircle(sky.Point.origin, radius, paint);
45 46
46 canvas.restore(); 47 canvas.restore();
47 48
48 canvas.translate(0.0, 50.0); 49 canvas.translate(0.0, 50.0);
49 var builder = new sky.LayerDrawLooperBuilder() 50 var builder = new sky.LayerDrawLooperBuilder()
50 ..addLayerOnTop( 51 ..addLayerOnTop(
51 new sky.DrawLooperLayerInfo() 52 new sky.DrawLooperLayerInfo()
52 ..setOffset(const sky.Point(150.0, 0.0)) 53 ..setOffset(const sky.Offset(150.0, 0.0))
53 ..setColorMode(sky.TransferMode.src) 54 ..setColorMode(sky.TransferMode.src)
54 ..setPaintBits(sky.PaintBits.all), 55 ..setPaintBits(sky.PaintBits.all),
55 (sky.Paint layerPaint) { 56 (sky.Paint layerPaint) {
56 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0); 57 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0);
57 layerPaint.setColorFilter(new sky.ColorFilter.mode( 58 layerPaint.setColorFilter(new sky.ColorFilter.mode(
58 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn)); 59 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn));
59 layerPaint.setMaskFilter(new sky.MaskFilter.blur( 60 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
60 sky.BlurStyle.normal, 3.0, highQuality: true)); 61 sky.BlurStyle.normal, 3.0, highQuality: true));
61 }) 62 })
62 ..addLayerOnTop( 63 ..addLayerOnTop(
63 new sky.DrawLooperLayerInfo() 64 new sky.DrawLooperLayerInfo()
64 ..setOffset(const sky.Point(75.0, 75.0)) 65 ..setOffset(const sky.Offset(75.0, 75.0))
65 ..setColorMode(sky.TransferMode.src) 66 ..setColorMode(sky.TransferMode.src)
66 ..setPaintBits(sky.PaintBits.shader), 67 ..setPaintBits(sky.PaintBits.shader),
67 (sky.Paint layerPaint) { 68 (sky.Paint layerPaint) {
68 sky.Gradient redYellow = new sky.Gradient.radial( 69 sky.Gradient redYellow = new sky.Gradient.radial(
69 new sky.Point(0.0, 0.0), radius/3.0, 70 new sky.Point(0.0, 0.0), radius/3.0,
70 [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)], 71 [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
71 null, sky.TileMode.mirror); 72 null, sky.TileMode.mirror);
72 layerPaint.setShader(redYellow); 73 layerPaint.setShader(redYellow);
73 // Since we're don't set sky.PaintBits.maskFilter, this has no effect. 74 // Since we're don't set sky.PaintBits.maskFilter, this has no effect.
74 layerPaint.setMaskFilter(new sky.MaskFilter.blur( 75 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
75 sky.BlurStyle.normal, 50.0, highQuality: true)); 76 sky.BlurStyle.normal, 50.0, highQuality: true));
76 }) 77 })
77 ..addLayerOnTop( 78 ..addLayerOnTop(
78 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)) , 79 new sky.DrawLooperLayerInfo()..setOffset(const sky.Offset(225.0, 75.0) ),
79 (sky.Paint layerPaint) { 80 (sky.Paint layerPaint) {
80 // Since this layer uses a DST color mode, this has no effect. 81 // Since this layer uses a DST color mode, this has no effect.
81 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0); 82 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
82 }); 83 });
83 paint.setDrawLooper(builder.build()); 84 paint.setDrawLooper(builder.build());
84 canvas.drawCircle(0.0, 0.0, radius, paint); 85 canvas.drawCircle(sky.Point.origin, radius, paint);
85 86
86 sky.view.picture = recorder.endRecording(); 87 sky.view.picture = recorder.endRecording();
87 } 88 }
88 89
89 void main() { 90 void main() {
90 sky.view.setBeginFrameCallback(beginFrame); 91 sky.view.setBeginFrameCallback(beginFrame);
91 sky.view.scheduleFrame(); 92 sky.view.scheduleFrame();
92 } 93 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/example/raw/launcher.dart ('k') | sky/sdk/lib/example/raw/shadow.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698