Skip to content

Commit 214fa9d

Browse files
committed
add mirrorX option
1 parent c3964d8 commit 214fa9d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@
9292
</Grid>
9393
<CheckBox x:Name="chkOutline" Content="Outline" HorizontalAlignment="Left" Margin="648,50,0,0" VerticalAlignment="Top" Width="64"/>
9494
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="24" Margin="10,181,0,0" Stroke="Black" VerticalAlignment="Top" Width="24"/>
95+
<CheckBox x:Name="chkMirrorX" Content="MirrorX" HorizontalAlignment="Left" Margin="648,80,0,0" VerticalAlignment="Top" Width="64"/>
9596
</Grid>
9697
</Window>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ void ErasePixel(MouseEventArgs e)
380380
canvasBitmap.WritePixels(rect, ColorData, 4, 0);
381381
}
382382

383+
void ErasePixel(int x, int y)
384+
{
385+
byte[] ColorData = { 0, 0, 0, 0 }; // B G R
386+
387+
if (x < 0 || x > canvasResolutionX - 1) return;
388+
if (y < 0 || y > canvasResolutionY - 1) return;
389+
390+
Int32Rect rect = new Int32Rect(x, y, 1, 1);
391+
canvasBitmap.WritePixels(rect, ColorData, 4, 0);
392+
}
393+
383394
void PickPalette(MouseEventArgs e)
384395
{
385396
byte[] ColorData = { 0, 0, 0, 0 }; // B G R !
@@ -474,6 +485,12 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
474485
{
475486
UpdateOutline();
476487
}
488+
489+
// mirror
490+
if (chkMirrorX.IsChecked == true)
491+
{
492+
DrawPixel(canvasResolutionX - x - 1, y);
493+
}
477494
}
478495

479496
void DrawingMouseUp(object sender, MouseButtonEventArgs e)
@@ -490,10 +507,20 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
490507
if (e.LeftButton == MouseButtonState.Pressed)
491508
{
492509
DrawPixel(x, y);
510+
// mirror
511+
if (chkMirrorX.IsChecked == true)
512+
{
513+
DrawPixel(canvasResolutionX - x - 1, y);
514+
}
493515
}
494516
else if (e.RightButton == MouseButtonState.Pressed)
495517
{
496-
ErasePixel(e);
518+
ErasePixel(x, y);
519+
// mirror
520+
if (chkMirrorX.IsChecked == true)
521+
{
522+
ErasePixel(canvasResolutionX - x - 1, y);
523+
}
497524
}
498525
else if (e.MiddleButton == MouseButtonState.Pressed)
499526
{
@@ -502,10 +529,12 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
502529

503530
ShowMousePos(x, y);
504531
ShowMousePixelColor(x, y);
532+
// outline
505533
if (chkOutline.IsChecked == true)
506534
{
507535
UpdateOutline();
508536
}
537+
509538
}
510539

511540
void ShowMousePos(int x, int y)

0 commit comments

Comments
 (0)