|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Unity.UIWidgets.ui { |
|
|
|
public class uiPicture { |
|
|
|
public uiPicture(List<uiDrawCmd> drawCmds, uiRect paintBounds) { |
|
|
|
this.drawCmds = drawCmds; |
|
|
|
this.paintBounds = paintBounds; |
|
|
|
public class uiPicture : PoolItem { |
|
|
|
public uiPicture() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static uiPicture create(List<uiDrawCmd> drawCmds, uiRect paintBounds) { |
|
|
|
var picture = ItemPoolManager.alloc<uiPicture>(); |
|
|
|
picture.drawCmds = drawCmds; |
|
|
|
picture.paintBounds = paintBounds; |
|
|
|
return picture; |
|
|
|
public readonly List<uiDrawCmd> drawCmds; |
|
|
|
public readonly uiRect paintBounds; |
|
|
|
public List<uiDrawCmd> drawCmds; |
|
|
|
public uiRect paintBounds; |
|
|
|
|
|
|
|
public override void clear() { |
|
|
|
//the recorder will dispose the draw commands
|
|
|
|
this.drawCmds = null; |
|
|
|
} |
|
|
|
readonly List<uiDrawCmd> _drawCmds = new List<uiDrawCmd>(); |
|
|
|
readonly List<uiDrawCmd> _drawCmds = new List<uiDrawCmd>(128); |
|
|
|
readonly List<uiCanvasState> _states = new List<uiCanvasState>(); |
|
|
|
readonly List<uiCanvasState> _states = new List<uiCanvasState>(32); |
|
|
|
|
|
|
|
public uiPictureRecorder() { |
|
|
|
this.reset(); |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void reset() { |
|
|
|
foreach (var drawCmd in this._drawCmds) { |
|
|
|
drawCmd.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
this._drawCmds.Clear(); |
|
|
|
this._states.Clear(); |
|
|
|
this._states.Add(new uiCanvasState { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var state = this._getState(); |
|
|
|
return new uiPicture(this._drawCmds, state.paintBounds); |
|
|
|
return uiPicture.create(this._drawCmds, state.paintBounds); |
|
|
|
} |
|
|
|
|
|
|
|
public void addDrawCmd(uiDrawCmd drawCmd) { |
|
|
|
|
|
|
uiMeshMesh mesh; |
|
|
|
if (paint.style == PaintingStyle.fill) { |
|
|
|
var cache = path.flatten(scale * devicePixelRatio); |
|
|
|
mesh = cache.getFillMesh(out _).transform(state.xform); |
|
|
|
var fillMesh = cache.getFillMesh(out _); |
|
|
|
mesh = fillMesh.transform(state.xform); |
|
|
|
fillMesh.dispose(); |
|
|
|
cache.dispose(); |
|
|
|
} else { |
|
|
|
float strokeWidth = (paint.strokeWidth * scale).clamp(0, 200.0f); |
|
|
|
|
|
|
} else { |
|
|
|
this._addPaintBounds(mesh.bounds); |
|
|
|
} |
|
|
|
|
|
|
|
mesh.dispose(); |
|
|
|
break; |
|
|
|
} |
|
|
|
case uiDrawImage cmd: { |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class uiCanvasState { |
|
|
|
struct uiCanvasState { |
|
|
|
public uiMatrix3 xform; |
|
|
|
public uiRect? scissor; |
|
|
|
public bool saveLayer; |
|
|
|
|
|
|
public uiCanvasState copy() { |
|
|
|
return new uiCanvasState { |
|
|
|
return new uiCanvasState{ |
|
|
|
paintBounds = this.paintBounds, |
|
|
|
paintBounds = this.paintBounds |
|
|
|
}; |
|
|
|
} |
|
|
|
} |