コード例 #1
0
        /// <summary>
        /// Function called during CPU idle time.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _renderer
            .Update(_ =>
            {
                _background.Position = new DX.Vector2(_background.Position.X, _background.Position.Y + (0.3f * GorgonTiming.Delta));

                // Just wrap around if we hit the top of the background.
                if (_background.Position.Y > _background.Bounds.Height)
                {
                    _background.Position = new DX.Vector2(_background.Position.X, _screen.Height);
                }

                if (_floatLeft)
                {
                    _floatOffset -= GorgonTiming.Delta * (_screen.Width / 16.0f);
                }
                else
                {
                    _floatOffset += GorgonTiming.Delta * (_screen.Width / 16.0f);
                }

                float floatBounds = _screen.Width / 4.0f;
                if (_floatOffset < -floatBounds)
                {
                    _floatOffset = -floatBounds;
                    _floatLeft   = !_floatLeft;
                }
                else if (_floatOffset > floatBounds)
                {
                    _floatOffset = floatBounds;
                    _floatLeft   = !_floatLeft;
                }

                _ship.Position = new DX.Vector2((_screen.Width / 2) + _floatOffset, _screen.Height - 120);
            })
            .Begin()
            .DrawSprite(_background)
            .DrawLoop(_stars.Length, (i, r) =>
            {
                // Our renderer interface is passed to this method so that we can call back into it for things like loops and such.
                // Draw our "stars".
                ref DX.Vector2 star = ref _stars[i];
                star = new DX.Vector2(star.X, star.Y + (((i % 2) == 0 ? 0.3f : 0.4f) * GorgonTiming.Delta));

                if (star.Y > 1.0f)
                {
                    star = new DX.Vector2(GorgonRandom.RandomSingle(), GorgonRandom.RandomSingle() * -1.0f);
                    return(true);
                }

                var position = new DX.Vector2(star.X * _screen.Width, star.Y * _screen.Height);

                float starColorValue = GorgonRandom.RandomSingle(0.35f, 1.0f);
                var starColor        = new GorgonColor(starColorValue, starColorValue, starColorValue, 1.0f);

                r.DrawFilledRectangle(new DX.RectangleF(position.X, position.Y, 1, 1), starColor);

                return(true);
            })
