forked from firka/flutter
Move Point to Offset (#9277)
* Manually fix every use of Point.x and Point.y
Some of these were moved to dx/dy, but not all.
* Manually convert uses of the old gradient API
* Remove old reference to Point.
* Mechanical changes
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]origin\b/Offset.zero/g'
git ls-files -z | xargs -0 sed -i 's/\bPoint[.]lerp\b/Offset.lerp/g'
git ls-files -z | xargs -0 sed -i 's/\bnew Point\b/new Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bconst Point\b/const Offset/g'
git ls-files -z | xargs -0 sed -i 's/\bstatic Point /static Offset /g'
git ls-files -z | xargs -0 sed -i 's/\bfinal Point /final Offset /g'
git ls-files -z | xargs -0 sed -i 's/^\( *\)Point /\1Offset /g'
git ls-files -z | xargs -0 sed -i 's/ui[.]Point\b/ui.Offset/g'
git ls-files -z | xargs -0 sed -i 's/(Point\b/(Offset/g'
git ls-files -z | xargs -0 sed -i 's/\([[{,]\) Point\b/\1 Offset/g'
git ls-files -z | xargs -0 sed -i 's/@required Point\b/@required Offset/g'
git ls-files -z | xargs -0 sed -i 's/<Point>/<Offset>/g'
git ls-files -z | xargs -0 sed -i 's/[.]toOffset()//g'
git ls-files -z | xargs -0 sed -i 's/[.]toPoint()//g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point, /show /g'
git ls-files -z | xargs -0 sed -i 's/\bshow Point;/show Offset;/g'
* Mechanical changes - dartdocs
I applied the following at the root of the Flutter repository:
git ls-files -z | xargs -0 sed -i 's/\ba \[Point\]/an [Offset]/g'
git ls-files -z | xargs -0 sed -i 's/\[Point\]/[Offset]/g'
* Further improvements and a test
* Fix minor errors from rebasing...
* Roll engine
This commit is contained in:
@@ -26,24 +26,24 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
canvas.drawPaint(new ui.Paint()..color = const ui.Color(0xFFFFFFFF));
|
||||
|
||||
final ui.Size size = paintBounds.size;
|
||||
final ui.Point mid = size.center(ui.Point.origin);
|
||||
final ui.Offset mid = size.center(ui.Offset.zero);
|
||||
final 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, logicalSize.height*2.0);
|
||||
canvas.clipRect(
|
||||
new ui.Rect.fromLTRB(0.0, -logicalSize.height, logicalSize.width, radius));
|
||||
canvas.translate(-mid.dx / 2.0, logicalSize.height * 2.0);
|
||||
canvas.clipRect(new ui.Rect.fromLTRB(0.0, -logicalSize.height, logicalSize.width, radius));
|
||||
|
||||
canvas.translate(mid.x, mid.y);
|
||||
canvas.translate(mid.dx, mid.dy);
|
||||
paint.color = const ui.Color.fromARGB(128, 255, 0, 255);
|
||||
canvas.rotate(math.PI/4.0);
|
||||
|
||||
final ui.Gradient yellowBlue = new ui.Gradient.linear(
|
||||
<ui.Point>[new ui.Point(-radius, -radius), const ui.Point(0.0, 0.0)],
|
||||
<ui.Color>[const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)]
|
||||
new ui.Offset(-radius, -radius),
|
||||
const ui.Offset(0.0, 0.0),
|
||||
<ui.Color>[const ui.Color(0xFFFFFF00), const ui.Color(0xFF0000FF)],
|
||||
);
|
||||
canvas.drawRect(new ui.Rect.fromLTRB(-radius, -radius, radius, radius),
|
||||
new ui.Paint()..shader = yellowBlue);
|
||||
@@ -57,11 +57,11 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
]);
|
||||
canvas.transform(scaleMatrix);
|
||||
paint.color = const ui.Color.fromARGB(128, 0, 255, 0);
|
||||
canvas.drawCircle(ui.Point.origin, radius, paint);
|
||||
canvas.drawCircle(ui.Offset.zero, radius, paint);
|
||||
canvas.restore();
|
||||
|
||||
paint.color = const ui.Color.fromARGB(128, 255, 0, 0);
|
||||
canvas.drawCircle(const ui.Point(150.0, 300.0), radius, paint);
|
||||
canvas.drawCircle(const ui.Offset(150.0, 300.0), radius, paint);
|
||||
|
||||
// When we're done issuing painting commands, we end the recording an receive
|
||||
// a Picture, which is an immutable record of the commands we've issued. You
|
||||
@@ -85,7 +85,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
final ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Picture picture = paint(paintBounds);
|
||||
final ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
|
||||
@@ -16,7 +16,7 @@ void beginFrame(Duration timeStamp) {
|
||||
final ui.Paragraph paragraph = paragraphBuilder.build()
|
||||
..layout(new ui.ParagraphConstraints(width: logicalSize.width));
|
||||
|
||||
final ui.Rect physicalBounds = ui.Point.origin & (logicalSize * devicePixelRatio);
|
||||
final ui.Rect physicalBounds = ui.Offset.zero & (logicalSize * devicePixelRatio);
|
||||
final ui.PictureRecorder recorder = new ui.PictureRecorder();
|
||||
final ui.Canvas canvas = new ui.Canvas(recorder, physicalBounds);
|
||||
canvas.scale(devicePixelRatio, devicePixelRatio);
|
||||
|
||||
@@ -19,7 +19,7 @@ void beginFrame(Duration timeStamp) {
|
||||
|
||||
// PAINT
|
||||
|
||||
final ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
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);
|
||||
|
||||
@@ -44,7 +44,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
final ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Picture picture = paint(paintBounds);
|
||||
final ui.Scene scene = composite(picture, paintBounds);
|
||||
ui.window.render(scene);
|
||||
|
||||
@@ -26,7 +26,7 @@ ui.Picture paint(ui.Rect paintBounds) {
|
||||
// The commands draw a circle in the center of the screen.
|
||||
final ui.Size size = paintBounds.size;
|
||||
canvas.drawCircle(
|
||||
size.center(ui.Point.origin),
|
||||
size.center(ui.Offset.zero),
|
||||
size.shortestSide * 0.45,
|
||||
new ui.Paint()..color = color
|
||||
);
|
||||
@@ -67,7 +67,7 @@ ui.Scene composite(ui.Picture picture, ui.Rect paintBounds) {
|
||||
}
|
||||
|
||||
void beginFrame(Duration timeStamp) {
|
||||
final ui.Rect paintBounds = ui.Point.origin & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
final ui.Rect paintBounds = ui.Offset.zero & (ui.window.physicalSize / ui.window.devicePixelRatio);
|
||||
// First, record a picture with our painting commands.
|
||||
final ui.Picture picture = paint(paintBounds);
|
||||
// Second, include that picture in a scene graph.
|
||||
|
||||
@@ -525,22 +525,22 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
if (child != null) {
|
||||
final Rect bounds = offset & size;
|
||||
// we move the offset to the center of the circle for the RenderSectors
|
||||
context.paintChild(child, bounds.center.toOffset());
|
||||
context.paintChild(child, bounds.center);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool hitTest(HitTestResult result, { Point position }) {
|
||||
bool hitTest(HitTestResult result, { Offset position }) {
|
||||
if (child == null)
|
||||
return false;
|
||||
double x = position.x;
|
||||
double y = position.y;
|
||||
double x = position.dx;
|
||||
double y = position.dy;
|
||||
// translate to our origin
|
||||
x -= size.width/2.0;
|
||||
y -= size.height/2.0;
|
||||
x -= size.width / 2.0;
|
||||
y -= size.height / 2.0;
|
||||
// convert to radius/theta
|
||||
final double radius = math.sqrt(x*x+y*y);
|
||||
final double theta = (math.atan2(x, -y) - math.PI/2.0) % kTwoPi;
|
||||
final double radius = math.sqrt(x * x + y * y);
|
||||
final double theta = (math.atan2(x, -y) - math.PI / 2.0) % kTwoPi;
|
||||
if (radius < innerRadius)
|
||||
return false;
|
||||
if (radius >= innerRadius + child.deltaRadius)
|
||||
|
||||
@@ -23,7 +23,7 @@ class Dot {
|
||||
Dot({ Color color }) : _paint = new Paint()..color = color;
|
||||
|
||||
final Paint _paint;
|
||||
Point position = Point.origin;
|
||||
Offset position = Offset.zero;
|
||||
double radius = 0.0;
|
||||
|
||||
void update(PointerEvent event) {
|
||||
@@ -58,7 +58,7 @@ class RenderDots extends RenderBox {
|
||||
|
||||
/// Makes this render object hittable so that it receives pointer events.
|
||||
@override
|
||||
bool hitTestSelf(Point position) => true;
|
||||
bool hitTestSelf(Offset position) => true;
|
||||
|
||||
/// Processes pointer events by mutating state and invalidating its previous
|
||||
/// painting commands.
|
||||
|
||||
@@ -10,9 +10,9 @@ class RenderDots extends RenderConstrainedBox {
|
||||
|
||||
// Makes this render box hittable so that we'll get pointer events.
|
||||
@override
|
||||
bool hitTestSelf(Point position) => true;
|
||||
bool hitTestSelf(Offset position) => true;
|
||||
|
||||
final Map<int, Point> _dots = <int, Point>{};
|
||||
final Map<int, Offset> _dots = <int, Offset>{};
|
||||
|
||||
@override
|
||||
void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
|
||||
@@ -31,7 +31,7 @@ class RenderDots extends RenderConstrainedBox {
|
||||
canvas.drawRect(offset & size, new Paint()..color = const Color(0xFF0000FF));
|
||||
|
||||
final Paint paint = new Paint()..color = const Color(0xFF00FF00);
|
||||
for (Point point in _dots.values)
|
||||
for (Offset point in _dots.values)
|
||||
canvas.drawCircle(point, 50.0, paint);
|
||||
|
||||
super.paint(context, offset);
|
||||
|
||||
@@ -27,18 +27,16 @@ class _GesturePainter extends CustomPainter {
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final Point center = (size.center(Point.origin).toOffset() * zoom + offset).toPoint();
|
||||
final Offset center = (size.center(Offset.zero) * zoom + offset);
|
||||
final double radius = size.width / 2.0 * zoom;
|
||||
final Gradient gradient = new RadialGradient(
|
||||
colors: forward ? <Color>[swatch.shade50, swatch.shade900]
|
||||
: <Color>[swatch.shade900, swatch.shade50]
|
||||
);
|
||||
final Paint paint = new Paint()
|
||||
..shader = gradient.createShader(new Rect.fromLTWH(
|
||||
center.x - radius,
|
||||
center.y - radius,
|
||||
radius * 2.0,
|
||||
radius * 2.0
|
||||
..shader = gradient.createShader(new Rect.fromCircle(
|
||||
center: center,
|
||||
radius: radius,
|
||||
));
|
||||
canvas.drawCircle(center, radius, paint);
|
||||
}
|
||||
@@ -63,7 +61,7 @@ class GestureDemo extends StatefulWidget {
|
||||
|
||||
class _GestureDemoState extends State<GestureDemo> {
|
||||
|
||||
Point _startingFocalPoint;
|
||||
Offset _startingFocalPoint;
|
||||
|
||||
Offset _previousOffset;
|
||||
Offset _offset = Offset.zero;
|
||||
@@ -92,8 +90,8 @@ class _GestureDemoState extends State<GestureDemo> {
|
||||
_zoom = (_previousZoom * details.scale);
|
||||
|
||||
// Ensure that item under the focal point stays in the same place despite zooming
|
||||
final Offset normalizedOffset = (_startingFocalPoint.toOffset() - _previousOffset) / _previousZoom;
|
||||
_offset = details.focalPoint.toOffset() - normalizedOffset * _zoom;
|
||||
final Offset normalizedOffset = (_startingFocalPoint - _previousOffset) / _previousZoom;
|
||||
_offset = details.focalPoint - normalizedOffset * _zoom;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user