Skip to content

Commit 7945cbe

Browse files
committed
add color picker dialog for main and secondary color, remove borders from color picker dialog, adding secondary eraser color box, PixelColor from SolidColorBrush
1 parent f1b7527 commit 7945cbe

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

PixelArtTool/ColorPicker.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343

4444
</Window.Resources>
4545
<Grid>
46-
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="58,24,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
47-
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="58,24,0,0" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseMove="OnLevelSaturationMouseMoved" MouseDown="OnLevelSaturationMouseDown" />
48-
<Rectangle x:Name="rectHueBar" Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="263,24,0,0" Stroke="Black" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseMove="OnHueRectangleMouseMoved" MouseDown="rectHueBar_MouseDown" />
46+
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="58,24,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" StrokeThickness="0" />
47+
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="58,24,0,0" StrokeThickness="0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseMove="OnLevelSaturationMouseMoved" MouseDown="OnLevelSaturationMouseDown" />
48+
<Rectangle x:Name="rectHueBar" Fill="{StaticResource HueBrush}" Width="20" Height="200" Margin="263,24,0,0" Stroke="Black" StrokeThickness="0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" MouseMove="OnHueRectangleMouseMoved" MouseDown="rectHueBar_MouseDown" />
4949
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,196,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
5050
<Button x:Name="okButton" IsDefault="True" Content="OK" Click="OnOkButtonClick" Margin="258,233,5,4"/>
5151
<Button x:Name="cancelButton" IsCancel="True" Content="Cancel" Margin="178,233,85,4"/>

PixelArtTool/EnumsAndStructs.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public PixelColor(byte r, byte g, byte b, byte a)
4949
Alpha = a;
5050
}
5151

52+
public PixelColor(SolidColorBrush b)
53+
{
54+
ColorBGRA = (UInt32)(b.Color.B + (b.Color.G << 8) + (b.Color.R << 16) + (b.Color.A << 24));
55+
Red = b.Color.R;
56+
Green = b.Color.G;
57+
Blue = b.Color.B;
58+
Alpha = b.Color.A;
59+
}
60+
5261
public SolidColorBrush AsSolidColorBrush()
5362
{
5463
return new SolidColorBrush(Color.FromArgb(Alpha, Red, Green, Blue));

PixelArtTool/MainWindow.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@
214214
<Button x:Name="btnLoadPalette" Click="OnLoadPaletteButton" Content="Load Palette" HorizontalAlignment="Left" Margin="9,329,0,0" VerticalAlignment="Top" Width="71"/>
215215
</Grid>
216216
<CheckBox x:Name="chkOutline" Content="Outline" HorizontalAlignment="Left" Margin="638,50,0,0" VerticalAlignment="Top" Width="64" Click="chkOutline_Click"/>
217-
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
217+
<Rectangle x:Name="rectCurrentColor" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="28" Margin="10,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" MouseDown="rectCurrentColor_MouseDown"/>
218218
<CheckBox x:Name="chkMirrorX" Content="Symmetry X" HorizontalAlignment="Left" Margin="638,71,0,0" VerticalAlignment="Top" Width="93" Unchecked="chkMirrorX_Unchecked" Checked="chkMirrorX_Checked"/>
219-
<Rectangle x:Name="rectSecondaryColor" Fill="Black" HorizontalAlignment="Left" Height="28" Margin="47,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
219+
<Rectangle x:Name="rectSecondaryColor" Fill="Black" HorizontalAlignment="Left" Height="28" Margin="47,256,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" MouseDown="rectSecondaryColor_MouseDown"/>
220220

221221
<!-- https://stackoverflow.com/a/32514853/5452781 -->
222222
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="459,130,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
@@ -240,6 +240,8 @@
240240
<ImageBrush ImageSource="Resources/Images/transparentbg.png"/>
241241
</Rectangle.Fill>
242242
</Rectangle>
243+
<Rectangle x:Name="rectGetTransparentSecondary" HorizontalAlignment="Left" Height="28" Margin="47,289,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" Fill="Black" />
244+
243245
<Rectangle x:Name="rectPixelPos" IsHitTestVisible="False" HorizontalAlignment="Left" VerticalAlignment="Top" Height="16" Stroke="Black" Width="16" Margin="89,50,0,0"/>
244246
<Button x:Name="btnSettings" Content="Settings" HorizontalAlignment="Left" Margin="674,6,0,0" VerticalAlignment="Top" Width="50" Click="btnSettings_Click"/>
245247

PixelArtTool/MainWindow.xaml.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Windows.Input;
1111
using System.Windows.Media;
1212
using System.Windows.Media.Imaging;
13+
using System.Windows.Shapes;
1314
using static PixelArtTool.Tools;
1415

1516
namespace PixelArtTool
@@ -1449,6 +1450,37 @@ public void ReplacePixels(PixelColor find, PixelColor replace)
14491450

14501451
}
14511452

1453+
// current color box
1454+
private void rectCurrentColor_MouseDown(object sender, MouseButtonEventArgs e)
1455+
{
1456+
var newcolor = PalettePicker();
1457+
if (newcolor != null)
1458+
{
1459+
((Rectangle)sender).Fill = newcolor;
1460+
currentColor = new PixelColor((SolidColorBrush)newcolor);
1461+
}
1462+
}
14521463

1464+
// TODO: take current color as param to return if cancelled?
1465+
Brush PalettePicker()
1466+
{
1467+
var dlg = new ColorPicker();
1468+
dlg.Owner = this;
1469+
var result = dlg.ShowDialog();
1470+
if (result == true)
1471+
{
1472+
return dlg.rectCurrentColor.Fill;
1473+
}
1474+
return null;
1475+
}
1476+
1477+
private void rectSecondaryColor_MouseDown(object sender, MouseButtonEventArgs e)
1478+
{
1479+
var newcolor = PalettePicker();
1480+
if (newcolor != null)
1481+
{
1482+
((Rectangle)sender).Fill = newcolor;
1483+
}
1484+
}
14531485
} // class
14541486
} // namespace

0 commit comments

Comments
 (0)