refactor: removed dash from project name and underscore from namespaces. Began working on pipeline project.

This commit is contained in:
2018-12-04 19:19:31 -06:00
parent 52fa550ced
commit 151480eaee
40 changed files with 316 additions and 114 deletions

View File

@@ -0,0 +1,166 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace RecrownedAthenaeum.DataTypes
{
public class NinePatch
{
[XmlIgnore]
public Color color;
[XmlIgnore]
readonly Texture2D texture;
readonly int a, b, c, d;
/// <summary>
/// A nine patch object.
/// </summary>
/// <param name="texture">Texture used for the nine patch. Dimensions must be greater than their sum border counter parts.</param>
/// <param name="a">Left side.</param>
/// <param name="b">Right side.</param>
/// <param name="c">Bottom side.</param>
/// <param name="d">Top side.</param>
public NinePatch(Texture2D texture, int a, int b, int c, int d)
{
this.texture = texture;
if (a + b >= texture.Width) throw new ArgumentOutOfRangeException("a and b cannot be greater than or equal to the width of texture.");
if (c + d >= texture.Height) throw new ArgumentOutOfRangeException("c and d cannot be greater or equal to the height of the texture.");
this.a = a;
this.b = b;
this.c = c;
this.d = d;
color = Color.White;
}
public void Draw(SpriteBatch batch, Rectangle destination)
{
Rectangle sourceRectangle;
Rectangle drawnRectangle;
//1x1
drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Y;
drawnRectangle.Width = a;
drawnRectangle.Height = c;
sourceRectangle.X = 0;
sourceRectangle.Y = 0;
sourceRectangle.Width = a;
sourceRectangle.Height = c;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x1
drawnRectangle.X = destination.X + a;
drawnRectangle.Y = destination.Y;
drawnRectangle.Width = destination.Width - a - b;
drawnRectangle.Height = c;
sourceRectangle.X = a;
sourceRectangle.Y = 0;
sourceRectangle.Width = texture.Width - a - b;
sourceRectangle.Height = c;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x1
drawnRectangle.X = destination.X + destination.Width - b;
drawnRectangle.Y = destination.Y;
drawnRectangle.Width = b;
drawnRectangle.Height = c;
sourceRectangle.X = texture.Width - b;
sourceRectangle.Y = 0;
sourceRectangle.Width = b;
sourceRectangle.Height = c;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//1x2
drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Y + c;
drawnRectangle.Width = a;
drawnRectangle.Height = destination.Height - d - c;
sourceRectangle.X = 0;
sourceRectangle.Y = c;
sourceRectangle.Width = a;
sourceRectangle.Height = texture.Height - c - d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x2
drawnRectangle.X = destination.X + a;
drawnRectangle.Y = destination.Y + c;
drawnRectangle.Width = destination.Width - a - b;
drawnRectangle.Height = destination.Height - c - d;
sourceRectangle.X = a;
sourceRectangle.Y = c;
sourceRectangle.Width = texture.Width - a - b;
sourceRectangle.Height = texture.Height - c - d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x2
drawnRectangle.X = destination.X + destination.Width - b;
drawnRectangle.Y = destination.Y + c;
drawnRectangle.Width = b;
drawnRectangle.Height = destination.Height - c - d;
sourceRectangle.X = texture.Width - b;
sourceRectangle.Y = c;
sourceRectangle.Width = b;
sourceRectangle.Height = texture.Height - c - d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//1x3
drawnRectangle.X = destination.X;
drawnRectangle.Y = destination.Height - d;
drawnRectangle.Width = a;
drawnRectangle.Height = d;
sourceRectangle.X = a;
sourceRectangle.Y = texture.Height - d;
sourceRectangle.Width = a;
sourceRectangle.Height = d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x3
drawnRectangle.X = destination.X + a;
drawnRectangle.Y = destination.Height - d;
drawnRectangle.Width = destination.Width - a - b;
drawnRectangle.Height = d;
sourceRectangle.X = a;
sourceRectangle.Y = texture.Height - d;
sourceRectangle.Width = texture.Width - a - b;
sourceRectangle.Height = d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x3
drawnRectangle.X = destination.X + destination.Width - b;
drawnRectangle.Y = destination.Height - d;
drawnRectangle.Width = b;
drawnRectangle.Height = d;
sourceRectangle.X = texture.Width - b;
sourceRectangle.Y = texture.Height - d;
sourceRectangle.Width = b;
sourceRectangle.Height = d;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecrownedAthenaeum.DataTypes
{
public class Resolution : IComparable<Resolution>
{
public int Width, Height;
public Resolution(int width, int height)
{
Width = width;
Height = height;
}
public Resolution()
{
}
public int CompareTo(Resolution other)
{
return Area() - other.Area();
}
public override string ToString()
{
return Width + "x" + Height;
}
public int Area()
{
return Width * Height;
}
}
}

View File

@@ -0,0 +1,73 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.DataTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace RecrownedAthenaeum.DataTypes
{
public class TextureAtlas
{
private Texture2D texture;
private Dictionary<string, TextureAtlasRegion> dictionaryOfRegions = new Dictionary<string, TextureAtlasRegion>();
public TextureAtlas(Texture2D texture, TextureAtlasRegion[] regions)
{
this.texture = texture;
foreach (TextureAtlasRegion region in regions)
{
dictionaryOfRegions.Add(region.name, region);
}
}
public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = new Vector2())
{
dictionaryOfRegions[name].Draw(batch, destination, texture, color, rotation, origin);
}
public Texture2D TextureOfRegion(string name, GraphicsDevice graphicsDevice)
{
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture);
}
public struct TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
{
public string name;
Rectangle sourceRectangle;
NinePatch ninepatch;
Texture2D regionTexture;
public void Draw(SpriteBatch batch, Rectangle destination, Texture2D fromTexture, Color color, float rotation, Vector2 origin)
{
batch.Draw(fromTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);
}
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice, Texture2D textureAtlas)
{
if (regionTexture == null)
{
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
textureAtlas.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
regionTexture.SetData(data);
}
return regionTexture;
}
public int CompareTo(TextureAtlasRegion other)
{
return name.CompareTo(other);
}
public void Dispose()
{
regionTexture?.Dispose();
}
}
}
}