public void SetStrokeJoin(StrokeJoin join) { var mode = ""; switch (join) { case StrokeJoin.Bevel: mode = "bevel"; break; case StrokeJoin.Miter: mode = "miter"; break; case StrokeJoin.Round: mode = "round"; break; default: throw new Exception("Invalid StrokeJoin"); } _jsRuntime.InvokeVoid( _p5InvokeFunction, "strokeJoin", mode ); }
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 static SKStrokeJoin ToSkia(this StrokeJoin penStrokeJoin) { return(penStrokeJoin switch { StrokeJoin.Miter => SKStrokeJoin.Miter, StrokeJoin.Round => SKStrokeJoin.Round, StrokeJoin.Bevel => SKStrokeJoin.Bevel, _ => SKStrokeJoin.Miter, });
LineJoin Translate(StrokeJoin sj) { switch (sj) { case (StrokeJoin.bevel): return(LineJoin.Bevel); case (StrokeJoin.mitre): return(LineJoin.Miter); case (StrokeJoin.round): return(LineJoin.Round); default: return(LineJoin.Bevel); } }
public static AM.PenLineJoin ToPenLineJoin(this StrokeJoin strokeJoin) { switch (strokeJoin) { default: case StrokeJoin.Miter: return(AM.PenLineJoin.Miter); case StrokeJoin.Round: return(AM.PenLineJoin.Round); case StrokeJoin.Bevel: return(AM.PenLineJoin.Bevel); } }
internal static SKStrokeJoin ToSKStrokeJoin(StrokeJoin join) { switch (join) { default: case StrokeJoin.Miter: return(SKStrokeJoin.Miter); case StrokeJoin.Round: return(SKStrokeJoin.Round); case StrokeJoin.Bevel: return(SKStrokeJoin.Bevel); } }
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 static PenLineJoin MapsuiStrokeJointoPenLineJoin(StrokeJoin penStrokeJoin) { switch (penStrokeJoin) { case StrokeJoin.Miter: return(PenLineJoin.Miter); case StrokeJoin.Round: return(PenLineJoin.Round); case StrokeJoin.Bevel: return(PenLineJoin.Bevel); default: return(PenLineJoin.Miter); } }
public static SKStrokeJoin ToSkia(this StrokeJoin penStrokeJoin) { switch (penStrokeJoin) { case StrokeJoin.Miter: return(SKStrokeJoin.Miter); case StrokeJoin.Round: return(SKStrokeJoin.Round); case StrokeJoin.Bevel: return(SKStrokeJoin.Bevel); default: return(SKStrokeJoin.Miter); } }
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer) { if (untypedValue == null) { serializer.Serialize(writer, null); return; } StrokeJoin value = (StrokeJoin)untypedValue; switch (value) { case StrokeJoin.Bevel: serializer.Serialize(writer, "bevel"); return; case StrokeJoin.Miter: serializer.Serialize(writer, "miter"); return; case StrokeJoin.Round: serializer.Serialize(writer, "round"); return; } throw new Exception("Cannot marshal type StrokeJoin"); }
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); }
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, }); }
void _calculateJoins(float w, StrokeJoin lineJoin, float miterLimit) { float iw = w > 0.0f ? 1.0f / w : 0.0f; var points = this._points; var paths = this._paths; for (var i = 0; i < paths.Count; i++) { var path = paths[i]; if (path.count <= 1) { continue; } var ip0 = path.first + path.count - 1; var ip1 = path.first; for (var j = 0; j < path.count; j++) { var p0 = points[ip0]; var p1 = points[ip1]; p0.dx = p1.x - p0.x; p0.dy = p1.y - p0.y; p0.len = uiPathUtils.normalize(ref p0.dx, ref p0.dy); points[ip0] = p0; ip0 = ip1++; } ip0 = path.first + path.count - 1; ip1 = path.first; path.convex = true; for (var j = 0; j < path.count; j++) { var p0 = points[ip0]; var p1 = points[ip1]; float dlx0 = p0.dy; float dly0 = -p0.dx; float dlx1 = p1.dy; float dly1 = -p1.dx; // Calculate extrusions p1.dmx = (dlx0 + dlx1) * 0.5f; p1.dmy = (dly0 + dly1) * 0.5f; float dmr2 = p1.dmx * p1.dmx + p1.dmy * p1.dmy; if (dmr2 > 0.000001f) { float scale = 1.0f / dmr2; if (scale > 600.0f) { scale = 600.0f; } p1.dmx *= scale; p1.dmy *= scale; } // Clear flags, but keep the corner. p1.flags &= uiPointFlags.corner; // Keep track of left turns. float cross = p1.dx * p0.dy - p0.dx * p1.dy; if (cross > 0.0f) { p1.flags |= uiPointFlags.left; } else if (cross < 0.0f) { path.convex = false; } // Calculate if we should use bevel or miter for inner join. float limit = Mathf.Max(1.01f, Mathf.Min(p0.len, p1.len) * iw); if (dmr2 * limit * limit < 1.0f) { p1.flags |= uiPointFlags.innerBevel; } // Check to see if the corner needs to be beveled. if ((p1.flags & uiPointFlags.corner) != 0) { if (lineJoin == StrokeJoin.bevel || lineJoin == StrokeJoin.round || dmr2 * miterLimit * miterLimit < 1.0f) { p1.flags |= uiPointFlags.bevel; } } points[ip0] = p0; points[ip1] = p1; ip0 = ip1++; } paths[i] = path; } }
public static PenLineJoin ToXaml(this StrokeJoin penStrokeJoin) { return(StyleConverter.MapsuiStrokeJointoPenLineJoin(penStrokeJoin)); }