コード例 #1
0
        private void CanvasPBX_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                var ind = GetComponentContainingPoint(e.Location);

                if (ind != -1)
                {
                    DeleteComponentFromGraph(ind);
                }

                List <Component> comFrom;
                List <Component> comTo;

                GetLinesContainingPoint(e.Location, out comFrom, out comTo);

                for (int i = 0; i < comFrom.Count; i++)
                {
                    comTo[i].RemoveInputComponent(comFrom[i]);
                }
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (newConnection != null)
                {
                    int ind = GetComponentContainingPoint(e.Location);
                    if (ind != -1)
                    {
                        if (ComponentsGraph[ind] != newConnection.c)
                        {
                            if (ComponentsGraph[ind].PointOnOutputConnection(e.Location) && newConnection.isInputToOutput)
                            {
                                if (!ComponentsGraph[ind].OutputComponents.Contains(newConnection.c) &&
                                    newConnection.c.IsValidInputComponent(ComponentsGraph[ind]))
                                {
                                    newConnection.c.AddInputComponent(ComponentsGraph[ind]);
                                }
                            }
                            else if (ComponentsGraph[ind].PointOnInputConnection(e.Location) &&
                                     newConnection.isOutputToInput)
                            {
                                if (!newConnection.c.OutputComponents.Contains(ComponentsGraph[ind]) && ComponentsGraph[ind].IsValidInputComponent(newConnection.c))
                                {
                                    ComponentsGraph[ind].AddInputComponent(newConnection.c);
                                }
                            }
                        }
                    }
                }
            }

            CanvasPBX.Invalidate();
            newConnection = null;
        }
コード例 #2
0
        private void CanvasPBX_MouseDown(object sender, MouseEventArgs e)
        {
            if (newConnection == null)
            {
                int ind = GetComponentContainingPoint(e.Location);

                if (ind != -1)
                {
                    if (ComponentsGraph[ind].PointOnInputConnection(e.Location))
                    {
                        newConnection = new MouseDownNewConnectionInfo()
                        {
                            isInputToOutput   = true,
                            isOutputToInput   = false,
                            isComponentToMove = false,
                            c = ComponentsGraph[ind]
                        };
                    }
                    else if (ComponentsGraph[ind].PointOnOutputConnection(e.Location))
                    {
                        newConnection = new MouseDownNewConnectionInfo()
                        {
                            isInputToOutput   = false,
                            isOutputToInput   = true,
                            isComponentToMove = false,
                            c = ComponentsGraph[ind]
                        };
                    }
                    else
                    {
                        newConnection = new MouseDownNewConnectionInfo()
                        {
                            isInputToOutput   = false,
                            isOutputToInput   = false,
                            isComponentToMove = true,
                            lastMouseLocation = e.Location,
                            c = ComponentsGraph[ind]
                        };
                    }
                }
            }
        }