Beispiel #1
0
        /// <summary>
        /// Function to process idle time in the application.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to end processing.</returns>
        private bool Idle()
        {
            if (labelMessage.Visible)
            {
                return(true);
            }

            _surface.Clear(Color.White);

            for (int i = 0; i < _controllers.Count; i++)
            {
                IGorgonGamingDevice controller = _controllers[i];

                // Do nothing if this joystick isn't connected.
                if (!controller.IsConnected)
                {
                    continue;
                }

                controller.Poll();

                // Clear the drawing if the primary button is clicked.
                if (controller.Button[0] == GamingDeviceButtonState.Down)
                {
                    _surface.ClearDrawing();
                }

                // Draw the controller cursor.
                DrawControllerCursor(controller, i);

                // Begin drawing.
                DrawSpray(controller, i);

                UpdateControllerLabels(controller, i);
            }

            _surface.Render();

            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Function to process during idle time.
        /// </summary>
        /// <returns><b>true</b> to continue processing, <b>false</b> to end processing.</returns>
        private bool Gorgon_Idle()
        {
            // Cursor position.
            Point mousePosition  = PointToClient(!_useWinFormsInput ? _mouse.Position : Cursor.Position);
            var   cursorPosition = new DX.Vector2(mousePosition.X, mousePosition.Y);

            if (!_useWinFormsInput)
            {
                Cursor.Position = PointToScreen(mousePosition);
            }

            // Dump to the screen.
            _2D.Begin(_noBlending);
            _2D.DrawFilledRectangle(new DX.RectangleF(0, 0, _backBuffer.Width, _backBuffer.Height), GorgonColor.White, _backBufferView, new DX.RectangleF(0, 0, 1, 1));
            _2D.End();

            if (_joystick != null)
            {
                // Poll the joystick.
                _joystick.Poll();

                GorgonRange xAxisRange = _joystick.Info.AxisInfo[GamingDeviceAxis.XAxis].Range;
                GorgonRange yAxisRange = _joystick.Info.AxisInfo[GamingDeviceAxis.YAxis].Range;

                // Adjust position to match screen coordinates.
                cursorPosition = new DX.Vector2(_joystick.Axis[GamingDeviceAxis.XAxis].Value - xAxisRange.Minimum,
                                                _joystick.Axis[GamingDeviceAxis.YAxis].Value - yAxisRange.Minimum);
                cursorPosition.X = cursorPosition.X / (xAxisRange.Range + 1) * _screen.Width;
                cursorPosition.Y = _screen.Height - (cursorPosition.Y / (yAxisRange.Range + 1) * _screen.Height);
            }


            // Draw cursor.
            _2D.Begin(_inverted);
            if (_radius > 3.0f)
            {
                _2D.DrawFilledEllipse(new DX.RectangleF(cursorPosition.X - (_radius / 2.0f), cursorPosition.Y - (_radius / 2.0f), _radius, _radius), Color.White);
            }
            else
            {
                _2D.DrawFilledRectangle(new DX.RectangleF(cursorPosition.X - (_radius / 2.0f), cursorPosition.Y - (_radius / 2.0f), _radius, _radius), Color.White);
            }
            _2D.End();

            // If we have a joystick button down, then draw a black dot.
            if ((_joystick != null) && (_joystick.Button[0] == GamingDeviceButtonState.Down))
            {
                var penPosition = new DX.RectangleF(cursorPosition.X - (_radius / 2.0f), cursorPosition.Y - (_radius / 2.0f), _radius, _radius);
                _graphics.SetRenderTarget(_backBuffer);
                _2D.Begin();

                if (_radius > 3.0f)
                {
                    _2D.DrawFilledEllipse(penPosition, Color.Black);
                }
                else
                {
                    _2D.DrawFilledRectangle(penPosition, Color.Black);
                }
                _2D.End();
                _graphics.SetRenderTarget(_screen.RenderTargetView);
            }

            _2D.Begin();
            _2D.DrawTextSprite(_messageSprite);
            _2D.End();

            _screen.Present(1);

            return(true);
        }