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.color = color;
|
||||||
this.rotation = rotation;
|
this.rotation = rotation;
|
||||||
this.offset = origin;
|
this.origin = origin;
|
||||||
bounds = destination;
|
bounds = destination;
|
||||||
Draw(spriteBatch);
|
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; } }
|
public bool Debugging { set { if (value) { if (rectangleRenderer == null) rectangleRenderer = new RectangleRenderer(); } else { rectangleRenderer?.Dispose(); rectangleRenderer = null; } } get { return rectangleRenderer != null; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Bounds of this module.
|
/// The bounds before factoring in the origin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Rectangle bounds;
|
public Rectangle bounds;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The how much of the entire boundary to offset when drawing.
|
/// Bounds of this module (after factoring in the origin).
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Origin of this module.
|
/// Origin of this module.
|
||||||
@ -68,7 +74,7 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
if (Debugging)
|
if (Debugging)
|
||||||
{
|
{
|
||||||
rectangleRenderer.Begin();
|
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();
|
rectangleRenderer.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,8 +132,8 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void CenterOrigin()
|
public void CenterOrigin()
|
||||||
{
|
{
|
||||||
offset.X = bounds.Width / 2f;
|
origin.X = bounds.Width / 2f;
|
||||||
offset.Y = bounds.Height / 2f;
|
origin.Y = bounds.Height / 2f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,13 @@ namespace RecrownedAthenaeum.UI.Modular
|
|||||||
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
|
scissorBounds = batch.GraphicsDevice.ScissorRectangle;
|
||||||
batch.GraphicsDevice.ScissorRectangle = scissor;
|
batch.GraphicsDevice.ScissorRectangle = scissor;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (UIModule module in modules)
|
foreach (UIModule module in modules)
|
||||||
{
|
{
|
||||||
int offsetX = module.bounds.X;
|
int offsetX = module.bounds.X;
|
||||||
int offsetY = module.bounds.Y;
|
int offsetY = module.bounds.Y;
|
||||||
module.bounds.X = bounds.X + offsetX - (int)module.offset.X;
|
module.bounds.X = bounds.X + offsetX;
|
||||||
module.bounds.Y = bounds.Y + offsetY - (int)module.offset.Y;
|
module.bounds.Y = bounds.Y + offsetY;
|
||||||
module.Draw(batch);
|
module.Draw(batch);
|
||||||
module.bounds.X = offsetX;
|
module.bounds.X = offsetX;
|
||||||
module.bounds.Y = offsetY;
|
module.bounds.Y = offsetY;
|
||||||
|
Loading…
Reference in New Issue
Block a user