コード例 #2
0
        /// <summary>
        /// Function to transfer a 24 bit rgb image into a <see cref="IGorgonImageBuffer"/>.
        /// </summary>
        /// <param name="bitmapLock">The lock on the bitmap to transfer from.</param>
        /// <param name="buffer">The buffer to transfer into.</param>
        private static void Transfer24Rgb(BitmapData bitmapLock, IGorgonImageBuffer buffer)
        {
            unsafe
            {
                byte *pixels = (byte *)bitmapLock.Scan0.ToPointer();

                for (int y = 0; y < bitmapLock.Height; y++)
                {
                    // We only need the width here, as our pointer will handle the stride by virtue of being an int.
                    byte *offset = pixels + (y * bitmapLock.Stride);

                    int destOffset = y * buffer.PitchInformation.RowPitch;
                    for (int x = 0; x < bitmapLock.Width; x++)
                    {
                        // The DXGI format nomenclature is a little confusing as we tend to think of the layout as being highest to
                        // lowest, but in fact, it is lowest to highest.
                        // So, we must convert to ABGR even though the DXGI format is RGBA. The memory layout is from lowest
                        // (R at byte 0) to the highest byte (A at byte 3).
                        // Thus, R is the lowest byte, and A is the highest: A(24), B(16), G(8), R(0).
                        byte b = *offset++;
                        byte g = *offset++;
                        byte r = *offset++;

                        var  color      = new GorgonColor(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
                        int *destBuffer = (int *)(Unsafe.AsPointer(ref buffer.Data[destOffset]));
                        *    destBuffer = color.ToABGR();
                        destOffset += 4;
                    }
                }
            }
        }
コード例 #3
0
ファイル: PanelSpriteEditor.cs プロジェクト: tmp7701/Gorgon
            /// <summary>
            /// Function to animate the anchor color.
            /// </summary>
            public void Animate()
            {
                if (!_isStarted)
                {
                    _lastTime  = GorgonTiming.SecondsSinceStart;
                    _isStarted = true;
                    return;
                }

                float   time = (GorgonTiming.SecondsSinceStart - _lastTime) * 4.0f;
                Vector3 result;

                Vector3.Lerp(ref _lastColor, ref _nextColor, time, out result);

                Color = new GorgonColor(result);

                if (time <= 1)
                {
                    return;
                }

                _lastTime  = GorgonTiming.SecondsSinceStart;
                _lastColor = _nextColor;
                _nextColor = new Vector3(GorgonRandom.RandomSingle(), GorgonRandom.RandomSingle(), GorgonRandom.RandomSingle());
            }
コード例 #4
0
ファイル: Program.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to handle idle time for the application.
        /// </summary>
        /// <returns>TRUE to continue processing, FALSE to stop.</returns>
        private static bool Idle()
        {
            // Clear the swap chain.
            _swap.Clear(_clearColor);

            // Animate our clear color so we have something to look at instead of a blank screen.
            _clearColor = new GorgonColor(
                _clearColor.Red + (GorgonTiming.Delta * _colorDirection * 0.0125f),
                _clearColor.Green + (GorgonTiming.Delta * _colorDirection * 0.0125f),
                _clearColor.Blue + (GorgonTiming.Delta * _colorDirection * 0.0125f)
                );

            if (((_clearColor.Red > (250.0f / 255.0f)) || (_clearColor.Red < (25.0f / 255.0f))) &&
                ((_clearColor.Green > (245.0f / 255.0f)) || (_clearColor.Green < (24.5f / 255.0f))) &&
                ((_clearColor.Blue > (220.0f / 255.0f)) || (_clearColor.Blue < (22.0f / 255.0f))))
            {
                _colorDirection *= -1;

                // Ensure that we don't get stuck.
                _clearColor = _colorDirection < 0
                                        ? new GorgonColor(250.0f / 255.0f, 245f / 255.0f, 220f / 255.0f)
                                        : new GorgonColor(25.0f / 255.0f, 24.5f / 255.0f, 22.0f / 255.0f);
            }

            // Now we flip our buffers on the swap chain.
            // We need to this or we won't see anything.
            // Note that we can limit this to flip on a specified number of vertical retraces.  This
            // will enable us to lock the frame rate to that of the refresh rate of the monitor.
            _swap.Flip();

            return(true);
        }
コード例 #5
0
ファイル: GorgonRenderables.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to create a new text object.
        /// </summary>
        /// <param name="name">Name of the text object.</param>
        /// <param name="font">Font to use for the text.</param>
        /// <param name="text">Initial text to display.</param>
        /// <param name="color">Color of the text.</param>
        /// <param name="shadowed">TRUE to place a shadow behind the text, FALSE to display normally.</param>
        /// <param name="shadowOffset">Offset of the shadow.</param>
        /// <param name="shadowOpacity">Opacity for the shadow.</param>
        /// <returns>A new text object.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the name parameter is an empty string.</exception>
        public GorgonText CreateText(string name, GorgonFont font, string text, GorgonColor color, bool shadowed, Vector2 shadowOffset, float shadowOpacity)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(Resources.GOR2D_PARAMETER_MUST_NOT_BE_EMPTY, "name");
            }

            var result = new GorgonText(_gorgon2D, _cache, name, font)
            {
                ShadowEnabled   = shadowed,
                ShadowOffset    = shadowOffset,
                ShadowOpacity   = shadowOpacity,
                Color           = color,
                Text            = text,
                CullingMode     = CullingMode.Back,
                AlphaTestValues = GorgonRangeF.Empty,
                BlendingMode    = BlendingMode.Modulate
            };

            return(result);
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TextureSamplerState"/> class.
 /// </summary>
 public TextureSamplerState()
 {
     BorderColor        = new GorgonColor(0);
     HorizontalWrapping = TextureAddressing.Clamp;
     VerticalWrapping   = TextureAddressing.Clamp;
     TextureFilter      = TextureFilter.Point;
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MiniTriVertex"/> struct.
 /// </summary>
 /// <param name="position">The position of the vertex in object space.</param>
 /// <param name="color">The color of the vertex.</param>
 public MiniTriVertex(DX.Vector3 position, GorgonColor color)
 {
     // Note that we're passing a 3D vector, but storing a 4D vector. We need the W coordinate set to 1.0f to indicate that the coordinates are normalized.
     // For more information about the W component, go to http://www.tomdalling.com/blog/modern-opengl/explaining-homogenous-coordinates-and-projective-geometry/
     Position = new DX.Vector4(position, 1.0f);
     Color    = color;
 }
コード例 #8
0
ファイル: PanelHatch.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to retrieve a color for the hatch pattern.
        /// </summary>
        /// <returns>The selected color or NULL (Nothing in VB.Net) if canceled.</returns>
        private GorgonColor?GetColor(GorgonColor oldColor)
        {
            ColorPickerDialog colorDialog = null;

            try
            {
                colorDialog = new ColorPickerDialog
                {
                    SelectedColor = oldColor,
                    OldColor      = oldColor
                };

                if (colorDialog.ShowDialog(ParentForm) == DialogResult.OK)
                {
                    return(colorDialog.SelectedColor);
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(ParentForm, ex);
            }
            finally
            {
                if (colorDialog != null)
                {
                    colorDialog.Dispose();
                }
            }

            return(null);
        }
コード例 #9
0
ファイル: Clipper.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Initializes a new instance of the <see cref="Clipper"/> class.
        /// </summary>
        /// <param name="renderer">The renderer to display the clipper UI.</param>
        /// <param name="renderControl">The control that will be rendered into.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="renderer"/> or the <paramref name="renderControl"/> parameter is NULL (Nothing in VB.Net).</exception>
        public Clipper(Gorgon2D renderer, Control renderControl)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException("renderer");
            }

            if (renderControl == null)
            {
                throw new ArgumentNullException("renderControl");
            }

            _scale               = new Vector2(1);
            _dragAreas           = new RectangleF[8];
            SelectorAnimateSpeed = 0.5f;
            DragNodeSize         = new Size(8, 8);
            DragNodeColor        = new GorgonColor(0, 1, 1, 0.5f);
            DragNodeHoverColor   = new GorgonColor(1, 0, 0, 0.5f);

            _renderControl = renderControl;
            _renderer      = renderer;

            _textureSize = new Size(1, 1);

            SelectionSprite = renderer.Renderables.CreateSprite("SelectionSprite",
                                                                new GorgonSpriteSettings
            {
                Color = new GorgonColor(0, 0, 0.8f, 0.5f),
                Size  = new Vector2(1)
            });

            SelectionSprite.TextureSampler.HorizontalWrapping = TextureAddressing.Wrap;
            SelectionSprite.TextureSampler.VerticalWrapping   = TextureAddressing.Wrap;
        }
