Пример #1
0
        public override void LoadFromStream(Stream aStream)
        {
            FPoints.Clear();

            base.LoadFromStream(aStream);

            FWidth     = (byte)aStream.ReadByte();
            FLineStyle = (HCPenStyle)aStream.ReadByte();

            int vCount = 0;

            byte[] vBuffer = BitConverter.GetBytes(vCount);
            aStream.Read(vBuffer, 0, vBuffer.Length);
            vCount = BitConverter.ToInt32(vBuffer, 0);

            int     vX = 0, vY = 0;
            HCPoint vPoint = null;

            for (int i = 0; i < vCount; i++)
            {
                aStream.Read(vBuffer, 0, vBuffer.Length);
                vX = BitConverter.ToInt32(vBuffer, 0);
                aStream.Read(vBuffer, 0, vBuffer.Length);
                vY     = BitConverter.ToInt32(vBuffer, 0);
                vPoint = new HCPoint(vX, vY);
                FPoints.Add(vPoint);
            }
        }
Пример #2
0
        public override void Assign(HCShape source)
        {
            base.Assign(source);

            FPoints.Clear();
            for (int i = 0; i < (source as HCShapePolygon).Points.Count; i++)
            {
                HCPoint vPoint = new HCPoint(
                    (source as HCShapePolygon).Points[i].X,
                    (source as HCShapePolygon).Points[i].Y);

                FPoints.Add(vPoint);
            }
        }
Пример #3
0
        protected int GetPointAt(int x, int y)
        {
            HCPoint vPoint = null;

            for (int i = 0; i < FPoints.Count; i++)
            {
                vPoint = FPoints[i];
                if (HC.PtInRect(new RECT(vPoint.X - PointSize, vPoint.Y - PointSize,
                                         vPoint.X + PointSize, vPoint.Y + PointSize), new POINT(x, y)))
                {
                    return(i);
                }
            }

            return(-1);
        }
Пример #4
0
        public override void ParseXml(XmlElement aNode)
        {
            FPoints.Clear();

            base.ParseXml(aNode);

            FWidth     = byte.Parse(aNode.Attributes["width"].Value);
            FLineStyle = (HCPenStyle)byte.Parse(aNode.Attributes["ls"].Value);

            HCPoint vPoint = null;

            for (int i = 0; i < aNode.ChildNodes.Count; i++)
            {
                vPoint = new HCPoint(int.Parse(aNode.ChildNodes[i].Attributes["x"].Value),
                                     int.Parse(aNode.ChildNodes[i].Attributes["y"].Value));

                FPoints.Add(vPoint);
            }
        }
Пример #5
0
        public override bool MouseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (StructState == HCStructState.hstcStructing)
                {
                    StructOver();
                }

                return(false);
            }

            if (e.Button != MouseButtons.Left)
            {
                return(false);
            }

            bool vResult = false;

            if (StructState != HCStructState.hstcStop)      // 没有处于构建状态
            {
                if (StructState == HCStructState.hstcStart) // 开始构建
                {
                    HCPoint vPoint = new HCPoint(e.X, e.Y);
                    FPoints.Add(vPoint);

                    vPoint = new HCPoint(e.X, e.Y);
                    FPoints.Add(vPoint);
                    FActivePointIndex = FPoints.Count - 1;
                    StructState       = HCStructState.hstcStructing;
                }
                else
                if (StructState == HCStructState.hstcStructing)
                {
                    HCPoint vPoint = new HCPoint(e.X, e.Y);
                    FPoints.Add(vPoint);
                    FActivePointIndex = FPoints.Count - 1;
                }
                else
                {
                    StructOver();
                }

                vResult = true;
            }
            else
            {
                int vIndex = GetPointAt(e.X, e.Y);
                if (FActivePointIndex != vIndex)
                {
                    FActivePointIndex = vIndex;
                    Active            = FActivePointIndex >= 0;
                    vResult           = Active;
                }
                else
                {
                    vResult = vIndex >= 0;
                }

                if (!vResult)  // 是否在线段上
                {
                    vIndex = GetLineAt(e.X, e.Y);
                    if (FActiveLineIndex != vIndex)
                    {
                        FActiveLineIndex = vIndex;
                        Active           = FActiveLineIndex >= 0;
                        vResult          = Active;
                    }
                    else
                    {
                        vResult = vIndex >= 0;
                    }
                }

                if (vResult)
                {
                    FMousePt.X = e.X;
                    FMousePt.Y = e.Y;
                }
            }

            return(vResult);
        }