public uiPaint( uiColor?color = null, BlendMode blendMode = BlendMode.srcOver, PaintingStyle style = PaintingStyle.fill, float strokeWidth = 0f, StrokeCap strokeCap = StrokeCap.butt, StrokeJoin strokeJoin = StrokeJoin.miter, float strokeMiterLimit = 4.0f, FilterMode filterMode = FilterMode.Bilinear, uiColorFilter?colorFilter = null, uiMaskFilter?maskFilter = null, uiImageFilter backdrop = null, PaintShader shader = null, bool invertColors = false ) { this.color = color ?? _kColorDefault; this.blendMode = blendMode; this.style = style; this.strokeWidth = strokeWidth; this.strokeCap = strokeCap; this.strokeJoin = strokeJoin; this.strokeMiterLimit = strokeMiterLimit; this.filterMode = filterMode; this.colorFilter = colorFilter; this.maskFilter = maskFilter; this.backdrop = backdrop; this.shader = shader; this.invertColors = invertColors; }
public void SetStrokeCap(StrokeCap cap) { var mode = ""; switch (cap) { case StrokeCap.Project: mode = "project"; break; case StrokeCap.Round: mode = "round"; break; case StrokeCap.Square: mode = "square"; break; default: throw new Exception("Invalid StrokeCap"); } _jsRuntime.InvokeVoid( _p5InvokeFunction, "strokeCap", mode ); }
public static AM.PenLineCap ToPenLineCap(this StrokeCap strokeCap) { switch (strokeCap) { default: case StrokeCap.Butt: return(AM.PenLineCap.Flat); case StrokeCap.Round: return(AM.PenLineCap.Round); case StrokeCap.Square: return(AM.PenLineCap.Square); } }
internal static SKStrokeCap ToSKStrokeCap(StrokeCap cap) { switch (cap) { default: case StrokeCap.Butt: return(SKStrokeCap.Butt); case StrokeCap.Round: return(SKStrokeCap.Round); case StrokeCap.Square: return(SKStrokeCap.Square); } }
public uiPaint(uiPaint paint) { this.color = paint.color; this.blendMode = paint.blendMode; this.style = paint.style; this.strokeWidth = paint.strokeWidth; this.strokeCap = paint.strokeCap; this.strokeJoin = paint.strokeJoin; this.strokeMiterLimit = paint.strokeMiterLimit; this.filterMode = paint.filterMode; this.colorFilter = paint.colorFilter; this.maskFilter = paint.maskFilter; this.backdrop = paint.backdrop; this.shader = paint.shader; this.invertColors = paint.invertColors; }
public Paint(Paint paint) { D.assert(paint != null); this.color = paint.color; this.blendMode = paint.blendMode; this.style = paint.style; this.strokeWidth = paint.strokeWidth; this.strokeCap = paint.strokeCap; this.strokeJoin = paint.strokeJoin; this.strokeMiterLimit = paint.strokeMiterLimit; this.filterMode = paint.filterMode; this.colorFilter = paint.colorFilter; this.maskFilter = paint.maskFilter; this.shader = paint.shader; this.invertColors = paint.invertColors; }
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) { if (untypedValue == null) { serializer.Serialize(writer, null); return; } StrokeCap value = (StrokeCap)untypedValue; switch (value) { case StrokeCap.Butt: serializer.Serialize(writer, "butt"); return; case StrokeCap.Round: serializer.Serialize(writer, "round"); return; case StrokeCap.Square: serializer.Serialize(writer, "square"); return; } throw new Exception("Cannot marshal type StrokeCap"); }
public void computeStrokeMesh(float strokeWidth, float fringe, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) { if (this._strokeMesh != null && this._fillMesh == null && // Ensure that the cached stroke mesh was not calculated in computeFillMesh this._strokeWidth == strokeWidth && this._fringe == fringe && this._lineCap == lineCap && this._lineJoin == lineJoin && this._miterLimit == miterLimit) { return; } var verticesUV = this._expandStroke(strokeWidth, fringe, lineCap, lineJoin, miterLimit); var paths = this._paths; var cindices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { D.assert(path.nstroke >= 2); cindices += (path.nstroke - 2) * 3; } } var indices = ObjectPool <uiList <int> > .alloc(); indices.SetCapacity(cindices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { for (var j = 2; j < path.nstroke; j++) { if ((j & 1) == 0) { indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j); } else { indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j); } } } } D.assert(indices.Count == cindices); ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = uiMeshMesh.create(null, verticesUV.strokeVertices, indices, verticesUV.strokeUV); ObjectPool <uiMeshMesh> .release(this._fillMesh); this._fillMesh = null; this._strokeWidth = strokeWidth; this._fringe = fringe; this._lineCap = lineCap; this._lineJoin = lineJoin; this._miterLimit = miterLimit; return; }
uiVertexUV _expandStroke(float w, float fringe, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) { float aa = fringe; float u0 = 0.0f, u1 = 1.0f; int ncap = 0; if (lineCap == StrokeCap.round || lineJoin == StrokeJoin.round) { ncap = uiPathUtils.curveDivs(w, Mathf.PI, this._tessTol); } w += aa * 0.5f; if (aa == 0.0f) { u0 = 0.5f; u1 = 0.5f; } this._calculateJoins(w, lineJoin, miterLimit); var points = this._points; var paths = this._paths; var cvertices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } cvertices += path.count * 2; cvertices += 8; } var _vertices = ObjectPool <uiList <Vector3> > .alloc(); _vertices.SetCapacity(cvertices); var _uv = ObjectPool <uiList <Vector2> > .alloc(); _uv.SetCapacity(cvertices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } path.istroke = _vertices.Count; int s, e, ip0, ip1; if (path.closed) { ip0 = path.first + path.count - 1; ip1 = path.first; s = 0; e = path.count; } else { ip0 = path.first; ip1 = path.first + 1; s = 1; e = path.count - 1; } var p0 = points[ip0]; var p1 = points[ip1]; if (!path.closed) { if (lineCap == StrokeCap.butt) { _vertices.buttCapStart(_uv, p0, p0.dx, p0.dy, w, 0.0f, aa, u0, u1); } else if (lineCap == StrokeCap.square) { _vertices.buttCapStart(_uv, p0, p0.dx, p0.dy, w, w, aa, u0, u1); } else { // round _vertices.roundCapStart(_uv, p0, p0.dx, p0.dy, w, ncap, u0, u1); } } for (var j = s; j < e; j++) { p0 = points[ip0]; p1 = points[ip1]; if ((p1.flags & (uiPointFlags.bevel | uiPointFlags.innerBevel)) != 0) { if (lineJoin == StrokeJoin.round) { _vertices.roundJoin(_uv, p0, p1, w, w, ncap, u0, u1, aa); } else { _vertices.bevelJoin(_uv, p0, p1, w, w, u0, u1, aa); } } else { _vertices.Add(new Vector2(p1.x + p1.dmx * w, p1.y + p1.dmy * w)); _vertices.Add(new Vector2(p1.x - p1.dmx * w, p1.y - p1.dmy * w)); _uv.Add(new Vector2(u0, 1)); _uv.Add(new Vector2(u1, 1)); } ip0 = ip1++; } if (!path.closed) { p0 = points[ip0]; p1 = points[ip1]; if (lineCap == StrokeCap.butt) { _vertices.buttCapEnd(_uv, p1, p0.dx, p0.dy, w, 0.0f, aa, u0, u1); } else if (lineCap == StrokeCap.square) { _vertices.buttCapEnd(_uv, p1, p0.dx, p0.dy, w, w, aa, u0, u1); } else { // round _vertices.roundCapEnd(_uv, p1, p0.dx, p0.dy, w, ncap, u0, u1); } } else { _vertices.Add(_vertices[path.istroke]); _vertices.Add(_vertices[path.istroke + 1]); _uv.Add(new Vector2(u0, 1)); _uv.Add(new Vector2(u1, 1)); } path.nstroke = _vertices.Count - path.istroke; paths[i] = path; } D.assert(_uv.Count == _vertices.Count); return(new uiVertexUV { strokeVertices = _vertices, strokeUV = _uv, }); }
public hStrokeCap(StrokeCap PathEndCap) { PathCap = PathEndCap; Value = "stroke-linecap=\"" + PathCap.ToString() + "\""; }
public uiMeshMesh getStrokeMesh(float strokeWidth, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) { if (this._strokeMesh != null && this._strokeWidth == strokeWidth && this._lineCap == lineCap && this._lineJoin == lineJoin && this._miterLimit == miterLimit) { return(this._strokeMesh); } var vertices = this._expandStroke(strokeWidth, lineCap, lineJoin, miterLimit); var paths = this._paths; var cindices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { D.assert(path.nstroke >= 2); cindices += (path.nstroke - 2) * 3; } } var indices = ObjectPool <uiList <int> > .alloc(); indices.SetCapacity(cindices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } if (path.nstroke > 0) { for (var j = 2; j < path.nstroke; j++) { if ((j & 1) == 0) { indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j); } else { indices.Add(path.istroke + j - 2); indices.Add(path.istroke + j - 1); indices.Add(path.istroke + j); } } } } D.assert(indices.Count == cindices); ObjectPool <uiMeshMesh> .release(this._strokeMesh); this._strokeMesh = uiMeshMesh.create(null, vertices, indices); this._strokeWidth = strokeWidth; this._lineCap = lineCap; this._lineJoin = lineJoin; this._miterLimit = miterLimit; return(this._strokeMesh); }
uiList <Vector3> _expandStroke(float w, StrokeCap lineCap, StrokeJoin lineJoin, float miterLimit) { this._calculateJoins(w, lineJoin, miterLimit); int ncap = 0; if (lineCap == StrokeCap.round || lineJoin == StrokeJoin.round) { ncap = uiPathUtils.curveDivs(w, Mathf.PI, this._tessTol); } var points = this._points; var paths = this._paths; var cvertices = 0; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } cvertices += path.count * 2; cvertices += 4; } var _vertices = ObjectPool <uiList <Vector3> > .alloc(); _vertices.SetCapacity(cvertices); for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } path.istroke = _vertices.Count; int s, e, ip0, ip1; if (path.closed) { ip0 = path.first + path.count - 1; ip1 = path.first; s = 0; e = path.count; } else { ip0 = path.first; ip1 = path.first + 1; s = 1; e = path.count - 1; } var p0 = points[ip0]; var p1 = points[ip1]; if (!path.closed) { if (lineCap == StrokeCap.butt) { _vertices.buttCapStart(p0, p0.dx, p0.dy, w, 0.0f); } else if (lineCap == StrokeCap.square) { _vertices.buttCapStart(p0, p0.dx, p0.dy, w, w); } else { // round _vertices.roundCapStart(p0, p0.dx, p0.dy, w, ncap); } } for (var j = s; j < e; j++) { p0 = points[ip0]; p1 = points[ip1]; if ((p1.flags & (uiPointFlags.bevel | uiPointFlags.innerBevel)) != 0) { if (lineJoin == StrokeJoin.round) { _vertices.roundJoin(p0, p1, w, w, ncap); } else { _vertices.bevelJoin(p0, p1, w, w); } } else { _vertices.Add(new Vector2(p1.x + p1.dmx * w, p1.y + p1.dmy * w)); _vertices.Add(new Vector2(p1.x - p1.dmx * w, p1.y - p1.dmy * w)); } ip0 = ip1++; } if (!path.closed) { p0 = points[ip0]; p1 = points[ip1]; if (lineCap == StrokeCap.butt) { _vertices.buttCapEnd(p1, p0.dx, p0.dy, w, 0.0f); } else if (lineCap == StrokeCap.square) { _vertices.buttCapEnd(p1, p0.dx, p0.dy, w, w); } else { // round _vertices.roundCapEnd(p1, p0.dx, p0.dy, w, ncap); } } else { _vertices.Add(_vertices[path.istroke]); _vertices.Add(_vertices[path.istroke + 1]); } path.nstroke = _vertices.Count - path.istroke; paths[i] = path; } return(_vertices); }