Example #1
0
        public void DrawImage(Object image, System.Drawing.RectangleF srcRect, System.Drawing.RectangleF destRect)
        {
            if (image is SharpDX.Direct2D1.Bitmap)
            {
                SharpDX.Direct2D1.Bitmap bImg = (SharpDX.Direct2D1.Bitmap)image;
                if (!bImg.IsDisposed)
                {
                    SharpDX.Mathematics.Interop.RawRectangleF src = new SharpDX.Mathematics.Interop.RawRectangleF
                    {
                        Top    = srcRect.Top,
                        Left   = srcRect.Left,
                        Bottom = srcRect.Bottom,
                        Right  = srcRect.Width
                    };

                    SharpDX.Mathematics.Interop.RawRectangleF dest = new SharpDX.Mathematics.Interop.RawRectangleF
                    {
                        Top    = destRect.Top,
                        Left   = destRect.Left,
                        Bottom = destRect.Bottom,
                        Right  = destRect.Right
                    };

                    d2dRenderTarget.DrawBitmap(bImg, dest, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear, src);
                }        // Endif image is not disposed
            }            // Endif image is DirectX Bitmap
        }
Example #2
0
        public override void Draw(SharpDX.Direct2D1.RenderTarget target)
        {
            if (this.spriteAnimation.CurrentFrame == null)
            {
                return;
            }
            var b = Tile.Bounds;

            target.DrawBitmap(this.spriteAnimation.CurrentFrame, new SharpDX.Mathematics.Interop.RawRectangleF(b.Left, b.Top, b.Right, b.Bottom), 1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
        }
Example #3
0
        private void DrawTexture(SharpDX.Direct2D1.RenderTarget renderTarget, Texture2D texture)
        {
            using (var surf = texture.QueryInterface <SharpDX.DXGI.Surface1>())
            {
                var prop = new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied));
                SharpDX.Direct2D1.Bitmap screenBits = new SharpDX.Direct2D1.Bitmap(renderTarget, surf, prop);
                try
                {
                    var   srcDecr   = surf.Description;
                    float srcWidth  = srcDecr.Width;
                    float srcHeight = srcDecr.Height;

                    float destX      = 0;
                    float destY      = 0;
                    float destWidth  = DestSize.Width;
                    float destHeight = DestSize.Height;

                    float scaleX = destWidth / srcWidth;
                    float scaleY = destHeight / srcHeight;

                    if (AspectRatio)
                    {
                        if (scaleY < scaleX)
                        {
                            scaleX = scaleY;
                            destX  = ((destWidth - srcWidth * scaleX) / 2);
                        }
                        else
                        {
                            scaleY = scaleX;
                            destY  = ((destHeight - srcHeight * scaleY) / 2);
                        }
                    }

                    destWidth  = srcWidth * scaleX;
                    destHeight = srcHeight * scaleY;

                    var destRect = new SharpDX.Mathematics.Interop.RawRectangleF
                    {
                        Left   = destX,
                        Right  = destX + destWidth,
                        Top    = destY,
                        Bottom = destY + destHeight,
                    };

                    renderTarget.DrawBitmap(screenBits, destRect, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                }
                finally
                {
                    screenBits?.Dispose();
                }
            }
        }
Example #4
0
        public override void Draw(SharpDX.Direct2D1.RenderTarget target)
        {
            var b = LocationResolver.Bounds;

            target.DrawBitmap(loader.Bitmap, new SharpDX.Mathematics.Interop.RawRectangleF(b.Left, b.Top, b.Right, b.Bottom), 1, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
        }