Added sprite batch settings to maintain sprite batch begin settings and keep consistency and control over settings. Ninepatch uses this.
This commit is contained in:
@@ -59,10 +59,8 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
|
||||
for (int i = 0; i < patches.Length; i++)
|
||||
{
|
||||
patches[i].X += textureRegion.X + 1;
|
||||
patches[i].Y += textureRegion.Y + 1;
|
||||
patches[i].Width -= 2;
|
||||
patches[i].Height -= 2;
|
||||
patches[i].X += textureRegion.X;
|
||||
patches[i].Y += textureRegion.Y;
|
||||
}
|
||||
return patches;
|
||||
}
|
||||
@@ -71,15 +69,15 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
{
|
||||
Rectangle[] patches =
|
||||
{
|
||||
new Rectangle(-left, -bottom, left, bottom),
|
||||
new Rectangle(0, -bottom, width, bottom),
|
||||
new Rectangle(width, -bottom, right, bottom),
|
||||
new Rectangle(-left, 0, left, height),
|
||||
new Rectangle(0, 0, width, height),
|
||||
new Rectangle(width, 0, right, height),
|
||||
new Rectangle(-left, height, left, top),
|
||||
new Rectangle(0, height, width, top),
|
||||
new Rectangle(width, height, right, top),
|
||||
new Rectangle(0, 0, left, bottom),
|
||||
new Rectangle(left, 0, width - left - right, bottom),
|
||||
new Rectangle(width -right, 0, right, bottom),
|
||||
new Rectangle(0, bottom, left, height - bottom - top),
|
||||
new Rectangle(left, bottom, width - left - right, height - top - bottom),
|
||||
new Rectangle(width - right, bottom, right, height - top - bottom),
|
||||
new Rectangle(0, height - top, left, top),
|
||||
new Rectangle(left, height - top, width - left - right, top),
|
||||
new Rectangle(width - right, height - top, right, top),
|
||||
};
|
||||
return patches;
|
||||
}
|
||||
@@ -90,8 +88,19 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <param name="spriteBatch">Batch to use.</param>
|
||||
/// <param name="destination">Where to the patch.</param>
|
||||
/// <param name="color">The color of the patch.</param>
|
||||
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color)
|
||||
/// <param name="spriteBatchSettings">The sprite batch settings to use to begin the batch in after drawing the ninepatch.</param>
|
||||
public void Draw(SpriteBatch spriteBatch, Color color, Rectangle destination, SpriteBatchSettings? spriteBatchSettings = null)
|
||||
{
|
||||
if (spriteBatchSettings == null) spriteBatchSettings = Configuration.spriteBatchSettings;
|
||||
spriteBatch.End();
|
||||
|
||||
SpriteBatchSettings ss = spriteBatchSettings.Value;
|
||||
SamplerState nSS = ss.samplerState;
|
||||
|
||||
ss.samplerState = SamplerState.PointClamp;
|
||||
|
||||
ss.BeginSpriteBatch(spriteBatch);
|
||||
|
||||
Rectangle[] destinations = GenenerateDestinationRectangles(destination.Width, destination.Height);
|
||||
for (int i = 0; i < destinations.Length; i++)
|
||||
{
|
||||
@@ -99,10 +108,15 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
destinations[i].Y += destination.Y;
|
||||
spriteBatch.Draw(texture, destinations[i], sourcePatches[i], color);
|
||||
}
|
||||
spriteBatch.End();
|
||||
|
||||
ss.samplerState = nSS;
|
||||
ss.BeginSpriteBatch(spriteBatch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw with more options.
|
||||
/// Uses the default <see cref="Configuration"/> for the spritebatch settings.
|
||||
/// </summary>
|
||||
/// <param name="spriteBatch">Spritebatch to use.</param>
|
||||
/// <param name="destination">The destination to draw the patch.</param>
|
||||
@@ -113,7 +127,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
{
|
||||
if (rotation != 0) throw new NotImplementedException("Ninepatches can't be rotated.");
|
||||
if (origin != default(Vector2)) throw new NotImplementedException("Ninepatches can't have origin changed (hint: use the destination rectangle to shift and position).");
|
||||
Draw(spriteBatch, destination, color);
|
||||
Draw(spriteBatch, color, destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -174,7 +174,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
|
||||
if (ninepatch != null)
|
||||
{
|
||||
ninepatch.Draw(batch, destination, Color.White);
|
||||
ninepatch.Draw(batch, Color.White, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user