@@ -157,6 +157,13 @@ void Start()
157
157
w . MouseWheel += new MouseWheelEventHandler ( DrawingMouseWheel ) ;
158
158
drawingImage . MouseUp += new MouseButtonEventHandler ( DrawingMouseUp ) ;
159
159
160
+ // FIXME init undos
161
+ for ( int i = 0 ; i < maxUndoCount ; i ++ )
162
+ {
163
+ undoBufferBitmap [ i ] = canvasBitmap . Clone ( ) ;
164
+ }
165
+
166
+
160
167
// build palette
161
168
paletteImage = imgPalette ;
162
169
RenderOptions . SetBitmapScalingMode ( paletteImage , BitmapScalingMode . NearestNeighbor ) ;
@@ -432,7 +439,15 @@ void PaletteLeftButtonDown(object sender, MouseButtonEventArgs e)
432
439
433
440
void DrawingRightButtonDown ( object sender , MouseButtonEventArgs e )
434
441
{
435
- ErasePixel ( e ) ;
442
+ int x = ( int ) ( e . GetPosition ( drawingImage ) . X / canvasScaleX ) ;
443
+ int y = ( int ) ( e . GetPosition ( drawingImage ) . Y / canvasScaleX ) ;
444
+
445
+ ErasePixel ( x , y ) ;
446
+
447
+ if ( chkMirrorX . IsChecked == true )
448
+ {
449
+ ErasePixel ( canvasResolutionX - x , y ) ;
450
+ }
436
451
}
437
452
438
453
void DrawingMiddleButtonDown ( object sender , MouseButtonEventArgs e )
@@ -451,9 +466,11 @@ void DrawingMiddleButtonDown(object sender, MouseButtonEventArgs e)
451
466
void DrawingLeftButtonDown ( object sender , MouseButtonEventArgs e )
452
467
{
453
468
// undo test
454
- undoBufferBitmap [ currentUndoIndex ++ ] = canvasBitmap . Clone ( ) ;
469
+ //undoBufferBitmap[currentUndoIndex++] = canvasBitmap.Clone();
470
+ currentUndoIndex = ++ currentUndoIndex % maxUndoCount ; // wrap
471
+ CopyBitmapPixels ( canvasBitmap , undoBufferBitmap [ currentUndoIndex ] ) ;
455
472
456
- // FIXME if undobuffer enabled above, sometimes Exception thrown: 'System.IndexOutOfRangeException' in PixelArtTool.exe
473
+ // FIXME if undobuffer clone enabled above, sometimes Exception thrown: 'System.IndexOutOfRangeException' in PixelArtTool.exe
457
474
// An unhandled exception of type 'System.IndexOutOfRangeException' occurred in PixelArtTool.exe
458
475
// Index was outside the bounds of the array.
459
476
// Console.WriteLine(drawingImage);
@@ -469,11 +486,15 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
469
486
// mirror
470
487
if ( chkMirrorX . IsChecked == true )
471
488
{
472
- DrawPixel ( canvasResolutionX - x - 1 , y ) ;
489
+ DrawPixel ( canvasResolutionX - x , y ) ;
473
490
}
474
491
break ;
475
492
case ToolMode . Fill :
476
493
FloodFill ( x , y , ( int ) currentColor . ColorBGRA ) ;
494
+ if ( chkMirrorX . IsChecked == true )
495
+ {
496
+ FloodFill ( canvasResolutionX - x , y , ( int ) currentColor . ColorBGRA ) ;
497
+ }
477
498
break ;
478
499
default :
479
500
break ;
@@ -506,11 +527,15 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
506
527
// mirror
507
528
if ( chkMirrorX . IsChecked == true )
508
529
{
509
- DrawPixel ( canvasResolutionX - x - 1 , y ) ;
530
+ DrawPixel ( canvasResolutionX - x , y ) ;
510
531
}
511
532
break ;
512
533
case ToolMode . Fill :
513
534
FloodFill ( x , y , ( int ) currentColor . ColorBGRA ) ;
535
+ if ( chkMirrorX . IsChecked == true )
536
+ {
537
+ FloodFill ( canvasResolutionX - x , y , ( int ) currentColor . ColorBGRA ) ;
538
+ }
514
539
break ;
515
540
default :
516
541
break ;
@@ -523,7 +548,7 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
523
548
// mirror
524
549
if ( chkMirrorX . IsChecked == true )
525
550
{
526
- ErasePixel ( canvasResolutionX - x - 1 , y ) ;
551
+ ErasePixel ( canvasResolutionX - x , y ) ;
527
552
}
528
553
}
529
554
else if ( e . MiddleButton == MouseButtonState . Pressed )
@@ -711,10 +736,10 @@ private void OnKeyUp(object sender, KeyEventArgs e)
711
736
712
737
private void CallUndo ( )
713
738
{
714
- if ( currentUndoIndex > 0 )
715
- {
716
- CopyBitmapPixels ( undoBufferBitmap [ -- currentUndoIndex ] , canvasBitmap ) ;
717
- }
739
+ currentUndoIndex -- ;
740
+ // TODO: only wrap to current last active index
741
+ if ( currentUndoIndex < 0 ) currentUndoIndex += maxUndoCount ; // wrap
742
+ CopyBitmapPixels ( undoBufferBitmap [ currentUndoIndex ] , canvasBitmap ) ;
718
743
}
719
744
720
745
void CopyBitmapPixels ( WriteableBitmap source , WriteableBitmap target )
0 commit comments