@@ -19,11 +19,20 @@ public partial class FormMain : Form
1919 private RectangleF _innerDrawingArea ;
2020 private int _ledSize , _rotation = 0 ;
2121 private double LedAngleBetweenColumns = 360 / LedColumns ;
22+ private Brush _colorBody , _colorEnabled , _colorDisabled ;
23+ private string _lastFile ;
2224
2325 public FormMain ( )
2426 {
2527 InitializeComponent ( ) ;
26- pictureBoxEditor . AllowDrop = true ;
28+ UpdateGui ( ) ;
29+ //pictureBoxEditor.AllowDrop = true;
30+
31+ // Default colors
32+ colorDialogBody . Color = Color . Yellow ;
33+ colorDialogHoles . Color = Color . LightGoldenrodYellow ;
34+ colorDialogLights . Color = Color . Blue ;
35+ UpdateColors ( ) ;
2736 }
2837
2938 private void pictureBoxEditor_Paint ( object sender , PaintEventArgs e )
@@ -39,7 +48,7 @@ private void pictureBoxEditor_Paint(object sender, PaintEventArgs e)
3948 e . Graphics . CompositingQuality = CompositingQuality . HighSpeed ;
4049 e . Graphics . SmoothingMode = SmoothingMode . HighQuality ;
4150 e . Graphics . FillRectangle ( Brushes . White , pictureBoxEditor . DisplayRectangle ) ;
42- e . Graphics . FillEllipse ( Brushes . Yellow , _drawingArea ) ;
51+ e . Graphics . FillEllipse ( _colorBody , _drawingArea ) ;
4352 e . Graphics . DrawEllipse ( Pens . Black , _drawingArea ) ;
4453
4554 e . Graphics . FillEllipse ( Brushes . White , _innerDrawingArea ) ;
@@ -56,15 +65,25 @@ private void pictureBoxEditor_Paint(object sender, PaintEventArgs e)
5665 p = RotatePoint ( p , _center , r + LedAngleBetweenColumns ) ;
5766 r = 0 ;
5867
59- e . Graphics . FillEllipse ( GetBit ( i + j * LedRows ) ? Brushes . Blue : Brushes . LightYellow ,
68+ e . Graphics . FillEllipse ( GetBit ( i + j * LedRows ) ? _colorEnabled : _colorDisabled ,
6069 p . X - _ledSize / 2 , p . Y - _ledSize / 2 , _ledSize , _ledSize ) ;
6170 }
6271 }
6372 }
6473
6574 private void LoadBin ( string path )
6675 {
76+ _lastFile = path ;
6777 _bits = new BitArray ( File . ReadAllBytes ( path ) . SelectMany ( GetBits ) . ToArray ( ) ) ;
78+ pictureBoxEditor . Invalidate ( ) ;
79+
80+ UpdateGui ( ) ;
81+ }
82+
83+ private void UpdateGui ( )
84+ {
85+ openNextFileToolStripMenuItem . Enabled = ! string . IsNullOrEmpty ( _lastFile ) ;
86+ Text = ( string . IsNullOrEmpty ( _lastFile ) ? "" : Path . GetFileName ( _lastFile ) + " - " ) + "Fidget Spinner Editor" ;
6887 }
6988
7089 private static IEnumerable < bool > GetBits ( byte b )
@@ -113,10 +132,7 @@ private void quitToolStripMenuItem_Click(object sender, EventArgs e)
113132 private void openToolStripMenuItem_Click ( object sender , EventArgs e )
114133 {
115134 if ( openFileDialogBin . ShowDialog ( ) == DialogResult . OK )
116- {
117135 LoadBin ( openFileDialogBin . FileName ) ;
118- pictureBoxEditor . Invalidate ( ) ;
119- }
120136 }
121137
122138 private void pictureBoxEditor_MouseMove ( object sender , MouseEventArgs e )
@@ -194,21 +210,34 @@ private void counterclockwiseToolStripMenuItem_Click(object sender, EventArgs e)
194210 private void bodyToolStripMenuItem_Click ( object sender , EventArgs e )
195211 {
196212 colorDialogBody . ShowDialog ( ) ;
213+ UpdateColors ( ) ;
214+ }
215+
216+ private void UpdateColors ( )
217+ {
218+ _colorBody = new SolidBrush ( colorDialogBody . Color ) ;
219+ _colorDisabled = new SolidBrush ( colorDialogHoles . Color ) ;
220+ _colorEnabled = new SolidBrush ( colorDialogLights . Color ) ;
221+ pictureBoxEditor . Invalidate ( ) ;
197222 }
198223
199224 private void lightsToolStripMenuItem_Click ( object sender , EventArgs e )
200225 {
201226 colorDialogLights . ShowDialog ( ) ;
227+ UpdateColors ( ) ;
202228 }
203229
204230 private void holesToolStripMenuItem_Click ( object sender , EventArgs e )
205231 {
206232 colorDialogHoles . ShowDialog ( ) ;
233+ UpdateColors ( ) ;
207234 }
208235
209236 private void newToolStripMenuItem_Click ( object sender , EventArgs e )
210237 {
211238 _bits . SetAll ( false ) ;
239+ _lastFile = null ;
240+ UpdateGui ( ) ;
212241 pictureBoxEditor . Invalidate ( ) ;
213242 }
214243
@@ -228,6 +257,19 @@ private void pictureBoxEditor_DragDrop(object sender, DragEventArgs e)
228257
229258 }
230259
260+ private void openNextFileToolStripMenuItem_Click ( object sender , EventArgs e )
261+ {
262+ var loadNext = false ;
263+ foreach ( var f in Directory . GetFiles ( Path . GetDirectoryName ( _lastFile ) , "*.bin" ) )
264+ if ( f == _lastFile )
265+ loadNext = true ;
266+ else if ( loadNext )
267+ {
268+ LoadBin ( f ) ;
269+ break ;
270+ }
271+ }
272+
231273 private void importToolStripMenuItem_Click ( object sender , EventArgs e )
232274 {
233275 if ( openFileDialogImport . ShowDialog ( ) == DialogResult . OK )
0 commit comments