Пример #1
0
        /// <summary>
        /// Adds or updates an OSD item.
        /// </summary>
        /// <param name="text">Item text</param>
        /// <param name="pos_x">Item X position</param>
        /// <param name="pos_y">Item Y position</param>
        /// <param name="color">Text color</param>
        /// <param name="identifier">Unique identifier, set to be able to update the item without recreating it</param>
        /// <param name="timer">Duration in frames, -1 for permanent, don't set to keep the previous value when updating an existing item</param>
        public void UpdateOSDItem(string text, int pos_x, int pos_y, RawColorBGRA color, string identifier = "", int timer = 0)
        {
            foreach (OSDItem osd in OSDItems)
            {
                if (osd.id != "" && osd.id == identifier)
                {
                    osd.text = text;
                    if (timer != 0)
                    {
                        osd.timer = timer;
                    }
                    osd.pos_x = pos_x - 8;
                    osd.pos_y = pos_y;
                    osd.color = color;
                    return;
                }
            }
            OSDItem newosd = new OSDItem();

            newosd.text  = text;
            newosd.id    = identifier;
            newosd.timer = timer;
            newosd.pos_x = pos_x - 8;
            newosd.pos_y = pos_y;
            newosd.color = color;
            OSDItems.Add(newosd);
        }
Пример #2
0
        public void RenderText(string text, RawRectangle rect, RawColorBGRA color)
        {
            var s = _Engine.DefaultSprite;

            s.Begin();
            _Font.DrawText(s, text, rect, FontDrawFlags.Left, color);
            s.End();
        }
Пример #3
0
 /// <summary>
 /// Draws a line strip in screen space with a specified input transformation matrix.
 /// </summary>
 /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="RawVector3"/>.</para></param>
 /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="RawMatrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param>
 /// <param name="color"><para>Color of the line. See <see cref="RawColor4"/>.</para></param>
 /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns>
 /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged>
 public void DrawTransform(RawVector3[] vertices, RawMatrix transform, RawColorBGRA color)
 {
     unsafe
     {
         fixed(void *pVertexListRef = vertices)
         DrawTransform((IntPtr)pVertexListRef, vertices.Length, ref transform, color);
     }
 }
Пример #4
0
 /// <summary>
 /// Draws a line strip in screen space. Input is in the form of an array that defines points (of <see cref="RawVector2"/>) on the line strip.
 /// </summary>
 /// <param name="vertices">No documentation.</param>
 /// <param name="color">No documentation.</param>
 /// <unmanaged>HRESULT ID3DXLine::Draw([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] D3DCOLOR Color)</unmanaged>
 public void Draw(RawVector2[] vertices, RawColorBGRA color)
 {
     unsafe
     {
         fixed(void *pVertexListRef = vertices)
         Draw((IntPtr)pVertexListRef, vertices.Length, color);
     }
 }
Пример #5
0
 /// <summary>
 /// Initializes an OSD which displays colored text/log on screen.
 /// </summary>
 /// <param name="device">Direct3D device to draw on</param>
 public OnScreenDisplay(Device device, RawColorBGRA color)
 {
     MessageList = new Dictionary <string, int>();
     OSDItems    = new List <OSDItem>();
     textSprite  = new Sprite(device);
     d3ddevice   = device;
     logcolor    = color;
     show_osd    = true;
 }
Пример #6
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Десереализация цветового значения из строки
            /// </summary>
            /// <param name="data">Строка данных</param>
            /// <returns>Цветовое значение</returns>
            //---------------------------------------------------------------------------------------------------------
            public static RawColorBGRA Deserialize(String data)
            {
                RawColorBGRA color = new RawColorBGRA();

                String[] color_data = data.Split(',');
                color.R = (Byte.Parse(color_data[0]));
                color.G = (Byte.Parse(color_data[1]));
                color.B = (Byte.Parse(color_data[2]));
                color.A = (Byte.Parse(color_data[3]));
                return(color);
            }
