Commit bc1b47e9 authored by Adam Barth's avatar Adam Barth

Merge pull request #755 from abarth/rm_painting_canvas

Remove PaintingCanvas
parents 5a17c2bc abf03595
...@@ -139,7 +139,7 @@ abstract class RenderDecoratedSector extends RenderSector { ...@@ -139,7 +139,7 @@ abstract class RenderDecoratedSector extends RenderSector {
return; return;
if (_decoration.backgroundColor != null) { if (_decoration.backgroundColor != null) {
final PaintingCanvas canvas = context.canvas; final Canvas canvas = context.canvas;
Paint paint = new Paint()..color = _decoration.backgroundColor; Paint paint = new Paint()..color = _decoration.backgroundColor;
Path path = new Path(); Path path = new Path();
double outerRadius = (parentData.radius + deltaRadius); double outerRadius = (parentData.radius + deltaRadius);
......
...@@ -62,7 +62,7 @@ class RenderTouchDemo extends RenderBox { ...@@ -62,7 +62,7 @@ class RenderTouchDemo extends RenderBox {
} }
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas; final Canvas canvas = context.canvas;
Paint white = new Paint() Paint white = new Paint()
..color = const Color(0xFFFFFFFF); ..color = const Color(0xFFFFFFFF);
canvas.drawRect(offset & size, white); canvas.drawRect(offset & size, white);
......
...@@ -10,7 +10,7 @@ class StockArrowPainter extends CustomPainter { ...@@ -10,7 +10,7 @@ class StockArrowPainter extends CustomPainter {
final Color color; final Color color;
final double percentChange; final double percentChange;
void paint(PaintingCanvas canvas, Size size) { void paint(Canvas canvas, Size size) {
Paint paint = new Paint()..color = color; Paint paint = new Paint()..color = color;
paint.strokeWidth = 1.0; paint.strokeWidth = 1.0;
const double padding = 2.0; const double padding = 2.0;
......
...@@ -30,7 +30,7 @@ class _GesturePainter extends CustomPainter { ...@@ -30,7 +30,7 @@ class _GesturePainter extends CustomPainter {
final bool doubleTapEnabled; final bool doubleTapEnabled;
final bool longPressEnabled; final bool longPressEnabled;
void paint(PaintingCanvas canvas, Size size) { void paint(Canvas canvas, Size size) {
Point center = (size.center(Point.origin).toOffset() * zoom + offset).toPoint(); Point center = (size.center(Point.origin).toOffset() * zoom + offset).toPoint();
double radius = size.width / 2.0 * zoom; double radius = size.width / 2.0 * zoom;
Gradient gradient = new RadialGradient( Gradient gradient = new RadialGradient(
......
...@@ -28,7 +28,7 @@ class _MarkerPainter extends CustomPainter { ...@@ -28,7 +28,7 @@ class _MarkerPainter extends CustomPainter {
final double size; final double size;
final MarkerType type; final MarkerType type;
void paint(PaintingCanvas canvas, _) { void paint(Canvas canvas, _) {
Paint paint = new Paint()..color = const Color(0x8000FF00); Paint paint = new Paint()..color = const Color(0x8000FF00);
double r = size / 2.0; double r = size / 2.0;
canvas.drawCircle(new Point(r, r), r, paint); canvas.drawCircle(new Point(r, r), r, paint);
......
...@@ -173,7 +173,7 @@ class _RenderSwitch extends RenderToggleable { ...@@ -173,7 +173,7 @@ class _RenderSwitch extends RenderToggleable {
final BoxPainter _thumbPainter = new BoxPainter(const BoxDecoration()); final BoxPainter _thumbPainter = new BoxPainter(const BoxDecoration());
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas; final Canvas canvas = context.canvas;
final bool isActive = onChanged != null; final bool isActive = onChanged != null;
......
...@@ -209,7 +209,7 @@ class _RenderTabBar extends RenderBox with ...@@ -209,7 +209,7 @@ class _RenderTabBar extends RenderBox with
return defaultHitTestChildren(result, position: position); return defaultHitTestChildren(result, position: position);
} }
void _paintIndicator(PaintingCanvas canvas, RenderBox selectedTab, Offset offset) { void _paintIndicator(Canvas canvas, RenderBox selectedTab, Offset offset) {
if (indicatorColor == null) if (indicatorColor == null)
return; return;
......
...@@ -38,12 +38,6 @@ class ParentData { ...@@ -38,12 +38,6 @@ class ParentData {
String toString() => '<none>'; String toString() => '<none>';
} }
/// Obsolete class that will be removed eventually
class PaintingCanvas extends Canvas {
PaintingCanvas(ui.PictureRecorder recorder, Rect bounds) : super(recorder, bounds);
// TODO(ianh): Just use ui.Canvas everywhere instead
}
typedef void PaintingContextCallback(PaintingContext context, Offset offset); typedef void PaintingContextCallback(PaintingContext context, Offset offset);
/// A place to paint. /// A place to paint.
...@@ -145,14 +139,14 @@ class PaintingContext { ...@@ -145,14 +139,14 @@ class PaintingContext {
// Recording state // Recording state
PictureLayer _currentLayer; PictureLayer _currentLayer;
ui.PictureRecorder _recorder; ui.PictureRecorder _recorder;
PaintingCanvas _canvas; Canvas _canvas;
/// The canvas on which to paint. /// The canvas on which to paint.
/// ///
/// The current canvas can change whenever you paint a child using this /// The current canvas can change whenever you paint a child using this
/// context, which means it's fragile to hold a reference to the canvas /// context, which means it's fragile to hold a reference to the canvas
/// returned by this getter. /// returned by this getter.
PaintingCanvas get canvas { Canvas get canvas {
if (_canvas == null) if (_canvas == null)
_startRecording(); _startRecording();
return _canvas; return _canvas;
...@@ -162,7 +156,7 @@ class PaintingContext { ...@@ -162,7 +156,7 @@ class PaintingContext {
assert(!_isRecording); assert(!_isRecording);
_currentLayer = new PictureLayer(paintBounds: _paintBounds); _currentLayer = new PictureLayer(paintBounds: _paintBounds);
_recorder = new ui.PictureRecorder(); _recorder = new ui.PictureRecorder();
_canvas = new PaintingCanvas(_recorder, _paintBounds); _canvas = new Canvas(_recorder, _paintBounds);
_containerLayer.append(_currentLayer); _containerLayer.append(_currentLayer);
} }
......
...@@ -991,7 +991,7 @@ class RenderSizeObserver extends RenderProxyBox { ...@@ -991,7 +991,7 @@ class RenderSizeObserver extends RenderProxyBox {
abstract class CustomPainter { abstract class CustomPainter {
const CustomPainter(); const CustomPainter();
void paint(PaintingCanvas canvas, Size size); void paint(Canvas canvas, Size size);
bool shouldRepaint(CustomPainter oldDelegate); bool shouldRepaint(CustomPainter oldDelegate);
bool hitTest(Point position) => null; bool hitTest(Point position) => null;
} }
......
...@@ -121,7 +121,7 @@ class EffectLine extends Node { ...@@ -121,7 +121,7 @@ class EffectLine extends Node {
} }
} }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
if (points.length < 2) return; if (points.length < 2) return;
_painter.points = points; _painter.points = points;
......
...@@ -33,7 +33,7 @@ class Label extends Node { ...@@ -33,7 +33,7 @@ class Label extends Node {
TextPainter _painter; TextPainter _painter;
double _width; double _width;
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
if (_painter == null) { if (_painter == null) {
PlainTextSpan textSpan = new PlainTextSpan(_text); PlainTextSpan textSpan = new PlainTextSpan(_text);
StyledTextSpan styledTextSpan = new StyledTextSpan(_textStyle, <TextSpan>[textSpan]); StyledTextSpan styledTextSpan = new StyledTextSpan(_textStyle, <TextSpan>[textSpan]);
......
...@@ -25,14 +25,14 @@ class Layer extends Node with SpritePaint { ...@@ -25,14 +25,14 @@ class Layer extends Node with SpritePaint {
..filterQuality = ui.FilterQuality.low ..filterQuality = ui.FilterQuality.low
..isAntiAlias = false; ..isAntiAlias = false;
void _prePaint(PaintingCanvas canvas, Matrix4 matrix) { void _prePaint(Canvas canvas, Matrix4 matrix) {
super._prePaint(canvas, matrix); super._prePaint(canvas, matrix);
_updatePaint(_cachedPaint); _updatePaint(_cachedPaint);
canvas.saveLayer(layerRect, _cachedPaint); canvas.saveLayer(layerRect, _cachedPaint);
} }
void _postPaint(PaintingCanvas canvas, Matrix4 totalMatrix) { void _postPaint(Canvas canvas, Matrix4 totalMatrix) {
canvas.restore(); canvas.restore();
super._postPaint(canvas, totalMatrix); super._postPaint(canvas, totalMatrix);
} }
......
...@@ -648,7 +648,7 @@ class Node { ...@@ -648,7 +648,7 @@ class Node {
// Rendering // Rendering
void _visit(PaintingCanvas canvas, Matrix4 totalMatrix) { void _visit(Canvas canvas, Matrix4 totalMatrix) {
assert(canvas != null); assert(canvas != null);
if (!visible) return; if (!visible) return;
...@@ -657,7 +657,7 @@ class Node { ...@@ -657,7 +657,7 @@ class Node {
_postPaint(canvas, totalMatrix); _postPaint(canvas, totalMatrix);
} }
void _prePaint(PaintingCanvas canvas, Matrix4 matrix) { void _prePaint(Canvas canvas, Matrix4 matrix) {
_savedTotalMatrix = new Matrix4.copy(matrix); _savedTotalMatrix = new Matrix4.copy(matrix);
// Get the transformation matrix and apply transform // Get the transformation matrix and apply transform
...@@ -672,7 +672,7 @@ class Node { ...@@ -672,7 +672,7 @@ class Node {
/// bounding box's origin, override [NodeWithSize] and call the applyTransformForPivot method before making calls for /// bounding box's origin, override [NodeWithSize] and call the applyTransformForPivot method before making calls for
/// drawing. /// drawing.
/// ///
/// void paint(PaintingCanvas canvas) { /// void paint(Canvas canvas) {
/// canvas.save(); /// canvas.save();
/// applyTransformForPivot(canvas); /// applyTransformForPivot(canvas);
/// ///
...@@ -680,10 +680,10 @@ class Node { ...@@ -680,10 +680,10 @@ class Node {
/// ///
/// canvas.restore(); /// canvas.restore();
/// } /// }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
} }
void _visitChildren(PaintingCanvas canvas, Matrix4 totalMatrix) { void _visitChildren(Canvas canvas, Matrix4 totalMatrix) {
// Sort children if needed // Sort children if needed
_sortChildren(); _sortChildren();
...@@ -709,7 +709,7 @@ class Node { ...@@ -709,7 +709,7 @@ class Node {
} }
} }
void _postPaint(PaintingCanvas canvas, Matrix4 totalMatrix) { void _postPaint(Canvas canvas, Matrix4 totalMatrix) {
totalMatrix.setFrom(_savedTotalMatrix); totalMatrix.setFrom(_savedTotalMatrix);
} }
......
...@@ -33,7 +33,7 @@ class NodeWithSize extends Node { ...@@ -33,7 +33,7 @@ class NodeWithSize extends Node {
/// If you use this method you will need to save and restore your canvas at the beginning and /// If you use this method you will need to save and restore your canvas at the beginning and
/// end of your [paint] method. /// end of your [paint] method.
/// ///
/// void paint(PaintingCanvas canvas) { /// void paint(Canvas canvas) {
/// canvas.save(); /// canvas.save();
/// applyTransformForPivot(canvas); /// applyTransformForPivot(canvas);
/// ///
...@@ -41,7 +41,7 @@ class NodeWithSize extends Node { ...@@ -41,7 +41,7 @@ class NodeWithSize extends Node {
/// ///
/// canvas.restore(); /// canvas.restore();
/// } /// }
void applyTransformForPivot(PaintingCanvas canvas) { void applyTransformForPivot(Canvas canvas) {
if (pivot.x != 0 || pivot.y != 0) { if (pivot.x != 0 || pivot.y != 0) {
double pivotInPointsX = size.width * pivot.x; double pivotInPointsX = size.width * pivot.x;
double pivotInPointsY = size.height * pivot.y; double pivotInPointsY = size.height * pivot.y;
......
...@@ -357,7 +357,7 @@ class ParticleSystem extends Node { ...@@ -357,7 +357,7 @@ class ParticleSystem extends Node {
_numEmittedParticles++; _numEmittedParticles++;
} }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
List<ui.RSTransform> transforms = <ui.RSTransform>[]; List<ui.RSTransform> transforms = <ui.RSTransform>[];
List<Rect> rects = <Rect>[]; List<Rect> rects = <Rect>[];
......
...@@ -14,7 +14,7 @@ class _PhysicsDebugDraw extends box2d.DebugDraw { ...@@ -14,7 +14,7 @@ class _PhysicsDebugDraw extends box2d.DebugDraw {
PhysicsWorld physicsWorld; PhysicsWorld physicsWorld;
PaintingCanvas canvas; Canvas canvas;
void drawSegment(Vector2 p1, Vector2 p2, box2d.Color3i color) { void drawSegment(Vector2 p1, Vector2 p2, box2d.Color3i color) {
Paint paint = new Paint() Paint paint = new Paint()
......
...@@ -267,7 +267,7 @@ class PhysicsWorld extends Node { ...@@ -267,7 +267,7 @@ class PhysicsWorld extends Node {
_contactHandler.addContactCallback(callback, tagA, tagB, type); _contactHandler.addContactCallback(callback, tagA, tagB, type);
} }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
if (drawDebug) { if (drawDebug) {
_debugDrawTransform = new Matrix4.fromFloat64List(canvas.getTotalMatrix()); _debugDrawTransform = new Matrix4.fromFloat64List(canvas.getTotalMatrix());
} }
...@@ -276,7 +276,7 @@ class PhysicsWorld extends Node { ...@@ -276,7 +276,7 @@ class PhysicsWorld extends Node {
/// Draws the debug data of the physics world, normally this method isn't /// Draws the debug data of the physics world, normally this method isn't
/// invoked directly. Instead, set the [drawDebug] property to true. /// invoked directly. Instead, set the [drawDebug] property to true.
void paintDebug(PaintingCanvas canvas) { void paintDebug(Canvas canvas) {
_debugDraw.canvas = canvas; _debugDraw.canvas = canvas;
b2World.drawDebugData(); b2World.drawDebugData();
} }
......
...@@ -44,7 +44,7 @@ class Sprite extends NodeWithSize with SpritePaint { ...@@ -44,7 +44,7 @@ class Sprite extends NodeWithSize with SpritePaint {
pivot = new Point(0.5, 0.5); pivot = new Point(0.5, 0.5);
} }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
// Account for pivot point // Account for pivot point
applyTransformForPivot(canvas); applyTransformForPivot(canvas);
......
...@@ -336,7 +336,7 @@ class SpriteBox extends RenderBox { ...@@ -336,7 +336,7 @@ class SpriteBox extends RenderBox {
} }
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
final PaintingCanvas canvas = context.canvas; final Canvas canvas = context.canvas;
canvas.save(); canvas.save();
// Move to correct coordinate space before drawing // Move to correct coordinate space before drawing
......
...@@ -73,7 +73,7 @@ class Texture { ...@@ -73,7 +73,7 @@ class Texture {
return new Texture._fromSpriteFrame(image, name, rect.size, false, false, srcFrame, dstFrame, new Point(0.5, 0.5)); return new Texture._fromSpriteFrame(image, name, rect.size, false, false, srcFrame, dstFrame, new Point(0.5, 0.5));
} }
void drawTexture(PaintingCanvas canvas, Point position, Paint paint) { void drawTexture(Canvas canvas, Point position, Paint paint) {
// Get drawing position // Get drawing position
double x = position.x; double x = position.x;
double y = position.y; double y = position.y;
......
...@@ -7,7 +7,7 @@ class TexturedLine extends Node { ...@@ -7,7 +7,7 @@ class TexturedLine extends Node {
TexturedLinePainter painter; TexturedLinePainter painter;
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
painter.paint(canvas); painter.paint(canvas);
} }
} }
...@@ -81,7 +81,7 @@ class TexturedLinePainter { ...@@ -81,7 +81,7 @@ class TexturedLinePainter {
Paint _cachedPaint = new Paint(); Paint _cachedPaint = new Paint();
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
// Check input values // Check input values
assert(_points != null); assert(_points != null);
if (_points.length < 2) return; if (_points.length < 2) return;
......
...@@ -54,7 +54,7 @@ class VirtualJoystick extends NodeWithSize { ...@@ -54,7 +54,7 @@ class VirtualJoystick extends NodeWithSize {
return true; return true;
} }
void paint(PaintingCanvas canvas) { void paint(Canvas canvas) {
applyTransformForPivot(canvas); applyTransformForPivot(canvas);
canvas.drawCircle(_handlePos, 25.0, _paintHandle); canvas.drawCircle(_handlePos, 25.0, _paintHandle);
canvas.drawCircle(_center, 40.0, _paintControl); canvas.drawCircle(_center, 40.0, _paintControl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment