Skip to content

Commit 4b2d88a

Browse files
committed
add undo/redo icons, allow mousedrag on saturation and hue rectangle color pickers, add temporary app icon, add ctrl+shift+s (save as), add ctrl+n (new image), add pixel position preview rectangle
1 parent 3e5eca3 commit 4b2d88a

File tree

6 files changed

+79
-26
lines changed

6 files changed

+79
-26
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
xmlns:local="clr-namespace:PixelArtTool"
77
xmlns:System="clr-namespace:System;assembly=mscorlib" x:Name="window" x:Class="PixelArtTool.MainWindow"
88
mc:Ignorable="d"
9-
Title="PixelArtTool (Test Version)" Height="412.222" Width="739.444" Background="#FF252526" KeyDown="OnKeyDown" KeyUp="OnKeyUp">
9+
Title="PixelArtTool (Test Version)" Height="412.222" Width="739.444" Background="#FF252526" KeyDown="OnKeyDown" KeyUp="OnKeyUp" Icon="Resources/Icons/appicon.ico">
1010
<Window.CommandBindings>
1111
<CommandBinding Command="ApplicationCommands.Undo" Executed="Executed_Undo" CanExecute="CanExecute_Undo"/>
1212
<CommandBinding Command="ApplicationCommands.Redo" Executed="Executed_Redo" CanExecute="CanExecute_Redo"/>
1313
<CommandBinding Command="ApplicationCommands.Paste" Executed="Executed_Paste" CanExecute="CanExecute_Paste"/>
1414
<CommandBinding Command="ApplicationCommands.Copy" Executed="Executed_Copy" CanExecute="CanExecute_Copy"/>
15+
<CommandBinding Command="ApplicationCommands.SaveAs" Executed="Executed_SaveAs" CanExecute="CanExecute_SaveAs"/>
16+
<CommandBinding Command="ApplicationCommands.New" Executed="Executed_New" CanExecute="CanExecute_New"/>
1517
</Window.CommandBindings>
1618
<Window.InputBindings>
1719
<KeyBinding Command="ApplicationCommands.Undo" Gesture="Ctrl+Z"/>
1820
<KeyBinding Command="ApplicationCommands.Redo" Gesture="Ctrl+Y"/>
1921
<KeyBinding Command="ApplicationCommands.Paste" Gesture="Ctrl+V"/>
2022
<KeyBinding Command="ApplicationCommands.Copy" Gesture="Ctrl+C"/>
23+
<KeyBinding Command="ApplicationCommands.SaveAs" Gesture="Ctrl+Shift+S"/>
24+
<KeyBinding Command="ApplicationCommands.New" Gesture="Ctrl+N"/>
2125
</Window.InputBindings>
2226
<Window.Resources>
2327

@@ -63,7 +67,7 @@
6367

6468
</Window.Resources>
6569

66-
<Grid>
70+
<Grid Margin="0,0,-8,-7">
6771
<Grid.Resources>
6872
<local:EnumBooleanConverter x:Key="ComparisonConverter" />
6973

@@ -101,10 +105,10 @@
101105

102106
<ToolBarTray Background="#FF1F1F1F" Height="32" VerticalAlignment="Top">
103107
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top" Background="#FF9C9C9C">
104-
<Button x:Name="btnNew" ToolTip="New (clear image)" Click="OnClearButton">
108+
<Button x:Name="btnNew" ToolTip="New (Ctrl+N)" Click="OnClearButton">
105109
<Image Source="/Resources/Buttons/newimage.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
106110
</Button>
107-
<Button x:Name="btnSave" ToolTip="Save as.." Click="OnSaveButton">
111+
<Button x:Name="btnSave" ToolTip="Save as..(Ctrl+Shift+s)" Click="OnSaveButton">
108112
<Image Source="/Resources/Buttons/save.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
109113
</Button>
110114
</ToolBar>
@@ -134,11 +138,11 @@
134138
</ToolBar>
135139

