void _drawImageNine(Image image, uiRect?src, uiRect center, uiRect dst, uiPaint paint) { D.assert(image != null); var scaleX = 1f / image.width; var scaleY = 1f / image.height; if (src == null) { src = uiRectHelper.one; } else { src = uiRectHelper.scale(src.Value, scaleX, scaleY); } center = uiRectHelper.scale(center, scaleX, scaleY); var layer = this._currentLayer; var state = layer.currentState; var mesh = ImageMeshGenerator.imageNineMesh(state.matrix, src.Value, center, image.width, image.height, dst); if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image)); }
void _drawWithMaskFilter(uiRect meshBounds, uiPaint paint, uiMaskFilter maskFilter, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound, TextBlobMesh textMesh, bool notEmoji, _drawPathDrawMeshCallbackDelegate drawCallback) { var layer = this._currentLayer; var clipBounds = layer.layerBounds; uiRect?stackBounds; bool iior; layer.clipStack.getBounds(out stackBounds, out iior); if (stackBounds != null) { clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value); } if (clipBounds.isEmpty) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } var state = layer.currentState; float sigma = state.scale * maskFilter.sigma; if (sigma <= 0) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } float sigma3 = 3 * sigma; var maskBounds = uiRectHelper.inflate(meshBounds, sigma3); maskBounds = uiRectHelper.intersect(maskBounds, uiRectHelper.inflate(clipBounds, sigma3)); if (maskBounds.isEmpty) { this._drawPathDrawMeshQuit(fillMesh, strokeMesh, textMesh); return; } var maskLayer = this._createMaskLayer(layer, maskBounds, drawCallback, paint, convex, alpha, strokeMult, tex, texBound, textMesh, fillMesh, strokeMesh, notEmoji); var blurLayer = this._createBlurLayer(maskLayer, sigma, sigma, layer); var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds); if (!this._applyClip(blurMesh.bounds)) { ObjectPool <uiMeshMesh> .release(blurMesh); return; } layer.draws.Add(CanvasShader.texRT(layer, paint, blurMesh, blurLayer)); }
void _setLastClipGenId(uint clipGenId, uiRect clipBounds) { var layer = this._currentLayer; layer.lastClipGenId = clipGenId; layer.lastClipBounds = clipBounds; }
public void updateBoundAndGenID(ClipElement prior) { this._genId = ClipStack.getNextGenID(); this._isIntersectionOfRects = false; if (this.isRect) { this._bound = this.rect.Value; if (prior == null || prior.isIntersectionOfRects()) { this._isIntersectionOfRects = true; } } else { this._bound = this.mesh.bounds; } if (prior != null) { this._bound = uiRectHelper.intersect(this._bound, prior.getBound()); } if (this._bound.isEmpty) { this.setEmpty(); } }
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(fillMesh.bounds)) { ObjectPool <uiMeshMesh> .release(fillMesh); ObjectPool <uiMeshMesh> .release(strokeMesh); return; } var layer = this._currentLayer; if (convex) { layer.draws.Add(CanvasShader.convexFill(layer, p, fillMesh)); } else { layer.draws.Add(CanvasShader.fill0(layer, fillMesh)); layer.draws.Add(CanvasShader.fill1(layer, p, fillMesh.boundsMesh)); } if (strokeMesh != null) { layer.draws.Add(CanvasShader.strokeAlpha(layer, p, alpha, strokeMult, strokeMesh)); layer.draws.Add(CanvasShader.stroke1(layer, strokeMesh.duplicate())); } }
public static ReducedClip create(ClipStack stack, uiRect layerBounds, uiRect queryBounds) { ReducedClip clip = ObjectPool <ReducedClip> .alloc(); uiRect?stackBounds; bool iior; stack.getBounds(out stackBounds, out iior); if (stackBounds == null) { clip.scissor = layerBounds; return(clip); } stackBounds = uiRectHelper.intersect(layerBounds, stackBounds.Value); if (iior) { clip.scissor = stackBounds; return(clip); } queryBounds = uiRectHelper.intersect(stackBounds.Value, queryBounds); if (queryBounds.isEmpty) { clip.scissor = uiRectHelper.zero; return(clip); } clip.scissor = queryBounds; clip._walkStack(stack, clip.scissor.Value); return(clip); }
void _drawTextDrawMeshCallback(uiPaint p, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool convex, float alpha, float strokeMult, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(textBlobBounds)) { ObjectPool <TextBlobMesh> .release(textMesh); return; } var layer = this._currentLayer; if (notEmoji) { layer.draws.Add(CanvasShader.texAlpha(layer, p, textMesh, tex)); } else { uiPaint paintWithWhite = new uiPaint(p); paintWithWhite.color = uiColor.white; if (EmojiUtils.image == null) { ObjectPool <TextBlobMesh> .release(textMesh); return; } var raw_mesh = textMesh.resolveMesh(); var meshmesh = raw_mesh.duplicate(); ObjectPool <TextBlobMesh> .release(textMesh); layer.draws.Add(CanvasShader.tex(layer, paintWithWhite, meshmesh, EmojiUtils.image)); } }
bool _convexContains(uiRect rect) { if (this.mesh.vertices.Count <= 2) { return(false); } for (var i = 0; i < this.mesh.vertices.Count; i++) { var p1 = this.mesh.vertices[i]; var p0 = this.mesh.vertices[i == this.mesh.vertices.Count - 1 ? 0 : i + 1]; var v = p1 - p0; if (v.x == 0.0 && v.y == 0.0) { continue; } float yL = v.y * (rect.left - p0.x); float xT = v.x * (rect.top - p0.y); float yR = v.y * (rect.right - p0.x); float xB = v.x * (rect.bottom - p0.y); if ((xT < yL) || (xT < yR) || (xB < yL) || (xB < yR)) { return(false); } } return(true); }
void _drawImageRect(Image image, uiRect?src, uiRect dst, uiPaint paint) { D.assert(image != null && image.valid); if (image == null || !image.valid) { return; } if (src == null) { src = uiRectHelper.one; } else { src = uiRectHelper.scale(src.Value, 1f / image.width, 1f / image.height); } var layer = this._currentLayer; var state = layer.currentState; var mesh = ImageMeshGenerator.imageMesh(state.matrix, src.Value, dst); if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } layer.draws.Add(CanvasShader.tex(layer, paint, mesh, image)); }
public static uiMeshMesh imageMesh(uiMatrix3?matrix, uiRect src, uiRect dst) { var vertices = ObjectPool <uiList <Vector3> > .alloc(); vertices.SetCapacity(4); var uv = ObjectPool <uiList <Vector2> > .alloc(); uv.SetCapacity(4); float uvx0 = src.left; float uvx1 = src.right; float uvy0 = 1.0f - src.top; float uvy1 = 1.0f - src.bottom; vertices.Add(new Vector2(dst.left, dst.top)); uv.Add(new Vector2(uvx0, uvy0)); vertices.Add(new Vector2(dst.left, dst.bottom)); uv.Add(new Vector2(uvx0, uvy1)); vertices.Add(new Vector2(dst.right, dst.bottom)); uv.Add(new Vector2(uvx1, uvy1)); vertices.Add(new Vector2(dst.right, dst.top)); uv.Add(new Vector2(uvx1, uvy0)); var _triangles = ObjectPool <uiList <int> > .alloc(); _triangles.AddRange(_imageTriangles); return(uiMeshMesh.create(matrix, vertices, _triangles, uv)); }
public static uiMeshMesh imageMesh(uiMatrix3?matrix, uiOffset srcTL, uiOffset srcBL, uiOffset srcBR, uiOffset srcTR, uiRect dst) { var vertices = ObjectPool <uiList <Vector3> > .alloc(); vertices.SetCapacity(4); var uv = ObjectPool <uiList <Vector2> > .alloc(); uv.SetCapacity(4); vertices.Add(new Vector2(dst.left, dst.top)); uv.Add(new Vector2(srcTL.dx, 1.0f - srcTL.dy)); vertices.Add(new Vector2(dst.left, dst.bottom)); uv.Add(new Vector2(srcBL.dx, 1.0f - srcBL.dy)); vertices.Add(new Vector2(dst.right, dst.bottom)); uv.Add(new Vector2(srcBR.dx, 1.0f - srcBR.dy)); vertices.Add(new Vector2(dst.right, dst.top)); uv.Add(new Vector2(srcTR.dx, 1.0f - srcTR.dy)); var _triangles = ObjectPool <uiList <int> > .alloc(); _triangles.AddRange(_imageTriangles); return(uiMeshMesh.create(matrix, vertices, _triangles, uv)); }
public static uiRect scale(uiRect a, float scaleX, float?scaleY = null) { scaleY = scaleY ?? scaleX; return(fromLTRB( a.left * scaleX, a.top * scaleY.Value, a.right * scaleX, a.bottom * scaleY.Value)); }
public static uiPicture create(List <uiDrawCmd> drawCmds, uiRect paintBounds) { var picture = ObjectPool <uiPicture> .alloc(); picture.drawCmds = drawCmds; picture.paintBounds = paintBounds; return(picture); }
void _clipUIRect(uiRect rect) { var path = uiPath.create(); path.addRect(rect); this._clipPath(path); uiPathCacheManager.putToCache(path); }
public void addRect(uiRect rect) { this._appendMoveTo(rect.left, rect.top); this._appendLineTo(rect.left, rect.bottom); this._appendLineTo(rect.right, rect.bottom); this._appendLineTo(rect.right, rect.top); this._appendClose(); }
public static uiRect roundOut(uiRect a, float devicePixelRatio) { return(fromLTRB( Mathf.Floor(a.left * devicePixelRatio) / devicePixelRatio, Mathf.Floor(a.top * devicePixelRatio) / devicePixelRatio, Mathf.Ceil(a.right * devicePixelRatio) / devicePixelRatio, Mathf.Ceil(a.bottom * devicePixelRatio) / devicePixelRatio)); }
public void addRect(uiRect rect) { this._updateRRectFlag(true, uiPathShapeHint.Rect); this._appendMoveTo(rect.left, rect.top); this._appendLineTo(rect.left, rect.bottom); this._appendLineTo(rect.right, rect.bottom); this._appendLineTo(rect.right, rect.top); this._appendClose(); }
public uiRect intersect(uiRect other) { return(uiRectHelper.fromLTRB( Mathf.Max(this.left, other.left), Mathf.Max(this.top, other.top), Mathf.Min(this.right, other.right), Mathf.Min(this.bottom, other.bottom) )); }
public static uiOffset[] toQuad(uiRect a) { uiOffset[] dst = new uiOffset[4]; dst[0] = new uiOffset(a.left, a.top); dst[1] = new uiOffset(a.right, a.top); dst[2] = new uiOffset(a.right, a.bottom); dst[3] = new uiOffset(a.left, a.bottom); return(dst); }
public static uiRect intersect(uiRect a, uiRect other) { return(fromLTRB( Mathf.Max(a.left, other.left), Mathf.Max(a.top, other.top), Mathf.Min(a.right, other.right), Mathf.Min(a.bottom, other.bottom) )); }
public static uiPicture create(List <uiDrawCmd> drawCmds, uiRect paintBounds, BBoxHierarchy <IndexedRect> bbh = null, uiList <int> stateUpdateIndices = null) { var picture = ObjectPool <uiPicture> .alloc(); picture.drawCmds = drawCmds; picture.paintBounds = paintBounds; picture.bbh = bbh; picture.stateUpdatesIndices = stateUpdateIndices; return(picture); }
public static bool overlaps(uiRect a, uiRect other) { if (a.right <= other.left || other.right <= a.left) { return(false); } if (a.bottom <= other.top || other.bottom <= a.top) { return(false); } return(true); }
public static uiRect normalize(uiRect a) { if (a.left <= a.right && a.top <= a.bottom) { return(a); } return(fromLTRB( Mathf.Min(a.left, a.right), Mathf.Min(a.top, a.bottom), Mathf.Max(a.left, a.right), Mathf.Max(a.top, a.bottom) )); }
void _drawPathDrawMeshCallback2(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } var layer = this._currentLayer; layer.draws.Add(CanvasShader.stroke0(layer, p, alpha, mesh)); layer.draws.Add(CanvasShader.stroke1(layer, mesh.duplicate())); }
RenderLayer _createMaskLayer(RenderLayer parentLayer, uiRect maskBounds, _drawPathDrawMeshCallbackDelegate drawCallback, uiPaint paint, bool convex, float alpha, float strokeMult, Texture tex, uiRect texBound, TextBlobMesh textMesh, uiMeshMesh fillMesh, uiMeshMesh strokeMesh, bool notEmoji) { var textureWidth = Mathf.CeilToInt(maskBounds.width * this._devicePixelRatio); if (textureWidth < 1) { textureWidth = 1; } var textureHeight = Mathf.CeilToInt(maskBounds.height * this._devicePixelRatio); if (textureHeight < 1) { textureHeight = 1; } var maskLayer = RenderLayer.create( rtID: Shader.PropertyToID(this._getNewRenderTextureKey()), width: textureWidth, height: textureHeight, layerBounds: maskBounds, filterMode: FilterMode.Bilinear, noMSAA: true ); parentLayer.addLayer(maskLayer); this._layers.Add(maskLayer); this._currentLayer = maskLayer; var parentState = parentLayer.states[parentLayer.states.Count - 1]; var maskState = maskLayer.states[maskLayer.states.Count - 1]; maskState.matrix = parentState.matrix; drawCallback.Invoke(uiPaint.shapeOnly(paint), fillMesh, strokeMesh, convex, alpha, strokeMult, tex, texBound, textMesh, notEmoji); var removed = this._layers.removeLast(); D.assert(removed == maskLayer); this._currentLayer = this._layers[this._layers.Count - 1]; return(maskLayer); }
void _walkStack(ClipStack stack, uiRect queryBounds) { foreach (var element in stack.stack) { if (element.isRect) { continue; } if (element.contains(queryBounds)) { continue; } this.maskElements.Add(element); this._lastElement = element; } }
public static uiMeshMesh create(uiRect rect) { uiMeshMesh newMesh = ObjectPool <uiMeshMesh> .alloc(); newMesh.vertices = ObjectPool <uiList <Vector3> > .alloc(); newMesh.vertices.Add(new Vector3(rect.right, rect.bottom)); newMesh.vertices.Add(new Vector3(rect.right, rect.top)); newMesh.vertices.Add(new Vector3(rect.left, rect.bottom)); newMesh.vertices.Add(new Vector3(rect.left, rect.top)); newMesh.triangles = ObjectPool <uiList <int> > .alloc(); newMesh.triangles.AddRange(_boundsTriangles); newMesh.rawBounds = rect; newMesh._bounds = newMesh.rawBounds; return(newMesh); }
void _drawPathDrawMeshCallback(uiPaint p, uiMeshMesh mesh, bool convex, float alpha, Texture tex, uiRect textBlobBounds, TextBlobMesh textMesh, bool notEmoji) { if (!this._applyClip(mesh.bounds)) { ObjectPool <uiMeshMesh> .release(mesh); return; } var layer = this._currentLayer; if (convex) { layer.draws.Add(CanvasShader.convexFill(layer, p, mesh)); } else { layer.draws.Add(CanvasShader.fill0(layer, mesh)); layer.draws.Add(CanvasShader.fill1(layer, p, mesh.boundsMesh)); } }
public bool contains(uiRect rect) { if (this.isRect) { return(uiRectHelper.contains(this.rect.Value, rect)); } if (this.convex) { if (this.mesh.matrix != null && !this.mesh.matrix.Value.isIdentity()) { if (this._invMat == null) { this._invMat = this.mesh.matrix.Value.invert(); } rect = this._invMat.Value.mapRect(rect); } return(this._convexContains(rect)); } return(false); }
public static UnityEngine.Rect toRect(uiRect rect) { return(new UnityEngine.Rect(rect.left, rect.top, rect.width, rect.height)); }