コード例 #1
0
        private void MouseManager_MouseMoved(object sender, MouseEventArgs e)
        {
            BodySelected = false;
            SelectedPin  = new SelectedPin();
            if (_boundingBox.Contains(e.MouseState.Position))
            {
                if (_area.Contains(e.MouseState.Position))
                {
                    BodySelected = true;
                }
                else
                {
                    for (int i = 0; i < InputPins.Count; i++)
                    {
                        Vector2 v = (InputPins[i] + Position.ToVector2());
                        if (Vector2.Distance(v, e.MouseState.Position.ToVector2()) <= pinsize)
                        {
                            SelectedPin = new SelectedPin(i + 1, InputPins, OutputPins, Position.ToVector2());
                        }
                        ;                                                                                        // selectpin == 0: null, < 0: Output, > 0: Input
                    }

                    for (int i = 0; i < OutputPins.Count; i++)
                    {
                        Vector2 v = (OutputPins[i] + Position.ToVector2());
                        if (Vector2.Distance(v, e.MouseState.Position.ToVector2()) <= pinsize)
                        {
                            SelectedPin = new SelectedPin(-i - 1, InputPins, OutputPins, Position.ToVector2()); // selectpin == 0: null, < 0: Output, > 0: Input
                        }
                    }
                }
            }
        }
コード例 #2
0
        public GateObject(IGate gate, Texture2D gateTexture, Point position)
        {
            this.gate   = gate;
            SelectedPin = new SelectedPin();

            int width = Math.Max(gate.Inputs.Length, gate.Outputs.Length);

            _area             = new Rectangle(position, new Point(size + padding * 2, size * width + padding * 2));
            _originalPosition = _area.Location;
            this.gateTexture  = createGateTexture(gateTexture);


            _boundingBox = _area;
            _boundingBox.Inflate(padding * 3, 0);

            InputPins  = CreatePinPosition(gate.Inputs.Length, -padding * 2, _area.Height);
            OutputPins = CreatePinPosition(gate.Outputs.Length, padding * 2 + _area.Width, _area.Height);

            Focus();
        }