/// <summary> /// Retreive a sprite that has to be drawn within the given destination /// rectangle, given the bounds of the viewport. Also contains a scaling /// factor. /// </summary> /// <param name="xFrame">Retrieve the Xth horizontal frame.</param> /// <param name="yFrame">Retrieve the Yth vertical frame.</param> /// <param name="dest">The destination rectangle for the sprite.</param> /// <param name="bounds">The view rectangle bounds.</param> /// <param name="factor">A scaling factor.</param> /// <returns></returns> public DirectDrawClippedRect GrabSprite(int xFrame, int yFrame, Rectangle dest, Rectangle bounds, int factor) { #if TRACE GraphicsEngine.Profiler.Start("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif if (xFrame < 0 || xFrame >= animationFrames || yFrame < 0 || yFrame >= animationTypes) { throw new Exception("Sprite request is out of range"); } var spriteRect = new Rectangle(xFrame, yFrame, frameWidth, frameHeight); var ddClipRect = new DirectDrawClippedRect(); ddClipRect.Destination = dest; ddClipRect.Source = spriteRect; 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, int)"); #endif return(ddClipRect); } ddClipRect.ClipRectBounds(dest, bounds, factor); #if TRACE GraphicsEngine.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return(ddClipRect); }
/// <summary> /// Retreive a sprite that has to be drawn within the given destination /// rectangle, given the bounds of the viewport. Also contains a scaling /// factor. /// </summary> /// <param name="xFrame">Retrieve the Xth horizontal frame.</param> /// <param name="yFrame">Retrieve the Yth vertical frame.</param> /// <param name="dest">The destination rectangle for the sprite.</param> /// <param name="bounds">The view rectangle bounds.</param> /// <param name="factor">A scaling factor.</param> /// <returns></returns> public DirectDrawClippedRect GrabSprite(int xFrame, int yFrame, RECT dest, RECT bounds, int factor) { #if TRACE ManagedDirectX.Profiler.Start("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif if (xFrame < 0 || xFrame >= animationFrames || yFrame < 0 || yFrame >= animationTypes) { throw new Exception("Sprite request is out of range"); } RECT 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; DirectDrawClippedRect ddClipRect= new DirectDrawClippedRect(); ddClipRect.Destination = dest; ddClipRect.Source = spriteRect; if (dest.Left >= bounds.Right || dest.Right <= bounds.Left || dest.Top >= bounds.Bottom || dest.Bottom <= bounds.Top) { ddClipRect.Invisible = true; #if TRACE ManagedDirectX.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return ddClipRect; } if (dest.Left < bounds.Left) { ddClipRect.Source.Left += (bounds.Left - dest.Left) << factor; ddClipRect.Destination.Left = bounds.Left; ddClipRect.ClipLeft = true; } if (dest.Top < bounds.Top) { ddClipRect.Source.Top += (bounds.Top - dest.Top) << factor; ddClipRect.Destination.Top = bounds.Top; ddClipRect.ClipTop = true; } if (dest.Right > bounds.Right) { ddClipRect.Source.Right -= (dest.Right - bounds.Right) << factor; ddClipRect.Destination.Right = bounds.Right; ddClipRect.ClipRight = true; } if (dest.Bottom > bounds.Bottom) { ddClipRect.Source.Bottom += (bounds.Bottom - dest.Bottom) << factor; ddClipRect.Destination.Bottom = bounds.Bottom; ddClipRect.ClipBottom = true; } #if TRACE ManagedDirectX.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return ddClipRect; }
/// <summary> /// Retreive a sprite that has to be drawn within the given destination /// rectangle, given the bounds of the viewport. Also contains a scaling /// factor. /// </summary> /// <param name="xFrame">Retrieve the Xth horizontal frame.</param> /// <param name="yFrame">Retrieve the Yth vertical frame.</param> /// <param name="dest">The destination rectangle for the sprite.</param> /// <param name="bounds">The view rectangle bounds.</param> /// <param name="factor">A scaling factor.</param> /// <returns></returns> public DirectDrawClippedRect GrabSprite(int xFrame, int yFrame, Rectangle dest, Rectangle bounds, int factor) { #if TRACE GraphicsEngine.Profiler.Start("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif if (xFrame < 0 || xFrame >= animationFrames || yFrame < 0 || yFrame >= animationTypes) { throw new Exception("Sprite request is out of range"); } var spriteRect = new Rectangle(xFrame, yFrame, frameWidth, frameHeight); var ddClipRect = new DirectDrawClippedRect(); ddClipRect.Destination = dest; ddClipRect.Source = spriteRect; 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, int)"); #endif return ddClipRect; } ddClipRect.ClipRectBounds(dest, bounds, factor); #if TRACE GraphicsEngine.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return ddClipRect; }
/// <summary> /// Retreive a sprite that has to be drawn within the given destination /// rectangle, given the bounds of the viewport. Also contains a scaling /// factor. /// </summary> /// <param name="xFrame">Retrieve the Xth horizontal frame.</param> /// <param name="yFrame">Retrieve the Yth vertical frame.</param> /// <param name="dest">The destination rectangle for the sprite.</param> /// <param name="bounds">The view rectangle bounds.</param> /// <param name="factor">A scaling factor.</param> /// <returns></returns> public DirectDrawClippedRect GrabSprite(int xFrame, int yFrame, RECT dest, RECT bounds, int factor) { #if TRACE ManagedDirectX.Profiler.Start("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #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 = spriteRect; if (dest.Left >= bounds.Right || dest.Right <= bounds.Left || dest.Top >= bounds.Bottom || dest.Bottom <= bounds.Top) { ddClipRect.Invisible = true; #if TRACE ManagedDirectX.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return(ddClipRect); } if (dest.Left < bounds.Left) { ddClipRect.Source.Left += (bounds.Left - dest.Left) << factor; ddClipRect.Destination.Left = bounds.Left; ddClipRect.ClipLeft = true; } if (dest.Top < bounds.Top) { ddClipRect.Source.Top += (bounds.Top - dest.Top) << factor; ddClipRect.Destination.Top = bounds.Top; ddClipRect.ClipTop = true; } if (dest.Right > bounds.Right) { ddClipRect.Source.Right -= (dest.Right - bounds.Right) << factor; ddClipRect.Destination.Right = bounds.Right; ddClipRect.ClipRight = true; } if (dest.Bottom > bounds.Bottom) { ddClipRect.Source.Bottom += (bounds.Bottom - dest.Bottom) << factor; ddClipRect.Destination.Bottom = bounds.Bottom; ddClipRect.ClipBottom = true; } #if TRACE ManagedDirectX.Profiler.End("DirectDrawSpriteSurface.GrabSprite(int, int, RECT, RECT, int)"); #endif return(ddClipRect); }