@@ -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