@@ -55,8 +55,11 @@ public partial class MainWindow : Window, INotifyPropertyChanged
55
55
int prevX ;
56
56
int prevY ;
57
57
58
- // drawing lines
59
58
bool leftShiftDown = false ;
59
+ bool leftCtrlDown = false ;
60
+
61
+
62
+ // drawing lines
60
63
private readonly int ddaMODIFIER_X = 0x7fff ;
61
64
private readonly int ddaMODIFIER_Y = 0x7fff ;
62
65
@@ -453,7 +456,7 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
453
456
}
454
457
break ;
455
458
case ToolMode . Fill :
456
- // NOTE: doesnt work with single pixel area.. because nothing to fill
459
+ // NOTE: double click doesnt work with single pixel area.. because nothing to fill
457
460
if ( wasDoubleClick == true )
458
461
{
459
462
// remove previous pixel by using old color (could take from undo also..)
@@ -466,10 +469,18 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
466
469
currentColor = previousColor ;
467
470
}
468
471
469
- FloodFill ( x , y , ( int ) currentColor . ColorBGRA ) ;
470
- if ( chkMirrorX . IsChecked == true )
472
+ // non-contiguous fill, fills all pixels that match target pixel color
473
+ if ( leftCtrlDown == true )
471
474
{
472
- FloodFill ( canvasResolutionX - x , y , ( int ) currentColor . ColorBGRA ) ;
475
+ ReplacePixels ( previousPixelColor , currentColor ) ;
476
+ }
477
+ else
478
+ {
479
+ FloodFill ( x , y , ( int ) currentColor . ColorBGRA ) ;
480
+ if ( chkMirrorX . IsChecked == true )
481
+ {
482
+ FloodFill ( canvasResolutionX - x , y , ( int ) currentColor . ColorBGRA ) ;
483
+ }
473
484
}
474
485
break ;
475
486
default :
@@ -718,6 +729,9 @@ void OnKeyDown(object sender, KeyEventArgs e)
718
729
lblToolInfo . Content = "Straight Lines" ;
719
730
leftShiftDown = true ;
720
731
break ;
732
+ case Key . LeftCtrl : // left control
733
+ leftCtrlDown = true ;
734
+ break ;
721
735
default :
722
736
break ;
723
737
}
@@ -731,6 +745,9 @@ private void OnKeyUp(object sender, KeyEventArgs e)
731
745
lblToolInfo . Content = "" ;
732
746
leftShiftDown = false ;
733
747
break ;
748
+ case Key . LeftCtrl :
749
+ leftCtrlDown = false ;
750
+ break ;
734
751
default :
735
752
break ;
736
753
}
@@ -910,6 +927,8 @@ void OnCopyImageToClipboard()
910
927
*/
911
928
}
912
929
930
+
931
+
913
932
void FloodFill ( int x , int y , int fillColor )
914
933
{
915
934
// get hit color pixel
@@ -1167,7 +1186,7 @@ private void rectHueBar_MouseDown(object sender, MouseButtonEventArgs e)
1167
1186
1168
1187
private void OnGetTransparentColorButton ( object sender , MouseButtonEventArgs e )
1169
1188
{
1170
- var c = new PixelColor ( 255 , 255 , 255 , 0 ) ;
1189
+ var c = new PixelColor ( 255 , 255 , 255 , 0 ) ;
1171
1190
currentColor = c ;
1172
1191
rectCurrentColor . Fill = c . AsSolidColorBrush ( ) ;
1173
1192
ResetCurrentBrightnessPreview ( currentColor ) ;
@@ -1410,5 +1429,25 @@ private void OnClearButton(object sender, MouseButtonEventArgs e)
1410
1429
}
1411
1430
1412
1431
}
1432
+
1433
+ public void ReplacePixels ( PixelColor find , PixelColor replace )
1434
+ {
1435
+ for ( int x = 0 ; x < canvasResolutionX ; x ++ )
1436
+ {
1437
+ for ( int y = 0 ; y < canvasResolutionY ; y ++ )
1438
+ {
1439
+ var pixel = GetPixelColor ( x , y , canvasBitmap ) ;
1440
+
1441
+ if ( pixel == find )
1442
+ {
1443
+ SetPixel ( outlineBitmap , x , y , ( int ) replace . ColorBGRA ) ;
1444
+ }
1445
+
1446
+ }
1447
+ }
1448
+
1449
+ }
1450
+
1451
+
1413
1452
} // class
1414
1453
} // namespace
0 commit comments