Update framework to account from engine API changes (#5887)

The engine now reports coordinates in physical pixels.
This commit is contained in:
Adam Barth
2016-09-15 13:13:42 -07:00
committed by GitHub
parent 9109bb02b9
commit 179ea4a0a6
17 changed files with 41 additions and 32 deletions

View File

@@ -29,10 +29,13 @@ ui.Picture paint(ui.Rect paintBounds) {
ui.Point mid = size.center(ui.Point.origin);
double radius = size.shortestSide / 2.0;
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
canvas.save();
canvas.translate(-mid.x/2.0, ui.window.size.height*2.0);
canvas.translate(-mid.x/2.0, logicalSize.height*2.0);
canvas.clipRect(
new ui.Rect.fromLTRB(0.0, -ui.window.size.height, ui.window.size.width, radius));
new ui.Rect.fromLTRB(0.0, -logicalSize.height, logicalSize.width, radius));
canvas.translate(mid.x, mid.y);
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
@@ -82,7 +85,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
ui.Picture picture = paint(paintBounds);
ui.Scene scene = composite(picture, paintBounds);
ui.window.render(scene);

View File

@@ -9,8 +9,7 @@ import 'dart:ui' as ui;
void beginFrame(Duration timeStamp) {
final double devicePixelRatio = ui.window.devicePixelRatio;
// TODO(abarth): ui.window.size should be in physical units.
final ui.Size logicalSize = ui.window.size;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder()
..addText('Hello, world.');

View File

@@ -19,7 +19,7 @@ void beginFrame(Duration timeStamp) {
// PAINT
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
ui.PictureRecorder recorder = new ui.PictureRecorder();
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);

View File

@@ -15,7 +15,10 @@ ui.Picture paint(ui.Rect paintBounds) {
ui.PictureRecorder recorder = new ui.PictureRecorder();
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
canvas.translate(ui.window.size.width / 2.0, ui.window.size.height / 2.0);
final double devicePixelRatio = ui.window.devicePixelRatio;
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
canvas.translate(logicalSize.width / 2.0, logicalSize.height / 2.0);
canvas.drawRect(new ui.Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
new ui.Paint()..color = const ui.Color.fromARGB(255, 0, 255, 0));
@@ -41,7 +44,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
ui.Picture picture = paint(paintBounds);
ui.Scene scene = composite(picture, paintBounds);
ui.window.render(scene);

View File

@@ -71,7 +71,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
}
void beginFrame(Duration timeStamp) {
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
// First, record a picture with our painting commands.
ui.Picture picture = paint(paintBounds);
// Second, include that picture in a scene graph.

View File

@@ -64,8 +64,8 @@ void main() {
expect(find.text('Account Balance'), findsNothing);
// drag the drawer out
Point left = new Point(0.0, ui.window.size.height / 2.0);
Point right = new Point(ui.window.size.width, left.y);
Point left = new Point(0.0, ui.window.physicalSize.height / 2.0);
Point right = new Point(ui.window.physicalSize.width, left.y);
TestGesture gesture = await tester.startGesture(left);
await tester.pump();
await gesture.moveTo(right);