Beispiel #1
0
        public static void buttCapEnd(this uiList <Vector3> dst, uiPathPoint p,
                                      float dx, float dy, float w, float d)
        {
            float px  = p.x + dx * d;
            float py  = p.y + dy * d;
            float dlx = dy;
            float dly = -dx;

            dst.Add(new Vector2(px + dlx * w, py + dly * w));
            dst.Add(new Vector2(px - dlx * w, py - dly * w));
        }
Beispiel #2
0
        public static void buttCapEnd(this uiList <Vector3> dst, uiList <Vector2> uv, uiPathPoint p,
                                      float dx, float dy, float w, float d, float aa, float u0, float u1)
        {
            float px  = p.x + dx * d;
            float py  = p.y + dy * d;
            float dlx = dy;
            float dly = -dx;

            dst.Add(new Vector2(px + dlx * w, py + dly * w));
            dst.Add(new Vector2(px - dlx * w, py - dly * w));
            dst.Add(new Vector2(px + dlx * w + dx * aa, py + dly * w + dy * aa));
            dst.Add(new Vector2(px - dlx * w + dx * aa, py - dly * w + dy * aa));
            uv.Add(new Vector2(u0, 1));
            uv.Add(new Vector2(u1, 1));
            uv.Add(new Vector2(u0, 0));
            uv.Add(new Vector2(u1, 0));
        }
Beispiel #3
0
        public static void roundCapEnd(this uiList <Vector3> dst, uiPathPoint p,
                                       float dx, float dy, float w, int ncap)
        {
            float px  = p.x;
            float py  = p.y;
            float dlx = dy;
            float dly = -dx;

            dst.Add(new Vector2(px + dlx * w, py + dly * w));
            dst.Add(new Vector2(px - dlx * w, py - dly * w));

            for (var i = 0; i < ncap; i++)
            {
                float a = (float)i / (ncap - 1) * Mathf.PI;
                float ax = Mathf.Cos(a) * w, ay = Mathf.Sin(a) * w;
                dst.Add(new Vector2(px, py));
                dst.Add(new Vector2(px - dlx * ax + dx * ay, py - dly * ax + dy * ay));
            }
        }
Beispiel #4
0
        uiVertexUV _expandFill(float fringe)
        {
            float aa     = fringe;
            float woff   = aa * 0.5f;
            var   points = this._points;
            var   paths  = this._paths;

            this._calculateJoins(fringe, StrokeJoin.miter, 4.0f);

            var cvertices = 0;

            for (var i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                if (path.count <= 2)
                {
                    continue;
                }

                cvertices += path.count;
            }

            this._fillConvex = false;
            for (var i = 0; i < paths.Count; i++)
            {
                var path = paths[i];
                if (path.count <= 2)
                {
                    continue;
                }

                if (this._fillConvex)
                {
                    // if more than two paths, convex is false.
                    this._fillConvex = false;
                    break;
                }

                if (!path.convex)
                {
                    // if not convex, convex is false.
                    break;
                }

                this._fillConvex = true;
            }

            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 <= 2)
                {
                    continue;
                }

                path.ifill = _vertices.Count;
                for (var j = 0; j < path.count; j++)
                {
                    var p = points[path.first + j];
                    if (aa > 0.0f)
                    {
                        _vertices.Add(new Vector2(p.x + p.dmx * woff, p.y + p.dmy * woff));
                    }
                    else
                    {
                        _vertices.Add(new Vector2(p.x, p.y));
                    }

                    _uv.Add(new Vector2(0.5f, 1.0f));
                }

                path.nfill = _vertices.Count - path.ifill;
                paths[i]   = path;
            }

            uiList <Vector3> _strokeVertices = null;
            uiList <Vector2> _strokeUV       = null;

            if (aa > 0.0f)
            {
                _strokeVertices = ObjectPool <uiList <Vector3> > .alloc();

                _strokeUV = ObjectPool <uiList <Vector2> > .alloc();

                cvertices = 0;
                for (var i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    if (path.count <= 2)
                    {
                        continue;
                    }

                    cvertices += path.count * 2;
                }
                _strokeVertices.SetCapacity(cvertices);
                _strokeUV.SetCapacity(cvertices);

                float lw = this._fillConvex ? woff : aa + woff;
                float rw = aa - woff;
                float lu = this._fillConvex ? 0.5f : 0.0f;
                float ru = 1.0f;

                for (var i = 0; i < paths.Count; i++)
                {
                    var path = paths[i];
                    if (path.count <= 2)
                    {
                        continue;
                    }

                    path.istroke = _strokeVertices.Count;
                    for (var j = 0; j < path.count; j++)
                    {
                        var p = points[path.first + j];
                        _strokeVertices.Add(new Vector2(p.x + p.dmx * lw, p.y + p.dmy * lw));
                        _strokeUV.Add(new Vector2(lu, 1.0f));
                        _strokeVertices.Add(new Vector2(p.x - p.dmx * rw, p.y - p.dmy * rw));
                        _strokeUV.Add(new Vector2(ru, 1.0f));
                    }

                    path.nstroke = _strokeVertices.Count - path.istroke;
                    paths[i]     = path;
                }
            }

            return(new uiVertexUV {
                fillVertices = _vertices,
                fillUV = _uv,
                strokeVertices = _strokeVertices,
                strokeUV = _strokeUV,
            });
        }
