Added offset to be used instead of origin in spritebatch does things I don't want it to do. Also added a project to more easily test this library.
This commit is contained in:
@@ -106,5 +106,15 @@ namespace RecrownedAthenaeum.Render
|
||||
|
||||
primitiveBatch.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the given rectangle.
|
||||
/// </summary>
|
||||
/// <param name="rectangle">Uses the x, y and dimensions to draw a rectangle.</param>
|
||||
/// <param name="color">The color of the rectangle.</param>
|
||||
public void Draw(Rectangle rectangle, Color color)
|
||||
{
|
||||
Draw(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,17 +18,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <summary>
|
||||
/// The texture to be rendered.
|
||||
/// </summary>
|
||||
public Texture2D Texture { get; set; }
|
||||
public Texture2D texture;
|
||||
|
||||
/// <summary>
|
||||
/// Scale of of the X axis.
|
||||
/// </summary>
|
||||
public float ScaleX { get { return (float)bounds.Width / Texture.Width; } set { bounds.Width = (int)(Texture.Width * value); } }
|
||||
public float ScaleX { get { return (float)bounds.Width / texture.Width; } set { bounds.Width = (int)(texture.Width * value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Scale of the Y axis.
|
||||
/// </summary>
|
||||
public float ScaleY { get { return (float)bounds.Height / Texture.Height; } set { bounds.Height = (int)(Texture.Height * value); } }
|
||||
public float ScaleY { get { return (float)bounds.Height / texture.Height; } set { bounds.Height = (int)(texture.Height * value); } }
|
||||
|
||||
/// <summary>
|
||||
/// Sets scale of X and Y.
|
||||
@@ -41,7 +41,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="texture">Texture to use.</param>
|
||||
public Image(Texture2D texture)
|
||||
{
|
||||
Texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
||||
this.texture = texture ?? throw new ArgumentException("Image requires a texture.");
|
||||
bounds = texture.Bounds;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
/// <param name="batch">The batch to use.</param>
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
batch.Draw(texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
base.Draw(batch);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
this.color = color;
|
||||
this.rotation = rotation;
|
||||
this.origin = origin;
|
||||
this.offset = origin;
|
||||
bounds = destination;
|
||||
Draw(spriteBatch);
|
||||
}
|
||||
|
@@ -24,11 +24,17 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// Bounds of this module.
|
||||
/// </summary>
|
||||
public Rectangle bounds;
|
||||
|
||||
/// <summary>
|
||||
/// The how much of the entire boundary to offset when drawing.
|
||||
/// </summary>
|
||||
public Vector2 offset;
|
||||
|
||||
/// <summary>
|
||||
/// Origin of this module.
|
||||
/// </summary>
|
||||
public Vector2 origin;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The parent of this module. May be null.
|
||||
/// </summary>
|
||||
@@ -59,7 +65,12 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// <param name="batch">Batch used to draw.</param>
|
||||
public virtual void Draw(SpriteBatch batch)
|
||||
{
|
||||
if (Debugging) { rectangleRenderer.Draw(bounds.X, bounds.Y, bounds.Width, bounds.Height, Color.Red); }
|
||||
if (Debugging)
|
||||
{
|
||||
rectangleRenderer.Begin();
|
||||
rectangleRenderer.Draw(bounds.X, bounds.Y, bounds.Width, bounds.Height, Color.Red);
|
||||
rectangleRenderer.End();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,8 +126,8 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// </summary>
|
||||
public void CenterOrigin()
|
||||
{
|
||||
origin.X = bounds.Width / 2f;
|
||||
origin.Y = bounds.Height / 2f;
|
||||
offset.X = bounds.Width / 2f;
|
||||
offset.Y = bounds.Height / 2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -61,8 +61,8 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
{
|
||||
int offsetX = module.bounds.X;
|
||||
int offsetY = module.bounds.Y;
|
||||
module.bounds.X = bounds.X + offsetX - (int)module.origin.X;
|
||||
module.bounds.Y = bounds.Y + offsetY - (int)module.origin.Y;
|
||||
module.bounds.X = bounds.X + offsetX - (int)module.offset.X;
|
||||
module.bounds.Y = bounds.Y + offsetY - (int)module.offset.Y;
|
||||
module.Draw(batch);
|
||||
module.bounds.X = offsetX;
|
||||
module.bounds.Y = offsetY;
|
||||
|
Reference in New Issue
Block a user