-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackInspector.cs
53 lines (46 loc) · 1.66 KB
/
StackInspector.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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OmsiScriptExampler {
public class StackInspector<T> : Control {
private AbstractStack<T> _abstractStack;
public StackInspector(AbstractStack<T> abstractStack) {
AbstractStack = abstractStack;
AbstractStack.StateChanged += AbstractStackOnStateChanged;
}
public StackInspector() {
}
private void AbstractStackOnStateChanged(object sender, EventArgs eventArgs) {
this.Invalidate();
}
public AbstractStack<T> AbstractStack {
get {
return _abstractStack;
}
set {
_abstractStack = value;
if (_abstractStack == null) return;
_abstractStack.StateChanged += AbstractStackOnStateChanged;
}
}
protected override void OnPaint(PaintEventArgs e) {
if (AbstractStack == null) {
return;
}
e.Graphics.Clear(Color.White);
var colWidth = this.Width / 8;
var rowHeight = this.Height / 2;
for (int i = 0; i < 8; i++) {
e.Graphics.DrawString(i.ToString(), this.Font, Brushes.Black, new PointF(colWidth * i, 0));
var value = AbstractStack.GetItemAt(i);
if (value == null)
continue;
e.Graphics.DrawString(value.ToString(), this.Font, Brushes.Black, new PointF(colWidth * i, rowHeight));
} // for end
}
}
}