Esempio n. 1
0
 public Texture(IDevice device, System.Drawing.Bitmap image)
 {
     this.device = (Device)device;
     System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
     texture = SharpDX.Direct3D9.Texture.FromMemory(((Device)device).device, (byte[])converter.ConvertTo(image, typeof(byte[])),
                                                    (int)(image.Width), (int)(image.Height), 1, SharpDX.Direct3D9.Usage.None, SharpDX.Direct3D9.Format.A8R8G8B8, SharpDX.Direct3D9.Pool.Default, SharpDX.Direct3D9.Filter.Linear, SharpDX.Direct3D9.Filter.Linear, 0);
     imageSize = image.Size;
     sprite    = new SharpDX.Direct3D9.Sprite(this.device.device);
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public Polygon(IDrawing.IDevice device)
 {
     this.device          = (Device)device;
     line                 = new SharpDX.Direct3D9.Line(this.device.device);
     line.Width           = lineWidth;
     line.Antialias       = true;
     fillerLine           = new SharpDX.Direct3D9.Line(this.device.device);
     fillerLine.Width     = lineWidth;
     fillerLine.Antialias = true;
     sprite               = new SharpDX.Direct3D9.Sprite(this.device.device);
     tex = new SharpDX.Direct3D9.Texture(this.device.device, this.device.size.Width, this.device.size.Height, 1, SharpDX.Direct3D9.Usage.RenderTarget, SharpDX.Direct3D9.Format.A8R8G8B8, SharpDX.Direct3D9.Pool.Default);
 }
Esempio n. 4
0
 /// <summary>
 /// Initialize the device on the control.
 /// </summary>
 /// <param name="control"></param>
 public void Initialize(Control control)
 {
     padding = control.Padding;
     size    = control.Size;
     //! Dispose the layers.
     for (int i = 0; i < layers.Count; i++)
     {
         if (layers[i] != null)
         {
             layers[i].Dispose();
         }
     }
     //! Dispose the sprite.
     if (sprite != null)
     {
         sprite.Dispose();
         sprite = null;
     }
     //! Dispose the main surface.
     if (mainSurface != null)
     {
         mainSurface.Dispose();
         mainSurface = null;
     }
     System.GC.Collect();
     //! if device isn't null then reset the device size.
     if (device != null)
     {
         device.Reset(new SharpDX.Direct3D9.PresentParameters(control.ClientSize.Width, control.ClientSize.Height));
     }
     else
     {
         //! create a new device.
         device = new SharpDX.Direct3D9.Device(new SharpDX.Direct3D9.Direct3D(), 0, SharpDX.Direct3D9.DeviceType.Hardware, control.Handle,
                                               SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing, new SharpDX.Direct3D9.PresentParameters(control.ClientSize.Width, control.ClientSize.Height));
     }
     //! create a new sprite.
     sprite = new SharpDX.Direct3D9.Sprite(device);
     //! Create layers.
     for (int i = 0; i < layers.Count; i++)
     {
         layers[i] = new Layer(new SharpDX.Direct3D9.Texture(device, size.Width, size.Height, 1, SharpDX.Direct3D9.Usage.RenderTarget, SharpDX.Direct3D9.Format.A8R8G8B8, SharpDX.Direct3D9.Pool.Default));
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Dispose the polygon
 /// </summary>
 public void Dispose()
 {
     if (line != null)
     {
         line.Dispose();
         line = null;
     }
     if (fillerLine != null)
     {
         fillerLine.Dispose();
         fillerLine = null;
     }
     if (sprite != null)
     {
         sprite.Dispose();
         sprite = null;
     }
     if (tex != null)
     {
         tex.Dispose();
         tex = null;
     }
 }
Esempio n. 6
0
 internal SpriteBatch(GraphicsDevice device)
 {
     sprite = new SharpDX.Direct3D9.Sprite(device.Device);
     sprite.Begin(SharpDX.Direct3D9.SpriteFlags.AlphaBlend);
 }