Beispiel #1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            _leftMouse  = e.Button == MouseButtons.Left;
            _stratPoint = e.Location;

            int    entityTYpe    = -1;//0:ShapeBase;1:ShapeBase.connectors;2:connections;3:connections.From;4:connections.To.
            Entity hoveredentity = shapes.Cast <ShapeBase>().FirstOrDefault(f =>
            {
                if (f.Hit(e.Location))
                {
                    return(true);
                }
                return(false);
            });

            if (hoveredentity == null && selectedEntity != null && selectedEntity is ShapeBase)
            {
                Connector connector = (selectedEntity as ShapeBase).HitConnector(e.Location);
                if (connector != null)
                {
                    Point point = e.Location;
                    point.Offset(-this.ViewOriginPoint.GetPoint().X, -this.ViewOriginPoint.GetPoint().Y);

                    Connection connection = this.AddConnection(connector.Point, point);
                    connection.From.ContainEntity = connector.ContainEntity;
                    connection.From.ConnectorsIndexOfContainEntity = connector.ConnectorsIndexOfContainEntity;
                    UpdateSelected(connection.To);
                    connector.AttachConnector(connection.From);
                    tracking = true;
                    Invalidate(true);
                    return;
                }
            }

            if (hoveredentity != null)
            {
                tracking = true;
                OnSelectChanged(hoveredentity, new SelectElementChangedEventArgs()
                {
                    CurrentEntity = hoveredentity, PreviousEntity = selectedEntity
                });
            }
            else
            {
                hoveredentity = connections.Cast <Connection>().FirstOrDefault(f =>
                {
                    if (f.Hit(e.Location))
                    {
                        entityTYpe = 2;
                        return(true);
                    }
                    if (f.From.Hit(e.Location))
                    {
                        entityTYpe = 3;
                        return(true);
                    }
                    if (f.To.Hit(e.Location))
                    {
                        entityTYpe = 4;
                        return(true);
                    }
                    return(false);
                });

                if (entityTYpe == 3)
                {
                    hoveredentity = ((Connection)hoveredentity).From;
                    tracking      = true;
                }
                else if (entityTYpe == 4)
                {
                    hoveredentity = ((Connection)hoveredentity).To;
                    tracking      = true;
                }
                else if (entityTYpe == 2)
                {
                    OnSelectChanged(hoveredentity, new SelectElementChangedEventArgs()
                    {
                        CurrentEntity = hoveredentity, PreviousEntity = selectedEntity
                    });
                }
            }

            if (hoveredentity == null)
            {
                OnSelectChanged(this.proxy, new SelectElementChangedEventArgs()
                {
                    CurrentEntity = hoveredentity, PreviousEntity = selectedEntity
                });
            }
            UpdateSelected(hoveredentity);
            Invalidate(true);
        }