Ejemplo n.º 1
0
 public static void Setup()
 {
     currentMouseState = new MouseState();
     currentMouseState.X = 0;
     currentMouseState.Y = 0;
     currentMouseState.Buttons = new Dictionary<MouseButtons, bool>();
     currentMouseState.Buttons.Add(MouseButtons.Left, false);
     currentMouseState.Buttons.Add(MouseButtons.Right, false);
     currentMouseState.Buttons.Add(MouseButtons.Middle, false);
 }
Ejemplo n.º 2
0
 public static MouseState GetMouseState()
 {
     MouseState m = new MouseState();
     m.X = currentMouseState.X;
     m.Y = currentMouseState.Y;
     m.Buttons = new Dictionary<MouseButtons, bool>();
     m.Buttons.Add(MouseButtons.Left, currentMouseState.Buttons[MouseButtons.Left]);
     m.Buttons.Add(MouseButtons.Right, currentMouseState.Buttons[MouseButtons.Right]);
     m.Buttons.Add(MouseButtons.Middle, currentMouseState.Buttons[MouseButtons.Middle]);
     return m;
 }
Ejemplo n.º 3
0
 public LogxMainForm()
 {
     MouseState.Setup();
     prevMS = MouseState.GetMouseState();
     Gate.LoadImages("Content\\TileSheet.png");
     SetupField();
     this.ClientSize = field.Size;
     this.MaximumSize = this.Size;
     this.MinimumSize = this.Size;
     this.MaximizeBox = false;
     this.SizeGripStyle = SizeGripStyle.Hide;
     this.SetStyle(ControlStyles.Opaque, true);
     this.Paint += new PaintEventHandler(LogxMainForm_Paint);
     this.MouseMove += new MouseEventHandler(LogxMainForm_MouseMove);
     this.MouseUp += new MouseEventHandler(LogxMainForm_MouseUp);
     this.MouseDown += new MouseEventHandler(LogxMainForm_MouseDown);
     this.KeyDown += new KeyEventHandler(LogxMainForm_KeyDown);
     this.KeyUp += new KeyEventHandler(LogxMainForm_KeyUp);
     this.Show();
     Run();
 }
Ejemplo n.º 4
0
        private void FrameUpdate()
        {
            currentMS = MouseState.GetMouseState();

            if (currentMS.Buttons[MouseButtons.Left] && !prevMS.Buttons[MouseButtons.Left])
            {
                for (int i = 0; i < gateList.Count; i++)
                {
                    if (gateList[i].location.X < currentMS.X &&
                        gateList[i].location.X + 32 > currentMS.X &&
                        gateList[i].location.Y < currentMS.Y &&
                        gateList[i].location.Y + 32 > currentMS.Y)
                    {
                        if (CtrlHeld)
                        {
                            if (gateList[i] is ButtonGate)
                            {
                                ((ButtonGate)gateList[i]).Toggle();
                                EvaluateCircuit();
                            }
                        }
                        else
                        {
                            pickedOffset.X = currentMS.X - gateList[i].location.X;
                            pickedOffset.Y = currentMS.Y - gateList[i].location.Y;
                            pickedGate = i;
                            selectedGate = i;
                        }
                        break;
                    }
                    else
                        pickedGate = -1;
                }
            }
            if (!currentMS.Buttons[MouseButtons.Left] && prevMS.Buttons[MouseButtons.Left])
            {
                pickedGate = -1;
            }

            if (pickedGate != -1)
            {
                gateList[pickedGate].location.X = currentMS.X - pickedOffset.X;
                gateList[pickedGate].location.Y = currentMS.Y - pickedOffset.Y;
                if (ShiftHeld)
                {
                    gateList[pickedGate].location.X -= gateList[pickedGate].location.X % 16;
                    gateList[pickedGate].location.Y -= gateList[pickedGate].location.Y % 16;
                }
            }

            if (currentMS.Buttons[MouseButtons.Right] && !prevMS.Buttons[MouseButtons.Right])
            {
                for (int i = 0; i < gateList.Count; i++)
                {
                    if (ShiftHeld)
                    {
                        if (gateList[i].location.X < currentMS.X &&
                            gateList[i].location.X + 32 > currentMS.X &&
                            gateList[i].location.Y < currentMS.Y &&
                            gateList[i].location.Y + 32 > currentMS.Y)
                        {
                            gateList[i].alive = false;
                            gateList.RemoveAt(i);
                            CleanupInputs();
                            break;
                        }
                    }
                    else
                    {
                        if (currentMS.X > gateList[i].location.X + 5 &&
                            currentMS.X < gateList[i].location.X + 15) //Selected Input Block
                        {
                            if (gateList[i].HasInput)
                            {
                                if (currentMS.Y > gateList[i].location.Y &&
                                    currentMS.Y < gateList[i].location.Y + 16) //Selected Top Input
                                {
                                    if (wiringAnchor == null)
                                    {
                                        wiringAnchor = new GateTie();
                                        wiringAnchor.inputNum = 0;
                                        wiringAnchor.gateptr = gateList[i];
                                    }
                                }
                                else if (currentMS.Y > gateList[i].location.Y + 16 &&
                                    currentMS.Y < gateList[i].location.Y + 32) //Selected Bottom Input
                                {
                                    if (wiringAnchor == null)
                                    {
                                        wiringAnchor = new GateTie();
                                        if (gateList[i].inputs.Length < 2) wiringAnchor.inputNum = 0;
                                        else wiringAnchor.inputNum = 1;
                                        wiringAnchor.gateptr = gateList[i];
                                    }
                                }
                            }
                        }
                        if (currentMS.X >= gateList[i].location.X + 18 &&
                            currentMS.X <= gateList[i].location.X + 23 &&
                            currentMS.Y >= gateList[i].location.Y &&
                            currentMS.Y <= gateList[i].location.Y + 32) //Selected Output Block
                        {
                            if (wiringAnchor != null)
                            {
                                if (wiringAnchor.gateptr != gateList[i])
                                {
                                    wiringAnchor.gateptr.inputs[wiringAnchor.inputNum] = gateList[i];
                                    wiringAnchor = null;
                                }
                            }
                        }
                    }
                }
            }

            if (SpaceHeld)
            {
                EvaluateCircuit();
            }

            prevMS = MouseState.GetMouseState();
        }