Пример #7
0
        /// <summary>
        /// Draws a line strip in screen space. Input is in the form of an array that defines points (of <see cref="RawVector2"/>) on the line strip.
        /// </summary>
        /// <param name="vertices">No documentation.</param>
        /// <param name="color">No documentation.</param>
        /// <unmanaged>HRESULT ID3DXLine::Draw([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] D3DCOLOR Color)</unmanaged>
        public void Draw <T>(T[] vertices, RawColorBGRA color) where T : struct
        {
            unsafe
            {
                if (Utilities.SizeOf <T>() != sizeof(RawVector2))
                {
                    throw new ArgumentException("Invalid size for T. Must be 2 floats (8 bytes)");
                }

                Draw((IntPtr)Interop.Fixed(vertices), vertices.Length, color);
            }
        }
Пример #8
0
        /// <summary>
        /// <p> Draws a run of glyphs to a bitmap target at the specified position.</p>
        /// </summary>
        /// <param name="baselineOriginX"><dd>  <p> The horizontal position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.</p> </dd></param>
        /// <param name="baselineOriginY"><dd>  <p> The vertical position of the baseline origin, in DIPs, relative to the upper-left corner of the DIB.</p> </dd></param>
        /// <param name="measuringMode"><dd>  <p> The measuring method for glyphs in the run, used with the other properties to determine the rendering mode.</p> </dd></param>
        /// <param name="glyphRun"><dd>  <p> The structure containing the properties of the glyph run.</p> </dd></param>
        /// <param name="renderingParams"><dd>  <p> The object that controls rendering behavior.</p> </dd></param>
        /// <param name="textColor"><dd>  <p> The foreground color of the text.</p> </dd></param>
        /// <param name="blackBoxRect"><dd>  <p> The optional rectangle that receives the bounding box (in pixels not DIPs) of all the pixels affected by  drawing the glyph run. The black box rectangle may extend beyond the dimensions of the bitmap.</p> </dd></param>
        /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
        /// <remarks>
        /// <p>You can use the <strong><see cref="SharpDX.DirectWrite.BitmapRenderTarget.DrawGlyphRun"/></strong> to render to a bitmap from a custom text renderer that you implement.  The custom text renderer should call this method from within the <strong><see cref="SharpDX.DirectWrite.TextRenderer.DrawGlyphRun"/></strong> callback method as shown in the following code.</p><pre>STDMETHODIMP GdiTextRenderer::DrawGlyphRun( __maybenull void* clientDrawingContext, FLOAT baselineOriginX, FLOAT baselineOriginY, <see cref="SharpDX.Direct2D1.MeasuringMode"/> measuringMode, __in <see cref="SharpDX.DirectWrite.GlyphRun"/> const* glyphRun, __in <see cref="SharpDX.DirectWrite.GlyphRunDescription"/> const* glyphRunDescription, <see cref="SharpDX.ComObject"/>* clientDrawingEffect )
        /// { <see cref="SharpDX.Result"/> hr = <see cref="SharpDX.Result.Ok"/>; // Pass on the drawing call to the render target to do the real work. <see cref="SharpDX.Mathematics.Interop.RawRectangle"/> dirtyRect = {0}; hr = pRenderTarget_-&gt;DrawGlyphRun( baselineOriginX, baselineOriginY, measuringMode, glyphRun, pRenderingParams_, RGB(0,200,255), &amp;dirtyRect ); return hr;
        /// }
        /// </pre><p>The <em>baselineOriginX</em>, <em>baslineOriginY</em>, <em>measuringMethod</em>, and <em>glyphRun</em> parameters are provided (as arguments) when the callback method is invoked.  The <em>renderingParams</em>, <em>textColor</em> and <em>blackBoxRect</em> are not.</p><p>Default rendering params can be retrieved by using the <strong><see cref="SharpDX.DirectWrite.Factory.CreateMonitorRenderingParams"/></strong> method.</p><p></p>
        /// </remarks>
        /// <include file='Documentation\CodeComments.xml' path="/comments/comment[@id='IDWriteBitmapRenderTarget::DrawGlyphRun']/*"/>
        /// <msdn-id>dd368167</msdn-id>
        /// <unmanaged>HRESULT IDWriteBitmapRenderTarget::DrawGlyphRun([In] float baselineOriginX,[In] float baselineOriginY,[In] DWRITE_MEASURING_MODE measuringMode,[In] const DWRITE_GLYPH_RUN* glyphRun,[In] IDWriteRenderingParams* renderingParams,[In] int textColor,[Out, Optional] RECT* blackBoxRect)</unmanaged>
        /// <unmanaged-short>IDWriteBitmapRenderTarget::DrawGlyphRun</unmanaged-short>
        public void DrawGlyphRun(float baselineOriginX,
                                 float baselineOriginY,
                                 SharpDX.Direct2D1.MeasuringMode measuringMode,
                                 SharpDX.DirectWrite.GlyphRun glyphRun,
                                 SharpDX.DirectWrite.RenderingParams renderingParams,
                                 RawColorBGRA textColor,
                                 out SharpDX.Mathematics.Interop.RawRectangle blackBoxRect)
        {
            int colorRgb = (textColor.R) | (textColor.G << 8) | (textColor.B << 16);

            DrawGlyphRun(baselineOriginX, baselineOriginY, measuringMode, glyphRun, renderingParams, colorRgb, out blackBoxRect);
        }
