Browse Source

Corrected Rectangle class.

* The Point setters actually work properly now. Oops.
improved_timing
Ian Burgmyer 5 years ago
parent
commit
82094e72b1
  1. 28
      DotSDL/Graphics/Rectangle.cs

28
DotSDL/Graphics/Rectangle.cs

@ -5,19 +5,24 @@ namespace DotSDL.Graphics {
/// Represents a rectangle in 2D space. /// Represents a rectangle in 2D space.
/// </summary> /// </summary>
public class Rectangle { public class Rectangle {
private readonly Point _position;
private readonly Point _size;
/// <summary> /// <summary>
/// The base <see cref="SdlRect"/> structure that this class wraps around. /// The base <see cref="SdlRect"/> structure that this class wraps around.
/// </summary> /// </summary>
internal Rect.SdlRect SdlRect; internal Rect.SdlRect SdlRect => new Rect.SdlRect {
X = _position.X, Y = _position.Y, W = _size.X, H = _size.Y
};
/// <summary> /// <summary>
/// A <see cref="Point"/> representing the position of the <see cref="Rectangle"/>. /// A <see cref="Point"/> representing the position of the <see cref="Rectangle"/>.
/// </summary> /// </summary>
public Point Position { public Point Position {
get => new Point(SdlRect.X, SdlRect.Y); get => _position;
set { set {
SdlRect.X = value.X; _position.X = value.X;
SdlRect.Y = value.Y; _position.Y = value.Y;
} }
} }
@ -25,10 +30,10 @@ namespace DotSDL.Graphics {
/// A <see cref="Point"/> representing the size of the <see cref="Rectangle"/>. /// A <see cref="Point"/> representing the size of the <see cref="Rectangle"/>.
/// </summary> /// </summary>
public Point Size { public Point Size {
get => new Point(SdlRect.W, SdlRect.H); get => _size;
set { set {
SdlRect.W = value.X; _size.X = value.X;
SdlRect.H = value.Y; _size.Y = value.Y;
} }
} }
@ -47,11 +52,14 @@ namespace DotSDL.Graphics {
/// <param name="width">The width of the new <see cref="Rectangle"/>.</param> /// <param name="width">The width of the new <see cref="Rectangle"/>.</param>
/// <param name="height">The height of the new <see cref="Rectangle"/>.</param> /// <param name="height">The height of the new <see cref="Rectangle"/>.</param>
public Rectangle(int x, int y, int width, int height) { public Rectangle(int x, int y, int width, int height) {
SdlRect = new Rect.SdlRect { _position = new Point {
X = x, X = x,
Y = y, Y = y,
W = width, };
H = height
_size = new Point {
X = width,
Y = height
}; };
} }
} }

Loading…
Cancel
Save