-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalPixel.cs
More file actions
66 lines (52 loc) · 1.76 KB
/
TerminalPixel.cs
File metadata and controls
66 lines (52 loc) · 1.76 KB
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
using System.Diagnostics;
using System.Drawing;
namespace TerminalRenderer;
[DebuggerDisplay("({Position.X}, {Position.Y}) | {BackgroundColor.Name}")]
public struct TerminalPixel : ITerminalRenderable
{
public Point Position = Point.Empty;
public Color BackgroundColor = Color.Black;
public Color ForegroundColor = Color.White;
private string _pixelContent = " ";
public static int PixelContentLength = 2;
public static TerminalPixel Default = new();
public string PixelContent
{
get => _pixelContent;
init
{
if (value.Length != PixelContentLength)
throw new Exception($"Pixel value has to be {PixelContentLength} characters");
_pixelContent = value;
}
}
public TerminalPixel()
{
PixelContent = " ";
BackgroundColor = Color.Black;
ForegroundColor = Color.White;
Position = Point.Empty;
}
public TerminalPixel(Point position, Color color)
{
Position = position;
BackgroundColor = color;
}
public TerminalPixel(Color color)
{
BackgroundColor = color;
}
public TerminalPixel(Point position)
{
Position = position;
}
public bool EquivalentTo(TerminalPixel b)
{
return BackgroundColor.ToArgb() == b.BackgroundColor.ToArgb()
&& ForegroundColor.ToArgb() == b.ForegroundColor.ToArgb()
&& _pixelContent == b._pixelContent;
}
public Point GetFramePosition(Point viewOffset) => new(Position.X - viewOffset.X, Position.Y - viewOffset.Y);
public Point GetFramePosition(TerminalDisplay display) => GetFramePosition(display.CameraPosition);
public IEnumerable<TerminalPixel> Render() => new[] {this};
}