Пример #9
0
        /// <summary>
        /// Draws a line strip in screen space with a specified input transformation matrix.
        /// </summary>
        /// <param name="vertices"><para>Array of vertices that make up the line. See <see cref="RawVector3"/>.</para></param>
        /// <param name="transform"><para>A scale, rotate, and translate (SRT) matrix for transforming the points. See <see cref="RawMatrix"/>. If this matrix is a projection matrix, any stippled lines will be drawn with a perspective-correct stippling pattern. Or, you can transform the vertices and use <see cref="SharpDX.Direct3D9.Line.Draw"/> to draw the line with a nonperspective-correct stipple pattern.</para></param>
        /// <param name="color"><para>Color of the line. See <see cref="RawColor4"/>.</para></param>
        /// <returns>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns>
        /// <unmanaged>HRESULT ID3DXLine::DrawTransform([In] const void* pVertexList,[In] unsigned int dwVertexListCount,[In] const D3DXMATRIX* pTransform,[In] D3DCOLOR Color)</unmanaged>
        public void DrawTransform <T>(T[] vertices, RawMatrix transform, RawColorBGRA color) where T : struct
        {
            unsafe
            {
                if (Utilities.SizeOf <T>() != sizeof(RawVector3))
                {
                    throw new ArgumentException("Invalid size for T. Must be 3 floats (12 bytes)");
                }

                DrawTransform((IntPtr)Interop.Fixed(vertices), vertices.Length, ref transform, color);
            }
        }
Пример #10
0
        public static void Init(Device device)
        {
            FontDescription desc;

            desc.CharacterSet    = FontCharacterSet.GB2312;
            desc.FaceName        = "";
            desc.Height          = height;
            desc.Width           = width;
            desc.Italic          = false;
            desc.MipLevels       = 1;
            desc.OutputPrecision = FontPrecision.Default;
            desc.PitchAndFamily  = FontPitchAndFamily.Default;
            desc.Quality         = FontQuality.Default;
            desc.Weight          = FontWeight.Light;

            font             = new Font(device, desc);
            DefaultFontColor = SharpDX.Color.White;
        }
