This repository was archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDrawX.cs
60 lines (53 loc) · 2.15 KB
/
DrawX.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Collections.Generic;
namespace HatlessEngine
{
/// <summary>
/// Static class containing settings used in Draw methods.
/// Also provides centralized access to draw functions and debug shape-drawing methods.
/// </summary>
public static class DrawX
{
internal static List<IDrawJob> DrawJobs = new List<IDrawJob>();
public static Color BackgroundColor = Color.Gray;
public static void Draw(Point point, Color color, int depth = 0)
{
DrawJobs.Add(new LineDrawJob(depth, new Rectangle(point, Point.Zero), new Point[] { point, point }, color));
}
public static void Draw(Line line, Color color, int depth = 0)
{
DrawJobs.Add(new LineDrawJob(depth, line.GetEnclosingRectangle(), line.GetPoints(), color));
}
public static void Draw(string str, Font font, Point pos, Color color, CombinedAlignment alignment = CombinedAlignment.TopLeft, int depth = 0)
{
font.Draw(str, pos, color, alignment, depth);
}
public static void Draw(Sprite sprite, Point pos, Point scale, Point origin, int frameIndex = 0, float rotation = 0f, int depth = 0)
{
sprite.Draw(pos, scale, origin, frameIndex, rotation, depth);
}
public static void Draw(Sprite sprite, Point pos, int frameIndex = 0, float rotation = 0f, int depth = 0)
{
sprite.Draw(pos, frameIndex, rotation, depth);
}
/// <summary>
/// Draws the outline of a shape. Drawing filled shapes is (currently?) only possible for AABB's. See DrawFilledRect.
/// </summary>
public static void DrawShapeOutline(Shape shape, Color color, int depth = 0)
{
//add the start point at the end of the array so it will draw the last line
Point[] shapePoints = shape.GetPoints();
Point[] points = new Point[shapePoints.Length + 1];
shapePoints.CopyTo(points, 0);
points[points.Length - 1] = points[0];
DrawJobs.Add(new LineDrawJob(depth, shape.GetEnclosingRectangle(), points, color));
}
public static void DrawFilledRect(Rectangle rect, Color color, int depth = 0)
{
DrawJobs.Add(new FilledRectDrawJob(depth, rect, color));
}
internal static List<IDrawJob> GetDrawJobsByArea(Rectangle area)
{
return DrawJobs.FindAll(j => j.Area.IntersectsWith(area));
}
}
}