Beispiel #1
0
        // ReSharper restore InconsistentNaming

        /// <summary>
        /// Function to build a list of unicode ranges.
        /// </summary>
        private static void BuildUnicodeRangeList()
        {
            IList <string> rangeLines = Resources.UnicodeBlocks.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            _ranges = new SortedDictionary <string, GorgonRange>();

            // Break out the lines.
            foreach (var line in rangeLines)
            {
                IList <string> items = line.Split(new[] { ';' });

                // Get range.
                if ((string.IsNullOrEmpty(items[0])) || (string.IsNullOrEmpty(items[1])))
                {
                    continue;
                }

                var range = new GorgonRange(int.Parse(items[0].Substring(0, items[0].IndexOf('.')), NumberStyles.HexNumber),
                                            int.Parse(items[0].Substring(items[0].LastIndexOf('.') + 1), NumberStyles.HexNumber));

                // Combine the first 2 latin categories into the one category.
                if (range.Maximum <= 0xff)
                {
                    if (!_ranges.ContainsKey("Latin + Latin Supplement"))
                    {
                        _ranges.Add("Latin + Latin Supplement", new GorgonRange(0, 0xFF));
                    }
                }
                else
                {
                    _ranges.Add(items[1].Trim(), range);
                }
            }
        }
Beispiel #2
0
 public override void UpdateSubResource(GorgonImageBuffer buffer,
                                        GorgonRange destRange,
                                        int destArrayIndex      = 0,
                                        int destMipLevel        = 0,
                                        GorgonGraphics deferred = null)
 {
     throw new NotSupportedException(Resources.GORGFX_DEPTH_OPERATION_NOT_SUPPORTED);
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JoystickDeadZoneAxes"/> class.
 /// </summary>
 internal JoystickDeadZoneAxes()
 {
     X          = GorgonRange.Empty;
     Y          = GorgonRange.Empty;
     SecondaryX = GorgonRange.Empty;
     SecondaryY = GorgonRange.Empty;
     Throttle   = GorgonRange.Empty;
     Rudder     = GorgonRange.Empty;
 }
Beispiel #4
0
            /// <summary>
            /// Function to calculate the mid point for a range value.
            /// </summary>
            /// <param name="range">Range to calculate.</param>
            /// <returns>The mid point of the range.</returns>
            private static int CalculateMidRange(GorgonRange range)
            {
                if (range == GorgonRange.Empty)
                {
                    return(0);
                }

                return((range.Range / 2) - range.Maximum);
            }
Beispiel #5
0
        /// <summary>
        /// Function to apply a deadzone to a value.
        /// </summary>
        /// <param name="value">Value to dead zone.</param>
        /// <param name="deadZone">Dead zone range.</param>
        /// <param name="midRange">Mid point for the range.</param>
        /// <returns>The actual axis data if it falls outside of the dead zone, or the center position value.</returns>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown when the joystick has not been initialized.</exception>
        private static int DeadZoneValue(int value, GorgonRange deadZone, int midRange)
        {
            // The dead zone range needs to be within the range of the axis.
            if ((!deadZone.Contains(value)) || (deadZone == GorgonRange.Empty))
            {
                return(value);
            }

            return(midRange);
        }
        /// <summary>
        /// Function to convert a <see cref="GorgonRange"/> of pixel coordinates to texel space.
        /// </summary>
        /// <param name="pixelCoordinates">The pixel coordinates to convert.</param>
        /// <param name="mipLevel">[Optional] The mip level to use.</param>
        /// <returns>A <see cref="GorgonRangeF"/> containing the texel space coordinates.</returns>
        /// <remarks>
        /// <para>
        /// If specified, the <paramref name="mipLevel"/> only applies to the <see cref="MipSlice"/> and <see cref="MipCount"/> for this view, it will be constrained if it falls outside of that range.
        /// Because of this, the coordinates returned may not be the exact size of the texture bound to the view at mip level 0. If the <paramref name="mipLevel"/> is omitted, then the first mip level
        /// for the underlying <see cref="Texture"/> is used.
        /// </para>
        /// </remarks>
        public GorgonRangeF ToTexel(GorgonRange pixelCoordinates, int?mipLevel = null)
        {
            float width = Texture.Width;

            if (mipLevel == null)
            {
                return(new GorgonRangeF(pixelCoordinates.Minimum / width, pixelCoordinates.Maximum / width));
            }

            width = GetMipWidth(mipLevel.Value);

            return(new GorgonRangeF(pixelCoordinates.Minimum / width, pixelCoordinates.Maximum / width));
        }
Beispiel #7
0
        /// <summary>
        /// Function to get an orientation for a value.
        /// </summary>
        /// <param name="value">Value to evaluate.</param>
        /// <param name="deadZone">The dead zone.</param>
        /// <param name="orientation">Orientation of the axis.</param>
        /// <param name="midRange">Mid point for the range.</param>
        /// <returns>The direction that the axis is pointed at.</returns>
        private static JoystickDirections GetDirection(int value, GorgonRange deadZone, JoystickDirections orientation, int midRange)
        {
            var result = JoystickDirections.Center;

            if ((deadZone != GorgonRange.Empty) && (deadZone.Contains(value)))
            {
                return(result);
            }

            switch (orientation)
            {
            case JoystickDirections.Horizontal:
                if (value > midRange)
                {
                    result = JoystickDirections.Right;
                }

                if (value < midRange)
                {
                    result = JoystickDirections.Left;
                }
                break;

            case JoystickDirections.Vertical:
                if (value < midRange)
                {
                    result = JoystickDirections.Down;
                }

                if (value > midRange)
                {
                    result = JoystickDirections.Up;
                }
                break;

            default:
                if (value > midRange)
                {
                    result = JoystickDirections.MoreThanCenter;
                }
                if (value < midRange)
                {
                    result = JoystickDirections.LessThanCenter;
                }
                break;
            }

            return(result);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture1DReadWriteView"/> class.
 /// </summary>
 /// <param name="texture">The texture to view.</param>
 /// <param name="format">The format for the view.</param>
 /// <param name="formatInfo">Information about the format.</param>
 /// <param name="firstMipLevel">The first mip level to view.</param>
 /// <param name="arrayIndex">The first array index to view.</param>
 /// <param name="arrayCount">The number of array indices to view.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="texture"/>, or the <paramref name="formatInfo"/> parameter is <b>null</b>.</exception>
 internal GorgonTexture1DReadWriteView(GorgonTexture1D texture,
                                       BufferFormat format,
                                       GorgonFormatInfo formatInfo,
                                       int firstMipLevel,
                                       int arrayIndex,
                                       int arrayCount)
     : base(texture)
 {
     FormatInformation = formatInfo ?? throw new ArgumentNullException(nameof(formatInfo));
     Format            = format;
     Texture           = texture;
     Bounds            = new GorgonRange(0, Width);
     MipSlice          = firstMipLevel;
     ArrayIndex        = arrayIndex;
     ArrayCount        = arrayCount;
 }
Beispiel #9
0
            /// <summary>
            /// Initializes a new instance of the <see cref="JoystickCapabilities"/> class.
            /// </summary>
            protected JoystickCapabilities()
            {
                VibrationMotorRanges = new GorgonRange[0];
                AxisCount            = 0;
                ButtonCount          = 0;
                XAxisRange           = GorgonRange.Empty;
                YAxisRange           = GorgonRange.Empty;
                SecondaryXAxisRange  = GorgonRange.Empty;
                SecondaryYAxisRange  = GorgonRange.Empty;
                ThrottleAxisRange    = GorgonRange.Empty;
                RudderAxisRange      = GorgonRange.Empty;
                ManufacturerID       = 0;
                ProductID            = 0;

                ExtraCapabilities = JoystickCapabilityFlags.None;
            }
Beispiel #10
0
        /// <summary>
        /// Function to draw the controller cursor.
        /// </summary>
        /// <param name="controller">Controller for the cursor.</param>
        /// <param name="index">Index of the controller.</param>
        private void DrawControllerCursor(IGorgonGamingDevice controller, int index)
        {
            GorgonRange xRange           = controller.Info.AxisInfo[GamingDeviceAxis.LeftStickX].Range;
            GorgonRange yRange           = controller.Info.AxisInfo[GamingDeviceAxis.LeftStickY].Range;
            int         playerColorValue = (int)(((uint)0xFF << (index * 8)) | 0xFF000000);                             // Get the color based on the controller 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(controller.Axis[GamingDeviceAxis.LeftStickX].Value - (float)xRange.Minimum,
                                        controller.Axis[GamingDeviceAxis.LeftStickY].Value - (float)yRange.Minimum);

            moveVector = new PointF((moveVector.X / (xRange.Range + 1) * 2.0f) - 1.0f,
                                    (moveVector.Y / (yRange.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;
        }
Beispiel #11
0
 /// <summary>
 /// Function to copy data from the CPU to the texture on the GPU.
 /// </summary>
 /// <param name="buffer">A buffer containing the image data to copy.</param>
 /// <param name="destRange">A start and end range value that will specify the region that will receive the data.</param>
 /// <param name="destArrayIndex">[Optional] The array index that will receive the data.</param>
 /// <param name="destMipLevel">[Optional] The mip map level that will receive the data.</param>
 /// <param name="deferred">[Optional] A deferred graphics context used to copy the data.</param>
 /// <exception cref="System.InvalidOperationException">Thrown when the texture is dynamic or immutable.
 /// <para>-or-</para>
 /// <para>Thrown when the texture is multisampled.</para>
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">Thrown when the <paramref name="destArrayIndex"/> or the <paramref name="destMipLevel"/> is less than 0 or greater than/equal to the
 /// number of array indices or mip levels in the texture.</exception>
 /// <remarks>
 /// Use this to copy data into a texture with a usage of staging or default.  If the <paramref name="destRange"/> values are larger than the dimensions of the texture, then the data will be clipped.
 /// <para>Passing NULL (Nothing in VB.Net) to the <paramref name="destArrayIndex"/> and/or the <paramref name="destMipLevel"/> parameters will use the first array index and/or mip map level.</para>
 /// <para>This method will not work with depth/stencil textures or with textures that have multisampling applied.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 public virtual void UpdateSubResource(GorgonImageBuffer buffer,
                                       GorgonRange destRange,
                                       int destArrayIndex      = 0,
                                       int destMipLevel        = 0,
                                       GorgonGraphics deferred = null)
 {
     OnUpdateSubResource(buffer,
                         new GorgonBox
     {
         Front  = 0,
         Depth  = 1,
         Left   = destRange.Minimum,
         Width  = destRange.Maximum,
         Top    = 0,
         Height = 1
     },
                         destArrayIndex,
                         destMipLevel,
                         deferred);
 }
Beispiel #12
0
        /// <summary>
        /// Function to draw a spray on the screen.
        /// </summary>
        /// <param name="device">Controller to use for the spray.</param>
        /// <param name="index">Index of the controller.</param>
        private void DrawSpray(IGorgonGamingDevice device, int index)
        {
            SprayCan state = _sprayStates[index];

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

            GorgonRange throttleRange = device.Info.AxisInfo[GamingDeviceAxis.RightTrigger].Range;

            // Find out if we're spraying.
            if (device.Axis[GamingDeviceAxis.RightTrigger].Value > throttleRange.Minimum)
            {
                if ((!state.IsActive) && (!state.NeedReset))
                {
                    // Convert the throttle value to a unit value.
                    float throttleUnit = ((float)(device.Axis[GamingDeviceAxis.RightTrigger].Value - throttleRange.Minimum) / throttleRange.Range);

                    // Set up the spray state.
                    state.Position        = state.Origin;
                    state.Amount          = throttleRange.Range / 2.0f;
                    state.Time            = throttleUnit * 10.0f;
                    state.VibrationAmount = device.Info.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);
        }
Beispiel #13
0
        /// <summary>
        /// Function to retrieve the ranges available to a specific font.
        /// </summary>
        /// <param name="font">Font to look up.</param>
        /// <param name="hDc">Device context.</param>
        /// <returns>A list of ranges.</returns>
        public static IDictionary <string, GorgonRange> GetUnicodeRanges(Font font, IntPtr hDc)
        {
            Dictionary <string, GorgonRange> result;

            if (_ranges == null)
            {
                BuildUnicodeRangeList();
            }

            uint size = GetFontUnicodeRanges(hDc, IntPtr.Zero);

            using (var stream = new GorgonDataStream((int)size))
            {
                GetFontUnicodeRanges(hDc, stream.BasePointer);

                // Skip the first 12 bytes.
                stream.Read <Int64>();
                stream.Read <Int32>();

                var itemCount = stream.Read <int>();
                result = new Dictionary <string, GorgonRange>(itemCount);

                for (int i = 0; i < itemCount; i++)
                {
                    var min   = stream.Read <ushort>();
                    var value = new GorgonRange(min, stream.Read <ushort>() + min - 1);

                    var rangeName = (from unicodeRange in _ranges
                                     where unicodeRange.Value.Contains(value.Minimum) && unicodeRange.Value.Contains(value.Maximum)
                                     select unicodeRange).SingleOrDefault();

                    if ((!string.IsNullOrEmpty(rangeName.Key)) && (!result.ContainsKey(rangeName.Key)))
                    {
                        result.Add(rangeName.Key, rangeName.Value);
                    }
                }
            }

            return(result);
        }
Beispiel #14
0
            /// <summary>
            /// Function to retrieve the capabilities of the controller device.
            /// </summary>
            /// <param name="buttonCount">Button count.</param>
            private void GetCaps(int buttonCount)
            {
                // Default to the standard XBOX 360 controller.
                // If we have other types, then we may have to alter this.
                AxisCount   = 6;
                ButtonCount = buttonCount;

                // Get ranges.
                SecondaryYAxisRange = SecondaryXAxisRange = YAxisRange = XAxisRange = new GorgonRange(-32768, 32767);
                ThrottleAxisRange   = RudderAxisRange = new GorgonRange(0, 255);

                VibrationMotorRanges = new ReadOnlyCollection <GorgonRange>(new[]
                {
                    new GorgonRange(0, 65535), new GorgonRange(0, 65535)
                });

                // BUG: As of this writing, there's a bug in XInputGetCapabilities in DirectX that's returning 255 even though
                // they've documented the ranges (and I've tested these) to be 0..65535.
                //VibrationMotorRanges[0] = new GorgonMinMax(0, caps.Vibration.LeftMotorSpeed);
                //VibrationMotorRanges[1] = new GorgonMinMax(0, caps.Vibration.RightMotorSpeed);

                ExtraCapabilities = JoystickCapabilityFlags.SupportsDiscreetPOV | JoystickCapabilityFlags.SupportsPOV | JoystickCapabilityFlags.SupportsRudder | JoystickCapabilityFlags.SupportsThrottle | JoystickCapabilityFlags.SupportsVibration | JoystickCapabilityFlags.SupportsSecondaryXAxis | JoystickCapabilityFlags.SupportsSecondaryYAxis;
            }
        /// <summary>
        /// Function to retrieve the capabilities from the DirectInput joystick.
        /// </summary>
        /// <param name="joystick">The DirectInput joystick to evaluate.</param>
        public void GetDeviceCaps(DI.Joystick joystick)
        {
            var defaults   = new Dictionary <GamingDeviceAxis, int>(new GorgonGamingDeviceAxisEqualityComparer());
            var axisRanges = new Dictionary <GamingDeviceAxis, GorgonRange>(new GorgonGamingDeviceAxisEqualityComparer());

            ProductID      = joystick.Properties.ProductId;
            ManufacturerID = joystick.Properties.VendorId;
            ButtonCount    = joystick.Capabilities.ButtonCount;
            POVCount       = joystick.Capabilities.PovCount;
            Capabilities   = POVCount > 0 ? GamingDeviceCapabilityFlags.SupportsPOV : GamingDeviceCapabilityFlags.None;

            IList <DI.DeviceObjectInstance> axisInfo = joystick.GetObjects(DI.DeviceObjectTypeFlags.Axis);

            foreach (DI.DeviceObjectInstance axis in axisInfo)
            {
                var usage = (HIDUsage)axis.Usage;
                DI.ObjectProperties properties = joystick.GetObjectPropertiesById(axis.ObjectId);

                // Skip this axis if retrieving the properties results in failure.
                if (properties == null)
                {
                    continue;
                }

                var range    = new GorgonRange(properties.Range.Minimum, properties.Range.Maximum);
                int midPoint = ((range.Range + 1) / 2) + range.Minimum;

                switch (usage)
                {
                case HIDUsage.X:
                    AxisMappings[GamingDeviceAxis.XAxis] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.XAxis]   = range;
                    defaults[GamingDeviceAxis.XAxis]     = range.Minimum < 0 ? 0 : midPoint;
                    break;

                case HIDUsage.Y:
                    AxisMappings[GamingDeviceAxis.YAxis] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.YAxis]   = range;
                    defaults[GamingDeviceAxis.YAxis]     = range.Minimum < 0 ? 0 : midPoint;
                    break;

                case HIDUsage.Slider:
                    AxisMappings[GamingDeviceAxis.Throttle] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.Throttle]   = range;
                    defaults[GamingDeviceAxis.Throttle]     = 0;
                    Capabilities |= GamingDeviceCapabilityFlags.SupportsThrottle;
                    break;

                case HIDUsage.Z:
                    AxisMappings[GamingDeviceAxis.ZAxis] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.ZAxis]   = range;
                    defaults[GamingDeviceAxis.ZAxis]     = range.Minimum < 0 ? 0 : midPoint;
                    Capabilities |= GamingDeviceCapabilityFlags.SupportsZAxis;
                    break;

                case HIDUsage.RelativeX:
                    AxisMappings[GamingDeviceAxis.XAxis2] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.XAxis2]   = range;
                    Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryXAxis;
                    defaults[GamingDeviceAxis.XAxis2] = midPoint;
                    break;

                case HIDUsage.RelativeY:
                    AxisMappings[GamingDeviceAxis.YAxis2] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.YAxis2]   = range;
                    Capabilities |= GamingDeviceCapabilityFlags.SupportsSecondaryYAxis;
                    defaults[GamingDeviceAxis.YAxis2] = midPoint;
                    break;

                case HIDUsage.RelativeZ:
                    AxisMappings[GamingDeviceAxis.ZAxis2] = axis.ObjectId;
                    axisRanges[GamingDeviceAxis.ZAxis2]   = range;
                    Capabilities |= GamingDeviceCapabilityFlags.SupportsRudder;
                    defaults[GamingDeviceAxis.ZAxis2] = 0;
                    break;
                }
            }

            AxisInfo = new GorgonGamingDeviceAxisList <GorgonGamingDeviceAxisInfo>(
                axisRanges.Select(item => new GorgonGamingDeviceAxisInfo(item.Key, item.Value, defaults[item.Key])));
        }