Пример #11
0
        /// <summary>
        /// <p>Adds a sprite to the list of batched sprites.</p>
        /// </summary>
        /// <param name="textureRef"><dd>  <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Texture"/></strong> interface that represents the sprite texture.</p> </dd></param>
        /// <param name="srcRectRef"><dd>  <p>Pointer to a <strong><see cref="RawRectangle"/></strong> structure that indicates the portion of the source texture to use for the sprite. If this parameter is <strong><c>null</c></strong>, then the entire source image is used for the sprite.</p> </dd></param>
        /// <param name="centerRef"><dd>  <p>Pointer to a <strong><see cref="RawVector3"/></strong> vector that identifies the center of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param>
        /// <param name="positionRef"><dd>  <p>Pointer to a <strong><see cref="RawVector3"/></strong> vector that identifies the position of the sprite. If this argument is <strong><c>null</c></strong>, the point (0,0,0) is used, which is the upper-left corner.</p> </dd></param>
        /// <param name="color"><dd>  <p> <strong><see cref="RawColor4"/></strong> type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the <strong>D3DCOLOR_RGBA</strong> macro to help generate this color.</p> </dd></param>
        /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</p></returns>
        /// <remarks>
        /// <p>To scale, rotate, or translate a sprite, call <strong><see cref="SharpDX.Direct3D9.Sprite.SetTransform"/></strong> with a matrix that contains the scale, rotate, and translate (SRT) values, before calling <see cref="SharpDX.Direct3D9.Sprite.Draw"/>. For information about setting SRT values in a matrix, see Matrix Transforms.</p>
        /// </remarks>
        /// <msdn-id>bb174251</msdn-id>
        /// <unmanaged>HRESULT ID3DXSprite::Draw([In] IDirect3DTexture9* pTexture,[In] const RECT* pSrcRect,[In] const D3DXVECTOR3* pCenter,[In] const D3DXVECTOR3* pPosition,[In] D3DCOLOR Color)</unmanaged>
        /// <unmanaged-short>ID3DXSprite::Draw</unmanaged-short>
        public unsafe void Draw(SharpDX.Direct3D9.Texture textureRef, RawColorBGRA color, RawRectangle?srcRectRef = null, RawVector3?centerRef = null, RawVector3?positionRef = null)
        {
            RawRectangle localRect = default(RawRectangle);
            RawVector3   localCenter;
            RawVector3   localPosition;

            if (srcRectRef.HasValue)
            {
                localRect = srcRectRef.Value;
            }
            if (centerRef.HasValue)
            {
                localCenter = centerRef.Value;
            }
            if (positionRef.HasValue)
            {
                localPosition = positionRef.Value;
            }
            Draw(textureRef, srcRectRef.HasValue ? (IntPtr)(void *)&localRect : IntPtr.Zero, centerRef.HasValue ? (IntPtr)(void *)&localCenter : IntPtr.Zero, positionRef.HasValue ? (IntPtr)(void *)&localPosition : IntPtr.Zero, color);
        }
Пример #12
0
        private void DrawProgresBar(int progressSize)
        {
            _progressBarSprite.Begin(SpriteFlags.AlphaBlend);

            var backgroundstream = BackgroundImage.ToStream(ImageFormat.Bmp);
            var foregroundstream = ForegroundImage.ToStream(ImageFormat.Bmp);

            var backgroundTexture = Texture.FromStream(Device, backgroundstream, 100, 16, 0,
                                                       Usage.None,
                                                       Format.A8B8G8R8, Pool.Default, Filter.Default, Filter.Default, 0);

            var foregroundTexture = Texture.FromStream(Device, foregroundstream,
                                                       progressSize, 16, 0,
                                                       Usage.None,
                                                       Format.A8B8G8R8, Pool.Default, Filter.Default, Filter.Default, 0);

            var color = new RawColorBGRA()
            {
                R = 255, A = 255, B = 255, G = 255
            };
            var pos = new RawVector3
            {
                X = 5, Y = 5, Z = 0
            };

            _progressBarSprite.Draw(backgroundTexture, color, null, null, pos);

            if (progressSize > 0)
            {
                _progressBarSprite.Draw(foregroundTexture, color, null, null, pos);
            }

            _progressBarSprite.End();
            backgroundstream.Dispose();
            foregroundstream.Dispose();
            backgroundTexture.Dispose();
            foregroundTexture.Dispose();
        }
Пример #13
0
        public void DrawTexture(string textureKey, RectangleF rect, float rotation = 0, float opacity = 1)
        {
            var textureEntry = this.textureManager.GetTexture(textureKey);

            this.sprite.Begin(SpriteFlags.AlphaBlend);

            byte alpha = 255;

            if (opacity < 1)
            {
                alpha = (byte)(alpha * Math.Max(opacity, 0));
            }

            var color   = new RawColorBGRA(255, 255, 255, alpha);
            var matrix  = this.sprite.Transform;
            var scaling = new Vector2(rect.Width / textureEntry.Bitmap.Width, rect.Height / textureEntry.Bitmap.Height);

            if (rotation == 0.0f)
            {
                this.sprite.Transform = Matrix.Scaling(scaling.X, scaling.Y, 0) * Matrix.Translation(rect.X, rect.Y, 0);
                this.sprite.Draw(textureEntry.Texture, color);
            }
            else
            {
                var center = textureEntry.Center.ToVector3();
                this.sprite.Transform = Matrix.Translation(-center)
                                        * Matrix.RotationZ(rotation)
                                        * Matrix.Translation(center)
                                        * Matrix.Scaling(scaling.X, scaling.Y, 0)
                                        * Matrix.Translation(rect.X, rect.Y, 0);
                this.sprite.Draw(textureEntry.Texture, color);
            }

            this.sprite.Transform = matrix;
            this.sprite.End();
        }
