I have a base class called Component. I also have 2 interfaces I2DComponent, and I3DComponent. I am currently working on the I2DComponent.
The implementation:
/// <summary>
/// Represtions a 2D object. These objects will be drawn after 3D objects,
/// and will have modifiers automatically provided in the editor.
/// </summary>
public interface I2DComponent
{
/// <summary>
/// Gets or sets the rectangle.
/// </summary>
/// <value>The rectangle.</value>
Rectangle Rectangle { get; set; }
/// <summary>
/// Gets the local position on the game screen.
/// </summary>
/// <value>The local position on the game screen.</value>
/// <remarks>The rectangle position minus the parent screen position.</remarks>
Rectangle LocalPosition { get; }
/// <summary>
/// Gets or sets the scale.
/// </summary>
/// <value>The scale.</value>
float Scale { get; set; }
}
So the problem is that I need access to the global position or the Rectangle for checking whether the mouse is over it.
if (component.Rectangle.Contains(mouse.Rectangle))
{
do somthing.
}
But when I am just accessing to moving it around i want to just be accessing the local position so that if i have a game screen at position 50, 50 then i can set the local position to 0, 0 and it will be at the top left corner of the parent game screen. I guess the real problem is that I don't want to be able to accidentally set the Rectangle by saying
component.Rectangle = new Rectangle(component.Rectangle.X + 5, component.Rectangle.Y + 5, component.Rectangle.Width, component.Rectangle.Height);
This is more or less an accessor design issue than anything and I want to make it look right, but I am having trouble doing so.
Update:
What if i changed changed it so that the I2D component only had Bounds and scale and then had a function in GameScreen to get the current "Global" position of the component.
Update:
These 2D objects are all objects that are draw as a hud or a gui object not in 3D space. just a clareification.
Update:
I am thinking about doing it recursively now but im not sure how i would go about doing this.