コード例 #10
0
ファイル: Gorgon2D.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to clear the current target and its depth/stencil buffer.
        /// </summary>
        /// <param name="color">Color to clear with.</param>
        /// <param name="depth">Depth value to clear with.</param>
        /// <param name="stencil">Stencil value to clear with.</param>
        /// <remarks>Unlike a render target <see cref="GorgonLibrary.Graphics.GorgonRenderTargetView.Clear">Clear</see> method, this will respect any clipping and/or viewport.
        /// However, this only affects the color buffer, the depth/stencil will be cleared in their entirety.</remarks>
        public void Clear(GorgonColor color, float depth, byte stencil)
        {
            if ((_clip == null) && (_viewPort == null))
            {
                if (DepthStencil != null)
                {
                    DepthStencil.ClearDepth(depth);
                    DepthStencil.ClearStencil(stencil);
                }

                Target.Clear(color);

                return;
            }

            if (DepthStencil != null)
            {
                DepthStencil.ClearDepth(depth);
                DepthStencil.ClearStencil(stencil);
            }

            var currentBlend = Drawing.BlendingMode;

            Drawing.BlendingMode = BlendingMode.None;
            Drawing.FilledRectangle(new RectangleF(0, 0, _currentTarget.Width, _currentTarget.Height), color);
            Drawing.BlendingMode = currentBlend;
        }
コード例 #11
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw a single point to the current target.
 /// </summary>
 /// <param name="position">Position of the point.</param>
 /// <param name="color">Color of the point.</param>
 /// <param name="thickness">Thickness of the point.</param>
 public void DrawPoint(Vector2 position, GorgonColor color, Vector2 thickness)
 {
     SetStates(_point);
     _point.Position       = position;
     _point.PointThickness = thickness;
     _point.Color          = color;
     _point.Draw();
 }
コード例 #12
0
ファイル: PanelGradient.cs プロジェクト: tmp7701/Gorgon
            /// <summary>
            /// Initializes a new instance of the <see cref="WeightHandle"/> class.
            /// </summary>
            /// <param name="weight">The weight of the node.</param>
            /// <param name="color">Color for the node.</param>
            /// <param name="index">The index of the corresponding interpolation value.</param>
            public WeightHandle(float weight, GorgonColor color, int index)
            {
                Weight = weight;
                Color  = color;
                Index  = index;

                _trianglePoints = new PointF[3];
            }