Пример #14
0
        public static void DrawRectangle(this Device device, RawPoint pt, Size2 size, RawColorBGRA color)
        {
            var rect = new RawRectangle
            {
                Left   = pt.X,
                Top    = pt.Y,
                Right  = pt.X + size.Width,
                Bottom = pt.Y + size.Height
            };

            device.Clear(ClearFlags.Target, color, 0, 0, new[] { rect });

            //using (var line = new Line(device))
            //{
            //    line.Width = size.Height;
            //    //line.Antialias = true;
            //    var extraHeight = (float)size.Width / 2;
            //    var vertices = new[]
            //    {
            //        new RawVector2(pt.X, pt.Y + extraHeight),
            //        new RawVector2(pt.X + size.Width, pt.Y + extraHeight)
            //    };
            //    line.Draw(vertices, color);
            //}
        }
Пример #15
0
        public static void DrawText(this Device device, string text, int fontSize, RawPoint pt, RawColorBGRA color)
        {
            if (text.Length == 0)
            {
                text = "ERROR: EMPTY STRING GIVEN";
            }
            var fontWidth  = device.Viewport.Width * fontSize / 1250;
            var fontHeight = Convert.ToInt32(fontWidth * 1.7);

            using (
                var font = new Font(device,
                                    new FontDescription
            {
                FaceName = "Arial",
                OutputPrecision = FontPrecision.TrueTypeOnly,
                Quality = FontQuality.Antialiased,
                Width = fontWidth,
                Height = fontHeight
            }))
            {
                font.DrawText(null, text, pt.X, pt.Y, color);
            }
        }
Пример #16
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="RawRectangle"/> 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>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </item></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></item> </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></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </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></item> </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></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </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="RawColor4"/>.</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, RawRectangle rect, FontDrawFlags drawFlags, RawColorBGRA color)
        {
            int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int)drawFlags, color);

            if (value == 0)
            {
                throw new SharpDXException("Draw failed");
            }
            return(value);
        }
Пример #17
0
 /// <summary>
 /// Draws formatted text.
 /// </summary>
 /// <param name="sprite">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.</param>
 /// <param name="text">Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</param>
 /// <param name="x">The x position to draw the text.</param>
 /// <param name="y">The y position to draw the text.</param>
 /// <param name="color">Color of the text. For more information, see <see cref="RawColor4"/>.</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>
 /// <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>
 /// <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>
 public int DrawText(Sprite sprite, string text, int x, int y, RawColorBGRA color)
 {
     return(DrawText(sprite, text, new RawRectangle(x, y, 0, 0), FontDrawFlags.NoClip, color));
 }
