@@ -30,6 +30,7 @@ public partial class MainWindow : Window
3030
3131 private byte _selectedTile ;
3232 private GeometryDrawing _selectedTileDrawing = new GeometryDrawing ( ) ;
33+ private GeometryDrawing _gridLinesDrawing = new GeometryDrawing ( ) ;
3334 private WriteableBitmap [ ] _rowBitmaps ;
3435
3536 private bool _painting = false ;
@@ -200,9 +201,30 @@ private void LoadWorldMapTiles()
200201 new Rect ( new Point ( 0 , 16 * y ) , new Size ( 16 * _map . Width , 16 ) ) ) ) ;
201202 }
202203
203- Map . Source = new DrawingImage ( rowGroup ) ;
204204 Map . Width = 16 * _map . Width ;
205205 Map . Height = 16 * _map . Height ;
206+
207+ var geometry = new GeometryGroup ( ) ;
208+ for ( int x = 0 ; x <= _map . Width ; x ++ )
209+ {
210+ geometry . Children . Add ( new LineGeometry ( new Point ( 16 * x , 0 ) , new Point ( 16 * x , Map . Height ) ) ) ;
211+ }
212+ for ( int y = 0 ; y <= _map . Height ; y ++ )
213+ {
214+ geometry . Children . Add ( new LineGeometry ( new Point ( 0 , 16 * y ) , new Point ( Map . Width , 16 * y ) ) ) ;
215+ }
216+ _gridLinesDrawing = new GeometryDrawing
217+ {
218+ Geometry = geometry ,
219+ Brush = Brushes . Transparent ,
220+ Pen = new Pen ( Brushes . Black , 1 )
221+ } ;
222+ if ( GridLinesButton . IsChecked == true )
223+ {
224+ rowGroup . Children . Add ( _gridLinesDrawing ) ;
225+ }
226+
227+ Map . Source = new DrawingImage ( rowGroup ) ;
206228 }
207229
208230 private void SaveWorldMap ( )
@@ -255,6 +277,18 @@ private void HighlightSelectedTile(int x, int y)
255277 tileGroup . Children . Add ( _selectedTileDrawing ) ;
256278 }
257279
280+ private void GridLinesButton_OnChecked ( object sender , RoutedEventArgs e )
281+ {
282+ var rowGroup = ( DrawingGroup ) ( ( DrawingImage ) Map . Source ) . Drawing ;
283+ rowGroup . Children . Add ( _gridLinesDrawing ) ;
284+ }
285+
286+ private void GridLinesButton_OnUnchecked ( object sender , RoutedEventArgs e )
287+ {
288+ var rowGroup = ( DrawingGroup ) ( ( DrawingImage ) Map . Source ) . Drawing ;
289+ rowGroup . Children . Remove ( _gridLinesDrawing ) ;
290+ }
291+
258292 private void CheckTilePropertyBoxes ( )
259293 {
260294 var tileProperties = ( WorldTileProperties ) _tileset . TileProperties [ _selectedTile ] ;
0 commit comments