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

Side by Side Diff: sky/examples/raw/painting.dart

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import 'dart:sky' as sky;
6 import 'dart:math' as math;
7 import 'dart:typed_data';
8
9 void beginFrame(double timeStamp) {
10 sky.PictureRecorder recorder = new sky.PictureRecorder();
11 Canvas canvas = new Canvas(recorder, sky.view.width, 200.0);
12
13 sky.Paint paint = new sky.Paint();
14 sky.Point mid = new sky.Point(sky.view.width / 2.0, sky.view.height / 2.0);
15 double radius = math.min(mid.x, mid.y);
16
17 canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
18
19 canvas.save();
20
21 canvas.translate(-mid.x/2.0, sky.view.height*2.0);
22 canvas.clipRect(
23 new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
24
25 canvas.translate(mid.x, mid.y);
26 paint.color = const sky.Color.fromARGB(128, 255, 0, 255);
27 canvas.rotate(math.PI/4.0);
28
29 sky.Gradient yellowBlue = new sky.Gradient.linear(
30 [new sky.Point(-radius, -radius), new sky.Point(0.0, 0.0)],
31 [const sky.Color(0xFFFFFF00), const sky.Color(0xFF0000FF)]);
32 canvas.drawRect(new sky.Rect.fromLTRB(-radius, -radius, radius, radius),
33 new sky.Paint()..setShader(yellowBlue));
34
35 // Scale x and y by 0.5.
36 var scaleMatrix = new Float32List.fromList([
37 0.5, 0.0, 0.0, 0.0,
38 0.0, 0.5, 0.0, 0.0,
39 0.0, 0.0, 0.0, 0.0,
40 0.0, 0.0, 0.0, 1.0,
41 ]);
42 canvas.concat(scaleMatrix);
43 paint.color = const sky.Color.fromARGB(128, 0, 255, 0);
44 canvas.drawCircle(0.0, 0.0, radius, paint);
45
46 canvas.restore();
47
48 canvas.translate(0.0, 50.0);
49 var builder = new sky.LayerDrawLooperBuilder()
50 ..addLayerOnTop(
51 new sky.DrawLooperLayerInfo()
52 ..setOffset(const sky.Point(150.0, 0.0))
53 ..setColorMode(sky.TransferMode.src)
54 ..setPaintBits(sky.PaintBits.all),
55 (sky.Paint layerPaint) {
56 layerPaint.color = const sky.Color.fromARGB(128, 255, 255, 0);
57 layerPaint.setColorFilter(new sky.ColorFilter.mode(
58 const sky.Color.fromARGB(128, 0, 0, 255), sky.TransferMode.srcIn));
59 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
60 sky.BlurStyle.normal, 3.0, highQuality: true));
61 })
62 ..addLayerOnTop(
63 new sky.DrawLooperLayerInfo()
64 ..setOffset(const sky.Point(75.0, 75.0))
65 ..setColorMode(sky.TransferMode.src)
66 ..setPaintBits(sky.PaintBits.shader),
67 (sky.Paint layerPaint) {
68 sky.Gradient redYellow = new sky.Gradient.radial(
69 new sky.Point(0.0, 0.0), radius/3.0,
70 [const sky.Color(0xFFFFFF00), const sky.Color(0xFFFF0000)],
71 null, sky.TileMode.mirror);
72 layerPaint.setShader(redYellow);
73 // Since we're don't set sky.PaintBits.maskFilter, this has no effect.
74 layerPaint.setMaskFilter(new sky.MaskFilter.blur(
75 sky.BlurStyle.normal, 50.0, highQuality: true));
76 })
77 ..addLayerOnTop(
78 new sky.DrawLooperLayerInfo()..setOffset(const sky.Point(225.0, 75.0)) ,
79 (sky.Paint layerPaint) {
80 // Since this layer uses a DST color mode, this has no effect.
81 layerPaint.color = const sky.Color.fromARGB(128, 255, 0, 0);
82 });
83 paint.setDrawLooper(builder.build());
84 canvas.drawCircle(0.0, 0.0, radius, paint);
85
86 sky.view.picture = recorder.endRecording();
87 }
88
89 void main() {
90 sky.view.setBeginFrameCallback(beginFrame);
91 sky.view.scheduleFrame();
92 }
OLDNEW
« no previous file with comments | « sky/examples/raw/launcher.dart ('k') | sky/examples/raw/pubspec.yaml » ('j') | sky/sdk/README.md » ('J')

Powered by Google App Engine
This is Rietveld 408576698