Terrarium.Renderer.DirectX.DirectDrawSpriteSurface.GrabSprite C# (CSharp) Method

GrabSprite() public method

Retreive a sprite that has to be drawn within the given destination rectangle, given the bounds of the viewport.
public GrabSprite ( int xFrame, int yFrame, Rectangle dest, Rectangle bounds ) : DirectDrawClippedRect
xFrame int Retrieve the Xth horizontal frame.
yFrame int Retrieve the Yth vertical frame.
dest System.Drawing.Rectangle The destination rectangle for the sprite.
bounds System.Drawing.Rectangle The view rectangle bounds.
return DirectDrawClippedRect
        public DirectDrawClippedRect GrabSprite(int xFrame, int yFrame, Rectangle dest, Rectangle bounds)
        {
            #if TRACE
            GraphicsEngine.Profiler.Start("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT)");
            #endif
            if (xFrame < 0 || xFrame >= animationFrames ||
                yFrame < 0 || yFrame >= animationTypes)
            {
                throw new Exception("Sprite request is out of range");
            }

            var spriteRect = new RECT();
            spriteRect.Top = yFrame * frameHeight;
            spriteRect.Bottom = spriteRect.Top;
            spriteRect.Bottom += frameHeight;

            spriteRect.Left = xFrame * frameWidth;
            spriteRect.Right = spriteRect.Left;
            spriteRect.Right += frameWidth;

            var ddClipRect = new DirectDrawClippedRect();
            ddClipRect.Destination = dest;
            ddClipRect.Source = Rectangle.FromLTRB(spriteRect.Left, spriteRect.Top, spriteRect.Right, spriteRect.Bottom);

            if (dest.Left >= bounds.Right || dest.Right <= bounds.Left || dest.Top >= bounds.Bottom ||
                dest.Bottom <= bounds.Top)
            {
                ddClipRect.Invisible = true;
            #if TRACE
                GraphicsEngine.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT)");
            #endif
                return ddClipRect;
            }

            ddClipRect.ClipRectBounds(dest, bounds);
            #if TRACE
            GraphicsEngine.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT)");
            #endif
            return ddClipRect;
        }

Same methods

DirectDrawSpriteSurface::GrabSprite ( int xFrame, int yFrame, Rectangle dest, Rectangle bounds, int factor ) : DirectDrawClippedRect
DirectDrawSpriteSurface::GrabSprite ( int xFrame, int yFrame ) : RECT