コード例 #1
0
        private void SetItemControlSelected(IItemControl control)
        {
            ItemControlType controlType = ItemControlTypes.TypesTable[control.GetType()];

            if (controlType == ItemControlType.Button)
            {
                foreach (IItemControl c in ControlsOnScreen.Values)
                {
                    c.Selected = c == control;
                }
            }
        }
コード例 #2
0
        private bool CheckOnSelectedItemControlUnhandleMouse()
        {
            //No control handled mouse
            if (_itemControlThatHandledMouse == null)
            {
                return(false);
            }

            //Get control type
            ItemControlType controlType = ItemControlTypes.TypesTable[_itemControlThatHandledMouse.GetType()];

            switch (controlType)
            {
            //LinkPoint
            case ItemControlType.LinkPoint:
            {
                if (ReadOnly)
                {
                    return(true);
                }

                LinkingArrow arrow    = Parent.CurrentLinkingArrow;
                MapItem      srcItem  = arrow.SourceItem;
                MapItem      destItem = arrow.DestinationItem;

                //If no endpoint defined for the current linking arrow
                if (destItem == null)
                {
                    //Remove linking arrow from parent arrows list
                    Parent.RemoveLinkingArrow(arrow);

                    //Set unselected state for the current link point
                    srcItem.RightLinkPoint.Selected = srcItem.GetRightSideLinkedArrow() != null;
                }

                //otherwise connect current linking arrow
                else
                {
                    bool cancelled = !Parent.LinkArrow(arrow, destItem, true);

                    //Check if linking was cancelled
                    if (cancelled)
                    {
                        //Remove linking arrow from parent arrows list
                        Parent.RemoveLinkingArrow(arrow);

                        //Set unselected state for the link points
                        destItem.LeftLinkPoint.Selected = srcItem.GetLeftSideLinkedArrow() != null;
                        srcItem.RightLinkPoint.Selected = srcItem.GetRightSideLinkedArrow() != null;
                    }
                }

                //Repaint source, destination items and parent
                if (this != srcItem)
                {
                    srcItem.Repaint();
                }
                Repaint();
                Parent.Repaint();

                break;
            }
            }

            //Mouse unhandled
            return(true);
        }
コード例 #3
0
        private bool CheckOnSelectedItemControlHandleMouse(Point pos)
        {
            if (ControlUnderCursor != null)
            {
                //Get current control type
                ItemControlType controlType = ItemControlTypes.TypesTable[ControlUnderCursor.GetType()];

                //Store current item control that handled mouse
                _itemControlThatHandledMouse = ControlUnderCursor;

                switch (controlType)
                {
                //LinkPoint
                case ItemControlType.LinkPoint:
                {
                    if (ReadOnly)
                    {
                        return(true);
                    }

                    //For right-side link point
                    if (ControlUnderCursor == RightLinkPoint)
                    {
                        //Add new linking arrow
                        Parent.CreateLinkingArrow(this);

                        //Set selected state for the current link point and repaint self
                        _itemControlThatHandledMouse.Selected = true;
                        Repaint();
                    }

                    //For left-side link point
                    else
                    {
                        LinkingArrow arrow = GetLeftSideLinkedArrow();
                        if (arrow != null)
                        {
                            Parent.UnlinkArrrow(arrow, this, true);
                            Parent.CurrentLinkingArrow            = arrow;
                            _itemControlThatHandledMouse.Selected = GetLeftSideLinkedArrow() != null;
                        }
                        else
                        {
                            _itemControlThatHandledMouse = null;
                        }
                    }
                    break;
                }

                //Image
                case ItemControlType.Image:
                {
                    return(false);
                }
                }

                //Case mouse movement
                CheckOnSelectedItemControlMouseMove(pos);

                //Mouse handled
                return(true);
            }

            //No control under cursor
            return(false);
        }
コード例 #4
0
        private void CheckOnSelectedItemControlMouseMove(Point pos)
        {
            //No control handled mouse
            if (_itemControlThatHandledMouse == null)
            {
                return;
            }

            //Get current control type
            ItemControlType controlType = ItemControlTypes.TypesTable[_itemControlThatHandledMouse.GetType()];

            switch (controlType)
            {
            //LinkPoint
            case ItemControlType.LinkPoint:
            {
                if (ReadOnly)
                {
                    return;
                }

                LinkingArrow arrow   = Parent.CurrentLinkingArrow;
                MapItem      srcItem = arrow.SourceItem;

                //Get destionation item under mouse cursor
                MapItem destItem = Parent.GetItemForLinkingUnderCursor(this, srcItem, pos);

                //If destionation exists
                if (destItem != null)
                {
                    //If destItem not setted yet as destination item for the current linking arrow
                    if (destItem != arrow.DestinationItem)
                    {
                        //Set left link point selected
                        destItem.LeftLinkPoint.Selected = true;
                        arrow.DestinationItem           = destItem;

                        //Repaint self and parent
                        Parent.Repaint();
                        destItem.Repaint();
                    }
                }

                //otherwise
                else
                {
                    destItem = arrow.DestinationItem;
                    if (destItem != null)
                    {
                        //Set left link point unselected
                        destItem.LeftLinkPoint.Selected = false;

                        //Repaint self
                        destItem.Repaint();

                        //Drop destination item references
                        destItem = arrow.DestinationItem = null;
                    }

                    //Update current linking arrow dest point according to mouse position
                    Point point = Parent.PointToClient(PointToScreen(pos));
                    Parent.UpdateLinkingArrowEndPoint(arrow, point);
                    Parent.Repaint();
                }

                //Temporary set destination item for the current linking arrow
                arrow.DestinationItem = destItem;

                break;
            }
            }
        }