Esempio n. 1
0
        /// <summary>
        /// Function to create the joystick device.
        /// </summary>
        private void CreateJoystick()
        {
            // If we have a joystick controller, then let's activate it.
            if (_factory.JoystickDevices.Count <= 0)
            {
                return;
            }

            // Find the first one that's active.
            var activeDevice = (from joystick in _factory.JoystickDevices
                                where joystick.IsConnected
                                select joystick).FirstOrDefault();

            if (activeDevice == null)
            {
                return;
            }

            // Note that joysticks from Raw Input are always exclusive access,
            // so setting _joystick.Exclusive = true; does nothing.
            _joystick = _factory.CreateJoystick(this, activeDevice.Name);

            // Show our joystick information.
            labelJoystick.Text    = string.Empty;
            panelJoystick.Visible = true;

            UpdateJoystickLabel(JoystickTransformed);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SprayCan" /> struct.
 /// </summary>
 /// <param name="joystick">The joystick that owns this spray.</param>
 /// <param name="controllerIndex">Index of the controller.</param>
 public SprayCan(GorgonJoystick joystick, int controllerIndex)
 {
     Index           = controllerIndex;
     Joystick        = joystick;
     Position        = PointF.Empty;
     Amount          = 0.0f;
     Time            = 0.0f;
     VibrationAmount = 0.0f;
     SprayAlpha      = 255.0f;
     IsActive        = false;
 }
Esempio n. 3
0
        /// <summary>
        /// Function to draw the joystick cursor.
        /// </summary>
        /// <param name="joystick">Joystick for the cursor.</param>
        /// <param name="index">Index of the joystick.</param>
        private void DrawJoystickCursor(GorgonJoystick joystick, int index)
        {
            var playerColorValue = (int)((uint)0xFF << (index * 8) | 0xFF000000);                                       // Get the color based on the joystick index.
            var cursorSize       = new Size(_surface.CursorSize.Width / 2, _surface.CursorSize.Height / 2);             // Get the cursor size with offset.

            // Transform the axis into a -1 .. 1 range.
            var moveVector = new PointF(joystick.X - (float)joystick.Capabilities.XAxisRange.Minimum,
                                        joystick.Y - (float)joystick.Capabilities.YAxisRange.Minimum);

            moveVector = new PointF((moveVector.X / (joystick.Capabilities.XAxisRange.Range + 1) * 2.0f) - 1.0f,
                                    (moveVector.Y / (joystick.Capabilities.YAxisRange.Range + 1) * 2.0f) - 1.0f);

            // Move at 100 units per second
            float speed    = panelDisplay.ClientSize.Width / 2.0f * GorgonTiming.Delta;
            var   position = new PointF((speed * moveVector.X) + _stickPosition[index].X,
                                        (speed * -moveVector.Y) + _stickPosition[index].Y);


            // Limit the range of the positioning.
            if (position.X < -cursorSize.Width)
            {
                position = new PointF(panelDisplay.ClientRectangle.Right + cursorSize.Width, position.Y);
            }

            if (position.Y <= -cursorSize.Height)
            {
                position = new PointF(position.X, panelDisplay.ClientRectangle.Bottom + cursorSize.Height);
            }

            if (position.X > panelDisplay.ClientRectangle.Right + cursorSize.Width)
            {
                position = new PointF(-cursorSize.Width, position.Y);
            }

            if (position.Y > panelDisplay.ClientRectangle.Bottom + cursorSize.Height)
            {
                position = new PointF(position.X, -cursorSize.Height);
            }

            // Draw our cursor.
            _surface.DrawCursor(Point.Round(position), Color.FromArgb(playerColorValue));

            // Update our global position.
            _stickPosition[index] = position;
        }
Esempio n. 4
0
        /// <summary>
        /// Function to draw a spray on the screen.
        /// </summary>
        /// <param name="joystick">Joystick to use for the spray.</param>
        /// <param name="index">Index of the joystick.</param>
        private void DrawSpray(GorgonJoystick joystick, int index)
        {
            SprayCan state = _sprayStates[index];

            // Update the origin of the spray.
            state.Origin = _stickPosition[index];

            // Find out if we're spraying.
            if (joystick.Throttle > joystick.Capabilities.ThrottleAxisRange.Minimum)
            {
                if ((!state.IsActive) && (!state.NeedReset))
                {
                    // Convert the throttle value to a unit value.
                    float throttleUnit = ((float)(joystick.Throttle - joystick.Capabilities.ThrottleAxisRange.Minimum) / joystick.Capabilities.ThrottleAxisRange.Range);

                    // Set up the spray state.
                    state.Position        = state.Origin;
                    state.Amount          = joystick.Capabilities.ThrottleAxisRange.Range / 2.0f;
                    state.Time            = throttleUnit * 10.0f;
                    state.VibrationAmount = joystick.Capabilities.VibrationMotorRanges[1].Maximum;
                    state.SprayAlpha      = (throttleUnit * 239.0f) + 16;
                    state.IsActive        = true;
                }
            }
            else
            {
                state.IsActive = false;
            }

            if (!state.IsActive)
            {
                return;
            }

            // Update the state spray effect.
            state.Update();
            _surface.DrawPoint(Point.Round(state.Position), state.SprayColor, state.SprayPointSize);
        }
Esempio n. 5
0
        /// <summary>
        /// Function to update the controller labels.
        /// </summary>
        /// <param name="joystick">Joystick to update.</param>
        /// <param name="index">Index of the joystick.</param>
        private void UpdateControllerLabels(GorgonJoystick joystick, int index)
        {
            var panel = (Panel)panelControllers.Controls["panelController" + index];
            var label = (Label)panel.Controls["labelController" + index];

            // Update the label visibility for the controller.
            if (joystick.IsConnected)
            {
                if (!panel.Visible)
                {
                    panel.Visible = true;
                }
            }
            else
            {
                label.Text = string.Format("{0} ({1})", joystick.Name, _factory.JoystickDevices[index].ClassName);

                // Turn off the other ones since we don't want to clutter
                // up the screen.
                if ((index > 0) && (panel.Visible))
                {
                    panel.Visible = false;
                }
                return;
            }

            // Set the label information.
            label.Text = string.Format("{0} ({7}): Stick 1 Position {1}x{2}. Stick 2 Position {3}x{4}. Right Trigger Position {5}. Left Trigger Position {6}.",
                                       joystick.Name,
                                       joystick.X,
                                       joystick.Y,
                                       joystick.SecondaryX,
                                       joystick.SecondaryY,
                                       joystick.Throttle,
                                       joystick.Rudder,
                                       _factory.JoystickDevices[index].ClassName);
        }
Esempio n. 6
0
        private int _counter            = -1;                                   // Joystick index counter.
        #endregion

        #region Methods.
        /// <summary>
        /// Handles the KeyDown event of the _keyboard control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="KeyboardEventArgs" /> instance containing the event data.</param>
        private void _keyboard_KeyDown(object sender, KeyboardEventArgs e)
        {
            switch (e.Key)
            {
            case KeyboardKeys.Escape:
                Close();                                                // Close
                break;

            case KeyboardKeys.F:
                _screen.UpdateSettings(!_screen.Settings.IsWindowed);
                break;

            case KeyboardKeys.Down:
                _radius -= 1.0f;
                if (_radius < 2.0f)
                {
                    _radius = 2.0f;
                }
                break;

            case KeyboardKeys.Up:
                _radius += 1.0f;
                if (_radius > 10.0f)
                {
                    _radius = 10.0f;
                }
                break;

            case KeyboardKeys.F1:
                _blendMode = BlendingMode.Modulate;
                break;

            case KeyboardKeys.F2:
                _blendMode = BlendingMode.Additive;
                break;

            case KeyboardKeys.F3:
                _blendMode = BlendingMode.None;
                break;

            case KeyboardKeys.C:
                // Fill the back up image with white.
                using (var imageLock = _backupImage.Lock(BufferLockFlags.Write))
                {
                    imageLock.Data.Fill(0xFF);
                }

                _backBuffer.CopySubResource(_backupImage,
                                            new Rectangle(0, 0, _backBuffer.Settings.Width, _backBuffer.Settings.Height));
                break;

            case KeyboardKeys.J:
                if (_input.JoystickDevices.Count != 0)
                {
                    // Disable if we go beyond the end of the list.
                    _counter++;
                    if ((_counter >= _input.JoystickDevices.Count) && (_joystick != null))
                    {
                        _joystick           = null;
                        _counter            = -1;
                        _messageSprite.Text = "Using mouse and keyboard.";
                        break;
                    }

                    // Move to the next joystick.
                    _joystick           = _joystickList[_counter];
                    _messageSprite.Text = "Using joystick " + _joystick.Name;
                }
                break;
            }
        }