Skip to content

Commit ea6706f

Browse files
committed
update pencil icon, add global color picker, adding color gradients window (for color picker), add previews with gray and white backgrounds
1 parent f6b7c48 commit ea6706f

File tree

4 files changed

+138
-10
lines changed

4 files changed

+138
-10
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,56 @@
1414
<KeyBinding Command="ApplicationCommands.Undo" Gesture="Ctrl+Z"/>
1515
</Window.InputBindings>
1616

17+
<Window.Resources>
18+
19+
<!-- Change this to any pure hue i.e. no more than 2 rgb components set and at least 1 set to FF -->
20+
<Color x:Key="CurrentColor">#00FF00</Color>
21+
22+
<LinearGradientBrush x:Key="HueBrush" StartPoint="0,0" EndPoint="0,1">
23+
<LinearGradientBrush.GradientStops>
24+
<GradientStop Color="#FF0000" Offset="0" />
25+
<GradientStop Color="#FFFF00" Offset="0.167" />
26+
<GradientStop Color="#00FF00" Offset="0.333" />
27+
<GradientStop Color="#00FFFF" Offset="0.5" />
28+
<GradientStop Color="#0000FF" Offset="0.667" />
29+
<GradientStop Color="#FF00FF" Offset="0.833" />
30+
<GradientStop Color="#FF0000" Offset="1" />
31+
</LinearGradientBrush.GradientStops>
32+
</LinearGradientBrush>
33+
34+
<VisualBrush x:Key="LevelSaturationBrush" TileMode="None">
35+
<VisualBrush.Visual>
36+
<Canvas Background="Black" Width="1" Height="1" SnapsToDevicePixels="True">
37+
<Rectangle Width="1" Height="1" SnapsToDevicePixels="True">
38+
<Rectangle.Fill>
39+
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
40+
<LinearGradientBrush.GradientStops>
41+
<GradientStop Color="White" Offset="0" />
42+
<GradientStop Color="{DynamicResource CurrentColor}" Offset="1" />
43+
</LinearGradientBrush.GradientStops>
44+
</LinearGradientBrush>
45+
</Rectangle.Fill>
46+
<Rectangle.OpacityMask>
47+
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
48+
<LinearGradientBrush.GradientStops>
49+
<GradientStop Color="#FFFFFFFF" Offset="0"/>
50+
<GradientStop Color="#00FFFFFF" Offset="1"/>
51+
</LinearGradientBrush.GradientStops>
52+
</LinearGradientBrush>
53+
</Rectangle.OpacityMask>
54+
</Rectangle>
55+
</Canvas>
56+
</VisualBrush.Visual>
57+
</VisualBrush>
58+
59+
</Window.Resources>
60+
1761
<Grid>
1862
<Grid.Resources>
1963
<local:EnumBooleanConverter x:Key="ComparisonConverter" />
2064
</Grid.Resources>
2165

22-
<ToolBarTray Background="White" Height="36" VerticalAlignment="Top">
66+
<ToolBarTray Background="White" Height="32" VerticalAlignment="Top">
2367
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top">
2468
<Button x:Name="btnNew" ToolTip="New (clear image)" Click="OnClearButton">
2569
<Image Source="/Resources/Buttons/emptybutton.png" />
@@ -32,11 +76,11 @@
3276
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top">
3377
<RadioButton GroupName="Toolbar" Tag="Draw" ToolTip="Pencil" Style="{StaticResource {x:Type ToggleButton}}"
3478
IsChecked="{Binding Path=CurrentTool, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static local:ToolMode.Draw},Mode=TwoWay}">
35-
<Image Source="/Resources/Buttons/drawmode.png" />
79+
<Image Source="/Resources/Buttons/drawmode.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
3680
</RadioButton>
3781
<RadioButton GroupName="Toolbar" Tag="Fill" ToolTip="Flood Fill" Style="{StaticResource {x:Type ToggleButton}}"
3882
IsChecked="{Binding Path=CurrentTool, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static local:ToolMode.Fill},Mode=TwoWay}">
39-
<Image Source="/Resources/Buttons/emptybutton.png" />
83+
<Image Source="/Resources/Buttons/emptybutton.png" RenderOptions.BitmapScalingMode="NearestNeighbor" />
4084
</RadioButton>
4185
</ToolBar>
4286