Beispiel #5
0
        public static void bevelJoin(this uiList <Vector3> dst, uiList <Vector2> uv, uiPathPoint p0, uiPathPoint p1,
                                     float lw, float rw, float lu, float ru, float fringe)
        {
            float rx0, ry0, rx1, ry1;
            float lx0, ly0, lx1, ly1;

            float dlx0 = p0.dy;
            float dly0 = -p0.dx;
            float dlx1 = p1.dy;
            float dly1 = -p1.dx;

            if ((p1.flags & uiPointFlags.left) != 0)
            {
                chooseBevel((p1.flags & uiPointFlags.innerBevel) != 0, p0, p1, lw,
                            out lx0, out ly0, out lx1, out ly1);

                dst.Add(new Vector2 {
                    x = lx0, y = ly0
                });
                dst.Add(new Vector2 {
                    x = p1.x - dlx0 * rw, y = p1.y - dly0 * rw
                });
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));

                if ((p1.flags & uiPointFlags.bevel) != 0)
                {
                    dst.Add(new Vector2(lx0, ly0));
                    dst.Add(new Vector2(p1.x - dlx0 * rw, p1.y - dly0 * rw));
                    dst.Add(new Vector2(lx1, ly1));
                    dst.Add(new Vector2(p1.x - dlx1 * rw, p1.y - dly1 * rw));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(ru, 1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(ru, 1));
                }
                else
                {
                    rx0 = p1.x - p1.dmx * rw;
                    ry0 = p1.y - p1.dmy * rw;
                    dst.Add(new Vector2(p1.x, p1.y));
                    dst.Add(new Vector2(p1.x - dlx0 * rw, p1.y - dly0 * rw));
                    dst.Add(new Vector2(rx0, ry0));
                    dst.Add(new Vector2(rx0, ry0));
                    dst.Add(new Vector2(p1.x, p1.y));
                    dst.Add(new Vector2(p1.x - dlx1 * rw, p1.y - dly1 * rw));
                    uv.Add(new Vector2(0.5f, 1));
                    uv.Add(new Vector2(ru, 1));
                    uv.Add(new Vector2(ru, 1));
                    uv.Add(new Vector2(ru, 1));
                    uv.Add(new Vector2(0.5f, 1));
                    uv.Add(new Vector2(ru, 1));
                }

                dst.Add(new Vector2(lx1, ly1));
                dst.Add(new Vector2(p1.x - dlx1 * rw, p1.y - dly1 * rw));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));
            }
            else
            {
                chooseBevel((p1.flags & uiPointFlags.innerBevel) != 0, p0, p1, -rw,
                            out rx0, out ry0, out rx1, out ry1);

                dst.Add(new Vector2(p1.x + dlx0 * lw, p1.y + dly0 * lw));
                dst.Add(new Vector2(rx0, ry0));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));

                if ((p1.flags & uiPointFlags.bevel) != 0)
                {
                    dst.Add(new Vector2(p1.x + dlx0 * lw, p1.y + dly0 * lw));
                    dst.Add(new Vector2(rx0, ry0));
                    dst.Add(new Vector2(p1.x + dlx1 * lw, p1.y + dly1 * lw));
                    dst.Add(new Vector2(rx1, ry1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(ru, 1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(ru, 1));
                }
                else
                {
                    lx0 = p1.x + p1.dmx * lw;
                    ly0 = p1.y + p1.dmy * lw;
                    dst.Add(new Vector2(p1.x + dlx0 * lw, p1.y + dly0 * lw));
                    dst.Add(new Vector2(p1.x, p1.y));
                    dst.Add(new Vector2(lx0, ly0));
                    dst.Add(new Vector2(lx0, ly0));
                    dst.Add(new Vector2(p1.x + dlx1 * lw, p1.y + dly1 * lw));
                    dst.Add(new Vector2(p1.x, p1.y));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(0.5f, 1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(0.5f, 1));
                }

                dst.Add(new Vector2(p1.x + dlx1 * lw, p1.y + dly1 * lw));
                dst.Add(new Vector2(rx1, ry1));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));
            }
        }
