|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using UnityEngine; |
|
|
|
public Picture(List<DrawCmd> drawCmds, Rect paintBounds) { |
|
|
|
public Picture(List<DrawCmd> drawCmds, Rect paintBounds, bool isDynamic = false) { |
|
|
|
this._isDynamic = isDynamic; |
|
|
|
|
|
|
|
public bool isDynamic { |
|
|
|
get { return this._isDynamic; } |
|
|
|
} |
|
|
|
|
|
|
|
bool _isDynamic; |
|
|
|
} |
|
|
|
|
|
|
|
public class PictureRecorder { |
|
|
|
|
|
|
|
|
|
|
bool _isDynamic; |
|
|
|
|
|
|
|
public PictureRecorder() { |
|
|
|
this.reset(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public void reset() { |
|
|
|
this._drawCmds.Clear(); |
|
|
|
this._isDynamic = false; |
|
|
|
this._states.Clear(); |
|
|
|
this._states.Add(new CanvasState { |
|
|
|
xform = Matrix3.I(), |
|
|
|
|
|
|
throw new Exception("unmatched save/restore commands"); |
|
|
|
} |
|
|
|
|
|
|
|
var state = this._getState(); |
|
|
|
return new Picture(new List<DrawCmd>(this._drawCmds), state.paintBounds); |
|
|
|
var state = this._getState(); |
|
|
|
return new Picture(new List<DrawCmd>(this._drawCmds), state.paintBounds, this._isDynamic); |
|
|
|
} |
|
|
|
|
|
|
|
public void addDrawCmd(DrawCmd drawCmd) { |
|
|
|
|
|
|
}); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case DrawRestore _: { |
|
|
|
var stateToRestore = this._getState(); |
|
|
|
this._states.RemoveAt(this._states.Count - 1); |
|
|
|
|
|
|
state.paintBounds = stateToRestore.paintBounds; |
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
case DrawTranslate cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
state.xform = new Matrix3(state.xform); |
|
|
|
|
|
|
|
|
|
|
case DrawScale cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
state.xform = new Matrix3(state.xform); |
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
case DrawSkew cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
state.xform = new Matrix3(state.xform); |
|
|
|
|
|
|
|
|
|
|
case DrawConcat cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
state.xform = new Matrix3(state.xform); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case DrawClipRect cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case DrawClipRRect cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case DrawClipPath cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
var scale = XformUtils.getScale(state.xform); |
|
|
|
|
|
|
state.scissor = state.scissor == null ? rect : state.scissor.intersect(rect); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
case DrawPath cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
var scale = XformUtils.getScale(state.xform); |
|
|
|
|
|
|
if (paint.style == PaintingStyle.fill) { |
|
|
|
var cache = path.flatten(scale * devicePixelRatio); |
|
|
|
mesh = cache.getFillMesh(out _).transform(state.xform); |
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f); |
|
|
|
float fringeWidth = 1 / devicePixelRatio; |
|
|
|
|
|
|
|
|
|
|
paint.strokeJoin, |
|
|
|
paint.strokeMiterLimit).transform(state.xform); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
case DrawImage cmd: { |
|
|
|
var state = this._getState(); |
|
|
|
var rect = Rect.fromLTWH(cmd.offset.dx, cmd.offset.dy, |
|
|
|
|
|
|
if (cmd.image.isDynamic) { |
|
|
|
this._isDynamic = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cmd.image.isDynamic) { |
|
|
|
this._isDynamic = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cmd.image.isDynamic) { |
|
|
|
this._isDynamic = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cmd.picture.isDynamic) { |
|
|
|
this._isDynamic = true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
throw new Exception("unknown drawCmd: " + drawCmd); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
if (state.paintBounds.isEmpty) { |
|
|
|
state.paintBounds = paintBounds; |
|
|
|
} else { |
|
|
|
} |
|
|
|
else { |
|
|
|
state.paintBounds = state.paintBounds.expandToInclude(paintBounds); |
|
|
|
} |
|
|
|
} |
|
|
|