Beispiel #16
0
        MultimediaJoystickButtons _buttonStates;                    // Button states.
        #endregion

        #region Methods.
        /// <summary>
        /// Function to shift the value to fall within the axis range.
        /// </summary>
        /// <param name="currentValue">Value to shift.</param>
        /// <param name="axisRange">Range to evaluate.</param>
        /// <returns>The shifted value.</returns>
        private static int CenterValue(int currentValue, GorgonRange axisRange)
        {
            return(currentValue - (axisRange.Range / 2));
        }
Beispiel #17
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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonGamingDeviceAxisInfo"/> struct.
 /// </summary>
 /// <param name="axis">The identifier for the axis.</param>
 /// <param name="range">The range of the axis.</param>
 /// <param name="defaultValue">The default value for the axis when in resting position.</param>
 public GorgonGamingDeviceAxisInfo(GamingDeviceAxis axis, GorgonRange range, int defaultValue)
 {
     Axis         = axis;
     Range        = range;
     DefaultValue = defaultValue;
 }
Beispiel #19
0
            /// <summary>
            /// Function to retrieve the joystick capabilities.
            /// </summary>
            /// <param name="joystickID">ID of the joystick.</param>
            private void GetCaps(int joystickID)
            {
                JOYCAPS caps      = default(JOYCAPS);                                                                   // Joystick capabilities.
                var     capsFlags = JoystickCapabilityFlags.None;                                                       // Extra capability flags.

                // NOTE: We have to use Marshal.SizeOf here because DirectAccess.SizeOf does -not- check data marshalling attributes
                //       when determining the size of a structure (this is a performance decision).  So, for structures that have
                //       marshalled strings and/or fixed size arrays that need marshalling attributes (like MarshalAsAttribte), then
                //		 we -must- use Marshal.SizeOf, otherwise we should use DirectAccess.SizeOf.
                int error = Win32API.joyGetDevCaps(joystickID, ref caps, Marshal.SizeOf(typeof(JOYCAPS)));

                // If the joystick is disconnected then leave.
                if (error == 0xA7)
                {
                    return;
                }

                // If it's any other error, then throw an exception.
                if (error > 0)
                {
                    throw new GorgonException(GorgonResult.CannotRead,
                                              string.Format(Resources.GORINP_RAW_CANNOT_GET_JOYSTICK_CAPS, joystickID,
                                                            error.FormatHex()));
                }

                // Gather device info.
                if ((caps.Capabilities & JoystickCaps.HasZ) == JoystickCaps.HasZ)
                {
                    capsFlags        |= JoystickCapabilityFlags.SupportsThrottle;
                    ThrottleAxisRange = new GorgonRange((int)caps.MinimumZ, (int)caps.MaximumZ);
                }
                if ((caps.Capabilities & JoystickCaps.HasRudder) == JoystickCaps.HasRudder)
                {
                    capsFlags      |= JoystickCapabilityFlags.SupportsRudder;
                    RudderAxisRange = new GorgonRange((int)caps.MinimumRudder, (int)caps.MaximumRudder);
                }
                if ((caps.Capabilities & JoystickCaps.HasPOV) == JoystickCaps.HasPOV)
                {
                    capsFlags |= JoystickCapabilityFlags.SupportsPOV;
                    if ((caps.Capabilities & JoystickCaps.POV4Directions) == JoystickCaps.POV4Directions)
                    {
                        capsFlags |= JoystickCapabilityFlags.SupportsDiscreetPOV;
                    }
                    if ((caps.Capabilities & JoystickCaps.POVContinuousDegreeBearings) == JoystickCaps.POVContinuousDegreeBearings)
                    {
                        capsFlags |= JoystickCapabilityFlags.SupportsContinuousPOV;
                    }
                }

                if ((caps.Capabilities & JoystickCaps.HasU) == JoystickCaps.HasU)
                {
                    capsFlags          |= JoystickCapabilityFlags.SupportsSecondaryXAxis;
                    SecondaryXAxisRange = new GorgonRange((int)caps.Axis5Minimum, (int)caps.Axis5Maximum);
                }

                if ((caps.Capabilities & JoystickCaps.HasV) == JoystickCaps.HasV)
                {
                    capsFlags          |= JoystickCapabilityFlags.SupportsSecondaryYAxis;
                    SecondaryYAxisRange = new GorgonRange((int)caps.Axis6Minimum, (int)caps.Axis6Maximum);
                }

                ExtraCapabilities = capsFlags;
                AxisCount         = (int)caps.AxisCount;
                ButtonCount       = (int)caps.ButtonCount;
                ManufacturerID    = caps.ManufacturerID;
                ProductID         = caps.ProductID;

                // Get primary axis ranges.  Force the range to split into halfs going from negative to positive so that 0 is our center.
                XAxisRange = new GorgonRange(-((int)caps.MaximumX / 2) - 1, ((int)caps.MaximumX / 2));
                YAxisRange = new GorgonRange(-((int)caps.MaximumY / 2) - 1, ((int)caps.MaximumY / 2));
            }
