Ejemplo n.º 1
0
        void PickDot(Vector3 mouse, out int segment, out int point)
        {
            float minDist = Mathf.Infinity;

            segment = -1;
            point   = -1;
            if (mLines == null)
            {
                return;
            }
            float mag = mPointSize;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.PointCount;
                for (int j = 0; j < total; ++j)
                {
                    Vector4 p = seg.getPoint(j);
                    if (p.w == 0f)
                    {
                        continue;
                    }
                    float dist = (mouse - ((Vector3)p)).sqrMagnitude;
                    if (dist < minDist)
                    {
                        mag = p.w;
                        if (mag < 0f)
                        {
                            mag = mPointSize;
                        }
                        minDist = dist;
                        segment = i;
                        point   = j;
                    }
                }
            }

            float sensitivity = 10f;

            if (mControl != null)
            {
                sensitivity = mControl.Sensitivity;
            }

            float thresh = mag + sensitivity;

            if ((ViewRect.HasValue && !ViewRect.Value.Contains(mouse)) || minDist > thresh * thresh)
            {
                segment = -1;
                point   = -1;
            }
        }
        IEnumerable <UIVertex> getDotVeritces()
        {
            if (mLines == null)
            {
                yield break;
            }
            float z        = 0f;
            float halfSize = mPointSize * 0.5f;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.PointCount;
                for (int j = mMinModifyIndex; j < total; ++j)
                {
                    Vector4 magPoint = seg.getPoint(j);
                    if (magPoint.w == 0f)
                    {
                        continue;
                    }

                    Vector3 point = (Vector3)magPoint;
                    halfSize = mPointSize * 0.5f;
                    ProcesssPoint(ref magPoint, ref halfSize);
                    Vector3 p1  = point + new Vector3(-halfSize, -halfSize, 0f);
                    Vector3 p2  = point + new Vector3(halfSize, -halfSize, 0f);
                    Vector3 p3  = point + new Vector3(-halfSize, halfSize, 0f);
                    Vector3 p4  = point + new Vector3(halfSize, halfSize, 0f);
                    Vector2 uv1 = new Vector2(0f, 0f);
                    Vector2 uv2 = new Vector2(1f, 0f);
                    Vector2 uv3 = new Vector2(0f, 1f);
                    Vector2 uv4 = new Vector2(1f, 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);

                    if (ClipRect.HasValue == false || ClipRect.Value.Contains(p1) || ClipRect.Value.Contains(p2) || ClipRect.Value.Contains(p3) ||
                        ClipRect.Value.Contains(p4))
                    {
                        yield return(v1);

                        yield return(v2);

                        yield return(v3);

                        yield return(v4);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        IEnumerable <UIVertex> getDotVeritces()
        {
            if (mLines == null)
            {
                yield break;
            }
            float z        = 0f;
            float halfSize = mPointSize * 0.5f;

            for (int i = 0; i < mLines.Count; ++i)
            {
                LineSegement seg   = mLines[i];
                int          total = seg.PointCount;
                for (int j = 0; j < total; ++j)
                {
                    Vector4 magPoint = seg.getPoint(j);
                    if (magPoint.w == 0f)
                    {
                        continue;
                    }

                    Vector3 point = (Vector3)magPoint;
                    halfSize = mPointSize * 0.5f;
                    if (magPoint.w >= 0f)
                    {
                        halfSize = magPoint.w * 0.5f;
                    }
                    Vector3 p1  = point + new Vector3(-halfSize, -halfSize, 0f);
                    Vector3 p2  = point + new Vector3(halfSize, -halfSize, 0f);
                    Vector3 p3  = point + new Vector3(-halfSize, halfSize, 0f);
                    Vector3 p4  = point + new Vector3(halfSize, halfSize, 0f);
                    Vector2 uv1 = new Vector2(0f, 0f);
                    Vector2 uv2 = new Vector2(1f, 0f);
                    Vector2 uv3 = new Vector2(0f, 1f);
                    Vector2 uv4 = new Vector2(1f, 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);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// sets the lines for this renderer
        /// </summary>
        /// <param name="lines"></param>
        internal void SetLines(List <LineSegement> lines)
        {
            //    mUseCache = false;
            mLines   = lines;
            mMinX    = float.PositiveInfinity;
            mMinY    = float.PositiveInfinity;
            mMaxX    = float.NegativeInfinity;
            mMaxY    = float.NegativeInfinity;
            mControl = GetComponentInParent <SensitivityControl>();

            if (mLines != null)
            {
                for (int i = 0; i < mLines.Count; i++)
                {
                    LineSegement seg         = mLines[i];
                    int          totalPoints = seg.PointCount;
                    for (int j = 0; j < totalPoints; j++)
                    {
                        Vector3 point = seg.getPoint(j);
                        mMinX = Mathf.Min(mMinX, point.x);
                        mMinY = Mathf.Min(mMinY, point.y);
                        mMaxX = Mathf.Max(mMaxX, point.x);
                        mMaxY = Mathf.Max(mMaxY, point.y);
                    }
                }
            }

            SetAllDirty();
            mIsMouseIn = false;
            for (int i = 0; i < mHoverObjectes.Count; i++)
            {
                mHoverObjectes[i].gameObject.SetActive(false);
                mHoverFreeObjects.Add(mHoverObjectes[i]);
            }
            mHoverObjectes.Clear();

            if (mCurrentHover != null)
            {
                mCurrentHover.gameObject.SetActive(false);
                mHoverFreeObjects.Add(mCurrentHover);
                mCurrentHover = null;
            }
            mPickedI = mPickedJ = -1;
            Rebuild(CanvasUpdate.PreRender);
        }
Ejemplo n.º 5
0
        internal void ModifyLines(List <Vector4> lines)
        {
            //mUseCache = false;
            if (mLines.Count == 0)
            {
                mLines.Add(new LineSegement(lines.ToArray()));
                return;
            }
            //bool regenerate = false;
            //if(mLines[0].)
            mLines[0].ModifiyLines(lines);
            mMinX    = float.PositiveInfinity;
            mMinY    = float.PositiveInfinity;
            mMaxX    = float.NegativeInfinity;
            mMaxY    = float.NegativeInfinity;
            mControl = GetComponentInParent <SensitivityControl>();

            if (mLines != null)
            {
                for (int i = 0; i < mLines.Count; i++)
                {
                    LineSegement seg         = mLines[i];
                    int          totalPoints = seg.PointCount;
                    for (int j = 0; j < totalPoints; j++)
                    {
                        Vector3 point = seg.getPoint(j);
                        mMinX = Mathf.Min(mMinX, point.x);
                        mMinY = Mathf.Min(mMinY, point.y);
                        mMaxX = Mathf.Max(mMaxX, point.x);
                        mMaxY = Mathf.Max(mMaxY, point.y);
                    }
                }
                //   lines.Add()
            }
            SetVerticesDirty();
            Rebuild(CanvasUpdate.PostLayout);
            mForceMouseMove = true;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// finds the minimum and maximum values of the currently set data
 /// </summary>
 void FindBoundingValues()
 {
     mMinX = float.PositiveInfinity;
     mMinY = float.PositiveInfinity;
     mMaxX = float.NegativeInfinity;
     mMaxY = float.NegativeInfinity;
     // this part finds the bounding box of the lines
     if (mLines != null)
     {
         for (int i = 0; i < mLines.Count; i++)
         {
             LineSegement seg         = mLines[i];
             int          totalPoints = seg.PointCount;
             for (int j = 0; j < totalPoints; j++)
             {
                 Vector3 point = seg.getPoint(j);
                 mMinX = Mathf.Min(mMinX, point.x);
                 mMinY = Mathf.Min(mMinY, point.y);
                 mMaxX = Mathf.Max(mMaxX, point.x);
                 mMaxY = Mathf.Max(mMaxY, point.y);
             }
         }
     }
 }