Пример #18
0
        /// <summary>
        /// Sets up the individual Direct3D Contstants and objects used for rendering.
        /// </summary>
        /// <param name="device"></param>
        private static unsafe void SetupRenderingConstants(Device device)
        {
            // Create our individual devices and fonts if necessary.
            // (Normally you would do this on initialization, not in the render function but this is just for clarity).
            if (!_initialized)
            {
                // Let's create a line for us to draw later.
                _sampleLine   = new Line(device);
                _lineVertices = new[]
                {
                    new RawVector2(100, 300),
                    new RawVector2(150, 200),
                    new RawVector2(250, 200)
                };

                // Create a font for us to draw later (SharpDX D3D9 Font)
                _sampleFont = new Font(device, 20, 0, FontWeight.Normal, 1, false, FontCharacterSet.Ansi,
                                       FontPrecision.Default, FontQuality.ClearType, FontPitchAndFamily.Modern, "Times New Roman");

                // Set position of text and colour of line + text.
                _semiTransparentGray = new RawColorBGRA(255, 255, 255, 128);
                _textRectangle       = new RawRectangle(100, 100, 9999, 9999);

                // Create triangle vertices.
                // Fun fact: W acts as the blend factor here.
                _triangleVertices = new[] {
                    new Vertex()
                    {
                        Color = Color.Red, Position = new Vector4(400.0f, 100.0f, 0.5f, 1.0f)
                    },
                    new Vertex()
                    {
                        Color = Color.Blue, Position = new Vector4(650.0f, 500.0f, 0.5f, 1.0f)
                    },
                    new Vertex()
                    {
                        Color = Color.Green, Position = new Vector4(150.0f, 500.0f, 0.5f, 1.0f)
                    }
                };

                // Set vertex render mode for our vertices.
                _vertexRenderingModes = new[]
                { VertexRenderingMode.RedToGreen, VertexRenderingMode.BlueToRed, VertexRenderingMode.GreenToBlue };

                // Create vertex buffer.
                _localVertexBuffer = new VertexBuffer(device, sizeof(Vertex) * 3, 0, VertexFormat.None, Pool.Default);
                _localVertexBuffer.Lock(0, 0, LockFlags.None).WriteRange(_triangleVertices);
                _localVertexBuffer.Unlock();

                // Specifies the Vertex Format
                var vertexElems = new[] { new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.PositionTransformed, 0),
                                          new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
                                          VertexElement.VertexDeclarationEnd };
                _vertexDeclaration = new VertexDeclaration(device, vertexElems);

                // Wrap SetPixelShader for us to call later (otherwise our shape may not show)
                // This uses Reloaded's Virtual Function Table Utility Class
                if (_directX9Overlay != null)
                {
                    VirtualFunctionTable.TableEntry vTableEntry = _directX9Overlay.DirectX9Hook.DirectXFunctions[(int)Direct3DDevice9.SetPixelShader];
                    _setPixelShaderFunction = vTableEntry.CreateWrapperFunction <SetPixelShaderDelegate>();
                }

                // Never run this again.
                _initialized = true;
            }
        }
Пример #19
0
 /// <summary>
 /// Mark an instantaneous event. PIX can use this event to trigger an action.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="name">The name to format.</param>
 /// <param name="parameters">The parameters to use to format the name.</param>
 /// <unmanaged>D3DPERF_SetMarker</unmanaged>
 public static void SetMarker(RawColorBGRA color, string name, params object[] parameters)
 {
     D3DPERF_SetMarker(color, string.Format(name, parameters));
 }
Пример #20
0
 /// <summary>
 /// Marks the beginning of a user-defined event. PIX can use this event to trigger an action.
 /// </summary>
 /// <param name="color">The Event color.</param>
 /// <param name="name">The Event formatted Name.</param>
 /// <param name="parameters">The parameters to use for the formatted name.</param>
 /// <returns>
 /// The zero-based level of the hierarchy that this event is starting in. If an error occurs, the return value will be negative.
 /// </returns>
 /// <unmanaged>D3DPERF_BeginEvent</unmanaged>
 public static int BeginEvent(RawColorBGRA color, string name, params object[] parameters)
 {
     return(D3DPERF_BeginEvent(color, string.Format(name, parameters)));
 }
Пример #21
0
 /// <summary>
 /// Marks the beginning of a user-defined event. PIX can use this event to trigger an action.
 /// </summary>
 /// <param name="color">The Event color.</param>
 /// <param name="name">The Event Name.</param>
 /// <returns>The zero-based level of the hierarchy that this event is starting in. If an error occurs, the return value will be negative.</returns>
 /// <unmanaged>D3DPERF_BeginEvent</unmanaged>
 public static int BeginEvent(RawColorBGRA color, string name)
 {
     return(D3DPERF_BeginEvent(color, name));
 }
Пример #22
0
 private extern static void D3DPERF_SetMarker(RawColorBGRA color, string wszName);