Beispiel #20
0
        /// <summary>
        /// Function to retrieve a list of character sets.
        /// </summary>
        private void GetCharacterSets()
        {
            if (CurrentFont == null)
            {
                return;
            }

            if (listRanges.SelectedIndices.Count == 0)
            {
                return;
            }

            ListViewItem charSet   = listRanges.SelectedItems[0];
            GorgonRange  range     = ((KeyValuePair <string, GorgonRange>)charSet.Tag).Value;
            int          lineCount = ((int)System.Math.Ceiling(range.Range / 8.0f)) - 1;

            if (lineCount > 6)
            {
                scrollVertical.Enabled     = true;
                scrollVertical.Minimum     = 0;
                scrollVertical.Maximum     = lineCount;
                scrollVertical.SmallChange = 1;
                scrollVertical.LargeChange = 6;
            }
            else
            {
                scrollVertical.Enabled = false;
            }

            try
            {
                SelectFont();

                // Set the font.
                for (int i = 1; i <= 48; i++)
                {
                    string checkBoxName = "checkBox" + i;
                    var    fontControl  = (CheckBox)panelCharacters.Controls[checkBoxName];                                                     // Font character.

                    fontControl.MouseEnter     -= fontControl_MouseEnter;
                    fontControl.CheckedChanged -= fontControl_CheckedChanged;

                    // If the range has less characters than our character list, then disable the rest of the check boxes.
                    if (i > range.Range)
                    {
                        fontControl.Enabled   = false;
                        fontControl.Font      = Font;
                        fontControl.BackColor = DarkFormsRenderer.DisabledColor;
                        fontControl.Text      = "";
                        fontControl.Checked   = false;
                        continue;
                    }

                    char c = Convert.ToChar(i + range.Minimum + _page);


                    if ((!IsCharacterSupported(c)) || (Convert.ToInt32(c) > range.Maximum))
                    {
                        fontControl.Enabled   = false;
                        fontControl.Font      = Font;
                        fontControl.BackColor = DarkFormsRenderer.DisabledColor;
                        fontControl.Text      = "";
                        fontControl.Checked   = false;
                        continue;
                    }

                    fontControl.Enabled   = true;
                    fontControl.BackColor = Color.White;

                    fontControl.Font    = CurrentFont;
                    fontControl.Text    = c.ToString(CultureInfo.CurrentUICulture);
                    fontControl.Checked = textCharacters.Text.IndexOf(fontControl.Text, StringComparison.Ordinal) != -1;

                    fontControl.CheckedChanged += fontControl_CheckedChanged;
                    fontControl.MouseEnter     += fontControl_MouseEnter;
                }
            }
            finally
            {
                DeselectFont();
                ValidateButtons();
            }
        }
