Browse Source

Organizational changes.

* DotSDL's Point and Rectangle classes now use SdlPoint and SdlRect
      structs internally to store their data.
    * The Sprite class has been fixed, so DotSDL compiles again. Whoops.
improved_timing
Ian Burgmyer 5 years ago
parent
commit
5ed16168e4
  1. 46
      DotSDL/Graphics/Point.cs
  2. 42
      DotSDL/Graphics/Rectangle.cs
  3. 12
      DotSDL/Graphics/Sprite.cs

46
DotSDL/Graphics/Point.cs

@ -1,26 +1,58 @@
namespace DotSDL.Graphics {
using DotSDL.Interop.Core;
namespace DotSDL.Graphics {
/// <summary>
/// Represents a point in 2D space.
/// </summary>
public struct Point {
public class Point {
private Rect.SdlPoint _point;
/// <summary>
/// Returns a <see cref="Point"/> with the coordinates (1, 1).
/// </summary>
public static Point One = new Point(1, 1);
/// <summary>
/// Returns a <see cref="Point"/> with the coordinates (1, 0).
/// </summary>
public static Point UnitX = new Point(1, 0);
/// <summary>
/// Returns a <see cref="Point"/> with the coordinates (0, 1).
/// </summary>
public static Point UnitY = new Point(0, 1);
/// <summary>
/// Returns a <see cref="Point"/> with the coordinates (0, 0).
/// </summary>
public static Point Zero = new Point(0, 0);
/// <summary>
/// The X coordinate of the point.
/// </summary>
public int X { get; set; }
public int X {
get => _point.X;
set => _point.X = value;
}
/// <summary>
/// The Y coordinate of the point.
/// </summary>
public int Y { get; set; }
public int Y {
get => _point.Y;
set => _point.Y = value;
}
/// <summary>
/// Creates a new <see cref="Point"/>.
/// </summary>
/// <param name="x">The X value of the new <see cref="Point"/>.</param>
/// <param name="y">The Y value of the new <see cref="Point"/>.</param>
public Point(int x, int y) {
X = x;
Y = y;
public Point(int x = 0, int y = 0) {
_point = new Rect.SdlPoint {
X = x,
Y = y
};
}
}
}

42
DotSDL/Graphics/Rectangle.cs

@ -1,28 +1,41 @@
namespace DotSDL.Graphics {
using DotSDL.Interop.Core;
namespace DotSDL.Graphics {
/// <summary>
/// Represents a rectangle in 2D space.
/// </summary>
public struct Rectangle {
public class Rectangle {
private Rect.SdlRect _rect;
/// <summary>
/// A <see cref="Point"/> representing the position of the <see cref="Rectangle"/>.
/// </summary>
public Point Position { get; set; }
public Point Position {
get => new Point(_rect.X, _rect.Y);
set {
_rect.X = value.X;
_rect.Y = value.Y;
}
}
/// <summary>
/// A <see cref="Point"/> representing the size of the <see cref="Rectangle"/>.
/// </summary>
public Point Size { get; set; }
public Point Size {
get => new Point(_rect.W, _rect.H);
set {
_rect.W = value.X;
_rect.H = value.Y;
}
}
/// <summary>
/// Creates a new <see cref="Rectangle"/>.
/// </summary>
/// <param name="position">A <see cref="Point"/> representing the position of the new <see cref="Rectangle"/>.</param>
/// <param name="size">A <see cref="Point"/> representing the size of the new <see cref="Rectangle"/>.</param>
public Rectangle(Point position, Point size) {
Position = position;
Size = size;
}
public Rectangle(Point position, Point size) : this(position.X, position.Y, size.X, size.Y) { }
/// <summary>
/// Creates a new <see cref="Rectangle"/>.
/// </summary>
@ -30,6 +43,13 @@
/// <param name="y">The Y position 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>
public Rectangle(int x, int y, int width, int height) : this(new Point(x, y), new Point(width, height)) { }
public Rectangle(int x, int y, int width, int height) {
_rect = new Rect.SdlRect {
X = x,
Y = y,
W = width,
H = height
};
}
}
}

12
DotSDL/Graphics/Sprite.cs

@ -43,7 +43,7 @@ namespace DotSDL.Graphics {
/// </summary>
/// <param name="width">The width of the new <see cref="Sprite"/>.</param>
/// <param name="height">The height of the new <see cref="Sprite"/>.</param>
public Sprite(int width, int height) : this(width, height, Vector2.Zero, Vector2.One, 0) { }
public Sprite(int width, int height) : this(width, height, Point.Zero, Vector2.One, 0) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
@ -51,7 +51,7 @@ namespace DotSDL.Graphics {
/// <param name="width">The width of the new <see cref="Sprite"/>.</param>
/// <param name="height">The height of the new <see cref="Sprite"/>.</param>
/// <param name="position">A <see cref="Vector2"/> representing the initial position of the new <see cref="Sprite"/>.</param>
public Sprite(int width, int height, Vector2 position) : this(width, height, position, Vector2.One, 0) { }
public Sprite(int width, int height, Point position) : this(width, height, position, Vector2.One, 0) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
@ -60,7 +60,7 @@ namespace DotSDL.Graphics {
/// <param name="height">The height of the new <see cref="Sprite"/>.</param>
/// <param name="zorder">A value indicating the order in which this <see cref="Sprite"/> is drawn. Higher numbered
/// sprites are drawn on top of other sprites and, thus, will appear above them.</param>
public Sprite(int width, int height, int zorder) : this(width, height, Vector2.Zero, Vector2.One, zorder) { }
public Sprite(int width, int height, int zorder) : this(width, height, Point.Zero, Vector2.One, zorder) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
@ -69,7 +69,7 @@ namespace DotSDL.Graphics {
/// <param name="height">The height of the new <see cref="Sprite"/>.</param>
/// <param name="position">A <see cref="Vector2"/> representing the initial position of the new <see cref="Sprite"/>.</param>
/// <param name="scale">A <see cref="Vector2"/> representing the initial scaling of the new <see cref="Sprite"/>.</param>
public Sprite(int width, int height, Vector2 position, Vector2 scale) : this(width, height, position, scale, 0) { }
public Sprite(int width, int height, Point position, Vector2 scale) : this(width, height, position, scale, 0) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
@ -79,7 +79,7 @@ namespace DotSDL.Graphics {
/// <param name="position">A <see cref="Vector2"/> representing the initial position of the new <see cref="Sprite"/>.</param>
/// <param name="zorder">A value indicating the order in which this <see cref="Sprite"/> is drawn. Higher numbered
/// sprites are drawn on top of other sprites and, thus, will appear above them.</param>
public Sprite(int width, int height, Vector2 position, int zorder) : this(width, height, position, Vector2.One, 0) { }
public Sprite(int width, int height, Point position, int zorder) : this(width, height, position, Vector2.One, 0) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
@ -90,7 +90,7 @@ namespace DotSDL.Graphics {
/// <param name="scale">A <see cref="Vector2"/> representing the initial scaling of the new <see cref="Sprite"/>.</param>
/// <param name="zorder">A value indicating the order in which this <see cref="Sprite"/> is drawn. Higher numbered
/// sprites are drawn on top of other sprites and, thus, will appear above them.</param>
public Sprite(int width, int height, Vector2 position, Vector2 scale, int zorder) : base(width, height) {
public Sprite(int width, int height, Point position, Vector2 scale, int zorder) : base(width, height) {
Position = position;
Scale = scale;
ZOrder = zorder;

Loading…
Cancel
Save