Ejemplo n.º 1
0
        IEnumerable <UIVertex> getFillVeritces()
        {
            if (mLines == null)
            {
                yield break;
            }
            float z = 0f;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg        = mLines[i];
                int          totalLines = seg.LineCount;
                for (int j = mMinModifyIndex; j < totalLines; ++j)
                {
                    Vector3 from;
                    Vector3 to;
                    seg.GetLine(j, out from, out to);

                    Vector2 toTrim   = to;
                    Vector2 fromTrim = from;
                    TrimItem(mFillRect.xMin, mFillRect.yMin, mFillRect.xMax, mFillRect.yMin, true, false, ref fromTrim, ref toTrim);
                    to   = new Vector3(toTrim.x, toTrim.y, to.z);
                    from = new Vector3(fromTrim.x, fromTrim.y, from.z);
                    Vector3 fromBottom = from;
                    Vector3 toBottom   = to;

                    fromBottom.y = mFillRect.yMin;
                    toBottom.y   = mFillRect.yMin;

                    float fromV = 1f;
                    float toV   = 1f;

                    if (mStretchY == false)
                    {
                        fromV = Mathf.Abs((from.y - mFillRect.yMin) / mFillRect.height);
                        toV   = Mathf.Abs((to.y - mFillRect.yMin) / mFillRect.height);
                    }

                    float   fromU = ((from.x - mFillRect.xMin) / mFillRect.width);
                    float   toU   = ((to.x - mFillRect.xMin) / mFillRect.width);
                    Vector2 uv1   = TransformUv(new Vector2(fromU, fromV));
                    Vector2 uv2   = TransformUv(new Vector2(toU, toV));
                    Vector2 uv3   = TransformUv(new Vector2(fromU, 0f));
                    Vector2 uv4   = TransformUv(new Vector2(toU, 0f));

                    UIVertex v1 = ChartCommon.CreateVertex(from, uv1, z);
                    UIVertex v2 = ChartCommon.CreateVertex(to, uv2, z);
                    UIVertex v3 = ChartCommon.CreateVertex(fromBottom, uv3, z);
                    UIVertex v4 = ChartCommon.CreateVertex(toBottom, uv4, z);

                    yield return(v1);

                    yield return(v2);

                    yield return(v3);

                    yield return(v4);
                }
            }
        }
Ejemplo n.º 2
0
        void PickLine(Vector3 mouse, out int segment, out int line)
        {
            float minDist = Mathf.Infinity;

            segment = -1;
            line    = -1;

            if (mLines == null)
            {
                return;
            }
            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.LineCount;
                for (int j = 0; j < total; ++j)
                {
                    Vector3 from;
                    Vector3 to;
                    seg.GetLine(j, out from, out to);
                    float dist = ChartCommon.SegmentPointSqrDistance(from, to, mouse);
                    if (dist < minDist)
                    {
                        minDist = dist;
                        segment = i;
                        line    = j;
                    }
                }
            }
            float sensitivity = 10f;

            if (mControl != null)
            {
                sensitivity = mControl.Sensitivity;
            }
            float thresh = (Thickness + sensitivity);

            if ((ViewRect.HasValue && !ViewRect.Value.Contains(mouse)) || minDist > thresh * thresh)
            {
                segment = -1;
                line    = -1;
            }
        }
Ejemplo n.º 3
0
        IEnumerable <UIVertex> getLineVertices()
        {
            if (mLines == null)
            {
                yield break;
            }
            float halfThickness = Thickness * 0.5f;
            float z             = 0f;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg        = mLines[i];
                int          totalLines = seg.LineCount;
                Line?        peek       = null;
                Line?        prev       = null;
                float        tileUv     = 0f;
                float        totalUv    = 0f;
                for (int j = mMinModifyIndex; j < totalLines; ++j)
                {
                    totalUv += (float)seg.GetLineMag(j);
                }
                for (int j = mMinModifyIndex; j < totalLines; ++j)
                {
                    Line line;
                    bool hasNext = j + 1 < totalLines;
                    if (peek.HasValue)
                    {
                        line = peek.Value;
                    }
                    else
                    {
                        line = seg.GetLine(j, halfThickness, prev.HasValue, hasNext);
                    }
                    peek = null;
                    if (j + 1 < totalLines)
                    {
                        peek = seg.GetLine(j + 1, halfThickness, true, j + 2 < totalLines);
                    }

                    Vector3 p1 = line.P1;
                    Vector3 p2 = line.P2;
                    Vector3 p3 = line.P3;
                    Vector3 p4 = line.P4;

                    Vector2 uv1 = new Vector2(tileUv * Tiling, 0f);
                    Vector2 uv2 = new Vector2(tileUv * Tiling, 1f);
                    tileUv += line.Mag / totalUv;

                    Vector2 uv3 = new Vector2(tileUv * Tiling, 0f);
                    Vector2 uv4 = new Vector2(tileUv * Tiling, 1f);

                    UIVertex v1 = ChartCommon.CreateVertex(p1, uv1, z);
                    UIVertex v2 = ChartCommon.CreateVertex(p2, uv2, z);
                    UIVertex v3 = ChartCommon.CreateVertex(p3, uv3, z);
                    UIVertex v4 = ChartCommon.CreateVertex(p4, uv4, z);

                    yield return(v1);

                    yield return(v2);

                    yield return(v3);

                    yield return(v4);

                    if (peek.HasValue)
                    {
                        float   myZ = z + 0.2f;
                        Vector3 a1, a2;
                        GetSide(line.To, line.Dir, line.Normal, halfThickness * 0.5f, halfThickness * 0.6f, v3.position.z, out a1, out a2);
                        yield return(v3);

                        yield return(v4);

                        yield return(ChartCommon.CreateVertex(a1, v3.uv0, myZ));

                        yield return(ChartCommon.CreateVertex(a2, v4.uv0, myZ));
                    }
                    if (prev.HasValue)
                    {
                        float   myZ = z + 0.2f;
                        Vector3 a1, a2;
                        GetSide(line.From, -line.Dir, line.Normal, halfThickness * 0.5f, halfThickness * 0.6f, v1.position.z, out a1, out a2);
                        yield return(ChartCommon.CreateVertex(a1, v1.uv0, myZ));

                        yield return(ChartCommon.CreateVertex(a2, v2.uv0, myZ));

                        yield return(v1);

                        yield return(v2);
                    }
                    //z -= 0.05f;
                    prev = line;
                }
            }
        }