Skip to content

Commit f0d341f

Browse files
committed
add symmetry position indicator, clear redo on new undo
1 parent 6f9e3c8 commit f0d341f

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
</Grid>
210210
<CheckBox x:Name="chkOutline" Content="Outline" HorizontalAlignment="Left" Margin="638,50,0,0" VerticalAlignment="Top" Width="64" Click="chkOutline_Click"/>
211211
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
212-
<CheckBox x:Name="chkMirrorX" Content="Symmetry X" HorizontalAlignment="Left" Margin="638,71,0,0" VerticalAlignment="Top" Width="93"/>
212+
<CheckBox x:Name="chkMirrorX" Content="Symmetry X" HorizontalAlignment="Left" Margin="638,71,0,0" VerticalAlignment="Top" Width="93" Unchecked="chkMirrorX_Unchecked" Checked="chkMirrorX_Checked"/>
213213
<Rectangle x:Name="rectSecondaryColor" Fill="Black" HorizontalAlignment="Left" Height="28" Margin="47,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
214214

215215
<!-- https://stackoverflow.com/a/32514853/5452781 -->
@@ -226,6 +226,8 @@
226226
</Rectangle.Fill>
227227
</Rectangle>
228228
<Line x:Name="lineCurrentHueLine" X1="91" Y1="312" X2="91" Y2="334" Stroke="White" StrokeThickness="1" />
229+
<Line x:Name="lineSymmetryXpositionA" X1="225" Y1="40" X2="225" Y2="50" Stroke="White" StrokeThickness="1" Visibility="Visible" />
230+
<Line x:Name="lineSymmetryXpositionB" X1="225" Y1="312" X2="225" Y2="306" Stroke="White" StrokeThickness="1" Visibility="Visible" />
229231
</Grid>
230232
<Rectangle x:Name="rectGetTransparent" HorizontalAlignment="Left" Height="28" Margin="10,289,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" MouseDown="OnGetTransparentColorButton">
231233
<Rectangle.Fill>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ void Start()
205205
currentColor = palette[currentColorIndex];
206206
SetCurrentColorPreviewBox(rectCurrentColor, currentColor);
207207
ResetCurrentBrightnessPreview(currentColor);
208+
209+
lineSymmetryXpositionA.Visibility = Visibility.Hidden;
210+
lineSymmetryXpositionB.Visibility = Visibility.Hidden;
211+
208212
}
209213

210214

@@ -461,6 +465,8 @@ void PaletteLeftButtonDown(object sender, MouseButtonEventArgs e)
461465

462466
void DrawingRightButtonDown(object sender, MouseButtonEventArgs e)
463467
{
468+
RegisterUndo();
469+
464470
int x = (int)(e.GetPosition(drawingImage).X / canvasScaleX);
465471
int y = (int)(e.GetPosition(drawingImage).Y / canvasScaleX);
466472

@@ -489,8 +495,7 @@ void DrawingMiddleButtonDown(object sender, MouseButtonEventArgs e)
489495
void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
490496
{
491497
// take current bitmap as currentimage
492-
currentItem = canvasBitmap.Clone();
493-
undoStack.Push(currentItem);
498+
RegisterUndo();
494499

495500
int x = (int)(e.GetPosition(drawingImage).X / canvasScaleX);
496501
int y = (int)(e.GetPosition(drawingImage).Y / canvasScaleX);
@@ -522,6 +527,13 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
522527
}
523528
} // DrawingLeftButtonDown
524529

530+
// save undo state
531+
void RegisterUndo()
532+
{
533+
currentItem = canvasBitmap.Clone();
534+
undoStack.Push(currentItem);
535+
redoStack.Clear();
536+
}
525537

526538
void DrawingMouseUp(object sender, MouseButtonEventArgs e)
527539
{
@@ -640,7 +652,7 @@ void DrawingMouseWheel(object sender, MouseWheelEventArgs e)
640652

641653
private void OnClearButton(object sender, RoutedEventArgs e)
642654
{
643-
//undoRedoWrapper.AddItem(canvasBitmap.Clone());
655+
RegisterUndo();
644656
ClearImage(canvasBitmap, emptyRect, emptyPixels, emptyStride);
645657
UpdateOutline();
646658
}
@@ -1210,6 +1222,17 @@ private void OnGetTransparentColorButton(object sender, MouseButtonEventArgs e)
12101222
ResetCurrentBrightnessPreview(currentColor);
12111223
}
12121224

1225+
private void chkMirrorX_Unchecked(object sender, RoutedEventArgs e)
1226+
{
1227+
lineSymmetryXpositionA.Visibility = Visibility.Hidden;
1228+
lineSymmetryXpositionB.Visibility = Visibility.Hidden;
1229+
}
1230+
1231+
private void chkMirrorX_Checked(object sender, RoutedEventArgs e)
1232+
{
1233+
lineSymmetryXpositionA.Visibility = Visibility.Visible;
1234+
lineSymmetryXpositionB.Visibility = Visibility.Visible;
1235+
}
12131236

12141237

12151238
} // class

0 commit comments

Comments
 (0)