Beispiel #6
0
        public static void roundJoin(this uiList <Vector3> dst, uiList <Vector2> uv, uiPathPoint p0, uiPathPoint p1,
                                     float lw, float rw, int ncap, float lu, float ru, float fringe)
        {
            float dlx0 = p0.dy;
            float dly0 = -p0.dx;
            float dlx1 = p1.dy;
            float dly1 = -p1.dx;

            if ((p1.flags & uiPointFlags.left) != 0)
            {
                float lx0, ly0, lx1, ly1;
                chooseBevel((p1.flags & uiPointFlags.innerBevel) != 0, p0, p1, lw,
                            out lx0, out ly0, out lx1, out ly1);

                float a0 = Mathf.Atan2(-dly0, -dlx0);
                float a1 = Mathf.Atan2(-dly1, -dlx1);
                if (a1 > a0)
                {
                    a1 -= Mathf.PI * 2;
                }

                dst.Add(new Vector2(lx0, ly0));
                dst.Add(new Vector2(p1.x - dlx0 * rw, p1.y - dly0 * rw));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));

                var n = Mathf.CeilToInt((a0 - a1) / Mathf.PI * ncap).clamp(2, ncap);
                for (var i = 0; i < n; i++)
                {
                    float u  = (float)i / (n - 1);
                    float a  = a0 + u * (a1 - a0);
                    float rx = p1.x + Mathf.Cos(a) * rw;
                    float ry = p1.y + Mathf.Sin(a) * rw;

                    dst.Add(new Vector2(p1.x, p1.y));
                    dst.Add(new Vector2(rx, ry));
                    uv.Add(new Vector2(0.5f, 1));
                    uv.Add(new Vector2(ru, 1));
                }

                dst.Add(new Vector2(lx1, ly1));
                dst.Add(new Vector2(p1.x - dlx1 * rw, p1.y - dly1 * rw));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));
            }
            else
            {
                float rx0, ry0, rx1, ry1;
                chooseBevel((p1.flags & uiPointFlags.innerBevel) != 0, p0, p1, -rw,
                            out rx0, out ry0, out rx1, out ry1);

                float a0 = Mathf.Atan2(dly0, dlx0);
                float a1 = Mathf.Atan2(dly1, dlx1);
                if (a1 < a0)
                {
                    a1 += Mathf.PI * 2;
                }

                dst.Add(new Vector2(p1.x + dlx0 * lw, p1.y + dly0 * lw));
                dst.Add(new Vector2(rx0, ry0));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));

                var n = Mathf.CeilToInt((a1 - a0) / Mathf.PI * ncap).clamp(2, ncap);
                for (var i = 0; i < n; i++)
                {
                    float u  = (float)i / (n - 1);
                    float a  = a0 + u * (a1 - a0);
                    float lx = p1.x + Mathf.Cos(a) * lw;
                    float ly = p1.y + Mathf.Sin(a) * lw;

                    dst.Add(new Vector2(lx, ly));
                    dst.Add(new Vector2(p1.x, p1.y));
                    uv.Add(new Vector2(lu, 1));
                    uv.Add(new Vector2(0.5f, 1));
                }

                dst.Add(new Vector2(p1.x + dlx1 * lw, p1.y + dly1 * lw));
                dst.Add(new Vector2(rx1, ry1));
                uv.Add(new Vector2(lu, 1));
                uv.Add(new Vector2(ru, 1));
            }
        }