Skip to content

Commit 661153c

Browse files
committed
paint
1 parent 92cbf3c commit 661153c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

FF4MapEdit/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</ToolBarTray>
2020
<Image x:Name="Tileset" HorizontalAlignment="Left" Height="128" Margin="10,35,0,0" VerticalAlignment="Top" Width="256" MouseLeftButtonUp="Tileset_MouseLeftButtonUp"/>
2121
<ScrollViewer HorizontalScrollBarVisibility="Auto" HorizontalAlignment="Left" Height="644" Margin="271,35,0,0" VerticalAlignment="Top" Width="991">
22-
<Image x:Name="Map" HorizontalAlignment="Left" Height="4096" Margin="0,0,0,0" VerticalAlignment="Top" Width="4096" MouseLeftButtonUp="Map_MouseLeftButtonUp"/>
22+
<Image x:Name="Map" HorizontalAlignment="Left" Height="4096" Margin="0,0,0,0" VerticalAlignment="Top" Width="4096" MouseLeftButtonUp="Map_MouseLeftButtonUp" MouseLeftButtonDown="Map_MouseLeftButtonDown" MouseMove="Map_MouseMove"/>
2323
</ScrollViewer>
2424
</Grid>
2525
</Window>

FF4MapEdit/MainWindow.xaml.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public partial class MainWindow : Window
3232
private GeometryDrawing _selectedTileDrawing = new GeometryDrawing();
3333
private WriteableBitmap[] _rowBitmaps;
3434

35+
private bool _painting = false;
36+
3537
public MainWindow()
3638
{
3739
InitializeComponent();
@@ -87,7 +89,7 @@ private void Tileset_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
8789
tileGroup.Children.Add(_selectedTileDrawing);
8890
}
8991

90-
private void Map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
92+
private void Map_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
9193
{
9294
if (_selectedTile == -1)
9395
{
@@ -101,6 +103,27 @@ private void Map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
101103
return;
102104
}
103105

106+
Paint(x, y);
107+
_painting = true;
108+
}
109+
110+
private void Map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
111+
{
112+
_painting = false;
113+
}
114+
115+
private void Map_MouseMove(object sender, MouseEventArgs e)
116+
{
117+
if (_painting)
118+
{
119+
int x, y;
120+
GetClickedTile(sender, e, out x, out y);
121+
Paint(x, y);
122+
}
123+
}
124+
125+
private void Paint(int x, int y)
126+
{
104127
_map[256*y + x] = (byte)_selectedTile;
105128

106129
_rowBitmaps[y].Lock();
@@ -111,6 +134,17 @@ private void Map_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
111134
private void GetClickedTile(object sender, MouseButtonEventArgs e, out int x, out int y)
112135
{
113136
var position = e.GetPosition((IInputElement)sender);
137+
PixelsToTile(position, out x, out y);
138+
}
139+
140+
private void GetClickedTile(object sender, MouseEventArgs e, out int x, out int y)
141+
{
142+
var position = e.GetPosition((IInputElement)sender);
143+
PixelsToTile(position, out x, out y);
144+
}
145+
146+
private static void PixelsToTile(Point position, out int x, out int y)
147+
{
114148
x = (int)position.X;
115149
y = (int)position.Y;
116150
x /= 16;

0 commit comments

Comments
 (0)