-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalRectangle.cs
73 lines (63 loc) · 1.9 KB
/
TerminalRectangle.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
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Drawing;
namespace TerminalRenderer;
public class TerminalRectangle : ITerminalRenderable
{
public Point TopLeft = Point.Empty;
public Point BottomRight = Point.Empty;
public TerminalPixel PixelType = new();
public int Width => Math.Abs(BottomRight.X - TopLeft.X);
public int Height => Math.Abs(BottomRight.Y - TopLeft.Y);
public int X
{
get => TopLeft.X;
set
{
int w = Width;
TopLeft.X = value;
BottomRight.X = value + w;
}
}
public int Y
{
get => TopLeft.Y;
set
{
int h = Height;
TopLeft.Y = value;
BottomRight.Y = value + h;
}
}
public TerminalRectangle(Rectangle rectangle, TerminalPixel pixels)
{
TopLeft = new Point(rectangle.Left, rectangle.Top);
BottomRight = new Point(rectangle.Right, rectangle.Bottom);
PixelType = pixels;
}
public TerminalRectangle(Point topLeft, Point bottomRight, TerminalPixel pixels)
{
TopLeft = topLeft;
BottomRight = bottomRight;
PixelType = pixels;
}
public TerminalRectangle(Point topLeft, int width, int height, TerminalPixel pixels)
: this(topLeft, new Point(topLeft.X + width, topLeft.Y + height), pixels)
{ }
public static TerminalRectangle Centered(Point center, int width, int height, TerminalPixel pixels)
{
var tl = new Point(center.X - width / 2, center.Y - height / 2);
return new TerminalRectangle(tl, width, height, pixels);
}
public IEnumerable<TerminalPixel> Render()
{
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
yield return PixelType with
{
Position = new Point(TopLeft.X + x, TopLeft.Y + y)
};
}
}
}
}