Ejemplo n.º 1
0
        static void DrawTexture(SharpDX.Direct3D9.Device device)
        {
            SharpDX.Direct3D9.Texture tex = null;
            Sprite sprite = null;

            tex    = SharpDX.Direct3D9.Texture.FromFile(device, "Resources/fire_seamless_tile_by_suicidecrew.jpg");
            sprite = new SharpDX.Direct3D9.Sprite(device);
            // to resize/rotate/position sprite.Transform = some 4x4 affine transform matrix (SharpDX.Matrix)

            sprite.Begin(SharpDX.Direct3D9.SpriteFlags.None);
            SharpDX.Vector3 pos   = new SharpDX.Vector3(0, 0, 0);
            SharpDX.Color   color = new SharpDX.ColorBGRA(0xffffffff);

            sprite.Draw(tex, color, new SharpDX.Mathematics.Interop.RawRectangle(1, 1, 100, 100), null, pos);

            // Finish drawing
            sprite.End();
        }
Ejemplo n.º 2
0
            public void DrawTexture(SharpDX.Direct3D9.Device device)
            {
                Sprite sprite = null;

                sprite = new SharpDX.Direct3D9.Sprite(device);
                // to resize/rotate/position sprite.Transform = some 4x4 affine transform matrix (SharpDX.Matrix)

                sprite.Begin(SharpDX.Direct3D9.SpriteFlags.None);
                SharpDX.Color color = new SharpDX.ColorBGRA(0xffffffff);

                if (isIn)
                {
                    sprite.Draw(texIn, color, rectangle, null, pos);
                }
                else
                {
                    sprite.Draw(texOut, color, rectangle, null, pos);
                }
                // Finish drawing
                sprite.End();
            }
Ejemplo n.º 3
0
        public static Vertex[] GetVertexArray(Vector2[] points, SharpDX.ColorBGRA color)
        {
            List <Vertex> verList = new List <Vertex>();

            verList.Add(new Vertex()
            {
                Color = color, Position = points[0]
            });
            verList.Add(new Vertex()
            {
                Color = color, Position = points[points.Length - 2]
            });
            verList.Add(new Vertex()
            {
                Color = color, Position = points[1]
            });
            for (int index = 1; index <= (points.Length) / 2; index++)
            {
                verList.Add(new Vertex()
                {
                    Color = color, Position = points[points.Length - index - 1]
                });
                verList.Add(new Vertex()
                {
                    Color = color, Position = points[points.Length - index - 2]
                });

                verList.Add(new Vertex()
                {
                    Color = color, Position = points[index]
                });
                verList.Add(new Vertex()
                {
                    Color = color, Position = points[index + 1]
                });
            }
            return(verList.ToArray());
        }
Ejemplo n.º 4
0
        public Color GetPixel(int x, int y)
        {
            try
            {
                var output = new uint[1];
                Control.CopyPixels(new s.Rectangle(x, y, 1, 1), output);
                var eto = new s.ColorBGRA(output[0]).ToEto();
                if (IsPremultiplied)
                {
                    eto = Color.FromPremultipliedArgb(eto.ToArgb());
                }
                else if (!HasAlpha)
                {
                    eto.A = 1;
                }

                return(eto);
            }
            catch (s.SharpDXException ex)
            {
                Debug.WriteLine("GetPixel: {0}", ex.ToString());
                throw;
            }
        }
Ejemplo n.º 5
0
 public static void DrawText(Font vFont, String vText, float vPosX, float vPosY, SharpDX.ColorBGRA vColor)
 {
     vFont.DrawText(null, vText, (int)vPosX, (int)vPosY, vColor);
 }