136140
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top" Background="#FF9C9C9C">
137-
<Button x:Name="btnUndo" ToolTip="Undo" Click="OnUndoButtonDown">
138-
<Image Source="/Resources/Buttons/emptybutton.png" />
141+
<Button x:Name="btnUndo" ToolTip="Undo (Ctrl+z)" Click="OnUndoButtonDown">
142+
<Image Source="/Resources/Buttons/undo.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
139143
</Button>
140-
<Button x:Name="btnRedo" ToolTip="Redo" Click="OnRedoButtonDown">
141-
<Image Source="/Resources/Buttons/emptybutton.png" />
144+
<Button x:Name="btnRedo" ToolTip="Redo (Ctrl+y)" Click="OnRedoButtonDown">
145+
<Image Source="/Resources/Buttons/redo.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
142146
</Button>
143147
</ToolBar>
144148

@@ -205,7 +209,7 @@
205209
<Button x:Name="btnScrollRight" Click="OnScrollButtonRightClicked" Content="&gt;" HorizontalAlignment="Left" Margin="415,262,0,0" VerticalAlignment="Top" Width="24"/>
206210
<Button x:Name="btnFlipX" Click="OnFlipXButtonDown" Content="FlipX" HorizontalAlignment="Left" Margin="365,316,0,0" VerticalAlignment="Top" Width="32"/>
207211
<Button x:Name="btnFlipY" Click="OnFlipYButtonDown" Content="FlipY" HorizontalAlignment="Left" Margin="402,316,0,0" VerticalAlignment="Top" Width="32"/>
208-
<Button x:Name="btnLoadPalette" Click="OnLoadPaletteButton" Content="Load Palette" HorizontalAlignment="Left" Margin="10,324,0,0" VerticalAlignment="Top" Width="71"/>
212+
<Button x:Name="btnLoadPalette" Click="OnLoadPaletteButton" Content="Load Palette" HorizontalAlignment="Left" Margin="9,329,0,0" VerticalAlignment="Top" Width="71"/>
209213
</Grid>
210214
<CheckBox x:Name="chkOutline" Content="Outline" HorizontalAlignment="Left" Margin="638,50,0,0" VerticalAlignment="Top" Width="64" Click="chkOutline_Click"/>
211215
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
@@ -214,8 +218,8 @@
214218

215219
<!-- https://stackoverflow.com/a/32514853/5452781 -->
216220
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="459,130,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
217-
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="459,130,0,0" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDown="OnLevelSaturationMouseDown" />
218-
<Rectangle x:Name="rectHueBar" Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="664,130,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" MouseDown="rectHueBar_MouseDown" HorizontalAlignment="Left" VerticalAlignment="Top" />
221+
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="459,130,0,0" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDown="OnLevelSaturationMouseDown" MouseMove="OnLevelSaturationMouseMoved" />
222+
<Rectangle x:Name="rectHueBar" Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="664,130,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" MouseDown="rectHueBar_MouseDown" HorizontalAlignment="Left" VerticalAlignment="Top" MouseMove="OnHueRectangleMouseMoved" />
219223
<Grid>
220224
<Rectangle x:Name="rectCurrentHue" Width="253" Height="14" Margin="91,316,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" >
221225
<Rectangle.Fill>
@@ -234,6 +238,7 @@
234238
<ImageBrush ImageSource="Resources/Images/transparentbg.png"/>
235239
</Rectangle.Fill>
236240
</Rectangle>
241+
<Rectangle x:Name="rectPixelPos" IsHitTestVisible="False" HorizontalAlignment="Left" VerticalAlignment="Top" Height="16" Stroke="Black" Width="16" Margin="90,50,0,0"/>
237242

238243
</Grid>
239244
</Window>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,12 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
591591
UpdateOutline();
592592
}
593593

594-
}
594+
// snap preview rectangle to grid
595+
var left = x * canvasScaleX;
596+
var top = y * canvasScaleX;
597+
rectPixelPos.Margin = new Thickness(89+left, 50+top, 0, 0);
598+
599+
} // drawingareamousemoved
595600

596601
void ShowMousePos(int x, int y)
597602
{
@@ -845,6 +850,26 @@ public void CanExecute_Copy(object sender, CanExecuteRoutedEventArgs e)
845850
e.CanExecute = true;
846851
}
847852

