Merge pull request #1034 from abarth/rm_view_picture
Remove all clients of sky.view.picture
This commit is contained in:
commit
aa8942f4cf
@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky' as sky;
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
void drawText(sky.Canvas canvas, String lh) {
|
void drawText(sky.Canvas canvas, String lh) {
|
||||||
sky.Paint paint = new sky.Paint();
|
sky.Paint paint = new sky.Paint();
|
||||||
@ -44,14 +45,10 @@ void drawText(sky.Canvas canvas, String lh) {
|
|||||||
layoutRoot.paint(canvas);
|
layoutRoot.paint(canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
sky.Picture paint(sky.Rect paintBounds) {
|
||||||
// prepare the rendering
|
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
|
|
||||||
// background
|
|
||||||
sky.Paint paint = new sky.Paint();
|
sky.Paint paint = new sky.Paint();
|
||||||
paint.color = const sky.Color(0xFFFFFFFF);
|
paint.color = const sky.Color(0xFFFFFFFF);
|
||||||
paint.setStyle(sky.PaintingStyle.fill);
|
paint.setStyle(sky.PaintingStyle.fill);
|
||||||
@ -61,7 +58,30 @@ void main() {
|
|||||||
drawText(canvas, '1.0');
|
drawText(canvas, '1.0');
|
||||||
drawText(canvas, 'lh');
|
drawText(canvas, 'lh');
|
||||||
|
|
||||||
// put it on the screen
|
return recorder.endRecording();
|
||||||
sky.view.picture = recorder.endRecording();
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
sky.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -2,37 +2,59 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky';
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
Picture draw(int a, int r, int g, int b) {
|
sky.Color color;
|
||||||
Size size = new Size(view.width, view.height);
|
|
||||||
|
sky.Picture paint(sky.Rect paintBounds) {
|
||||||
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
|
sky.Size size = paintBounds.size;
|
||||||
|
|
||||||
PictureRecorder recorder = new PictureRecorder();
|
|
||||||
final double devicePixelRatio = view.devicePixelRatio;
|
|
||||||
Canvas canvas = new Canvas(recorder, Point.origin & (size * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
double radius = size.shortestSide * 0.45;
|
double radius = size.shortestSide * 0.45;
|
||||||
|
sky.Paint paint = new sky.Paint()
|
||||||
|
..color = color;
|
||||||
|
canvas.drawCircle(size.center(sky.Point.origin), radius, paint);
|
||||||
|
|
||||||
Paint paint = new Paint()..color = new Color.fromARGB(a, r, g, b);
|
|
||||||
canvas.drawCircle(size.center(Point.origin), radius, paint);
|
|
||||||
return recorder.endRecording();
|
return recorder.endRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleEvent(Event event) {
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
if (event.type == "pointerdown") {
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
view.picture = draw(255, 0, 0, 255);
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
view.scheduleFrame();
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool handleEvent(sky.Event event) {
|
||||||
|
if (event.type == 'pointerdown') {
|
||||||
|
color = new sky.Color.fromARGB(255, 0, 0, 255);
|
||||||
|
sky.view.scheduleFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == "pointerup") {
|
if (event.type == 'pointerup') {
|
||||||
view.picture = draw(255, 0, 255, 0);
|
color = new sky.Color.fromARGB(255, 0, 255, 0);
|
||||||
view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.type == "back") {
|
if (event.type == 'back') {
|
||||||
print("Pressed back button.");
|
print('Pressed back button.');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +62,9 @@ bool handleEvent(Event event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
print("Hello, world");
|
print('Hello, world');
|
||||||
view.picture = draw(255, 0, 255, 0);
|
color = new sky.Color.fromARGB(255, 0, 255, 0);
|
||||||
view.scheduleFrame();
|
sky.view.setFrameCallback(beginFrame);
|
||||||
|
sky.view.setEventCallback(handleEvent);
|
||||||
view.setEventCallback(handleEvent);
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import "dart:math" as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky' as sky;
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
const kMaxIterations = 100;
|
const kMaxIterations = 100;
|
||||||
int peakCount = 1000; // this is the number that must be reached for us to start reporting the peak number of nodes in the tree each frame
|
int peakCount = 1000; // this is the number that must be reached for us to start reporting the peak number of nodes in the tree each frame
|
||||||
@ -32,7 +33,7 @@ String colorToCSSString(sky.Color color) {
|
|||||||
return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${color.alpha / 255.0})';
|
||||||
}
|
}
|
||||||
|
|
||||||
void doFrame(double timeStamp) {
|
void mutate(sky.Canvas canvas) {
|
||||||
// mutate the DOM randomly
|
// mutate the DOM randomly
|
||||||
int iterationsLeft = kMaxIterations;
|
int iterationsLeft = kMaxIterations;
|
||||||
sky.Node node = root;
|
sky.Node node = root;
|
||||||
@ -201,16 +202,37 @@ void doFrame(double timeStamp) {
|
|||||||
|
|
||||||
// draw the result
|
// draw the result
|
||||||
report("recording...");
|
report("recording...");
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
layoutRoot.maxWidth = sky.view.width;
|
layoutRoot.maxWidth = sky.view.width;
|
||||||
layoutRoot.layout();
|
layoutRoot.layout();
|
||||||
layoutRoot.paint(canvas);
|
layoutRoot.paint(canvas);
|
||||||
report("painting...");
|
report("painting...");
|
||||||
sky.view.picture = recorder.endRecording();
|
}
|
||||||
sky.view.scheduleFrame();
|
|
||||||
|
sky.Picture paint(sky.Rect paintBounds) {
|
||||||
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
|
mutate(canvas);
|
||||||
|
return recorder.endRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -218,6 +240,6 @@ void main() {
|
|||||||
root.style['display'] = 'paragraph';
|
root.style['display'] = 'paragraph';
|
||||||
root.style['color'] = '#FFFFFF';
|
root.style['color'] = '#FFFFFF';
|
||||||
layoutRoot.rootElement = root;
|
layoutRoot.rootElement = root;
|
||||||
sky.view.setFrameCallback(doFrame);
|
sky.view.setFrameCallback(beginFrame);
|
||||||
sky.view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,17 @@ import 'dart:sky' as sky;
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
sky.Picture paint(sky.Rect paintBounds) {
|
||||||
sky.Size size = new sky.Size(sky.view.width, sky.view.height);
|
|
||||||
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
final double devicePixelRatio = sky.view.devicePixelRatio;
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
sky.Canvas canvas = new sky.Canvas(recorder, sky.Point.origin & (size * devicePixelRatio));
|
sky.Size size = paintBounds.size;
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
|
|
||||||
sky.Paint paint = new sky.Paint();
|
sky.Paint paint = new sky.Paint();
|
||||||
sky.Point mid = size.center(sky.Point.origin);
|
sky.Point mid = size.center(sky.Point.origin);
|
||||||
double radius = size.shortestSide / 2.0;
|
double radius = size.shortestSide / 2.0;
|
||||||
|
|
||||||
canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
|
canvas.drawPaint(new sky.Paint()..color = const sky.Color(0xFFFFFFFF));
|
||||||
|
|
||||||
canvas.save();
|
canvas.save();
|
||||||
|
|
||||||
canvas.translate(-mid.x/2.0, sky.view.height*2.0);
|
canvas.translate(-mid.x/2.0, sky.view.height*2.0);
|
||||||
canvas.clipRect(
|
canvas.clipRect(
|
||||||
new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
|
new sky.Rect.fromLTRB(0.0, -sky.view.height, sky.view.width, radius));
|
||||||
@ -39,7 +35,7 @@ void beginFrame(double timeStamp) {
|
|||||||
var scaleMatrix = new Float32List.fromList([
|
var scaleMatrix = new Float32List.fromList([
|
||||||
0.5, 0.0, 0.0, 0.0,
|
0.5, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.5, 0.0, 0.0,
|
0.0, 0.5, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0,
|
0.0, 0.0, 0.0, 1.0,
|
||||||
]);
|
]);
|
||||||
canvas.concat(scaleMatrix);
|
canvas.concat(scaleMatrix);
|
||||||
@ -81,7 +77,27 @@ void beginFrame(double timeStamp) {
|
|||||||
paint.setDrawLooper(builder.build());
|
paint.setDrawLooper(builder.build());
|
||||||
canvas.drawCircle(sky.Point.origin, radius, paint);
|
canvas.drawCircle(sky.Point.origin, radius, paint);
|
||||||
|
|
||||||
sky.view.picture = recorder.endRecording();
|
return recorder.endRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -2,41 +2,62 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky';
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
sky.Picture paint(sky.Rect paintBounds) {
|
||||||
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
|
||||||
double size = 100.0;
|
double size = 100.0;
|
||||||
PictureRecorder recorder = new PictureRecorder();
|
|
||||||
final double devicePixelRatio = view.devicePixelRatio;
|
|
||||||
Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
canvas.translate(size + 10.0, size + 10.0);
|
canvas.translate(size + 10.0, size + 10.0);
|
||||||
|
|
||||||
Paint paint = new Paint();
|
sky.Paint paint = new sky.Paint();
|
||||||
paint.color = const Color.fromARGB(255, 0, 255, 0);
|
paint.color = const sky.Color.fromARGB(255, 0, 255, 0);
|
||||||
var builder = new LayerDrawLooperBuilder()
|
var builder = new sky.LayerDrawLooperBuilder()
|
||||||
// Shadow layer.
|
// Shadow layer.
|
||||||
..addLayerOnTop(
|
..addLayerOnTop(
|
||||||
new DrawLooperLayerInfo()
|
new sky.DrawLooperLayerInfo()
|
||||||
..setPaintBits(PaintBits.all)
|
..setPaintBits(sky.PaintBits.all)
|
||||||
..setOffset(const Offset(5.0, 5.0))
|
..setOffset(const sky.Offset(5.0, 5.0))
|
||||||
..setColorMode(TransferMode.src),
|
..setColorMode(sky.TransferMode.src),
|
||||||
new Paint()
|
new sky.Paint()
|
||||||
..color = const Color.fromARGB(128, 55, 55, 55)
|
..color = const sky.Color.fromARGB(128, 55, 55, 55)
|
||||||
..setMaskFilter(
|
..setMaskFilter(
|
||||||
new MaskFilter.blur(BlurStyle.normal, 5.0, highQuality: true))
|
new sky.MaskFilter.blur(sky.BlurStyle.normal, 5.0))
|
||||||
)
|
)
|
||||||
// Main layer.
|
// Main layer.
|
||||||
..addLayerOnTop(new DrawLooperLayerInfo(), new Paint());
|
..addLayerOnTop(new sky.DrawLooperLayerInfo(), new sky.Paint());
|
||||||
paint.setDrawLooper(builder.build());
|
paint.setDrawLooper(builder.build());
|
||||||
|
|
||||||
canvas.drawPaint(
|
canvas.drawPaint(
|
||||||
new Paint()..color = const Color.fromARGB(255, 255, 255, 255));
|
new sky.Paint()..color = const sky.Color.fromARGB(255, 255, 255, 255));
|
||||||
canvas.drawRect(new Rect.fromLTRB(-size, -size, size, size), paint);
|
canvas.drawRect(new sky.Rect.fromLTRB(-size, -size, size, size), paint);
|
||||||
view.picture = recorder.endRecording();
|
|
||||||
|
return recorder.endRecording();
|
||||||
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
view.setFrameCallback(beginFrame);
|
sky.view.setFrameCallback(beginFrame);
|
||||||
view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,21 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import "dart:math" as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky';
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
LayoutRoot layoutRoot = new LayoutRoot();
|
sky.LayoutRoot layoutRoot = new sky.LayoutRoot();
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
sky.Picture paint(sky.Rect paintBounds, double delta) {
|
||||||
if (timeBase == null)
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
timeBase = timeStamp;
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
double delta = timeStamp - timeBase;
|
|
||||||
PictureRecorder recorder = new PictureRecorder();
|
canvas.translate(sky.view.width / 2.0, sky.view.height / 2.0);
|
||||||
final double devicePixelRatio = view.devicePixelRatio;
|
|
||||||
Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
canvas.translate(view.width / 2.0, view.height / 2.0);
|
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
canvas.drawRect(new sky.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||||
new Paint()..color = const Color.fromARGB(255, 0, 255, 0));
|
new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0));
|
||||||
|
|
||||||
double sin = math.sin(delta / 200);
|
double sin = math.sin(delta / 200);
|
||||||
layoutRoot.maxWidth = 150.0 + (50 * sin);
|
layoutRoot.maxWidth = 150.0 + (50 * sin);
|
||||||
@ -28,12 +25,34 @@ void beginFrame(double timeStamp) {
|
|||||||
canvas.translate(layoutRoot.maxWidth / -2.0, (layoutRoot.maxWidth / 2.0) - 125);
|
canvas.translate(layoutRoot.maxWidth / -2.0, (layoutRoot.maxWidth / 2.0) - 125);
|
||||||
layoutRoot.paint(canvas);
|
layoutRoot.paint(canvas);
|
||||||
|
|
||||||
view.picture = recorder.endRecording();
|
return recorder.endRecording();
|
||||||
view.scheduleFrame();
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
if (timeBase == null)
|
||||||
|
timeBase = timeStamp;
|
||||||
|
double delta = timeStamp - timeBase;
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds, delta);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
var document = new Document();
|
var document = new sky.Document();
|
||||||
var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف .");
|
var arabic = document.createText("هذا هو قليلا طويلة من النص الذي يجب التفاف .");
|
||||||
var more = document.createText(" و أكثر قليلا لجعله أطول. ");
|
var more = document.createText(" و أكثر قليلا لجعله أطول. ");
|
||||||
var block = document.createElement('p');
|
var block = document.createElement('p');
|
||||||
@ -45,6 +64,6 @@ void main() {
|
|||||||
|
|
||||||
layoutRoot.rootElement = block;
|
layoutRoot.rootElement = block;
|
||||||
|
|
||||||
view.setFrameCallback(beginFrame);
|
sky.view.setFrameCallback(beginFrame);
|
||||||
view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -3,32 +3,29 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
import 'dart:sky';
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
|
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
|
|
||||||
Image image = null;
|
sky.Image image = null;
|
||||||
String url1 = "https://www.dartlang.org/logos/dart-logo.png";
|
String url1 = "https://www.dartlang.org/logos/dart-logo.png";
|
||||||
String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
|
String url2 = "http://i2.kym-cdn.com/photos/images/facebook/000/581/296/c09.jpg";
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
sky.Picture paint(sky.Rect paintBounds, double delta) {
|
||||||
if (timeBase == null)
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
timeBase = timeStamp;
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
double delta = timeStamp - timeBase;
|
|
||||||
PictureRecorder recorder = new PictureRecorder();
|
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||||
final double devicePixelRatio = view.devicePixelRatio;
|
|
||||||
Canvas canvas = new Canvas(recorder, Point.origin & new Size(view.width * devicePixelRatio, view.height * devicePixelRatio));
|
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
|
||||||
canvas.translate(view.width / 2.0, view.height / 2.0);
|
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.scale(0.2, 0.2);
|
canvas.scale(0.2, 0.2);
|
||||||
Paint paint = new Paint()..color = const Color.fromARGB(255, 0, 255, 0);
|
sky.Paint paint = new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0);
|
||||||
|
|
||||||
// Draw image
|
// Draw image
|
||||||
if (image != null)
|
if (image != null)
|
||||||
canvas.drawImage(image, new Point(-image.width / 2.0, -image.height / 2.0), paint);
|
canvas.drawImage(image, new sky.Point(-image.width / 2.0, -image.height / 2.0), paint);
|
||||||
|
|
||||||
// Draw cut out of image
|
// Draw cut out of image
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
@ -36,26 +33,49 @@ void beginFrame(double timeStamp) {
|
|||||||
var w = image.width.toDouble();
|
var w = image.width.toDouble();
|
||||||
var h = image.width.toDouble();
|
var h = image.width.toDouble();
|
||||||
canvas.drawImageRect(image,
|
canvas.drawImageRect(image,
|
||||||
new Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75),
|
new sky.Rect.fromLTRB(w * 0.25, h * 0.25, w * 0.75, h * 0.75),
|
||||||
new Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0),
|
new sky.Rect.fromLTRB(-w / 4.0, -h / 4.0, w / 4.0, h / 4.0),
|
||||||
paint);
|
paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
view.picture = recorder.endRecording();
|
return recorder.endRecording();
|
||||||
view.scheduleFrame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sky.Scene composite(sky.Picture picture, sky.Rect paintBounds) {
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
return sceneBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginFrame(double timeStamp) {
|
||||||
|
if (timeBase == null)
|
||||||
|
timeBase = timeStamp;
|
||||||
|
double delta = timeStamp - timeBase;
|
||||||
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
|
sky.Picture picture = paint(paintBounds, delta);
|
||||||
|
sky.Scene scene = composite(picture, paintBounds);
|
||||||
|
sky.view.scene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void handleImageLoad(result) {
|
void handleImageLoad(result) {
|
||||||
if (result != image) {
|
if (result != image) {
|
||||||
print("${result.width}x${result.width} image loaded!");
|
print("${result.width}x${result.width} image loaded!");
|
||||||
image = result;
|
image = result;
|
||||||
view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
} else {
|
} else {
|
||||||
print("Existing image was loaded again");
|
print("Existing image was loaded again");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handleEvent(Event event) {
|
bool handleEvent(sky.Event event) {
|
||||||
if (event.type == "pointerdown") {
|
if (event.type == "pointerdown") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -70,6 +90,6 @@ bool handleEvent(Event event) {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
image_cache.load(url1).first.then(handleImageLoad);
|
image_cache.load(url1).first.then(handleImageLoad);
|
||||||
view.setEventCallback(handleEvent);
|
sky.view.setEventCallback(handleEvent);
|
||||||
view.setFrameCallback(beginFrame);
|
sky.view.setFrameCallback(beginFrame);
|
||||||
}
|
}
|
||||||
|
@ -2,30 +2,44 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'dart:sky';
|
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
import 'dart:sky' as sky;
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
double timeBase = null;
|
double timeBase = null;
|
||||||
|
|
||||||
void beginFrame(double timeStamp) {
|
void beginFrame(double timeStamp) {
|
||||||
tracing.begin('beginFrame');
|
sky.tracing.begin('beginFrame');
|
||||||
if (timeBase == null)
|
if (timeBase == null)
|
||||||
timeBase = timeStamp;
|
timeBase = timeStamp;
|
||||||
double delta = timeStamp - timeBase;
|
double delta = timeStamp - timeBase;
|
||||||
PictureRecorder recorder = new PictureRecorder();
|
|
||||||
final double devicePixelRatio = view.devicePixelRatio;
|
// paint
|
||||||
Canvas canvas = new Canvas(recorder, new Rect.fromLTWH(0.0, 0.0, view.width * devicePixelRatio, view.height * devicePixelRatio));
|
sky.Rect paintBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width, sky.view.height);
|
||||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
sky.PictureRecorder recorder = new sky.PictureRecorder();
|
||||||
canvas.translate(view.width / 2.0, view.height / 2.0);
|
sky.Canvas canvas = new sky.Canvas(recorder, paintBounds);
|
||||||
|
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||||
canvas.rotate(math.PI * delta / 1800);
|
canvas.rotate(math.PI * delta / 1800);
|
||||||
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
canvas.drawRect(new sky.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
|
||||||
new Paint()..color = const Color.fromARGB(255, 0, 255, 0));
|
new sky.Paint()..color = const sky.Color.fromARGB(255, 0, 255, 0));
|
||||||
view.picture = recorder.endRecording();
|
sky.Picture picture = recorder.endRecording();
|
||||||
view.scheduleFrame();
|
|
||||||
tracing.end('beginFrame');
|
// composite
|
||||||
|
final double devicePixelRatio = sky.view.devicePixelRatio;
|
||||||
|
sky.Rect sceneBounds = new sky.Rect.fromLTWH(0.0, 0.0, sky.view.width * devicePixelRatio, sky.view.height * devicePixelRatio);
|
||||||
|
Float32List deviceTransform = new Float32List(16)
|
||||||
|
..[0] = devicePixelRatio
|
||||||
|
..[5] = devicePixelRatio;
|
||||||
|
sky.SceneBuilder sceneBuilder = new sky.SceneBuilder(sceneBounds)
|
||||||
|
..pushTransform(deviceTransform)
|
||||||
|
..addPicture(sky.Offset.zero, picture, paintBounds)
|
||||||
|
..pop();
|
||||||
|
sky.view.scene = sceneBuilder.build();
|
||||||
|
|
||||||
|
sky.tracing.end('beginFrame');
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
view.setFrameCallback(beginFrame);
|
sky.view.setFrameCallback(beginFrame);
|
||||||
view.scheduleFrame();
|
sky.view.scheduleFrame();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import 'package:sky/src/widgets/icon.dart';
|
|||||||
import 'package:sky/src/widgets/ink_well.dart';
|
import 'package:sky/src/widgets/ink_well.dart';
|
||||||
import 'package:sky/src/widgets/theme.dart';
|
import 'package:sky/src/widgets/theme.dart';
|
||||||
|
|
||||||
typedef EventDisposition OnPressedFunction();
|
typedef void OnPressedFunction();
|
||||||
|
|
||||||
class DrawerItem extends ButtonBase {
|
class DrawerItem extends ButtonBase {
|
||||||
DrawerItem({ Key key, this.icon, this.child, this.onPressed, this.selected: false })
|
DrawerItem({ Key key, this.icon, this.child, this.onPressed, this.selected: false })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user