mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Update examples for window.physicalSize (#3086)
Now the engine always gives values in physical pixels.
This commit is contained in:
parent
fcdbe8b001
commit
31161a9568
@ -9,15 +9,15 @@ 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 physicalSize = ui.window.physicalSize;
|
||||
final ui.Size logicalSize = physicalSize / devicePixelRatio;
|
||||
|
||||
final ui.ParagraphBuilder paragraphBuilder = new ui.ParagraphBuilder()
|
||||
..addText('Hello, world.');
|
||||
final ui.Paragraph paragraph = paragraphBuilder.build(new ui.ParagraphStyle())
|
||||
..layout(new ui.ParagraphConstraints(width: logicalSize.width));
|
||||
|
||||
final ui.Rect physicalBounds = ui.Point.origin & (logicalSize * devicePixelRatio);
|
||||
final ui.Rect physicalBounds = ui.Point.origin & physicalSize;
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, physicalBounds);
|
||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
||||
|
||||
@ -17,31 +17,32 @@ void beginFrame(Duration timeStamp) {
|
||||
// system clock independently, the animations that we processed later would be
|
||||
// slightly ahead of the animations we processed earlier.
|
||||
|
||||
// PAINT
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
|
||||
ui.Rect paintBounds = ui.Point.origin & ui.window.size;
|
||||
ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
// PAINT
|
||||
final ui.Size logicalSize = ui.window.physicalSize / devicePixelRatio;
|
||||
final ui.Rect paintBounds = ui.Point.origin & logicalSize;
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, paintBounds);
|
||||
canvas.translate(paintBounds.width / 2.0, paintBounds.height / 2.0);
|
||||
|
||||
// Here we determine the rotation according to the timeStamp given to us by
|
||||
// the engine.
|
||||
double t = timeStamp.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND / 1800.0;
|
||||
final double t = timeStamp.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND / 1800.0;
|
||||
canvas.rotate(math.PI * (t % 1.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));
|
||||
ui.Picture picture = recorder.endRecording();
|
||||
final ui.Picture picture = recorder.endRecording();
|
||||
|
||||
// COMPOSITE
|
||||
|
||||
final double devicePixelRatio = ui.window.devicePixelRatio;
|
||||
Float64List deviceTransform = new Float64List(16)
|
||||
final Float64List deviceTransform = new Float64List(16)
|
||||
..[0] = devicePixelRatio
|
||||
..[5] = devicePixelRatio
|
||||
..[10] = 1.0
|
||||
..[15] = 1.0;
|
||||
ui.SceneBuilder sceneBuilder = new ui.SceneBuilder()
|
||||
final ui.SceneBuilder sceneBuilder = new ui.SceneBuilder()
|
||||
..pushTransform(deviceTransform)
|
||||
..addPicture(ui.Offset.zero, picture)
|
||||
..pop();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user