コード例 #1
0
ファイル: Form1.cs プロジェクト: rabirland/LogicCircuit
        private void AddWire(Wire wire)
        {
            var wireEntry = new WireEntry(wire);

            this._circuit.Connect(wire);
            this._wires.Add(wireEntry);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: rabirland/LogicCircuit
 private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)         // Wire
 {
     if (this._selectedWire != null)
     {
         this._circuit.Disconnect(this._selectedWire.Wire);
         this._wires.Remove(this._selectedWire);
         this._selectedWire = null;
         this.CircuitPanel.Refresh();
     }
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: rabirland/LogicCircuit
        private void CircuitPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (this._selectedPort != null && this._selected == null)
            {
                throw new Exception("Unexpected selection error");
            }

            if (this._didDragging)
            {
                return;
            }


            if (e.Button == MouseButtons.Left)
            {
                if (this._interacted != null)                                                          // _dragging should be auto-filled in the MouseDown listener, if it's null => the user hasn't clicked on a node
                {
                    if (this.IsNodeInputPortClicked(this._interacted, e.Location, out int portNumber)) // Check if we clicked on an input port
                    {
                        // There is already have a selected output port and not on the same object
                        if (this._selectedPort != null && this._selectedPort == 0 && this._selected != this._interacted)
                        {
                            this.AddWire(new Wire(this._selected.Node, this._interacted.Node, portNumber));

                            // Clear port selection
                            this._selected     = null;
                            this._selectedPort = null;
                        }
                        else                         // No port selected OR there was an input port selected OR we tried to connect a gate with itself => replace the selection
                        {
                            // Mark port selection
                            this._selected     = this._interacted;
                            this._selectedPort = portNumber;                             // No current selected port => select the clicked one
                        }
                    }
                    else if (IsNodeOutputPortClicked(this._interacted, e.Location))                     // No input port was selected => Check is the output port was selected
                    {
                        // There was an input port selected and not on the same object => connect
                        if (this._selectedPort != null && this._selectedPort > 0 && this._selected != this._interacted)
                        {
                            this.AddWire(new Wire(this._interacted.Node, this._selected.Node, this._selectedPort.Value));

                            // Clear port selection
                            this._selected     = null;
                            this._selectedPort = null;
                        }
                        else                         // There was no port selected OR there was an input port selected OR we clicked on an input port but on the same object => replace the selection
                        {
                            this._selected     = this._interacted;
                            this._selectedPort = 0;
                        }
                    }
                    else                     // Not clicked on output port either => simply clicked on the object somewhere
                    {
                    }
                }
                else                 // Clicked outside of a node
                {
                    this._selected     = null;
                    this._selectedPort = null;
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                WireEntry wireEntry;
                if (this._interacted != null)                 // Clicked on node
                {
                    this._selected     = _interacted;
                    this._selectedPort = null;
                    this.nodeRightClickMenu.Show(this.CircuitPanel.PointToScreen(e.Location));
                }
                else if ((wireEntry = GetWireAt(e.Location)) != null)                 // Clicked near wire
                {
                    this._selectedWire = wireEntry;
                    wireRightClickMenu.Show(this.CircuitPanel.PointToScreen(e.Location));
                }
                else
                {
                    this._selected     = null;
                    this._selectedWire = null;
                    this._selectedPort = null;
                }
            }

            // Stop Dragging
            this._interacted = null;

            this.CircuitPanel.Refresh();
        }