Пример #23
0
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Сериализация цветового значения в строку
 /// </summary>
 /// <param name="color">Цветовое значение</param>
 /// <returns>Строка</returns>
 //---------------------------------------------------------------------------------------------------------
 public static String Serialize(this RawColorBGRA color)
 {
     return(String.Format("{0},{1},{2},{3}", color.R, color.G, color.B, color.A));
 }
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Чтение данных цветового значения из формата атрибутов
            /// </summary>
            /// <param name="xml_reader">Средство чтения данных формата XML</param>
            /// <param name="name">Имя атрибута</param>
            /// <param name="default_value">Значение по умолчанию в случает отсутствия атрибута</param>
            /// <returns>Цветовое значение</returns>
            //---------------------------------------------------------------------------------------------------------
            public static RawColorBGRA ReadDXColorBGRAFromAttribute(this XmlReader xml_reader, String name, RawColorBGRA default_value)
            {
                String value;

                if ((value = xml_reader.GetAttribute(name)) != null)
                {
                    return(XRawColorBGRA.Deserialize(value));
                }
                return(default_value);
            }
Пример #25
0
 /// <summary>
 /// <p>Adds a sprite to the list of batched sprites.</p>
 /// </summary>
 /// <param name="textureRef"><dd>  <p>Pointer to an <strong><see cref="SharpDX.Direct3D9.Texture"/></strong> interface that represents the sprite texture.</p> </dd></param>
 /// <param name="color"><dd>  <p> <strong><see cref="RawColor4"/></strong> type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the <strong>D3DCOLOR_RGBA</strong> macro to help generate this color.</p> </dd></param>
 /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Result.Ok"/>. If the method fails, the return value can be one of the following: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</p></returns>
 /// <remarks>
 /// <p>To scale, rotate, or translate a sprite, call <strong><see cref="SharpDX.Direct3D9.Sprite.SetTransform"/></strong> with a matrix that contains the scale, rotate, and translate (SRT) values, before calling <see cref="SharpDX.Direct3D9.Sprite.Draw"/>. For information about setting SRT values in a matrix, see Matrix Transforms.</p>
 /// </remarks>
 /// <msdn-id>bb174251</msdn-id>
 /// <unmanaged>HRESULT ID3DXSprite::Draw([In] IDirect3DTexture9* pTexture,[In] const RECT* pSrcRect,[In] const D3DXVECTOR3* pCenter,[In] const D3DXVECTOR3* pPosition,[In] D3DCOLOR Color)</unmanaged>
 /// <unmanaged-short>ID3DXSprite::Draw</unmanaged-short>
 public void Draw(SharpDX.Direct3D9.Texture textureRef, RawColorBGRA color)
 {
     Draw(textureRef, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, color);
 }
Пример #26
0
 /// <summary>
 /// Mark an instantaneous event. PIX can use this event to trigger an action.
 /// </summary>
 /// <param name="color">The color.</param>
 /// <param name="name">The name.</param>
 /// <unmanaged>D3DPERF_SetMarker</unmanaged>
 public static void SetMarker(RawColorBGRA color, string name)
 {
     D3DPERF_SetMarker(color, name);
 }
Пример #27
0
 public static void DrawText(string text, int row, int column, RawColorBGRA color)
 {
     font.DrawText(null, text, column * width, row * height, color);
 }