853+
public void Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
854+
{
855+
OnSaveButton(null, null);
856+
}
857+
858+
public void CanExecute_SaveAs(object sender, CanExecuteRoutedEventArgs e)
859+
{
860+
e.CanExecute = true;
861+
}
862+
863+
public void Executed_New(object sender, ExecutedRoutedEventArgs e)
864+
{
865+
OnClearButton(null, null);
866+
}
867+
868+
public void CanExecute_New(object sender, CanExecuteRoutedEventArgs e)
869+
{
870+
e.CanExecute = true;
871+
}
872+
848873
// paste image from clipboard to canvas
849874
void OnPasteImageFromClipboard()
850875
{
@@ -1193,20 +1218,7 @@ private void rectHueBar_MouseDown(object sender, MouseButtonEventArgs e)
11931218
rectSaturation.OpacityMask = opacityBrush;
11941219
}
11951220

1196-
private void OnLevelSaturationMouseDown(object sender, MouseButtonEventArgs e)
1197-
{
1198-
CustomPoint cursor;
1199-
GetCursorPos(out cursor);
1200-
var c1 = Win32GetScreenPixel((int)cursor.X, (int)cursor.Y);
1201-
var c2 = new PixelColor();
1202-
c2.Alpha = c1.A;
1203-
c2.Red = c1.R;
1204-
c2.Green = c1.G;
1205-
c2.Blue = c1.B;
1206-
currentColor = c2;
1207-
rectCurrentColor.Fill = new SolidColorBrush(Color.FromArgb(c2.Alpha, c2.Red, c2.Green, c2.Blue));
1208-
ResetCurrentBrightnessPreview(currentColor);
1209-
}
1221+
12101222

12111223
private void OnGetTransparentColorButton(object sender, MouseButtonEventArgs e)
12121224
{
@@ -1232,6 +1244,32 @@ private void chkMirrorX_Checked(object sender, RoutedEventArgs e)
12321244
lineSymmetryXpositionB.Visibility = Visibility.Visible;
12331245
}
12341246

1247+
private void OnLevelSaturationMouseMoved(object sender, MouseEventArgs e)
1248+
{
1249+
if (rectSaturation.IsMouseOver == false) return;
1250+
if (e.LeftButton == MouseButtonState.Pressed) OnLevelSaturationMouseDown(null, null);
1251+
}
1252+
1253+
private void OnLevelSaturationMouseDown(object sender, MouseButtonEventArgs e)
1254+
{
1255+
CustomPoint cursor;
1256+
GetCursorPos(out cursor);
1257+
var c1 = Win32GetScreenPixel((int)cursor.X, (int)cursor.Y);
1258+
var c2 = new PixelColor();
1259+
c2.Alpha = c1.A;
1260+
c2.Red = c1.R;
1261+
c2.Green = c1.G;
1262+
c2.Blue = c1.B;
1263+
currentColor = c2;
1264+
rectCurrentColor.Fill = new SolidColorBrush(Color.FromArgb(c2.Alpha, c2.Red, c2.Green, c2.Blue));
1265+
ResetCurrentBrightnessPreview(currentColor);
1266+
}
1267+
1268+
private void OnHueRectangleMouseMoved(object sender, MouseEventArgs e)
1269+
{
1270+
if (rectHueBar.IsMouseOver == false) return;
1271+
if (e.LeftButton == MouseButtonState.Pressed) rectHueBar_MouseDown(null, null);
1272+
}
12351273
} // class
12361274

12371275
} // namespace

PixelArtTool/PixelArtTool.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<WarningLevel>4</WarningLevel>
3636
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3737
</PropertyGroup>
38+
<PropertyGroup>
39+
<ApplicationIcon>Resources\Icons\appicon.ico</ApplicationIcon>
40+
</PropertyGroup>
3841
<ItemGroup>
3942
<Reference Include="System" />
4043
<Reference Include="System.Data" />
@@ -118,5 +121,12 @@
118121
<ItemGroup>
119122
<Resource Include="Resources\Images\transparentbg.png" />
120123
</ItemGroup>
124+
<ItemGroup>
125+
<Resource Include="Resources\Buttons\redo.png" />
126+
<Resource Include="Resources\Buttons\undo.png" />
127+
</ItemGroup>
128+
<ItemGroup>
129+
<Resource Include="Resources\Icons\appicon.ico" />
130+
</ItemGroup>
121131
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
122132
</Project>
1.12 KB
Loading
1.12 KB
Loading
290 KB
Binary file not shown.

0 commit comments

Comments
 (0)