Browse Source

WIP: Sprite support.

* Clarified xmldoc information in DotSDL.Graphics.Canvas.
    * Added some classes to support sprites.
improved_timing
Ian Burgmyer 6 years ago
parent
commit
a707cfc87b
  1. 3
      DotSDL/Graphics/Canvas.cs
  2. 24
      DotSDL/Graphics/FlipDirection.cs
  3. 38
      DotSDL/Graphics/Sprite.cs
  4. 78
      DotSDL/Math/Vector2.cs

3
DotSDL/Graphics/Canvas.cs

@ -48,7 +48,8 @@
}
/// <summary>
/// Resizes the <see cref="Canvas"/>.
/// Resizes the <see cref="Canvas"/>. Please note that this will also clear the canvas of
/// its existing contents.
/// </summary>
/// <param name="width">The new width of the <see cref="Canvas"/>.</param>
/// <param name="height">The new height of the <see cref="Canvas"/>.</param>

24
DotSDL/Graphics/FlipDirection.cs

@ -0,0 +1,24 @@
using System;
namespace DotSDL.Graphics {
/// <summary>
/// The axis upon which a sprite should be flipped.
/// </summary>
[Flags]
public enum FlipDirection {
/// <summary>
/// The sprite should not be flipped.
/// </summary>
None = 0x00,
/// <summary>
/// The sprite should be flipped along the X (horizontal) axis.
/// </summary>
Horizontal = 0x01,
/// <summary>
/// The sprite should be flipped along the Y (vertical) axis.
/// </summary>
Vertical = 0x02
}
}

38
DotSDL/Graphics/Sprite.cs

@ -0,0 +1,38 @@
namespace DotSDL.Graphics {
/// <summary>
/// Represents a graphical, two-dimensional object in a program.
/// </summary>
public class Sprite : Canvas {
public Point Position { get; }
public Point Scale { get; }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
/// </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, 0, 0) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
/// </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>
/// <param name="x">The initial X position of the new <see cref="Sprite"/>.</param>
/// <param name="y">The initial Y position of the new <see cref="Sprite"/>.</param>
public Sprite(int width, int height, int x, int y) : this(width, height, new Point { X = x, Y = y }) { }
/// <summary>
/// Initializes a new <see cref="Sprite"/>.
/// </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>
/// <param name="position">A <see cref="Point"/> representing the initial position of the new <see cref="Sprite"/>.</param>
public Sprite(int width, int height, Point position) : base(width, height) {
Position = position;
SetSize(width, height);
Scale = new Point { X = 1, Y = 1 };
}
}
}

78
DotSDL/Math/Vector2.cs

@ -0,0 +1,78 @@
using System;
using System.Xml;
namespace DotSDL.Math {
/// <summary>
/// Represents a two dimensional vector using single-precision floats.
/// </summary>
public class Vector2 {
public float X { get; set; }
public float Y { get; set; }
/// <summary>
/// Creates a new <see cref="Vector2"/>.
/// </summary>
public Vector2() : this(0, 0) { }
/// <summary>
/// Creates a new <see cref="Vector2"/>.
/// </summary>
/// <param name="x">The X value of the new <see cref="Vector2"/>.</param>
/// <param name="y">The Y value of the new <see cref="Vector2"/>.</param>
public Vector2(float x, float y) {
X = x;
Y = y;
}
/// <summary>
/// Creates a new <see cref="Vector2"/>.
/// </summary>
/// <param name="vec">An existing <see cref="Vector2"/> to copy into the new object.</param>
public Vector2(Vector2 vec) : this(vec.X, vec.Y) { }
/// <summary>
/// Adds two <see cref="Vector2"/> objects together.
/// </summary>
/// <param name="vec1">The left <see cref="Vector2"/> operand.</param>
/// <param name="vec2">The right <see cref="Vector2"/> operand.</param>
/// <returns>The result of <paramref name="vec1"/> + <paramref name="vec2"/>.</returns>
public static Vector2 operator +(Vector2 vec1, Vector2 vec2) {
return new Vector2(vec1.X + vec2.X,
vec1.Y + vec2.Y);
}
/// <summary>
/// Subtracts two <see cref="Vector2"/> objects.
/// </summary>
/// <param name="vec1">The left <see cref="Vector2"/> operand.</param>
/// <param name="vec2">The right <see cref="Vector2"/> operand.</param>
/// <returns>The result of <paramref name="vec1"/> - <paramref name="vec2"/>.</returns>
public static Vector2 operator -(Vector2 vec1, Vector2 vec2) {
return new Vector2(vec1.X - vec2.X,
vec1.Y - vec2.Y);
}
/// <summary>
/// Multiplies a <see cref="Vector2"/> by a scalar value.
/// </summary>
/// <param name="vec">The left <see cref="Vector2"/> operand.</param>
/// <param name="scalar">The right <see cref="float"/> operand.</param>
/// <returns>The result of <paramref name="vec"/> * <paramref name="scalar"/>.</returns>
public static Vector2 operator *(Vector2 vec, float scalar) {
return new Vector2(vec.X * scalar,
vec.Y * scalar);
}
/// <summary>
/// Divides a <see cref="Vector2"/> by a scalar value.
/// </summary>
/// <param name="vec">The left <see cref="Vector2"/> operand.</param>
/// <param name="scalar">The right <see cref="float"/> operand.</param>
/// <returns>The result of <paramref name="vec"/> / <paramref name="scalar"/>.</returns>
/// <exception cref="DivideByZeroException">The scalar value is zero.</exception>
public static Vector2 operator /(Vector2 vec, float scalar) {
return new Vector2(vec.X / scalar,
vec.Y / scalar);
}
}
}
Loading…
Cancel
Save