Ejemplo n.º 6
0
        private void DrawCircle(
            float x,
            float y,
            float radius,
            int rotate,
            bool smoothing,
            int resolution,
            SharpDX.ColorBGRA color)
        {
            var vertices = new VertexBuffer(
                Drawing.Direct3DDevice,
                SharpDX.Utilities.SizeOf <Vector4>() * 2 * (resolution + 4),
                Usage.WriteOnly,
                VertexFormat.Diffuse | VertexFormat.PositionRhw,
                Pool.Default);

            var angle = rotate * (float)Math.PI / 180f;
            var pi    = (float)Math.PI;

            var data = new List <Vector4>();

            for (var i = 0; i < resolution + 4; i++)
            {
                var x1 = x - radius * (float)Math.Cos(i * (2f * pi / resolution));
                var y1 = y - radius * (float)Math.Sin(i * (2f * pi / resolution));
                data.AddRange(new[] { new Vector4(x1, y1, 0f, 1.0f), color.ToVector4() });
            }

            // Rotate matrix
            var res = 2 * resolution + 4;

            for (var i = 0; i < res; i = i + 2)
            {
                data[i] = new Vector4(
                    (float)(x + Math.Cos(angle) * (data[i].X - x) - Math.Sin(angle) * (data[i].Y - y)),
                    (float)(y + Math.Sin(angle) * (data[i].X - x) + Math.Cos(angle) * (data[i].Y - y)),
                    data[i].Z,
                    data[i].W);
            }

            vertices.Lock(0, 0, LockFlags.None).WriteRange(data.ToArray());
            vertices.Unlock();

            VertexElement[] vertexElements =
            {
                new VertexElement(
                    0,
                    0,
                    DeclarationType.Float4,
                    DeclarationMethod.Default,
                    DeclarationUsage.Position,
                    0),
                new VertexElement(
                    0,
                    16,
                    DeclarationType.Float4,
                    DeclarationMethod.Default,
                    DeclarationUsage.Color,
                    0),
                VertexElement.VertexDeclarationEnd
            };

            var vertexDeclaration = new VertexDeclaration(Drawing.Direct3DDevice, vertexElements);

            if (smoothing)
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, true);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, true);
            }
            else
            {
                Drawing.Direct3DDevice.SetRenderState(RenderState.MultisampleAntialias, false);
                Drawing.Direct3DDevice.SetRenderState(RenderState.AntialiasedLineEnable, false);
            }

            var olddec = Drawing.Direct3DDevice.VertexDeclaration;

            Drawing.Direct3DDevice.SetStreamSource(0, vertices, 0, SharpDX.Utilities.SizeOf <Vector4>() * 2);
            Drawing.Direct3DDevice.VertexDeclaration = vertexDeclaration;
            Drawing.Direct3DDevice.DrawPrimitives(PrimitiveType.LineStrip, 0, resolution);
            Drawing.Direct3DDevice.VertexDeclaration = olddec;

            vertexDeclaration.Dispose();
            vertices.Dispose();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Draws formatted text.
        /// </summary>
        /// <param name="sprite"><para>Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</para></param>
        /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
        /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
        /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
        /// <param name="color"><para>Color of the text. For more information, see <see cref="SharpDX.Color4"/>.</para></param>
        /// <returns>If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.</returns>
        /// <remarks>
        /// The parameters of this method are very similar to those of the GDI DrawText function.This method supports both ANSI and Unicode strings.This method must be called inside a  BeginScene ... EndScene block. The only exception is when an application calls DrawText with DT_CALCRECT to calculate the size of a given block of text.Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.This method supports only fonts whose escapement and orientation are both zero.
        /// </remarks>
        /// <unmanaged>int ID3DXFont::DrawTextW([In] ID3DXSprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] void* pRect,[In] unsigned int Format,[In] D3DCOLOR Color)</unmanaged>
        public unsafe int DrawText(SharpDX.Direct3D9.Sprite sprite, string text, SharpDX.Rectangle rect, FontDrawFlags drawFlags, SharpDX.ColorBGRA color)
        {
            int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int)drawFlags, color);

            if (value == 0)
            {
                throw new SharpDXException("Draw failed");
            }
            return(value);
        }
Ejemplo n.º 8
0
 public static Color ToEto(this s.ColorBGRA value)
 {
     return(Color.FromArgb(value.R, value.G, value.B, value.A));
 }
Ejemplo n.º 9
0
 public static void DrawText(Font fuente, String text, float posx, float posy, SharpDX.ColorBGRA color)
 {
     fuente.DrawText(null, text, (int)posx, (int)posy, color);
 }