forked from Thraka/SadConsole.Drawing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.cs
199 lines (179 loc) · 7.79 KB
/
Cell.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System.Drawing;
using System.Runtime.Serialization;
namespace SadConsole
{
/// <summary>
/// Represents an individual glyph on the screen with a foreground, background, and effect.
/// </summary>
[DataContract]
public class Cell : ICellAppearance
{
private int _glyphIndex;
private Color _foreground;
private Color _background;
//private SpriteEffects _spriteEffect;
/// <summary>
/// The desired foreground color of this cell. When set, copies the value to ActualForeground.
/// </summary>
[DataMember]
public Color Foreground
{
get { return _foreground; }
set
{
_foreground = value;
ActualForeground = value;
}
}
/// <summary>
/// The desired background color of this cell. When set, copies the value to ActualBackground.
/// </summary>
[DataMember]
public Color Background
{
get { return _background; }
set
{
_background = value;
ActualBackground = value;
}
}
/// <summary>
/// The glyph index of the graphic font to print when this cell is drawn. When set, copies the value to <see cref="ActualGlyphIndex"/>.
/// </summary>
[DataMember]
public int GlyphIndex
{
get { return _glyphIndex; }
set
{
_glyphIndex = value;
ActualGlyphIndex = value;
}
}
///// <summary>
///// The SpriteBatch sprite mirror effect used when rendering the cell. Defaults to None.
///// </summary>
//[DataMember]
//public SpriteEffects SpriteEffect
//{
// get { return _spriteEffect; }
// set { _spriteEffect = value; ActualSpriteEffect = value; }
//}
/// <summary>
/// The actual foreground color of this cell when drawing.
/// <remarks>The actual foreground may or may not match the desired foreground. When effects are processed, they will normally set this value. If the effect is removed, the actual foreground color is taken from desired foreground color.</remarks>
/// </summary>
public virtual Color ActualForeground { get; set; }
/// <summary>
/// The actual background color of this cell when drawing.
/// <remarks>The actual background may or may not match the desired background. When effects are processed, they will normally set this value. If the effect is removed, the actual background color is taken from desired background color.</remarks>
/// </summary>
public virtual Color ActualBackground { get; set; }
/// <summary>
/// The actual glyph index of this cell when drawing.
/// <remarks>The actual index may or may not match the desired index. When effects are processed, they may change this value. If the effect is removed, the actual index is taken from desired index.</remarks>
/// </summary>
public virtual int ActualGlyphIndex { get; set; }
/// <summary>
/// The effect associated with this cell. Processed by the <see cref="T:SadConsole.TextSurface"/> class.
/// </summary>
//public Effects.ICellEffect Effect { get; set; }
/// <summary>
/// true when this cell will be drawn; otehrwise false.
/// </summary>
[DataMember]
public bool IsVisible { get; set; }
//[DataMember]
///// <summary>
///// The SpriteBatch sprite mirror effect used when rendering the cell.
///// </summary>
///// <remarks>The actual sprite effect may or may not match the desired sprite effect. When cell effects are processed, they may change this value. If the cell effect is removed, the actual sprite effect is taken from desired sprite effect.</remarks>
//public SpriteEffects ActualSpriteEffect { get; set; }
#region Constructors
public Cell()
{
Reset();
}
#endregion
/// <summary>
/// Resets this cell with default values.
/// </summary>
public virtual void Reset()
{
Foreground = Color.White;
Background = Color.Transparent;
GlyphIndex = 0;
IsVisible = true;
//SpriteEffect = SpriteEffects.None;
//Effect = null;
}
/// <summary>
/// Returns a string representing the Actual* property values.
/// </summary>
/// <returns>A string representing this cell.</returns>
public override string ToString()
{
return string.Format("{0} {1} {2}", ActualGlyphIndex, ActualForeground.ToString(), ActualBackground.ToString());
}
/// <summary>
/// This should be called by anything creating and configuring a cell on the console. Configure the cell (foreground, background, index etc) and then call this.
/// </summary>
public virtual void OnCreated() { }
/// <summary>
/// Copies this cells information to a new cell. Preserves appearance, Actual* properties, and glyph information.
/// </summary>
/// <param name="destination">The cell to copy to.</param>
public virtual void Copy(Cell destination)
{
CopyAppearanceTo(destination);
destination.ActualGlyphIndex = this.ActualGlyphIndex;
destination.ActualBackground = this.ActualBackground;
destination.ActualForeground = this.ActualForeground;
//destination.ActualSpriteEffect = this.ActualSpriteEffect;
}
/// <summary>
/// Applies this appearance instance values to the destination appearance.
/// </summary>
/// <param name="destination">The target of the appearance copy.</param>
public void CopyAppearanceTo(ICellAppearance destination)
{
destination.Foreground = this.Foreground;
destination.Background = this.Background;
destination.GlyphIndex = this.GlyphIndex;
//destination.SpriteEffect = this.SpriteEffect;
}
///// <summary>
///// Updates and applies the <see cref="P:SadConsole.Cell.Effect"/> to this cell. WARNING: Do not use with TextSurface. This should only be called when the cell has a standalone effect that isn't managed by the TextSurface.
///// </summary>
//public void UpdateAndApplyEffect(double elapsedTime)
//{
// if (Effect != null)
// {
// Effect.Update(elapsedTime);
// Effect.Apply(this);
// }
//}
/// <summary>
/// Draws a single cell using the specified SpriteBatch.
/// </summary>
/// <param name="batch">Rendering batch.</param>
/// <param name="position">Pixel position on the screen to render.</param>
/// <param name="size">Rendering size of the cell.</param>
/// <param name="font">Font used to draw the cell.</param>
public void Render(SpriteBatch batch, Point position, Point size, Font font)
{
Render(batch, new Rectangle(position.X, position.Y, size.X, size.Y), font);
}
/// <summary>
/// Draws a single cell using the specified SpriteBatch.
/// </summary>
/// <param name="batch">Rendering batch.</param>
/// <param name="drawingRectangle">Where on the sreen to draw the cell, in pixels.</param>
/// <param name="font">Font used to draw the cell.</param>
public void Render(SpriteBatch batch, Rectangle drawingRectangle, Font font)
{
batch.DrawCell(this, drawingRectangle, font.SolidGlyphRectangle, Color.Transparent, font);
}
}
}