Пример #28
0
        /// <summary>
        /// Loads a volume from memory.
        /// </summary>
        /// <param name="destPaletteRef"><para>Pointer to a  <see cref="SharpDX.Direct3D9.PaletteEntry"/> structure, the destination palette of 256 colors or <c>null</c>.</para></param>
        /// <param name="destBox"><para>Pointer to a <see cref="SharpDX.Direct3D9.Box"/> structure. Specifies the destination box. Set this parameter to <c>null</c> to specify the entire volume.</para></param>
        /// <param name="srcMemoryPointer"><para>Pointer to the top-left corner of the source volume in memory.</para></param>
        /// <param name="srcFormat"><para>Member of the <see cref="SharpDX.Direct3D9.Format"/> enumerated type, the pixel format of the source volume.</para></param>
        /// <param name="srcRowPitch"><para>Pitch of source image, in bytes. For DXT formats (compressed texture formats), this number should represent the size of one row of cells, in bytes.</para></param>
        /// <param name="srcSlicePitch"><para>Pitch of source image, in bytes. For DXT formats (compressed texture formats), this number should represent the size of one slice of cells, in bytes.</para></param>
        /// <param name="srcPaletteRef"><para>Pointer to a <see cref="SharpDX.Direct3D9.PaletteEntry"/> structure, the source palette of 256 colors or <c>null</c>.</para></param>
        /// <param name="srcBox"><para>Pointer to a <see cref="SharpDX.Direct3D9.Box"/> structure. Specifies the source box. <c>null</c> is not a valid value for this parameter.</para></param>
        /// <param name="filter"><para>A combination of one or more <see cref="SharpDX.Direct3D9.Filter"/> controlling how the image is filtered. Specifying D3DX_DEFAULT for this parameter is the equivalent of specifying <see cref="SharpDX.Direct3D9.Filter.Triangle"/> | <see cref="SharpDX.Direct3D9.Filter.Dither"/>.</para></param>
        /// <param name="colorKey"><para> <see cref="RawColor4"/> value to replace with transparent black, or 0 to disable the color key. This is always a 32-bit ARGB color, independent of the source image format. Alpha is significant and should usually be set to FF for opaque color keys. Thus, for opaque black, the value would be equal to 0xFF000000.</para></param>
        /// <returns>If the function succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the function fails, the return value can be one of the following values: <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>, D3DXERR_INVALIDDATA.</returns>
        /// <remarks>
        /// Writing to a non-level-zero surface of the volume texture will not cause the dirty rectangle to be updated. If <see cref="SharpDX.Direct3D9.D3DX9.LoadVolumeFromMemory"/> is called and the texture was not already dirty (this is unlikely under normal usage scenarios), the application needs to explicitly call <see cref="SharpDX.Direct3D9.VolumeTexture.AddDirtyBox"/> on the volume texture.
        /// </remarks>
        /// <unmanaged>HRESULT D3DXLoadVolumeFromMemory([In] IDirect3DVolume9* pDestVolume,[Out, Buffer] const PALETTEENTRY* pDestPalette,[In] const void* pDestBox,[In] const void* pSrcMemory,[In] D3DFORMAT SrcFormat,[In] unsigned int SrcRowPitch,[In] unsigned int SrcSlicePitch,[In, Buffer] const PALETTEENTRY* pSrcPalette,[In] const void* pSrcBox,[In] D3DX_FILTER Filter,[In] int ColorKey)</unmanaged>
        public unsafe void LoadFromMemory(SharpDX.Direct3D9.PaletteEntry[] destPaletteRef, Box?destBox, System.IntPtr srcMemoryPointer, SharpDX.Direct3D9.Format srcFormat, int srcRowPitch, int srcSlicePitch, SharpDX.Direct3D9.PaletteEntry[] srcPaletteRef, Box srcBox, SharpDX.Direct3D9.Filter filter, RawColorBGRA colorKey)
        {
            Box localDestBox;

            if (destBox.HasValue)
            {
                localDestBox = destBox.Value;
            }

            D3DX9.LoadVolumeFromMemory(
                this, destPaletteRef, new IntPtr(&localDestBox), srcMemoryPointer, srcFormat, srcRowPitch, srcSlicePitch, srcPaletteRef, new IntPtr(&srcBox), filter, *(int *)&colorKey);
        }
 //---------------------------------------------------------------------------------------------------------
 /// <summary>
 /// Запись значение цвета в формат атрибутов
 /// </summary>
 /// <param name="xml_writer">Средство записи данных в формат XML</param>
 /// <param name="name">Имя атрибута</param>
 /// <param name="color">Цвет</param>
 //---------------------------------------------------------------------------------------------------------
 public static void WriteColorToAttribute(this XmlWriter xml_writer, String name, RawColorBGRA color)
 {
     xml_writer.WriteStartAttribute(name);
     xml_writer.WriteValue(color.Serialize());
     xml_writer.WriteEndAttribute();
 }
Пример #30
0
 private extern static int D3DPERF_BeginEvent(RawColorBGRA color, string name);