-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.cs
81 lines (80 loc) · 2.46 KB
/
GUI.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
using System;
using System.Reflection;
using System.Collections.Generic;
namespace BasicGUI
{
public class GUI
{
public static int DebugSleepTime { get; set; } = 50;
public static int OrigBufferWidth { get; set; }
public static int OrigBufferHeight { get; set; }
public static int GutterSize { get; set; } = 2;
public static int TotalRowGutterSize => GUI.GutterSize * ( Rows.Count + 1 );
public static int RowHeight => ( GUI.OrigBufferHeight - GUI.TotalRowGutterSize ) / GUI.Rows.Count;
public static IUserInput UserInput { get; set; }
public static List<Row> Rows { get; set; }
public bool TitleSet { get; set; }
public GUI()
{
GUI.OrigBufferWidth = Console.BufferWidth;
GUI.OrigBufferHeight = Console.BufferHeight;
GUI.Rows = new List<Row>();
GUI.UserInput = new UserInput();
}
public void SetTitle(Assembly assembly, string resourceName)
{
IWindow title = new TitleWindow(assembly, resourceName);
this.AddRow(title);
this.TitleSet = true;
}
public void AddRow(List<IWindow> windows)
{
Row row = new Row();
row.OpenWindows(windows);
GUI.Rows.Add(row);
}
public void AddRow(IWindow window)
{
Row row = new Row();
row.OpenWindow(window);
GUI.Rows.Add(row);
}
public void CloseWindow(IWindow window)
{
foreach ( IRow row in Rows )
{
if ( row.Windows.Contains(window) )
{
row.Windows.Remove(window);
row.DistributeWindows();
this.Refresh();
}
}
}
public void CloseAll()
{
if (this.TitleSet == false)
{
GUI.Rows = new List<Row>();
}
else
{
for ( int i = 1; i < GUI.Rows.Count; i++ )
{
GUI.Rows.RemoveAt(i);
}
}
}
public void Refresh()
{
int i = 0;
Console.Clear();
foreach (Row row in Rows)
{
row.RowTop = ( (GUI.GutterSize + GUI.RowHeight) * i ) + GUI.GutterSize;
row.DistributeWindows();
i++;
}
}
}
}