@@ -23,10 +23,12 @@ public enum DrawMode : byte
23
23
public partial class MainWindow : Window
24
24
{
25
25
WriteableBitmap canvasBitmap ;
26
+ WriteableBitmap gridBitmap ;
26
27
WriteableBitmap paletteBitmap ;
27
28
Window w ;
28
29
29
30
Image drawingImage ;
31
+ Image gridImage ;
30
32
Image paletteImage ;
31
33
32
34
// bitmap settings
@@ -40,6 +42,8 @@ public partial class MainWindow : Window
40
42
int dpiX = 96 ;
41
43
int dpiY = 96 ;
42
44
45
+ byte gridAlpha = 16 ;
46
+
43
47
// colors
44
48
PixelColor currentColor ;
45
49
PixelColor [ ] palette ;
@@ -66,6 +70,18 @@ public MainWindow()
66
70
67
71
void Start ( )
68
72
{
73
+
74
+ // setup background grid
75
+ gridImage = imgGrid ;
76
+ RenderOptions . SetBitmapScalingMode ( gridImage , BitmapScalingMode . NearestNeighbor ) ;
77
+ RenderOptions . SetEdgeMode ( gridImage , EdgeMode . Aliased ) ;
78
+ w = ( MainWindow ) Application . Current . MainWindow ;
79
+ //var gridScaleX = (int)gridImage.Width / canvasResolutionX;
80
+ gridBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
81
+ gridImage . Source = gridBitmap ;
82
+ DrawBackgroundGrid ( ) ;
83
+
84
+
69
85
// build drawing area
70
86
drawingImage = imgCanvas ;
71
87
RenderOptions . SetBitmapScalingMode ( drawingImage , BitmapScalingMode . NearestNeighbor ) ;
@@ -615,7 +631,6 @@ private void CallUndo()
615
631
if ( currentUndoIndex > 0 )
616
632
{
617
633
canvasBitmap = undoBufferBitmap [ -- currentUndoIndex ] ;
618
- Console . WriteLine ( "restore undo " + currentUndoIndex ) ;
619
634
imgCanvas . Source = canvasBitmap ;
620
635
}
621
636
}
@@ -629,5 +644,23 @@ public void CanExecute_Undo(object sender, CanExecuteRoutedEventArgs e)
629
644
{
630
645
e . CanExecute = true ;
631
646
}
647
+
648
+ void DrawBackgroundGrid ( )
649
+ {
650
+ for ( int x = 0 ; x < 16 ; x ++ )
651
+ {
652
+ for ( int y = 0 ; y < 16 ; y ++ )
653
+ {
654
+ PixelColor c = new PixelColor ( ) ;
655
+ c . Alpha = gridAlpha ;
656
+ byte v = ( byte ) ( ( ( x % 2 ) == ( y % 2 ) ) ? 255 : 0 ) ;
657
+ c . Red = v ;
658
+ c . Green = v ;
659
+ c . Blue = v ;
660
+ SetPixel ( gridBitmap , x , y , ( int ) c . ColorBGRA ) ;
661
+ }
662
+ }
663
+ }
664
+
632
665
} // class
633
666
} // namespace
0 commit comments