|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using Unity.UIWidgets.Runtime.external; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
|
|
|
var queryBound = this._currentLayer.currentState.matrix?.invert().Value |
|
|
|
.mapRect(this._currentLayer.layerBounds) ?? |
|
|
|
this._currentLayer.layerBounds; |
|
|
|
|
|
|
|
if (!uiRectHelper.contains(queryBound, uiRectHelper.fromRect(picture.paintBounds).Value)) { |
|
|
|
var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); |
|
|
|
List<int> cmdIndices = indices.ToList(); |
|
|
|
cmdIndices.AddRange(picture.stateUpdatesIndices); |
|
|
|
cmdIndices.Sort(); |
|
|
|
drawCmds = new List<DrawCmd>(); |
|
|
|
for (int i = 0; i < cmdIndices.Count; i++) { |
|
|
|
drawCmds.Add(picture.drawCmds[cmdIndices[i]]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var drawCmd in drawCmds) { |
|
|
|
switch (drawCmd) { |
|
|
|
case DrawSave _: |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case DrawPath cmd: { |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect( |
|
|
|
cmd.path.getBoundsWithMargin(5)).Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
var uipath = uiPath.fromPath(cmd.path); |
|
|
|
this._drawPath(uipath, uiPaint.fromPaint(cmd.paint)); |
|
|
|
uiPathCacheManager.putToCache(uipath); |
|
|
|
|
|
|
case DrawImage cmd: { |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromLTWH( |
|
|
|
cmd.offset.dx, cmd.offset.dy, |
|
|
|
cmd.image.width / this._devicePixelRatio, |
|
|
|
cmd.image.height / this._devicePixelRatio), queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
this._drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, |
|
|
|
case DrawImage cmd: {_drawImage(cmd.image, (uiOffset.fromOffset(cmd.offset)).Value, |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect(cmd.dst).Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
this._drawImageRect(cmd.image, uiRectHelper.fromRect(cmd.src), uiRectHelper.fromRect(cmd.dst).Value, |
|
|
|
uiPaint.fromPaint(cmd.paint)); |
|
|
|
break; |
|
|
|
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromLTRB( |
|
|
|
cmd.dst.left + ((cmd.center.left - cmd.src.left) * cmd.src.width), |
|
|
|
cmd.dst.top + ((cmd.center.top - cmd.src.top) * cmd.src.height), |
|
|
|
cmd.dst.right - ((cmd.src.right - cmd.center.right) * cmd.src.width), |
|
|
|
cmd.dst.bottom - ((cmd.src.bottom - cmd.center.bottom) * cmd.src.height) |
|
|
|
), queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
this._drawImageNine(cmd.image, uiRectHelper.fromRect(cmd.src), |
|
|
|
uiRectHelper.fromRect(cmd.center).Value, uiRectHelper.fromRect(cmd.dst).Value, |
|
|
|
uiPaint.fromPaint(cmd.paint)); |
|
|
|
|
|
|
case DrawPicture cmd: { |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect( |
|
|
|
cmd.picture.paintBounds).Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect( |
|
|
|
cmd.textBlob.Value.boundsInText.translate(cmd.offset.dx, cmd.offset.dy)).Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
this._paintTextShadow(cmd.textBlob, cmd.offset); |
|
|
|
this._drawTextBlob(cmd.textBlob, (uiOffset.fromOffset(cmd.offset)).Value, |
|
|
|
uiPaint.fromPaint(cmd.paint)); |
|
|
|
|
|
|
var queryBound = this._currentLayer.currentState.matrix?.invert().Value |
|
|
|
.mapRect(this._currentLayer.layerBounds) ?? |
|
|
|
this._currentLayer.layerBounds; |
|
|
|
|
|
|
|
if (!uiRectHelper.contains(queryBound, picture.paintBounds)) { |
|
|
|
var indices = picture.bbh.Search(queryBound).Select(bound => bound.index); |
|
|
|
List<int> cmdIndices = indices.ToList(); |
|
|
|
cmdIndices.Capacity += picture.stateUpdatesIndices.Count; |
|
|
|
for (int i = 0; i < picture.stateUpdatesIndices.Count; i++) { |
|
|
|
cmdIndices.Add(picture.stateUpdatesIndices[i]); |
|
|
|
} |
|
|
|
cmdIndices.Sort(); |
|
|
|
drawCmds = new List<uiDrawCmd>(); |
|
|
|
for (int i = 0; i < cmdIndices.Count; i++) { |
|
|
|
drawCmds.Add(picture.drawCmds[cmdIndices[i]]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var drawCmd in drawCmds) { |
|
|
|
switch (drawCmd) { |
|
|
|
case uiDrawSave _: |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case uiDrawPath cmd: { |
|
|
|
if (uiRectHelper.intersect(cmd.path.getBoundsWithMargin(5), queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromLTWH( |
|
|
|
cmd.offset.Value.dx, cmd.offset.Value.dy, |
|
|
|
cmd.image.width / this._devicePixelRatio, |
|
|
|
cmd.image.height / this._devicePixelRatio), queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(cmd.dst.Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromLTRB( |
|
|
|
cmd.dst.Value.left + ((cmd.center.Value.left - cmd.src.Value.left) * cmd.src.Value.width), |
|
|
|
cmd.dst.Value.top + ((cmd.center.Value.top - cmd.src.Value.top) * cmd.src.Value.height), |
|
|
|
cmd.dst.Value.right - ((cmd.src.Value.right - cmd.center.Value.right) * cmd.src.Value.width), |
|
|
|
cmd.dst.Value.bottom - ((cmd.src.Value.bottom - cmd.center.Value.bottom) * cmd.src.Value.height) |
|
|
|
), queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect( |
|
|
|
cmd.picture.paintBounds).Value, queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (uiRectHelper.intersect(uiRectHelper.fromRect( |
|
|
|
cmd.textBlob.Value.boundsInText.translate(cmd.offset.Value.dx, cmd.offset.Value.dy)).Value, |
|
|
|
queryBound).isEmpty) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
this._paintTextShadow(cmd.textBlob, new Offset(cmd.offset.Value.dx, cmd.offset.Value.dy)); |
|
|
|
this._drawTextBlob(cmd.textBlob, cmd.offset.Value, cmd.paint); |
|
|
|
break; |
|
|
|