-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMainWindow.xaml.cs
156 lines (130 loc) · 4.67 KB
/
MainWindow.xaml.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
using System;
using Microsoft.Win32;
using System.Windows;
using System.Windows.Controls;
namespace MatrixGraphicsGenerator
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
Matrix matrix;
Collection collection;
CollectionEditWindow collectionEditWindow;
public MainWindow()
{
InitializeComponent();
matrix = new Matrix(new Tuple<int, int>(8, 8), MatrixGrid, CodeTextBox, CodeTypeButton, NameTextBox);
}
/// <summary>
/// Turns on necessary collection buttons
/// </summary>
void SwitchToCollectionMode()
{
AddToCollectionButton.IsEnabled = true;
NameTextBox.IsEnabled = true;
EditCollectionButton.IsEnabled = true;
ExportCollectionButton.IsEnabled = true;
if (collectionEditWindow != null)
collectionEditWindow.Close();
}
private void DisableAllButton_Click(object sender, RoutedEventArgs e)
{
matrix.SetAll(false);
}
private void EnableAllButton_Click(object sender, RoutedEventArgs e)
{
matrix.SetAll(true);
}
private void InvertButton_Click(object sender, RoutedEventArgs e)
{
matrix.InvertAll();
}
private void CopyButton_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(CodeTextBox.Text);
}
private void NewCollectionButton_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "JSON (*.json)|*.json";
if (dialog.ShowDialog() == true)
{
collection = new Collection(dialog.FileName);
SwitchToCollectionMode();
}
}
private void OpenCollectionButton_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JSON (*.json)|*.json";
if (dialog.ShowDialog() == true)
{
collection = new Collection(dialog.FileName);
SwitchToCollectionMode();
}
}
private void AddToCollectionButton_Click(object sender, RoutedEventArgs e)
{
collection.AddGraphic(matrix.GetMatrixData());
if (collectionEditWindow != null)
collectionEditWindow.DisplayCollection(collection, matrix, MatrixGrid);
}
private void EditCollectionButton_Click(object sender, RoutedEventArgs e)
{
collectionEditWindow = new CollectionEditWindow();
collectionEditWindow.DisplayCollection(collection, matrix, MatrixGrid);
collectionEditWindow.Owner = this;
collectionEditWindow.Show();
}
private void ShiftLeftButton_Click(object sender, RoutedEventArgs e)
{
matrix.ShiftHorizontally(false);
}
private void ShiftRightButton_Click(object sender, RoutedEventArgs e)
{
matrix.ShiftHorizontally(true);
}
private void ShiftUpwardsButton_Click(object sender, RoutedEventArgs e)
{
matrix.ShiftVertically(true);
}
private void ShiftDownwardsButton_Click(object sender, RoutedEventArgs e)
{
matrix.ShiftVertically(false);
}
private void ResizeButton_Click(object sender, RoutedEventArgs e)
{
ResizeWindow resizeWindow = new ResizeWindow(matrix);
resizeWindow.Show();
}
private void ExportCollectionButton_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Arduino/C (*.c)|*.c";
if (dialog.ShowDialog() == true)
{
collection.Export(dialog.FileName);
SwitchToCollectionMode();
}
}
private void TextChangedEventHandler(object sender, TextChangedEventArgs args)
{
if (collection == null)
return;
bool graphicExists = false;
collection.Graphics.ForEach(x =>
{
if (NameTextBox.Text == x.Name)
{
graphicExists = true;
AddToCollectionButton.Content = "Overwrite";
return;
}
});
if (AddToCollectionButton != null && !graphicExists)
AddToCollectionButton.Content = "Add to Collection";
}
}
}