@@ -103,17 +147,40 @@
103147
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="16" Margin="425,50,0,0" VerticalAlignment="Top" Width="16">
104148
<Image x:Name="imgPreview1x" HorizontalAlignment="Left" Height="16" Margin="-1" VerticalAlignment="Top" Width="16" Stretch="Fill"/>
105149
</Border>
150+
<Rectangle x:Name="recPreviewBg2xb" Fill="Gray" HorizontalAlignment="Left" Height="32" Margin="375,100,0,0" VerticalAlignment="Top" Width="32"/>
151+
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="32" Margin="375,100,0,0" VerticalAlignment="Top" Width="32">
152+
<Image x:Name="imgPreview2xb" HorizontalAlignment="Left" Height="32" Margin="-1" VerticalAlignment="Top" Width="32" Stretch="Fill"/>
153+
</Border>
154+
<Rectangle x:Name="recPreviewBg1xb" Fill="Gray" HorizontalAlignment="Left" Height="16" Margin="425,100,0,0" VerticalAlignment="Top" Width="16"/>
155+
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="16" Margin="425,100,0,0" VerticalAlignment="Top" Width="16">
156+
<Image x:Name="imgPreview1xb" HorizontalAlignment="Left" Height="16" Margin="-1" VerticalAlignment="Top" Width="16" Stretch="Fill"/>
157+
</Border>
158+
<Rectangle x:Name="recPreviewBg2xc" Fill="White" HorizontalAlignment="Left" Height="32" Margin="375,150,0,0" VerticalAlignment="Top" Width="32"/>
159+
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="32" Margin="375,150,0,0" VerticalAlignment="Top" Width="32">
160+
<Image x:Name="imgPreview2xc" HorizontalAlignment="Left" Height="32" Margin="-1" VerticalAlignment="Top" Width="32" Stretch="Fill"/>
161+
</Border>
162+
<Rectangle x:Name="recPreviewBg1xc" Fill="White" HorizontalAlignment="Left" Height="16" Margin="425,150,0,0" VerticalAlignment="Top" Width="16"/>
163+
<Border BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Left" Height="16" Margin="425,150,0,0" VerticalAlignment="Top" Width="16">
164+
<Image x:Name="imgPreview1xc" HorizontalAlignment="Left" Height="16" Margin="-1" VerticalAlignment="Top" Width="16" Stretch="Fill"/>
165+
</Border>
106166
<Button x:Name="btnScrollUp" Click="OnScrollButtonUpClicked" Content="/\" HorizontalAlignment="Left" Margin="388,252,0,0" VerticalAlignment="Top" Width="24"/>
107167
<Button x:Name="btnScrollDown" Click="OnScrollButtonDownClicked" Content="\/" HorizontalAlignment="Left" Margin="388,274,0,0" VerticalAlignment="Top" Width="24"/>
108168
<Button x:Name="btnScrollLeft" Click="OnScrollButtonLeftClicked" Content="&lt;" HorizontalAlignment="Left" Margin="361,263,0,0" VerticalAlignment="Top" Width="24"/>
109169
<Button x:Name="btnScrollRight" Click="OnScrollButtonRightClicked" Content="&gt;" HorizontalAlignment="Left" Margin="415,262,0,0" VerticalAlignment="Top" Width="24"/>
110-
<Button x:Name="btnFlipX" Click="OnFlipXButtonDown" Content="FlipX" HorizontalAlignment="Left" Margin="462,251,0,0" VerticalAlignment="Top" Width="32"/>
111-
<Button x:Name="btnFlipY" Click="OnFlipYButtonDown" Content="FlipY" HorizontalAlignment="Left" Margin="462,276,0,0" VerticalAlignment="Top" Width="32"/>
112-
<Button x:Name="btnLoadPalette" Click="OnLoadPaletteButton" Content="Load Palette" HorizontalAlignment="Left" Margin="620,276,0,0" VerticalAlignment="Top" Width="77"/>
170+
<Button x:Name="btnFlipX" Click="OnFlipXButtonDown" Content="FlipX" HorizontalAlignment="Left" Margin="353,316,0,0" VerticalAlignment="Top" Width="32"/>
171+
<Button x:Name="btnFlipY" Click="OnFlipYButtonDown" Content="FlipY" HorizontalAlignment="Left" Margin="390,316,0,0" VerticalAlignment="Top" Width="32"/>
172+
<Button x:Name="btnLoadPalette" Click="OnLoadPaletteButton" Content="Load Palette" HorizontalAlignment="Left" Margin="10,321,0,0" VerticalAlignment="Top" Width="71"/>
113173
</Grid>
114174
<CheckBox x:Name="chkOutline" Content="Outline" HorizontalAlignment="Left" Margin="648,50,0,0" VerticalAlignment="Top" Width="64"/>
115175
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,276,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
116176
<CheckBox x:Name="chkMirrorX" Content="MirrorX" HorizontalAlignment="Left" Margin="648,80,0,0" VerticalAlignment="Top" Width="64"/>
117177
<Rectangle x:Name="rectSecondaryColor" Fill="Black" HorizontalAlignment="Left" Height="28" Margin="47,276,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
178+
179+
<!-- https://stackoverflow.com/a/32514853/5452781 -->
180+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="452,113,0,0">
181+
<Rectangle Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="10" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" />
182+
<Rectangle Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="10" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" />
183+
</StackPanel>
184+
118185
</Grid>
119186
</Window>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ public enum ToolMode
3232
/// </summary>
3333
public partial class MainWindow : Window, INotifyPropertyChanged
3434
{
35+
[StructLayout(LayoutKind.Sequential)]
36+
public struct POINT
37+
{
38+
public int X;
39+
public int Y;
40+
41+
public static implicit operator Point(POINT point)
42+
{
43+
return new Point(point.X, point.Y);
44+
}
45+
}
46+
47+
[DllImport("user32.dll", SetLastError = true)]
48+
public static extern IntPtr GetDesktopWindow();
49+
[DllImport("user32.dll", SetLastError = true)]
50+
public static extern IntPtr GetWindowDC(IntPtr window);
51+
[DllImport("gdi32.dll", SetLastError = true)]
52+
public static extern uint GetPixel(IntPtr dc, int x, int y);
53+
[DllImport("user32.dll", SetLastError = true)]
54+
public static extern int ReleaseDC(IntPtr window, IntPtr dc);
55+
[DllImport("user32.dll")]
56+
static extern bool GetCursorPos(out POINT lpPoint);
57+
3558
WriteableBitmap canvasBitmap;
3659
WriteableBitmap gridBitmap;
3760
WriteableBitmap outlineBitmap;
@@ -133,6 +156,14 @@ void Start()
133156
imgPreview1x.Source = canvasBitmap;
134157
RenderOptions.SetBitmapScalingMode(imgPreview2x, BitmapScalingMode.NearestNeighbor);
135158
imgPreview2x.Source = canvasBitmap;
159+
RenderOptions.SetBitmapScalingMode(imgPreview1xb, BitmapScalingMode.NearestNeighbor);
160+
imgPreview1xb.Source = canvasBitmap;
161+
RenderOptions.SetBitmapScalingMode(imgPreview2xb, BitmapScalingMode.NearestNeighbor);
162+
imgPreview2xb.Source = canvasBitmap;
163+
RenderOptions.SetBitmapScalingMode(imgPreview1xc, BitmapScalingMode.NearestNeighbor);
164+
imgPreview1xc.Source = canvasBitmap;
165+
RenderOptions.SetBitmapScalingMode(imgPreview2xc, BitmapScalingMode.NearestNeighbor);
166+
imgPreview2xc.Source = canvasBitmap;
136167

137168
// drawing events
138169
drawingImage.MouseMove += new MouseEventHandler(DrawingAreaMouseMoved);
@@ -705,6 +736,19 @@ void OnKeyDown(object sender, KeyEventArgs e)
705736
// TODO: add tool shortcut keys
706737
switch (e.Key)
707738
{
739+
case Key.I: // TEST global color picker
740+
POINT cursor;
741+
GetCursorPos(out cursor);
742+
var c1 = Win32GetScreenPixel((int)cursor.X, (int)cursor.Y);
743+
var c2 = new PixelColor();
744+
c2.Alpha = c1.A;
745+
c2.Red = c1.R;
746+
c2.Green = c1.G;
747+
c2.Blue = c1.B;
748+
currentColor = c2;
749+
rectCurrentColor.Fill = new SolidColorBrush(Color.FromArgb(c2.Alpha, c2.Red, c2.Green, c2.Blue));
750+
// Console.WriteLine(cursor.X + "," + cursor.Y + " = " + c1);
751+
break;
708752
case Key.X: // swap current/secondary colors
709753
var tempcolor = rectCurrentColor.Fill;
710754
rectCurrentColor.Fill = rectSecondaryColor.Fill;
@@ -717,7 +761,6 @@ void OnKeyDown(object sender, KeyEventArgs e)
717761
c.Blue = t.B;
718762
c.Alpha = t.A;
719763
currentColor = c;
720-
721764
break;
722765
case Key.B: // brush
723766
CurrentTool = ToolMode.Draw;
@@ -997,6 +1040,24 @@ private void OnLoadPaletteButton(object sender, RoutedEventArgs e)
9971040
LoadPalette(openFileDialog.FileName);
9981041
}
9991042
}
1043+
1044+
// https://stackoverflow.com/a/24759418/5452781
1045+
public static Color Win32GetScreenPixel(int x, int y)
1046+
{
1047+
IntPtr desk = GetDesktopWindow();
1048+
IntPtr dc = GetWindowDC(desk);
1049+
int a = (int)GetPixel(dc, x, y);
1050+
ReleaseDC(desk, dc);
1051+
return Color.FromArgb(255, (byte)((a >> 0) & 0xff), (byte)((a >> 8) & 0xff), (byte)((a >> 16) & 0xff));
1052+
}
1053+
1054+
public static Point GetCursorPosition()
1055+
{
1056+
POINT lpPoint;
1057+
GetCursorPos(out lpPoint);
1058+
return lpPoint;
1059+
}
1060+
10001061
} // class
10011062

10021063
// https://stackoverflow.com/a/2908885/5452781

PixelArtTool/PixelArtTool.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@
118118
<ItemGroup>
119119
<None Include="App.config" />
120120
</ItemGroup>
121-
<ItemGroup>
122-
<Resource Include="Resources\Buttons\drawmode.png" />
123-
</ItemGroup>
124121
<ItemGroup>
125122
<Resource Include="Resources\Palettes\aap-64-1x.png" />
126123
</ItemGroup>
127124
<ItemGroup>
128125
<Resource Include="Resources\Buttons\emptybutton.png" />
129126
</ItemGroup>
127+
<ItemGroup>
128+
<Resource Include="Resources\Buttons\drawmode.png" />
129+
</ItemGroup>
130130
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
131131
</Project>
1.02 KB
Loading

0 commit comments

Comments
 (0)