Skip to content

Commit 300fb8a

Browse files
committed
grid lines
1 parent ad96cf6 commit 300fb8a

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

FF4MapEdit/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ComboBox x:Name="MapComboBox" Width="300" Height="32" SelectedValuePath="Tag" SelectionChanged="MapComboBox_SelectionChanged" />
2424
</ToolBar>
2525
<ToolBar>
26-
<ToggleButton x:Name="GridButton" ToolTip="Toggle Grid Lines">
26+
<ToggleButton x:Name="GridLinesButton" ToolTip="Toggle Grid Lines" Checked="GridLinesButton_OnChecked" Unchecked="GridLinesButton_OnUnchecked">
2727
<Image Width="32" Height="32" Source="icons/iconfinder_Grid_131737.png"></Image>
2828
</ToggleButton>
2929
<ToggleButton x:Name="FloodFillButton" ToolTip="Flood Fill">

FF4MapEdit/MainWindow.xaml.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)