Improved variable naming for ninepatch classes.

This commit is contained in:
Harrison Deng 2018-12-29 00:29:31 -06:00
parent 3bbbd672be
commit eedc083e03
3 changed files with 80 additions and 80 deletions

View File

@ -9,15 +9,15 @@ namespace RecrownedAthenaeum.Pipeline.NinePatch
public class NinePatchData public class NinePatchData
{ {
public string textureName; public string textureName;
public int a, b, c, d; public int left, right, down, top;
public NinePatchData(string textureName, int a, int b, int c, int d) public NinePatchData(string textureName, int left, int right, int down, int top)
{ {
this.textureName = textureName; this.textureName = textureName;
this.a = a; this.left = left;
this.b = b; this.right = right;
this.c = c; this.down = down;
this.d = d; this.top = top;
} }
} }
} }

View File

@ -14,26 +14,26 @@ namespace RecrownedAthenaeum.DataTypes
public Color color; public Color color;
public Rectangle textureRegion; public Rectangle textureRegion;
readonly Texture2D texture; readonly Texture2D texture;
readonly int a, b, c, d; readonly int left, right, bottom, top;
/// <summary> /// <summary>
/// A nine patch object. /// A nine patch object.
/// </summary> /// </summary>
/// <param name="texture">Texture used for the nine patch. Dimensions must be greater than their sum border counter parts. If used as part of texture atlas, the texture should be the texture of the entire atlas.</param> /// <param name="texture">Texture used for the nine patch. Dimensions must be greater than their sum border counter parts. If used as part of texture atlas, the texture should be the texture of the entire atlas.</param>
/// <param name="a">Left side.</param> /// <param name="left">Left side.</param>
/// <param name="b">Right side.</param> /// <param name="right">Right side.</param>
/// <param name="c">Bottom side.</param> /// <param name="bottom">Bottom side.</param>
/// <param name="d">Top side.</param> /// <param name="top">Top side.</param>
public NinePatch(Texture2D texture, int a, int b, int c, int d) public NinePatch(Texture2D texture, int left, int right, int bottom, int top)
{ {
this.texture = texture; this.texture = texture;
textureRegion = texture.Bounds; textureRegion = texture.Bounds;
if (a + b >= textureRegion.Width) throw new ArgumentOutOfRangeException("a and b cannot be greater than or equal to the width of region."); if (left + right >= textureRegion.Width) throw new ArgumentOutOfRangeException("a and b cannot be greater than or equal to the width of region.");
if (c + d >= textureRegion.Height) throw new ArgumentOutOfRangeException("c and d cannot be greater or equal to the height of the texture."); if (bottom + top >= textureRegion.Height) throw new ArgumentOutOfRangeException("c and d cannot be greater or equal to the height of the texture.");
this.a = a; this.left = left;
this.b = b; this.right = right;
this.c = c; this.bottom = bottom;
this.d = d; this.top = top;
color = Color.White; color = Color.White;
} }
@ -46,13 +46,13 @@ namespace RecrownedAthenaeum.DataTypes
//1x1 //1x1
drawnRectangle.X = destination.X; drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Y; drawnRectangle.Y = destination.Y;
drawnRectangle.Width = a; drawnRectangle.Width = left;
drawnRectangle.Height = c; drawnRectangle.Height = bottom;
sourceRectangle.X = 0; sourceRectangle.X = 0;
sourceRectangle.Y = 0; sourceRectangle.Y = 0;
sourceRectangle.Width = a; sourceRectangle.Width = left;
sourceRectangle.Height = c; sourceRectangle.Height = bottom;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
@ -60,30 +60,30 @@ namespace RecrownedAthenaeum.DataTypes
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x1 //2x1
drawnRectangle.X = destination.X + a; drawnRectangle.X = destination.X + left;
drawnRectangle.Y = destination.Y; drawnRectangle.Y = destination.Y;
drawnRectangle.Width = destination.Width - a - b; drawnRectangle.Width = destination.Width - left - right;
drawnRectangle.Height = c; drawnRectangle.Height = bottom;
sourceRectangle.X = a; sourceRectangle.X = left;
sourceRectangle.Y = 0; sourceRectangle.Y = 0;
sourceRectangle.Width = textureRegion.Width - a - b; sourceRectangle.Width = textureRegion.Width - left - right;
sourceRectangle.Height = c; sourceRectangle.Height = bottom;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x1 //3x1
drawnRectangle.X = destination.X + destination.Width - b; drawnRectangle.X = destination.X + destination.Width - right;
drawnRectangle.Y = destination.Y; drawnRectangle.Y = destination.Y;
drawnRectangle.Width = b; drawnRectangle.Width = right;
drawnRectangle.Height = c; drawnRectangle.Height = bottom;
sourceRectangle.X = textureRegion.Width - b; sourceRectangle.X = textureRegion.Width - right;
sourceRectangle.Y = 0; sourceRectangle.Y = 0;
sourceRectangle.Width = b; sourceRectangle.Width = right;
sourceRectangle.Height = c; sourceRectangle.Height = bottom;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
@ -91,44 +91,44 @@ namespace RecrownedAthenaeum.DataTypes
//1x2 //1x2
drawnRectangle.X = destination.X; drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Y + c; drawnRectangle.Y = destination.Y + bottom;
drawnRectangle.Width = a; drawnRectangle.Width = left;
drawnRectangle.Height = destination.Height - d - c; drawnRectangle.Height = destination.Height - top - bottom;
sourceRectangle.X = 0; sourceRectangle.X = 0;
sourceRectangle.Y = c; sourceRectangle.Y = bottom;
sourceRectangle.Width = a; sourceRectangle.Width = left;
sourceRectangle.Height = textureRegion.Height - c - d; sourceRectangle.Height = textureRegion.Height - bottom - top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x2 //2x2
drawnRectangle.X = destination.X + a; drawnRectangle.X = destination.X + left;
drawnRectangle.Y = destination.Y + c; drawnRectangle.Y = destination.Y + bottom;
drawnRectangle.Width = destination.Width - a - b; drawnRectangle.Width = destination.Width - left - right;
drawnRectangle.Height = destination.Height - c - d; drawnRectangle.Height = destination.Height - bottom - top;
sourceRectangle.X = a; sourceRectangle.X = left;
sourceRectangle.Y = c; sourceRectangle.Y = bottom;
sourceRectangle.Width = textureRegion.Width - a - b; sourceRectangle.Width = textureRegion.Width - left - right;
sourceRectangle.Height = textureRegion.Height - c - d; sourceRectangle.Height = textureRegion.Height - bottom - top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x2 //3x2
drawnRectangle.X = destination.X + destination.Width - b; drawnRectangle.X = destination.X + destination.Width - right;
drawnRectangle.Y = destination.Y + c; drawnRectangle.Y = destination.Y + bottom;
drawnRectangle.Width = b; drawnRectangle.Width = right;
drawnRectangle.Height = destination.Height - c - d; drawnRectangle.Height = destination.Height - bottom - top;
sourceRectangle.X = textureRegion.Width - b; sourceRectangle.X = textureRegion.Width - right;
sourceRectangle.Y = c; sourceRectangle.Y = bottom;
sourceRectangle.Width = b; sourceRectangle.Width = right;
sourceRectangle.Height = textureRegion.Height - c - d; sourceRectangle.Height = textureRegion.Height - bottom - top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
@ -136,44 +136,44 @@ namespace RecrownedAthenaeum.DataTypes
//1x3 //1x3
drawnRectangle.X = destination.X; drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Height - d; drawnRectangle.Y = destination.Height - top;
drawnRectangle.Width = a; drawnRectangle.Width = left;
drawnRectangle.Height = d; drawnRectangle.Height = top;
sourceRectangle.X = a; sourceRectangle.X = left;
sourceRectangle.Y = textureRegion.Height - d; sourceRectangle.Y = textureRegion.Height - top;
sourceRectangle.Width = a; sourceRectangle.Width = left;
sourceRectangle.Height = d; sourceRectangle.Height = top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x3 //2x3
drawnRectangle.X = destination.X + a; drawnRectangle.X = destination.X + left;
drawnRectangle.Y = destination.Height - d; drawnRectangle.Y = destination.Height - top;
drawnRectangle.Width = destination.Width - a - b; drawnRectangle.Width = destination.Width - left - right;
drawnRectangle.Height = d; drawnRectangle.Height = top;
sourceRectangle.X = a; sourceRectangle.X = left;
sourceRectangle.Y = textureRegion.Height - d; sourceRectangle.Y = textureRegion.Height - top;
sourceRectangle.Width = textureRegion.Width - a - b; sourceRectangle.Width = textureRegion.Width - left - right;
sourceRectangle.Height = d; sourceRectangle.Height = top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color); spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x3 //3x3
drawnRectangle.X = destination.X + destination.Width - b; drawnRectangle.X = destination.X + destination.Width - right;
drawnRectangle.Y = destination.Height - d; drawnRectangle.Y = destination.Height - top;
drawnRectangle.Width = b; drawnRectangle.Width = right;
drawnRectangle.Height = d; drawnRectangle.Height = top;
sourceRectangle.X = textureRegion.Width - b; sourceRectangle.X = textureRegion.Width - right;
sourceRectangle.Y = textureRegion.Height - d; sourceRectangle.Y = textureRegion.Height - top;
sourceRectangle.Width = b; sourceRectangle.Width = right;
sourceRectangle.Height = d; sourceRectangle.Height = top;
sourceRectangle.X += textureRegion.X; sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y; sourceRectangle.Y += textureRegion.Y;

View File

@ -33,7 +33,7 @@ namespace RecrownedAthenaeum.Pipeline
if (regionData.ninePatchData != null) if (regionData.ninePatchData != null)
{ {
NinePatchData nPatchData = regionData.ninePatchData; NinePatchData nPatchData = regionData.ninePatchData;
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.a, nPatchData.b, nPatchData.c, nPatchData.d); nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.down, nPatchData.down);
} }
regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture); regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);