コード例 #13
0
ファイル: GorgonRenderables.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to create a new sprite object.
 /// </summary>
 /// <param name="name">Name of the sprite.</param>
 /// <param name="size">Size of the sprite.</param>
 /// <param name="color">Color for the sprite.</param>
 /// <returns>A new sprite.</returns>
 /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the name parameter is an empty string.</exception>
 public GorgonSprite CreateSprite(string name, Vector2 size, GorgonColor color)
 {
     return(CreateSprite(name, new GorgonSpriteSettings
     {
         Color = color,
         InitialScale = new Vector2(1.0f),
         Size = size
     }));
 }
コード例 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlendState"/> class.
 /// </summary>
 public BlendState()
 {
     SourceBlend      = BlendType.SourceAlpha;
     DestinationBlend = BlendType.InverseSourceAlpha;
     BlendFactor      = new GorgonColor(0);
     BlendOperation   = BlendOperation.Add;
     AlphaOperation   = BlendOperation.Add;
     WriteMask        = ColorWriteMaskFlags.All;
 }
コード例 #15
0
ファイル: Program.cs プロジェクト: hammerforgegames/Gorgon
        /// <summary>
        /// Function called during CPU idle time.
        /// </summary>
        /// <returns><b>true</b> to continue executing, <b>false</b> to stop.</returns>
        private static bool Idle()
        {
            _background.Position = new DX.Vector2(_background.Position.X, _background.Position.Y + (0.3f * GorgonTiming.Delta));

            // Just wrap around if we hit the top of the background.
            if (_background.Position.Y > _background.Bounds.Height)
            {
                _background.Position = new DX.Vector2(_background.Position.X, _screen.Height);
            }

            if (_floatLeft)
            {
                _floatOffset -= GorgonTiming.Delta * (_screen.Width / 16.0f);
            }
            else
            {
                _floatOffset += GorgonTiming.Delta * (_screen.Width / 16.0f);
            }

            float floatBounds = _screen.Width / 4.0f;

            if (_floatOffset < -floatBounds)
            {
                _floatOffset = -floatBounds;
                _floatLeft   = !_floatLeft;
            }
            else if (_floatOffset > floatBounds)
            {
                _floatOffset = floatBounds;
                _floatLeft   = !_floatLeft;
            }

            _ship.Position = new DX.Vector2((_screen.Width / 2) + _floatOffset, _screen.Height - 120);

            _renderer.Begin();
            _renderer.DrawSprite(_background);

            // Draw our "stars".
            for (int i = 0; i < _stars.Length; ++i)
            {
                ref DX.Vector2 star = ref _stars[i];
                star = new DX.Vector2(star.X, star.Y + (((i % 2) == 0 ? 0.3f : 0.4f) * GorgonTiming.Delta));

                if (star.Y > 1.0f)
                {
                    star = new DX.Vector2(GorgonRandom.RandomSingle(), GorgonRandom.RandomSingle() * -1.0f);
                    continue;
                }

                var position = new DX.Vector2(star.X * _screen.Width, star.Y * _screen.Height);

                float starColorValue = GorgonRandom.RandomSingle(0.35f, 1.0f);
                var   starColor      = new GorgonColor(starColorValue, starColorValue, starColorValue, 1.0f);

                _renderer.DrawFilledRectangle(new DX.RectangleF(position.X, position.Y, 1, 1), starColor);
            }
コード例 #16
0
        /// <summary>
        /// Function to convert the image data into a premultiplied format.
        /// </summary>
        /// <param name="baseImage">The image to convert.</param>
        /// <returns>A <see cref="IGorgonImage"/> containing the image data with the premultiplied alpha pixel data.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="baseImage"/> is <b>null</b>.</exception>
        /// <exception cref="ArgumentException">Thrown when the original format could not be converted to <see cref="BufferFormat.R8G8B8A8_UNorm"/>.</exception>
        /// <remarks>
        /// <para>
        /// Use this to convert an image to a premultiplied format. This takes each Red, Green and Blue element and multiplies them by the Alpha element.
        /// </para>
        /// <para>
        /// Because this method will only operate on <see cref="BufferFormat.R8G8B8A8_UNorm"/> formattted image data, the image will be converted to that format and converted back to its original format
        /// after the alpha is premultiplied. This may cause color fidelity issues. If the image cannot be converted, then an exception will be thrown.
        /// </para>
        /// </remarks>
        public static IGorgonImage ConvertToPremultipliedAlpha(this IGorgonImage baseImage)
        {
            IGorgonImage newImage = null;

            if (baseImage == null)
            {
                throw new ArgumentNullException(nameof(baseImage));
            }

            try
            {
                // Worker image.
                var cloneImageInfo = new GorgonImageInfo(baseImage)
                {
                    HasPreMultipliedAlpha = true
                };
                newImage = new GorgonImage(cloneImageInfo);
                baseImage.CopyTo(newImage);

                if (newImage.Format != BufferFormat.R8G8B8A8_UNorm)
                {
                    if (!newImage.CanConvertToFormat(BufferFormat.R8G8B8A8_UNorm))
                    {
                        throw new ArgumentException(string.Format(Resources.GORIMG_ERR_FORMAT_NOT_SUPPORTED, BufferFormat.R8G8B8A8_UNorm), nameof(baseImage));
                    }

                    // Clone the image so we can convert it to the correct format.
                    newImage.ConvertToFormat(BufferFormat.R8G8B8A8_UNorm);
                }

                unsafe
                {
                    int *imagePtr = (int *)(newImage.ImageData);

                    for (int i = 0; i < newImage.SizeInBytes; i += newImage.FormatInfo.SizeInBytes)
                    {
                        var color = GorgonColor.FromABGR(*imagePtr);
                        color         = new GorgonColor(color.Red * color.Alpha, color.Green * color.Alpha, color.Blue * color.Alpha, color.Alpha);
                        *(imagePtr++) = color.ToABGR();
                    }
                }

                if (newImage.Format != baseImage.Format)
                {
                    newImage.ConvertToFormat(baseImage.Format);
                }

                newImage.CopyTo(baseImage);

                return(baseImage);
            }
            finally
            {
                newImage?.Dispose();
            }
        }
コード例 #17
0
ファイル: GorgonLine.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to set the color for a specific vertex on the line.
 /// </summary>
 /// <param name="point">Point on the line to set.</param>
 /// <param name="color">Color to set.</param>
 /// <remarks>The <paramref name="point"/> parameter is </remarks>
 public void SetVertexColor(LineEndPoints point, GorgonColor color)
 {
     if (point == LineEndPoints.Start)
     {
         Vertices[0].Color = color;
     }
     else
     {
         Vertices[1].Color = color;
     }
 }
コード例 #18
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw a rectangle onto the current target.
 /// </summary>
 /// <param name="rectangle">Rectangle dimensions.</param>
 /// <param name="color">Color for the rectangle.</param>
 /// <param name="thickness">Thickness of the lines to draw.</param>
 /// <param name="texture">Texture to apply to the rectangle.</param>
 /// <param name="textureRegion">Texture dimensions to use.</param>
 public void DrawRectangle(RectangleF rectangle, GorgonColor color, Vector2 thickness, GorgonTexture2D texture, RectangleF textureRegion)
 {
     SetStates(_rect);
     _rect.IsFilled      = false;
     _rect.Color         = color;
     _rect.Texture       = texture;
     _rect.TextureRegion = textureRegion;
     _rect.Rectangle     = rectangle;
     _rect.LineThickness = thickness;
     _rect.Draw();
 }
コード例 #19
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw a filled rectangle onto the current target.
 /// </summary>
 /// <param name="rectangle">Rectangle dimensions.</param>
 /// <param name="color">Color for the rectangle.</param>
 /// <param name="texture">Texture to apply to the rectangle.</param>
 /// <param name="textureRegion">Texture dimensions to use.</param>
 public void FilledRectangle(RectangleF rectangle, GorgonColor color, GorgonTexture2D texture, RectangleF textureRegion)
 {
     SetStates(_rect);
     _rect.IsFilled      = true;
     _rect.Color         = color;
     _rect.Texture       = texture;
     _rect.TextureRegion = textureRegion;
     _rect.Rectangle     = rectangle;
     _rect.LineThickness = new Vector2(1.0f);
     _rect.Draw();
 }
コード例 #20
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw a filled ellipse onto the current target.
 /// </summary>
 /// <param name="dimensions">Ellipse dimensions.</param>
 /// <param name="color">Color for the ellipse.</param>
 /// <param name="quality">Quality of rendering for the ellipse.</param>
 /// <param name="texture">Texture to apply to the ellipse.</param>
 /// <param name="textureRegion">Texture dimensions to use.</param>
 /// <remarks>The <paramref name="quality"/> parameter can have a value from 4 to 256.  The higher the quality, the better looking the ellipse, however this will impact performance.</remarks>
 public void FilledEllipse(RectangleF dimensions, GorgonColor color, int quality, GorgonTexture2D texture, RectangleF textureRegion)
 {
     SetStates(_ellipse);
     _ellipse.IsFilled      = true;
     _ellipse.Position      = dimensions.Location;
     _ellipse.Size          = dimensions.Size;
     _ellipse.Color         = color;
     _ellipse.Quality       = quality;
     _ellipse.Texture       = texture;
     _ellipse.TextureRegion = textureRegion;
     _ellipse.Draw();
 }
コード例 #21
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw a line to the current target.
 /// </summary>
 /// <param name="startPosition">Starting position.</param>
 /// <param name="endPosition">Ending position.</param>
 /// <param name="color">Color of the line.</param>
 /// <param name="thickness">Thickness of the line.</param>
 /// <param name="texture">Texture to apply to the line.</param>
 /// <param name="textureStart">Starting point on the texture.</param>
 /// <param name="textureEnd">Ending point on the texture.</param>
 public void DrawLine(Vector2 startPosition, Vector2 endPosition, GorgonColor color, Vector2 thickness, GorgonTexture2D texture, Vector2 textureStart, Vector2 textureEnd)
 {
     SetStates(_line);
     _line.StartPoint    = startPosition;
     _line.EndPoint      = endPosition;
     _line.Color         = color;
     _line.LineThickness = thickness;
     _line.Texture       = texture;
     _line.TextureStart  = textureStart;
     _line.TextureEnd    = textureEnd;
     _line.Draw();
 }
コード例 #22
0
ファイル: GorgonDrawing.cs プロジェクト: tmp7701/Gorgon
 /// <summary>
 /// Function to draw an ellipse onto the current target.
 /// </summary>
 /// <param name="dimensions">Ellipse dimensions.</param>
 /// <param name="color">Color for the ellipse.</param>
 /// <param name="quality">Quality of rendering for the ellipse.</param>
 /// <param name="thickness">Thickness of the line.</param>
 /// <param name="texture">Texture to apply to the ellipse.</param>
 /// <param name="textureRegion">Texture dimensions to use.</param>
 /// <remarks>The <paramref name="quality"/> parameter can have a value from 4 to 256.  The higher the quality, the better looking the ellipse, however this will impact performance.</remarks>
 public void DrawEllipse(RectangleF dimensions, GorgonColor color, int quality, Vector2 thickness, GorgonTexture2D texture, RectangleF textureRegion)
 {
     SetStates(_ellipse);
     _ellipse.IsFilled      = false;
     _ellipse.Position      = dimensions.Location;
     _ellipse.Size          = dimensions.Size;
     _ellipse.Color         = color;
     _ellipse.Quality       = quality;
     _ellipse.Texture       = texture;
     _ellipse.TextureRegion = textureRegion;
     _ellipse.LineThickness = thickness;
     _ellipse.Draw();
 }
コード例 #23
0
        /// <summary>
        /// Function to save the state information to this object.
        /// </summary>
        private void Save()
        {
            _targets               = _graphics.Output.GetRenderTargets();
            _uavs                  = _graphics.Output.GetUnorderedAccessViews();
            _indexBuffer           = _graphics.Input.IndexBuffer;
            _vertexBuffer          = _graphics.Input.VertexBuffers[0];
            _inputLayout           = _graphics.Input.Layout;
            _primitiveType         = _graphics.Input.PrimitiveType;
            _pixelShader           = _graphics.Shaders.PixelShader.Current;
            _vertexShader          = _graphics.Shaders.VertexShader.Current;
            _blendStates           = _graphics.Output.BlendingState.States;
            _blendFactor           = _graphics.Output.BlendingState.BlendFactor;
            _blendSampleMask       = _graphics.Output.BlendingState.BlendSampleMask;
            _rasterStates          = _graphics.Rasterizer.States;
            _samplerState          = _graphics.Shaders.PixelShader.TextureSamplers[0];
            _resource              = _graphics.Shaders.PixelShader.Resources[0];
            _depthStencilState     = _graphics.Output.DepthStencilState.States;
            _depthStencilReference = _graphics.Output.DepthStencilState.StencilReference;
            _rasterStates.IsScissorTestingEnabled = false;
            _depthStencil = _graphics.Output.DepthStencilView;
            _viewports    = _graphics.Rasterizer.GetViewports();
            _scissorTests = _graphics.Rasterizer.GetScissorRectangles();
            _alphaTest    = new Gorgon2DAlphaTest(Gorgon2D.IsAlphaTestEnabled, GorgonRangeF.Empty);

            _vsConstantBuffers = new Dictionary <int, GorgonConstantBuffer>();
            _psConstantBuffers = new Dictionary <int, GorgonConstantBuffer>();

            // Only store the constant buffers that we were using.
            // We need to store all the constant buffers because the effects
            // make use of multiple constant slots.  Unlike the resource views,
            // where we know that we're only using the first item (all bets are
            // off if a user decides to use another resource view slot), there's no
            // guarantee that we'll be only using 1 or 2 constant buffer slots.
            for (int i = 0; i < _graphics.Shaders.VertexShader.ConstantBuffers.Count; i++)
            {
                if (_graphics.Shaders.VertexShader.ConstantBuffers[i] != null)
                {
                    _vsConstantBuffers[i] = _graphics.Shaders.VertexShader.ConstantBuffers[i];
                }
            }

            for (int i = 0; i < _graphics.Shaders.PixelShader.ConstantBuffers.Count; i++)
            {
                if (_graphics.Shaders.PixelShader.ConstantBuffers[i] != null)
                {
                    _psConstantBuffers[i] = _graphics.Shaders.PixelShader.ConstantBuffers[i];
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Function to send model data to the GPU for rendering.
        /// </summary>
        /// <param name="model">The model containing the data to render.</param>
        private static void RenderModel(Model model)
        {
            // Send the transform for the model to the GPU so we can update its position and rotation.
            model.UpdateTransform();
            UpdateWVP(ref model.WorldMatrix);

            GorgonColor color = model.Material.Diffuse;

            _materialBuffer.Buffer.SetData(ref color, copyMode: CopyMode.Discard);

            GorgonDrawIndexCall drawCall = model == _sphere ? _drawCalls[2] : (model == _planes[0] ? _drawCalls[0] : _drawCalls[1]);

            // Finally, send the draw call to the GPU.
            _graphics.Submit(drawCall);
        }
コード例 #25
0
        /// <summary>
        /// Function to validate the state of the OK button.
        /// </summary>
        /// <returns><b>true</b> if the OK button is valid, <b>false</b> if not.</returns>
        protected override bool OnValidateOk()
        {
            GorgonColor color;

            if (RadioAlpha.Checked)
            {
                color = new GorgonColor(Picker.OriginalColor, ColorShow.UpperColor.A / 255.0f);
            }
            else
            {
                color = Picker.OriginalColor;
            }

            return((DataContext != null) && ((_originalMask != DataContext.ClipMaskType) || (!DataContext.ClipMaskValue.Equals(in color))));
        }
コード例 #26
0
        /// <summary>
        /// Function to draw the glyph character outline onto the bitmap.
        /// </summary>
        /// <param name="character">Character to write.</param>
        /// <param name="glyphBitmap">The bitmap that will receive the glyph.</param>
        /// <param name="glyphGraphics">The graphics context for the glyph bitmap.</param>
        private void DrawGlyphCharacterOutline(char character, Bitmap glyphBitmap, System.Drawing.Graphics glyphGraphics)
        {
            string charString = character.ToString(CultureInfo.CurrentCulture);

            glyphGraphics.Clear(Color.FromArgb(0));

            using (var outlineRenderer = new GraphicsPath())
            {
                outlineRenderer.AddString(charString,
                                          _fontData.Font.FontFamily,
                                          (int)_fontInfo.FontStyle,
                                          _fontData.Font.Size,
                                          new RectangleF(0, 0, glyphBitmap.Width, glyphBitmap.Height),
                                          _fontData.DrawFormat);

                // If we want an outline, then draw that first.
                if ((_fontInfo.OutlineColor1 == _fontInfo.OutlineColor2) ||
                    (_fontInfo.OutlineSize < 3))
                {
                    using (var outlinePen = new Pen(_fontInfo.OutlineColor1, _fontInfo.OutlineSize * 2))
                    {
                        outlinePen.LineJoin = LineJoin.Round;
                        glyphGraphics.DrawPath(outlinePen, outlineRenderer);
                    }
                }
                else
                {
                    GorgonColor start = _fontInfo.OutlineColor1;
                    GorgonColor end   = _fontInfo.OutlineColor2;

                    // Fade from the first to the second color via a linear function.
                    for (int i = _fontInfo.OutlineSize; i > 0; --i)
                    {
                        float delta = ((float)(i - 1) / (_fontInfo.OutlineSize - 1));

                        GorgonColor.Lerp(in start, in end, delta, out GorgonColor penColor);

                        using (var outlinePen = new Pen(penColor, i))
                        {
                            outlinePen.LineJoin = LineJoin.Round;
                            glyphGraphics.DrawPath(outlinePen, outlineRenderer);
                        }
                    }
                }
            }

            glyphGraphics.Flush();
        }
コード例 #27
0
        /// <summary>
        /// Function to interpolate a new key frame from the nearest previous and next key frames.
        /// </summary>
        /// <param name="keyValues">Nearest previous and next key frames.</param>
        /// <param name="keyTime">The time to assign to the key.</param>
        /// <param name="unitTime">The time, expressed in unit time.</param>
        /// <returns>
        /// The interpolated key frame containing the interpolated values.
        /// </returns>
        protected override IKeyFrame GetTweenKey(ref NearestKeys keyValues, float keyTime, float unitTime)
        {
            var next = (GorgonKeyGorgonColor)keyValues.NextKey;
            var prev = (GorgonKeyGorgonColor)keyValues.PreviousKey;

            switch (InterpolationMode)
            {
            case TrackInterpolationMode.Linear:
                return(new GorgonKeyGorgonColor(keyTime, GorgonColor.Lerp(prev.Value, next.Value, unitTime)));

            case TrackInterpolationMode.Spline:
                return(new GorgonKeyGorgonColor(keyTime, Spline.GetInterpolatedValue(keyValues.PreviousKeyIndex, unitTime)));

            default:
                return(prev);
            }
        }
コード例 #28
0
        /// <summary>Function to read back the specifics of the font brush data from a file reader.</summary>
        /// <param name="reader">The reader used to read the brush data.</param>
        internal override void ReadBrushData(GorgonBinaryReader reader)
        {
            WrapMode = (GlyphBrushWrapMode)reader.ReadInt32();
            int count = reader.ReadInt32();

            Points.Clear();
            for (int i = 0; i < count; ++i)
            {
                Points.Add(reader.ReadValue <DX.Vector2>());
            }

            BlendFactors.Clear();
            count = reader.ReadInt32();
            for (int i = 0; i < count; ++i)
            {
                BlendFactors.Add(reader.ReadSingle());
            }

            BlendPositions.Clear();
            count = reader.ReadInt32();
            for (int i = 0; i < count; ++i)
            {
                BlendPositions.Add(reader.ReadSingle());
            }

            CenterColor = new GorgonColor(reader.ReadInt32());
            CenterPoint = reader.ReadValue <DX.Vector2>();
            FocusScales = reader.ReadValue <DX.Vector2>();

            count = reader.ReadInt32();
            Interpolation.Clear();

            for (int i = 0; i < count; ++i)
            {
                Interpolation.Add(new GorgonGlyphBrushInterpolator(reader.ReadSingle(), new GorgonColor(reader.ReadInt32())));
            }

            count = reader.ReadInt32();
            SurroundColors.Clear();

            for (int i = 0; i < count; ++i)
            {
                SurroundColors.Add(new GorgonColor(reader.ReadInt32()));
            }
        }
コード例 #29
0
ファイル: GorgonRenderables.cs プロジェクト: tmp7701/Gorgon
        /// <summary>
        /// Function to create a point object.
        /// </summary>
        /// <param name="name">Name of the point.</param>
        /// <param name="position">The position of the point.</param>
        /// <param name="color">Color of the point.</param>
        /// <returns>A new point primitive object.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the <paramref name="name"/> parameter is NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the name parameter is an empty string.</exception>
        public GorgonPoint CreatePoint(string name, Vector2 position, GorgonColor color)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(Resources.GOR2D_PARAMETER_MUST_NOT_BE_EMPTY, "name");
            }

            return(new GorgonPoint(_gorgon2D, name)
            {
                Position = position,
                Color = color
            });
        }
コード例 #30
0
        /// <summary>Function to retrieve a color.</summary>
        /// <param name="originalColor">The original color being changed.</param>
        /// <returns>The new color, or <b>null</b> if cancelled.</returns>
        public GorgonColor?GetColor(GorgonColor originalColor)
        {
            FormColorPicker picker = null;

            try
            {
                picker = new FormColorPicker
                {
                    OriginalColor = originalColor,
                    Color         = originalColor
                };

                return(picker.ShowDialog(GorgonApplication.MainForm) == DialogResult.Cancel ? null : (GorgonColor?)picker.Color);
            }
            finally
            {
                picker?.Dispose();
            }
        }