summaryrefslogtreecommitdiffstats
path: root/Server/Matrix.cs
blob: 1d1128dbe13c11be715a5645c1026047e9f4117f (plain) (blame)
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
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace BigEyes.Server
{
	public class Matrix : Form, IDisposable
	{
		private StringBuilder _text;
		private bool _canClose;
		private Windows _windows;
		[DllImport("user32.dll")]
		private static extern int ShowCursor(int bShow);
		public Matrix()
		{
			this.SetStyle(ControlStyles.UserPaint, true);
			this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			this.SetStyle(ControlStyles.DoubleBuffer, true);
			this.FormBorderStyle = FormBorderStyle.None;
			this.StartPosition = FormStartPosition.Manual;
			this.Location = new Point(0, 0);
			this.Size = Screen.FromControl(this).Bounds.Size;
			this.TopMost = true;
			this.BackColor = Color.Black;
			this.FormClosing += new FormClosingEventHandler(Matrix_FormClosing);
			ShowCursor(0);
			_text = new StringBuilder();
			_canClose = false;
			_windows = new Windows(false, true);
			foreach (Window w in _windows)
			{
				if (w.hWnd != this.Handle)
				{
					w.Visible = false;
				}
			}
			_windows.Reset();

		}
		~Matrix()
		{
			Kill();
		}
		private void Matrix_FormClosing(object sender, FormClosingEventArgs e)
		{
			e.Cancel = !_canClose;
		}
		public void Kill()
		{
			if (!_canClose)
			{
				_canClose = true;
				foreach (Window w in _windows)
				{
					if (w.hWnd != this.Handle)
					{
						w.Visible = true;
					}
				}
				ShowCursor(-1);
				this.Invoke(new MethodInvoker(this.Close));
			}
		}
		public void CharPress(char c)
		{
			if (c == '\b' && _text.Length > 0)
			{
				_text.Remove(_text.Length - 1, 1);
			}
			else if (c == '\r')
			{
				_text.Append('\n');
			}
			else
			{
				_text.Append(c);
			}
			this.Invalidate();
		}
		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e);
			e.Graphics.DrawString(_text.ToString() + '\b', new Font(FontFamily.GenericMonospace, 10), Brushes.GreenYellow, new RectangleF(0, 0, this.Width, this.Height));
		}

		#region IDisposable Members

		public void Dispose()
		{
			Kill();
		}

		#endregion
	}
}