Added setup system. Changed reader and writer for texture atlas and nine patch to have image and serialized data be in same file. Some refactors occurred as well.
This commit is contained in:
@@ -28,10 +28,11 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <param name="right">Right side.</param>
|
||||
/// <param name="bottom">Bottom side.</param>
|
||||
/// <param name="top">Top side.</param>
|
||||
public NinePatch(Texture2D texture, int left, int right, int bottom, int top)
|
||||
/// <param name="textureBounds">The dimensions and potentially the coordinates of the rectangle on an atlas. If left to default of null, will only be set to texture bounds.</param>
|
||||
public NinePatch(Texture2D texture, int left, int right, int bottom, int top, Rectangle? textureBounds = null)
|
||||
{
|
||||
this.texture = texture;
|
||||
textureRegion = texture.Bounds;
|
||||
if (textureBounds.HasValue) textureRegion = textureBounds.Value; else textureRegion = texture.Bounds;
|
||||
if (left + right >= textureRegion.Width) throw new ArgumentOutOfRangeException("a and b cannot be greater than or equal to the width of region.");
|
||||
if (bottom + top >= textureRegion.Height) throw new ArgumentOutOfRangeException("c and d cannot be greater or equal to the height of the texture.");
|
||||
this.left = left;
|
||||
|
@@ -65,10 +65,11 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// Creates or obtains a previously created texture of a region.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of region.</param>
|
||||
/// <param name="graphicsDevice">graphics device to be used.</param>
|
||||
/// <param name="graphicsDevice">graphics device to be used. Default is null and will resort to using graphics device from <see cref="Setup"/>'s graphics device manager.</param>
|
||||
/// <returns>The texture from the region.</returns>
|
||||
public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice)
|
||||
public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice = null)
|
||||
{
|
||||
if (graphicsDevice == null) graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice;
|
||||
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
|
||||
}
|
||||
|
||||
@@ -174,15 +175,16 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <summary>
|
||||
/// Create or obtains a previously created texture of this region.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">The graphics device to use to create the texture.</param>
|
||||
/// <param name="graphicsDevice">The graphics device to use to create the texture. Will use graphics device from <see cref="Setup"/>'s graphics device manager if left to null.</param>
|
||||
/// <returns>The texture of the region.</returns>
|
||||
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice)
|
||||
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice = null)
|
||||
{
|
||||
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
|
||||
if (regionTexture == null)
|
||||
{
|
||||
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
||||
if (graphicsDevice == null) graphicsDevice = Setup.graphicsDeviceManager.GraphicsDevice;
|
||||
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
||||
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
||||
regionTexture.SetData(data);
|
||||
|
Reference in New Issue
Block a user