|
|
|
|
|
|
using Unity.UIWidgets.gestures; |
|
|
|
using Unity.UIWidgets.rendering; |
|
|
|
using Unity.UIWidgets.ui; |
|
|
|
using UnityEngine; |
|
|
|
using Canvas = Unity.UIWidgets.ui.Canvas; |
|
|
|
public interface ICustomPainter : Listenable { |
|
|
|
public interface CustomPainter : Listenable { |
|
|
|
bool shouldRepaint(ICustomPainter oldDelegate); |
|
|
|
bool shouldRepaint(CustomPainter oldDelegate); |
|
|
|
|
|
|
|
public abstract class CustomPainter : ICustomPainter { |
|
|
|
public CustomPainter(Listenable repaint = null) { |
|
|
|
|
|
|
|
public abstract class AbstractCustomPainter : CustomPainter { |
|
|
|
public AbstractCustomPainter(Listenable repaint = null) { |
|
|
|
this._repaint = repaint; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract void paint(Canvas canvas, Size size); |
|
|
|
|
|
|
|
public abstract bool shouldRepaint(ICustomPainter oldDelegate); |
|
|
|
public abstract bool shouldRepaint(CustomPainter oldDelegate); |
|
|
|
|
|
|
|
public virtual bool hitTest(Offset position) { |
|
|
|
return true; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public class RenderCustomPaint : RenderProxyBox { |
|
|
|
|
|
|
|
ICustomPainter painter = null, |
|
|
|
ICustomPainter foregroundPainter = null, |
|
|
|
CustomPainter painter = null, |
|
|
|
CustomPainter foregroundPainter = null, |
|
|
|
): base(child) { |
|
|
|
) : base(child) { |
|
|
|
preferredSize = preferredSize ?? Size.zero; |
|
|
|
this.preferredSize = preferredSize; |
|
|
|
this._painter = painter; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ICustomPainter _painter; |
|
|
|
|
|
|
|
CustomPainter _painter; |
|
|
|
public ICustomPainter painter { |
|
|
|
get => this._painter; |
|
|
|
public CustomPainter painter { |
|
|
|
get { return this._painter; } |
|
|
|
if (this._painter == value) |
|
|
|
if (this._painter == value) { |
|
|
|
ICustomPainter oldPainter = this._painter; |
|
|
|
} |
|
|
|
|
|
|
|
CustomPainter oldPainter = this._painter; |
|
|
|
ICustomPainter _foregroundPainter; |
|
|
|
CustomPainter _foregroundPainter; |
|
|
|
public ICustomPainter foregroundPainter { |
|
|
|
get => this._foregroundPainter; |
|
|
|
public CustomPainter foregroundPainter { |
|
|
|
get { return this._foregroundPainter; } |
|
|
|
if (this._foregroundPainter == value) |
|
|
|
if (this._foregroundPainter == value) { |
|
|
|
ICustomPainter oldPainter = this._foregroundPainter; |
|
|
|
} |
|
|
|
|
|
|
|
CustomPainter oldPainter = this._foregroundPainter; |
|
|
|
void _didUpdatePainter(ICustomPainter newPainter, ICustomPainter oldPainter) { |
|
|
|
void _didUpdatePainter(CustomPainter newPainter, CustomPainter oldPainter) { |
|
|
|
if (newPainter == null) { |
|
|
|
D.assert(oldPainter != null); |
|
|
|
this.markNeedsPaint(); |
|
|
|
|
|
|
Size _preferredSize; |
|
|
|
|
|
|
|
public Size preferredSize { |
|
|
|
get => this._preferredSize; |
|
|
|
get { return this._preferredSize; } |
|
|
|
if (this.preferredSize == value) |
|
|
|
if (this.preferredSize == value) { |
|
|
|
} |
|
|
|
|
|
|
|
this._preferredSize = value; |
|
|
|
this.markNeedsLayout(); |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
protected override bool hitTestChildren(HitTestResult result, Offset position) { |
|
|
|
if (this._foregroundPainter != null && (this._foregroundPainter.hitTest(position))) |
|
|
|
if (this._foregroundPainter != null && (this._foregroundPainter.hitTest(position))) { |
|
|
|
} |
|
|
|
|
|
|
|
return base.hitTestChildren(result, position: position); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
this.size = this.constraints.constrain(this.preferredSize); |
|
|
|
} |
|
|
|
|
|
|
|
void _paintWithPainter(Canvas canvas, Offset offset, ICustomPainter painter) { |
|
|
|
void _paintWithPainter(Canvas canvas, Offset offset, CustomPainter painter) { |
|
|
|
int debugPreviousCanvasSaveCount = 0; |
|
|
|
canvas.save(); |
|
|
|
D.assert(() => { |
|
|
|
|
|
|
if (offset != Offset.zero) |
|
|
|
if (offset != Offset.zero) { |
|
|
|
} |
|
|
|
|
|
|
|
if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount) |
|
|
|
if (debugNewCanvasSaveCount > debugPreviousCanvasSaveCount) { |
|
|
|
throw new UIWidgetsError( |
|
|
|
$"{debugNewCanvasSaveCount - debugPreviousCanvasSaveCount} more " + |
|
|
|
$"time{((debugNewCanvasSaveCount - debugPreviousCanvasSaveCount == 1) ? "" : "s")} " + |
|
|
|
|
|
|
); |
|
|
|
if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount) |
|
|
|
} |
|
|
|
|
|
|
|
if (debugNewCanvasSaveCount < debugPreviousCanvasSaveCount) { |
|
|
|
throw new UIWidgetsError( |
|
|
|
$"The {painter} custom painter called canvas.restore() " + |
|
|
|
$"{debugPreviousCanvasSaveCount - debugNewCanvasSaveCount} more " + |
|
|
|
|
|
|
"You should only call restore() if you first called save() or saveLayer()." |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return debugNewCanvasSaveCount == debugPreviousCanvasSaveCount; |
|
|
|
}); |
|
|
|
canvas.restore(); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void _setRasterCacheHints(PaintingContext context) { |
|
|
|
if (this.isComplex) |
|
|
|
if (this.isComplex) { |
|
|
|
if (this.willChange) |
|
|
|
} |
|
|
|
|
|
|
|
if (this.willChange) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |