ConvertColor() публичный статический Метод

Converts the Color into a DXColor.
public static ConvertColor ( Color color ) : SlimDX.Color4
color System.Drawing.Color The Color.
Результат SlimDX.Color4
Пример #1
0
 /// <summary>
 /// Begins the draw operation.
 /// </summary>
 public void Begin()
 {
     _direct3D9Device.BeginScene();
     _direct3D9Device.Clear(ClearFlags.Target, DirectXHelper.ConvertColor(_graphicsDevice.ClearColor), 0, 0);
     _sprite.Transform = Matrix.Identity;
     _sprite.Begin(SpriteFlags.AlphaBlend);
 }
Пример #2
0
        /// <summary>
        /// Draws a Rectangle.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="rectangle">The Rectangle.</param>
        public void DrawRectangle(Pen pen, Rectangle rectangle)
        {
            var dxPen = pen.Instance as DirectXPen;

            if (dxPen == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXPen as resource.");
            }

            var line = new Line(_direct3D9Device)
            {
                Antialias = true, Width = dxPen.Width
            };

            line.Begin();

            line.Draw(
                DirectXHelper.ConvertToVertex(
                    new Vector2(rectangle.X, rectangle.Y),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y),
                    new Vector2(rectangle.X, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X, rectangle.Y),
                    new Vector2(rectangle.X, rectangle.Y + rectangle.Height),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y),
                    new Vector2(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height)),
                DirectXHelper.ConvertColor(dxPen.Color));

            line.End();
        }
Пример #3
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="spriteSheet">The SpriteSheet.</param>
        /// <param name="position">The Position.</param>
        /// <param name="color">The Color.</param>
        /// <param name="opacity">The Opacity.</param>
        public void DrawTexture(SpriteSheet spriteSheet, Vector2 position, Color color, float opacity = 1)
        {
            var dxTexture = spriteSheet.Texture2D as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXTexture as resource.");
            }

            _sprite.Draw(dxTexture.GetTexture(), DirectXHelper.ConvertToWinRectangle(spriteSheet.Rectangle), null,
                         DirectXHelper.ConvertVector3(position), DirectXHelper.ConvertColor(color));
        }
Пример #4
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="texture">The Texture.</param>
        /// <param name="position">The Position.</param>
        /// <param name="opacity">The Opacity.</param>
        /// <param name="color">The Color.</param>
        public void DrawTexture(Texture2D texture, Vector2 position, Color color, float opacity = 1)
        {
            var dxTexture = texture as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXTexture as resource.");
            }

            _sprite.Draw(dxTexture.GetTexture(), null, DirectXHelper.ConvertVector2(position),
                         DirectXHelper.ConvertColor(color));
        }
Пример #5
0
        /// <summary>
        /// Draws a string.
        /// </summary>
        /// <param name="text">The Text.</param>
        /// <param name="font">The Font.</param>
        /// <param name="position">The Position.</param>
        /// <param name="color">The Color.</param>
        public void DrawString(string text, Font font, Vector2 position, Color color)
        {
            var dxFont = font.Instance as DirectXFont;

            if (dxFont == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXFont as resource.");
            }

            dxFont.GetFont()
            .DrawString(_sprite, text, (int)position.X, (int)position.Y, DirectXHelper.ConvertColor(color));
        }
Пример #6
0
        /// <summary>
        /// Fills a Ellipse.
        /// </summary>
        /// <param name="color">The Color.</param>
        /// <param name="ellipse">The Ellipse.</param>
        public void FillEllipse(Color color, Ellipse ellipse)
        {
            var line = new Line(_direct3D9Device)
            {
                Antialias = false, Width = 2
            };

            line.Begin();

            line.Draw(DirectXHelper.ConvertToVertex(ellipse.Points), DirectXHelper.ConvertColor(color));

            line.End();
        }
Пример #7
0
        /// <summary>
        /// Draws a string.
        /// </summary>
        /// <param name="text">The Text.</param>
        /// <param name="font">The Font.</param>
        /// <param name="rectangle">The Rectangle.</param>
        /// <param name="color">The Color.</param>
        public void DrawString(string text, Font font, Rectangle rectangle, Color color)
        {
            var dxFont = font.Instance as DirectXFont;

            if (dxFont == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXFont as resource.");
            }

            dxFont.GetFont()
            .DrawString(_sprite, text, DirectXHelper.ConvertToWinRectangle(rectangle), DrawTextFormat.WordBreak,
                        DirectXHelper.ConvertColor(color));
        }
Пример #8
0
        /// <summary>
        /// Fills a Rectangle.
        /// </summary>
        /// <param name="color">The Color.</param>
        /// <param name="rectangle">The Rectangle.</param>
        public void FillRectangle(Color color, Rectangle rectangle)
        {
            var line = new Line(_direct3D9Device)
            {
                Antialias = true, Width = rectangle.Height
            };

            line.Begin();
            line.Draw(
                DirectXHelper.ConvertToVertex(new Vector2(rectangle.X, rectangle.Center.Y),
                                              new Vector2(rectangle.X + rectangle.Width, rectangle.Center.Y)),
                DirectXHelper.ConvertColor(color));
            line.End();
        }
Пример #9
0
        /// <summary>
        /// Draws a Polygon.
        /// </summary>
        /// <param name="pen">The Pen.</param>
        /// <param name="polygon">The Polygon.</param>
        public void DrawPolygon(Pen pen, Polygon polygon)
        {
            var dxPen = pen.Instance as DirectXPen;

            if (dxPen == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXPen as resource.");
            }

            var line = new Line(_direct3D9Device)
            {
                Antialias = true, Width = dxPen.Width
            };

            line.Begin();
            line.Draw(DirectXHelper.ConvertToVertex(polygon.Points), DirectXHelper.ConvertColor(dxPen.Color));
            line.End();
        }
Пример #10
0
        /// <summary>
        /// Draws a Texture.
        /// </summary>
        /// <param name="spriteSheet">The SpriteSheet.</param>
        /// <param name="rectangle">The Rectangle.</param>
        /// <param name="color">The Color.</param>
        /// <param name="opacity">The Opacity.</param>
        public void DrawTexture(SpriteSheet spriteSheet, Rectangle rectangle, Color color, float opacity = 1)
        {
            var dxTexture = spriteSheet.Texture2D as DirectXTexture;

            if (dxTexture == null)
            {
                throw new ArgumentException("DirectX9 expects a DirectXTexture as resource.");
            }

            //calc percentages for scaling

            float scaleX = rectangle.Width / spriteSheet.Rectangle.Width;
            float scaleY = rectangle.Height / spriteSheet.Rectangle.Height;

            _sprite.Transform = Matrix.Scaling(scaleX, scaleY, 1f);

            _sprite.Draw(dxTexture.GetTexture(), DirectXHelper.ConvertToWinRectangle(spriteSheet.Rectangle), null,
                         DirectXHelper.ConvertVector3(new Vector2(rectangle.X / scaleX, rectangle.Y / scaleY)),
                         DirectXHelper.ConvertColor(color));

            _sprite.Transform = Matrix.Identity;
        }