Implemented spritebatch's method of handling the origin.
This commit is contained in:
parent
f311cc38f3
commit
8bd6ba6dc8
@ -67,7 +67,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
|
||||
{
|
||||
this.color = color;
|
||||
this.rotation = rotation;
|
||||
this.offset = origin;
|
||||
this.origin = origin;
|
||||
bounds = destination;
|
||||
Draw(spriteBatch);
|
||||
}
|
||||
|
@ -21,14 +21,20 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
public bool Debugging { set { if (value) { if (rectangleRenderer == null) rectangleRenderer = new RectangleRenderer(); } else { rectangleRenderer?.Dispose(); rectangleRenderer = null; } } get { return rectangleRenderer != null; } }
|
||||
|
||||
/// <summary>
|
||||
/// Bounds of this module.
|
||||
/// The bounds before factoring in the origin.
|
||||
/// </summary>
|
||||
public Rectangle bounds;
|
||||
|
||||
/// <summary>
|
||||
/// The how much of the entire boundary to offset when drawing.
|
||||
/// Bounds of this module (after factoring in the origin).
|
||||
/// </summary>
|
||||
public Vector2 offset;
|
||||
public Rectangle ActualBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Rectangle((int)(bounds.X - origin.X), (int)(bounds.Y - origin.Y), bounds.Width, bounds.Height);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Origin of this module.
|
||||
@ -68,7 +74,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
if (Debugging)
|
||||
{
|
||||
rectangleRenderer.Begin();
|
||||
rectangleRenderer.Draw(bounds.X, bounds.Y, bounds.Width, bounds.Height, Color.Red);
|
||||
rectangleRenderer.Draw(ActualBounds.X, ActualBounds.Y, ActualBounds.Width, ActualBounds.Height, Color.Red);
|
||||
rectangleRenderer.End();
|
||||
}
|
||||
}
|
||||
@ -126,8 +132,8 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
/// </summary>
|
||||
public void CenterOrigin()
|
||||
{
|
||||
offset.X = bounds.Width / 2f;
|
||||
offset.Y = bounds.Height / 2f;
|
||||
origin.X = bounds.Width / 2f;
|
||||
origin.Y = bounds.Height / 2f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,12 +57,13 @@ namespace RecrownedAthenaeum.UI.Modular
|
||||
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
|
||||
batch.GraphicsDevice.ScissorRectangle = scissor;
|
||||
}
|
||||
|
||||
foreach (UIModule module in modules)
|
||||
{
|
||||
int offsetX = module.bounds.X;
|
||||
int offsetY = module.bounds.Y;
|
||||
module.bounds.X = bounds.X + offsetX - (int)module.offset.X;
|
||||
module.bounds.Y = bounds.Y + offsetY - (int)module.offset.Y;
|
||||
module.bounds.X = bounds.X + offsetX;
|
||||
module.bounds.Y = bounds.Y + offsetY;
|
||||
module.Draw(batch);
|
||||
module.bounds.X = offsetX;
|
||||
module.bounds.Y = offsetY;
|
||||
|
Loading…
Reference in New Issue
Block a user