Class PropagatedSpriteBatch
Definition
Namespace: StardewUI.Graphics
Assembly: StardewUI.dll
Sprite batch wrapper with transform propagation.
Inheritance
Object ⇦ PropagatedSpriteBatch
Implements
ISpriteBatch, IDisposable
Members
Constructors
Name | Description |
---|---|
PropagatedSpriteBatch(SpriteBatch, GlobalTransform, RenderTargetPool) | Sprite batch wrapper with transform propagation. |
PropagatedSpriteBatch(SpriteBatch, Transform) | Initializes a new PropagatedSpriteBatch using a local transform interpreted as global. |
Methods
Details
Constructors
PropagatedSpriteBatch(SpriteBatch, GlobalTransform, RenderTargetPool)
Sprite batch wrapper with transform propagation.
public PropagatedSpriteBatch(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, StardewUI.Graphics.GlobalTransform transform, StardewUI.Graphics.RenderTargetPool renderTargetPool);
Parameters
spriteBatch
SpriteBatch
The XNA/MonoGame sprite batch.
transform
GlobalTransform
Transformation to apply.
renderTargetPool
RenderTargetPool
Shared pool of RenderTarget2D instances to use for creating internal targets, such as those used for transformed clipping regions. The batch does not take ownership of the pool, nor do any targets explicitly provided (e.g. via InitializeRenderTarget(RenderTarget2D, Int32, Int32) or SetRenderTarget(RenderTarget2D, Color?)) get automatically pooled.
PropagatedSpriteBatch(SpriteBatch, Transform)
Initializes a new PropagatedSpriteBatch using a local transform interpreted as global.
public PropagatedSpriteBatch(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, StardewUI.Graphics.Transform transform);
Parameters
spriteBatch
SpriteBatch
The XNA/MonoGame sprite batch.
transform
Transform
Transformation to apply.
Remarks
Provided for legacy compatibility; assumes that the local transform is the outermost transform and converts it directly to a global transform.
Methods
Blend(BlendState)
Sets up subsequent draw calls to use the designated blending settings.
Parameters
blendState
BlendState
Blend state determining the color/alpha blend behavior.
Returns
A disposable instance which, when disposed, will revert to the previous blending state.
Clip(Rectangle)
Sets up subsequent draw calls to clip contents within the specified bounds.
Parameters
clipRect
Rectangle
The clipping bounds in local coordinates.
Returns
A disposable instance which, when disposed, will revert to the previous clipping state.
DelegateDraw(Action<SpriteBatch, Vector2>)
Draws using a delegate action on a concrete SpriteBatch.
public void DelegateDraw(Action<Microsoft.Xna.Framework.Graphics.SpriteBatch, Microsoft.Xna.Framework.Vector2> draw);
Parameters
draw
Action<SpriteBatch, Vector2>
A function that accepts an underlying SpriteBatch as well as the transformed (global/screen) position and draws using that position as the origin (top left).
Remarks
Delegation is provided as a fallback for game-specific "utilities" that require a SpriteBatch and are not trivial to reimplement; the method acts as a bridge between the abstract ISpriteBatch and the concrete-dependent logic.
Most view types shouldn't use this; it is only needed for a few niche features like SpriteText.
Dispose()
Draw(Texture2D, Vector2, Rectangle?, Color?, float, float, SpriteEffects, float)
public void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, float scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture
Texture2D
position
Vector2
sourceRectangle
Nullable<Rectangle>
rotation
Single
scale
Single
effects
SpriteEffects
layerDepth
Single
Draw(Texture2D, Vector2, Rectangle?, Color?, float, Vector2?, SpriteEffects, float)
public void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, Microsoft.Xna.Framework.Vector2? scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture
Texture2D
position
Vector2
sourceRectangle
Nullable<Rectangle>
rotation
Single
effects
SpriteEffects
layerDepth
Single
Draw(Texture2D, Rectangle, Rectangle?, Color?, float, SpriteEffects, float)
public void Draw(Microsoft.Xna.Framework.Graphics.Texture2D texture, Microsoft.Xna.Framework.Rectangle destinationRectangle, Microsoft.Xna.Framework.Rectangle? sourceRectangle, Microsoft.Xna.Framework.Color? color, float rotation, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
texture
Texture2D
destinationRectangle
Rectangle
sourceRectangle
Nullable<Rectangle>
rotation
Single
effects
SpriteEffects
layerDepth
Single
DrawString(SpriteFont, string, Vector2, Color, float, float, SpriteEffects, float)
public void DrawString(Microsoft.Xna.Framework.Graphics.SpriteFont spriteFont, string text, Microsoft.Xna.Framework.Vector2 position, Microsoft.Xna.Framework.Color color, float rotation, float scale, Microsoft.Xna.Framework.Graphics.SpriteEffects effects, float layerDepth);
Parameters
spriteFont
SpriteFont
text
string
position
Vector2
color
Color
rotation
Single
scale
Single
effects
SpriteEffects
layerDepth
Single
InitializeRenderTarget(RenderTarget2D, int, int)
Initializes a RenderTarget2D for use with SetRenderTarget(RenderTarget2D, Color?).
public void InitializeRenderTarget(Microsoft.Xna.Framework.Graphics.RenderTarget2D target, int width, int height);
Parameters
target
RenderTarget2D
The previous render target, if any, to reuse if possible.
width
Int32
The target width.
height
Int32
The target height.
Remarks
This will reuse an existing render target if available, i.e. if target
is not null
and matches the specified width
and height
; otherwise it will replace any previous target
and replace it with a new instance.
SaveTransform()
Saves the current transform, so that it can later be restored to its current state.
Returns
A disposable instance which, when disposed, restores the transform of this ISpriteBatch to the same state it was in before SaveTransform
was called.
Remarks
This is typically used in hierarchical layout; i.e. a view with children would apply a transform before handing the canvas or sprite batch down to any of those children, and then restore it after the child is done with it. This enables a single ISpriteBatch instance to be used for the entire layout rather than having to create a tree.
SetRenderTarget(RenderTarget2D, Color?)
Sets up subsequent draw calls to use a custom render target.
public System.IDisposable SetRenderTarget(Microsoft.Xna.Framework.Graphics.RenderTarget2D renderTarget, Microsoft.Xna.Framework.Color? clearColor);
Parameters
renderTarget
RenderTarget2D
The new render target.
clearColor
Nullable<Color>
Color to clear the renderTarget
with after making it active, or null
to skip clearing.
Returns
A disposable instance which, when disposed, will revert to the previous render target(s).
Remarks
This will also reset any active transforms for the new render target, e.g. those resulting from Translate(Vector2). Previously-active transforms will be restored when the render target is reverted by calling Dispose() on the result.
Transform(Transform, TransformOrigin)
Applies an arbitrary transformation to subsequent operations.
public void Transform(StardewUI.Graphics.Transform transform, StardewUI.Graphics.TransformOrigin origin);
Parameters
transform
Transform
The transform properties (scale, rotation and translation).
origin
TransformOrigin
The origin (i.e. center) of the transformation, or null
to use the Default origin.