@@ -44,6 +44,8 @@ public partial class MainWindow : Window, INotifyPropertyChanged
44
44
45
45
// colors
46
46
PixelColor currentColor ;
47
+ PixelColor eraseColor = new PixelColor ( 0 , 0 , 0 , 0 ) ;
48
+
47
49
PixelColor [ ] palette ;
48
50
PixelColor lightColor ;
49
51
PixelColor darkColor ;
@@ -59,7 +61,6 @@ public partial class MainWindow : Window, INotifyPropertyChanged
59
61
bool leftShiftDown = false ;
60
62
bool leftCtrlDown = false ;
61
63
62
-
63
64
// drawing lines
64
65
private readonly int ddaMODIFIER_X = 0x7fff ;
65
66
private readonly int ddaMODIFIER_Y = 0x7fff ;
@@ -149,7 +150,7 @@ void Start(bool loadSettings = true)
149
150
darkColor . Alpha = gridAlpha ;
150
151
151
152
// get values from settings
152
- if ( loadSettings == true ) LoadSettings ( ) ;
153
+ if ( loadSettings == true ) LoadSettings ( ) ;
153
154
154
155
// setup background grid
155
156
gridBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
@@ -250,12 +251,13 @@ void DrawPixel(int x, int y)
250
251
251
252
void ErasePixel ( int x , int y )
252
253
{
253
- byte [ ] ColorData = { 0 , 0 , 0 , 0 } ; // B G R
254
+ // byte[] ColorData = { 0, 0, 0, 0 }; // B G R
254
255
if ( x < 0 || x > canvasResolutionX - 1 ) return ;
255
256
if ( y < 0 || y > canvasResolutionY - 1 ) return ;
256
257
257
- Int32Rect rect = new Int32Rect ( x , y , 1 , 1 ) ;
258
- canvasBitmap . WritePixels ( rect , ColorData , 4 , 0 ) ;
258
+ // Int32Rect rect = new Int32Rect(x, y, 1, 1);
259
+ // canvasBitmap.WritePixels(rect, ColorData, 4, 0);
260
+ SetPixel ( canvasBitmap , x , y , ( int ) eraseColor . ColorBGRA ) ;
259
261
}
260
262
261
263
void PickPalette ( MouseEventArgs e )
@@ -713,12 +715,20 @@ void OnKeyDown(object sender, KeyEventArgs e)
713
715
rectCurrentColor . Fill = currentColor . AsSolidColorBrush ( ) ;
714
716
break ;
715
717
case Key . X : // swap current/secondary colors
716
- var tempcolor = rectCurrentColor . Fill ;
717
- rectCurrentColor . Fill = rectSecondaryColor . Fill ;
718
- rectSecondaryColor . Fill = tempcolor ;
719
- // TODO move to converter
720
- var t = ( ( SolidColorBrush ) rectCurrentColor . Fill ) . Color ;
721
- currentColor = new PixelColor ( t . R , t . G , t . B , t . A ) ;
718
+ if ( leftShiftDown == true ) // swap eraser colors
719
+ {
720
+ var tempcolor = rectEraserColor . Fill ;
721
+ rectEraserColor . Fill = rectEraserColorSecondary . Fill ;
722
+ rectEraserColorSecondary . Fill = tempcolor ;
723
+ eraseColor = new PixelColor ( ( ( SolidColorBrush ) rectEraserColor . Fill ) . Color ) ;
724
+ }
725
+ else // regular color
726
+ {
727
+ var tempcolor = rectCurrentColor . Fill ;
728
+ rectCurrentColor . Fill = rectSecondaryColor . Fill ;
729
+ rectSecondaryColor . Fill = tempcolor ;
730
+ currentColor = new PixelColor ( ( ( SolidColorBrush ) rectCurrentColor . Fill ) . Color ) ;
731
+ }
722
732
break ;
723
733
case Key . B : // brush
724
734
CurrentTool = ToolMode . Draw ;
@@ -732,6 +742,7 @@ void OnKeyDown(object sender, KeyEventArgs e)
732
742
break ;
733
743
case Key . LeftCtrl : // left control
734
744
leftCtrlDown = true ;
745
+ lblCtrlInfo . Content = "Double click to replace target colors" ;
735
746
break ;
736
747
default :
737
748
break ;
@@ -748,6 +759,7 @@ private void OnKeyUp(object sender, KeyEventArgs e)
748
759
break ;
749
760
case Key . LeftCtrl :
750
761
leftCtrlDown = false ;
762
+ lblCtrlInfo . Content = "-" ;
751
763
break ;
752
764
default :
753
765
break ;
@@ -1390,7 +1402,7 @@ private void drawingImage_MouseEnter(object sender, MouseEventArgs e)
1390
1402
private void OnClearButton ( object sender , MouseButtonEventArgs e )
1391
1403
{
1392
1404
// shiftdown or right button, just clear without dialog
1393
- if ( leftShiftDown == true || ( e != null && e . RightButton == MouseButtonState . Pressed ) )
1405
+ if ( leftShiftDown == true || ( e != null && e . RightButton == MouseButtonState . Pressed ) )
1394
1406
{
1395
1407
ClearImage ( canvasBitmap , emptyRect , emptyPixels , emptyStride ) ;
1396
1408
UpdateOutline ( ) ;
@@ -1429,7 +1441,6 @@ private void OnClearButton(object sender, MouseButtonEventArgs e)
1429
1441
Console . WriteLine ( "Unknown error.." ) ;
1430
1442
break ;
1431
1443
}
1432
-
1433
1444
}
1434
1445
1435
1446
public void ReplacePixels ( PixelColor find , PixelColor replace )
@@ -1442,12 +1453,10 @@ public void ReplacePixels(PixelColor find, PixelColor replace)
1442
1453
1443
1454
if ( pixel == find )
1444
1455
{
1445
- SetPixel ( outlineBitmap , x , y , ( int ) replace . ColorBGRA ) ;
1456
+ SetPixel ( canvasBitmap , x , y , ( int ) replace . ColorBGRA ) ;
1446
1457
}
1447
-
1448
1458
}
1449
1459
}
1450
-
1451
1460
}
1452
1461
1453
1462
// current color box
0 commit comments