Beispiel #21
0
 /// <summary>
 /// Function to copy a texture subresource from another texture.
 /// </summary>
 /// <param name="sourceTexture">Source texture to copy.</param>
 /// <param name="sourceRange">The dimensions of the source area to copy.</param>
 /// <param name="destX">Horizontal offset into the destination texture to place the copied data.</param>
 /// <param name="unsafeCopy">[Optional] TRUE to disable all range checking for coorindates, FALSE to clip coorindates to safe ranges.</param>
 /// <param name="deferred">[Optional] The deferred context to use when copying the sub resource.</param>
 /// <remarks>Use this method to copy a specific sub resource of a texture to another sub resource of another texture, or to a different sub resource of the same texture.  The <paramref name="sourceRange"/>
 /// coordinates must be inside of the destination, if it is not, then the source data will be clipped against the destination region. No stretching or filtering is supported by this method.
 /// <para>For SM_4_1 and SM_5 video devices, texture formats can be converted if they belong to the same format group (e.g. R8G8B8A8, R8G8B8A8_UInt, R8G8B8A8_Int, R8G8B8A8_UIntNormal, etc.. are part of the R8G8B8A8 group).  If the
 /// video device is a SM_4 then no format conversion will be done and an exception will be thrown if format conversion is attempted.</para>
 /// <para>When copying sub resources (e.g. mip-map levels), the mip levels and array indices must be different if copying to the same texture.  If they are not, an exception will be thrown.</para>
 /// <para>Pass NULL (Nothing in VB.Net) to the sourceRange parameter to copy the entire sub resource.</para>
 /// <para>Video devices that have a feature level of SM2_a_b cannot copy sub resource data in a 1D texture if the texture is not a staging texture.</para>
 /// <para>The <paramref name="unsafeCopy"/> parameter is meant to provide a performance increase by skipping any checking of the destination and source coorindates passed in to the function.  When set to TRUE it will
 /// just pass the coordinates without testing and adjusting for clipping.  If your coordinates are outside of the source/destination texture range, then the behaviour will be undefined (i.e. depending on your
 /// video driver, it may clip, or throw an exception or do nothing).  Care must be taken to ensure the coordinates fit within the source and destination if this parameter is set to TRUE.</para>
 /// <para>If the <paramref name="deferred"/> parameter is NULL (Nothing in VB.Net) then the immediate context will be used.  If this method is called from multiple threads, then a deferred context should be passed for each thread that is
 /// accessing the sub resource.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the texture parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the formats cannot be converted because they're not of the same group or the current video device is a SM_4 device.
 /// <para>-or-</para>
 /// <para>Thrown when the subResource and destSubResource are the same and the source texture is the same as this texture.</para>
 /// </exception>
 /// <exception cref="System.InvalidOperationException">Thrown when this texture is an immutable texture.
 /// </exception>
 /// <exception cref="System.NotSupportedException">Thrown when the video device has a feature level of SM2_a_b and this texture or the source texture are not staging textures.</exception>
 public void CopySubResource(GorgonTexture1D sourceTexture, GorgonRange sourceRange, int destX = 0, bool unsafeCopy = false, GorgonGraphics deferred = null)
 {
     CopySubResource(sourceTexture, sourceRange, 0, 0, destX, 0, 0, unsafeCopy, deferred);
 }
Beispiel #22
0
        /// <summary>
        /// Function to set the alpha value for an image.
        /// </summary>
        /// <param name="sourceImage">The source image.</param>
        /// <param name="currentMipLevel">The current mip map level.</param>
        /// <param name="currentArrayOrDepth">The current array index or depth slice.</param>
        /// <param name="value">The value to assign.</param>
        /// <param name="inclusionRange">The range of alpha values to update.</param>
        /// <returns>A new image with the updated alpha.</returns>
        public IGorgonImage SetAlphaValue(IGorgonImage sourceImage, int currentMipLevel, int currentArrayOrDepth, int value, GorgonRange inclusionRange)
        {
            IGorgonImage result = sourceImage.Clone();

            result.Buffers[currentMipLevel, currentArrayOrDepth]
            .SetAlpha(value / 255.0f, new GorgonRangeF(inclusionRange.Minimum / 255.0f, inclusionRange.Maximum / 255.0f));

            return(result);
        }