コード例 #1
0
ファイル: formMain.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (_surface == null)
            {
                return;
            }

            _surface.Dispose();
            _surface = null;
        }
コード例 #2
0
ファイル: formMain.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // Load the XInput plug-in assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.XInput.dll");

                // Create our factory.
                _factory = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonXInputPlugIn");

                // Ensure that we have and XBox controller to work with.
                if (_factory.JoystickDevices.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "No XBox controllers were found on this system.\nThis example requires an XBox controller.");
                    Gorgon.Quit();
                    return;
                }

                // Enumerate the active joysticks.  We'll only take 3 of the 4 available xbox controllers.
                _joystick      = new GorgonJoystick[3];
                _stickPosition = new PointF[_joystick.Count];
                _sprayStates   = new SprayCan[_joystick.Count];

                for (int i = 0; i < _joystick.Count; i++)
                {
                    var joystick = _factory.CreateJoystick(this, _factory.JoystickDevices[i].Name);

                    // Set a dead zone on the joystick.
                    // A dead zone will stop input from the joystick until it reaches the outside
                    // of the specified coordinates.
                    joystick.DeadZone.X          = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 4, joystick.Capabilities.XAxisRange.Maximum / 4);
                    joystick.DeadZone.Y          = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 4, joystick.Capabilities.YAxisRange.Maximum / 4);
                    joystick.DeadZone.SecondaryX = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 128, joystick.Capabilities.XAxisRange.Maximum / 128);
                    joystick.DeadZone.SecondaryY = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 128, joystick.Capabilities.YAxisRange.Maximum / 128);

                    _joystick[i] = joystick;

                    // Start at a random spot.
                    _stickPosition[i] = new Point(GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Width - 64), GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Height - 64));

                    // Turn off spray for all controllers.
                    _sprayStates[i] = new SprayCan(joystick, i);
                }

                // Check for connected controllers.
                while (!_joystick.Any(item => item.IsConnected))
                {
                    if (MessageBox.Show(this,
                                        "There are no XBox controllers connected.\nPlease plug in an XBox controller and click OK.",
                                        "No Controllers", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.Cancel)
                    {
                        continue;
                    }

                    Gorgon.Quit();
                    return;
                }

                // Get the graphics interface for our panel.
                _surface = new DrawingSurface(panelDisplay);

                // Set up our idle loop.
                Gorgon.ApplicationIdleLoopMethod += Idle;
            }
            catch (Exception ex)
            {
                // We do this here instead of just calling the dialog because this
                // function will send the exception to the Gorgon log file.
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
        }