Skip to content

Commit da5eb2d

Browse files
committed
add undo key (ctrl+z), fix undo buffer counter, add tooltips to all buttons, add current tool info label (only for left shift now)
1 parent 3999a26 commit da5eb2d

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="PixelArtTool.MainWindow"
88
mc:Ignorable="d"
99
Title="PixelArtTool" Height="412.222" Width="739.444" Background="#FF252526" KeyDown="OnKeyDown" KeyUp="OnKeyUp">
10+
<Window.CommandBindings>
11+
<CommandBinding Command="ApplicationCommands.Undo" Executed="Executed_Undo" CanExecute="CanExecute_Undo"/>
12+
</Window.CommandBindings>
13+
<Window.InputBindings>
14+
<KeyBinding Command="ApplicationCommands.Undo" Gesture="Ctrl+Z"/>
15+
</Window.InputBindings>
16+
1017
<Grid>
1118
<ToolBarTray Background="White" Height="36" VerticalAlignment="Top">
1219
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top">
@@ -19,19 +26,19 @@
1926
</ToolBar>
2027

2128
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top">
22-
<RadioButton GroupName="Toolbar" Style="{StaticResource {x:Type ToggleButton}}">
29+
<RadioButton GroupName="Toolbar" ToolTip="Test" Style="{StaticResource {x:Type ToggleButton}}">
2330
<Image Source="/Resources/Buttons/drawmode.png" />
2431
</RadioButton>
25-
<RadioButton GroupName="Toolbar" Style="{StaticResource {x:Type ToggleButton}}">
32+
<RadioButton GroupName="Toolbar" ToolTip="Test" Style="{StaticResource {x:Type ToggleButton}}">
2633
<Image Source="/Resources/Buttons/drawmode.png" />
2734
</RadioButton>
2835
</ToolBar>
2936

3037
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top">
31-
<RadioButton GroupName="Toolbar2" Style="{StaticResource {x:Type ToggleButton}}">
38+
<RadioButton GroupName="Toolbar2" ToolTip="Test" Style="{StaticResource {x:Type ToggleButton}}">
3239
<Image Source="/Resources/Buttons/emptybutton.png" />
3340
</RadioButton>
34-
<RadioButton GroupName="Toolbar2" Style="{StaticResource {x:Type ToggleButton}}">
41+
<RadioButton GroupName="Toolbar2" ToolTip="Test" Style="{StaticResource {x:Type ToggleButton}}">
3542
<Image Source="/Resources/Buttons/emptybutton.png" />
3643
</RadioButton>
3744
</ToolBar>
@@ -60,10 +67,13 @@
6067

6168
<StatusBar Height="30" Margin="0,281,0,0" VerticalAlignment="Bottom">
6269
<StatusBarItem Height="30" VerticalAlignment="Center">
63-
<Label x:Name="lblMousePos" Content="Label"/>
70+
<Label x:Name="lblMousePos" Content="Mouse Coord"/>
6471
</StatusBarItem>
6572
<StatusBarItem Height="30" VerticalAlignment="Center">
66-
<Label x:Name="lblPixelColor" Content="Label"/>
73+
<Label x:Name="lblPixelColor" Content="Pixel Color"/>
74+
</StatusBarItem>
75+
<StatusBarItem Height="30" VerticalAlignment="Center">
76+
<Label x:Name="lblToolInfo" Content="-"/>
6777
</StatusBarItem>
6878
</StatusBar>
6979
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="128" Margin="10,50,0,0" VerticalAlignment="Top" Width="64">

PixelArtTool/MainWindow.xaml.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void DrawingMiddleButtonDown(object sender, MouseButtonEventArgs e)
436436
void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
437437
{
438438
// undo test
439-
undoBufferBitmap[++currentUndoIndex] = canvasBitmap.Clone();
439+
undoBufferBitmap[currentUndoIndex++] = canvasBitmap.Clone();
440440
//Console.WriteLine("save undo " + currentUndoIndex);
441441

442442
int x = (int)(e.GetPosition(drawingImage).X / canvasScaleX);
@@ -567,12 +567,7 @@ private void OpacitySliderValueChanged(object sender, RoutedPropertyChangedEvent
567567

568568
private void OnUndoButtonDown(object sender, RoutedEventArgs e)
569569
{
570-
if (currentUndoIndex > 0)
571-
{
572-
canvasBitmap = undoBufferBitmap[--currentUndoIndex];
573-
Console.WriteLine("restore undo " + currentUndoIndex);
574-
imgCanvas.Source = canvasBitmap;
575-
}
570+
CallUndo();
576571
}
577572

578573
private void OnModeSelectionChanged(object sender, SelectionChangedEventArgs e)
@@ -590,6 +585,7 @@ void OnKeyDown(object sender, KeyEventArgs e)
590585
switch (e.Key)
591586
{
592587
case Key.LeftShift:
588+
lblToolInfo.Content = "Straight Lines";
593589
leftShiftDown = true;
594590
break;
595591
default:
@@ -602,6 +598,7 @@ private void OnKeyUp(object sender, KeyEventArgs e)
602598
switch (e.Key)
603599
{
604600
case Key.LeftShift:
601+
lblToolInfo.Content = "";
605602
leftShiftDown = false;
606603
verticalLine = false;
607604
horizontalLine = false;
@@ -612,5 +609,25 @@ private void OnKeyUp(object sender, KeyEventArgs e)
612609
break;
613610
}
614611
}
612+
613+
private void CallUndo()
614+
{
615+
if (currentUndoIndex > 0)
616+
{
617+
canvasBitmap = undoBufferBitmap[--currentUndoIndex];
618+
Console.WriteLine("restore undo " + currentUndoIndex);
619+
imgCanvas.Source = canvasBitmap;
620+
}
621+
}
622+
623+
public void Executed_Undo(object sender, ExecutedRoutedEventArgs e)
624+
{
625+
CallUndo();
626+
}
627+
628+
public void CanExecute_Undo(object sender, CanExecuteRoutedEventArgs e)
629+
{
630+
e.CanExecute = true;
631+
}
615632
} // class
616633
} // namespace

0 commit comments

Comments
 (0)