Skip to content

Commit 928ca77

Browse files
committed
pick color from saturation rectangle on click, adding custom highlight colors for toolbar buttons
1 parent eea7d1b commit 928ca77

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

PixelArtTool/MainWindow.xaml

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,37 @@
6060
<Grid>
6161
<Grid.Resources>
6262
<local:EnumBooleanConverter x:Key="ComparisonConverter" />
63+
64+
<!-- https://stackoverflow.com/a/18400415/5452781 -->
65+
<!-- Brushes for colours/backgrounds -->
66+
<SolidColorBrush x:Key="BackgroundBrushKey" Color="Transparent"/>
67+
<SolidColorBrush x:Key="BorderBrushHiddenKey" Color="Transparent"/>
68+
<SolidColorBrush x:Key="CheckedBrushKey" Color="Black"/>
69+
70+
<!-- Template -->
71+
<ControlTemplate x:Key="ToggleButtonLeft" TargetType="{x:Type ToggleButton}">
72+
<Border
73+
Name="Border"
74+
Background="{StaticResource BackgroundBrushKey}"
75+
BorderBrush="{StaticResource BorderBrushHiddenKey}"
76+
BorderThickness="1"
77+
CornerRadius="0,0,0,0">
78+
<ContentPresenter
79+
HorizontalAlignment="Center"
80+
Margin="{TemplateBinding Padding}"
81+
VerticalAlignment="Center"
82+
Content="{TemplateBinding Content}"
83+
/>
84+
</Border>
85+
<ControlTemplate.Triggers>
86+
<Trigger Property="ToggleButton.IsMouseOver" Value="true">
87+
<Setter TargetName="Border" Property="Background" Value="Yellow"/>
88+
</Trigger>
89+
<Trigger Property="IsChecked" Value="true">
90+
<Setter TargetName="Border" Property="Background" Value="{StaticResource CheckedBrushKey}"/>
91+
</Trigger>
92+
</ControlTemplate.Triggers>
93+
</ControlTemplate>
6394
</Grid.Resources>
6495

6596
<ToolBarTray Background="#FF1F1F1F" Height="32" VerticalAlignment="Top">
@@ -73,11 +104,11 @@
73104
</ToolBar>
74105

75106
<ToolBar Band="1" BandIndex="1" VerticalAlignment="Top" Background="#FF9C9C9C">
76-
<RadioButton GroupName="Toolbar" Tag="Draw" ToolTip="Brush (D)" Style="{StaticResource {x:Type ToggleButton}}"
107+
<RadioButton GroupName="Toolbar" Tag="Draw" ToolTip="Brush (D)" Template="{DynamicResource ToggleButtonLeft}" Style="{StaticResource {x:Type ToggleButton}}"
77108
IsChecked="{Binding Path=CurrentTool, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static local:ToolMode.Draw},Mode=TwoWay}">
78109
<Image Source="/Resources/Buttons/drawmode.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
79110
</RadioButton>
80-
<RadioButton GroupName="Toolbar" Tag="Fill" ToolTip="Flood Fill (F)" Style="{StaticResource {x:Type ToggleButton}}"
111+
<RadioButton GroupName="Toolbar" Tag="Fill" ToolTip="Flood Fill (F)" Template="{DynamicResource ToggleButtonLeft}" Style="{StaticResource {x:Type ToggleButton}}"
81112
IsChecked="{Binding Path=CurrentTool, Converter={StaticResource ComparisonConverter}, ConverterParameter={x:Static local:ToolMode.Fill},Mode=TwoWay}">
82113
<Image Source="/Resources/Buttons/paint.png" Width="24" Height="24" RenderOptions.BitmapScalingMode="NearestNeighbor" />
83114
</RadioButton>
@@ -176,9 +207,9 @@
176207
<Rectangle x:Name="rectSecondaryColor" Fill="Black" HorizontalAlignment="Left" Height="28" Margin="47,276,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
177208

178209
<!-- https://stackoverflow.com/a/32514853/5452781 -->
179-
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="459,130,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
180-
<Rectangle x:Name="rectSaturation" Fill="{StaticResource LevelSaturationBrush}" Width="200" Height="200" Margin="459,130,0,0" StrokeThickness="1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" />
181-
<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" />
210+
<Rectangle x:Name="tempRect" Width="200" Height="200" Margin="459,130,0,0" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Top" UseLayoutRounding="False" Fill="Black" />
211+
<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" />
212+
<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" />
182213

183214
</Grid>
184215
</Window>

PixelArtTool/MainWindow.xaml.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,20 @@ private void rectHueBar_MouseDown(object sender, MouseButtonEventArgs e)
11251125
rectSaturation.OpacityMask = opacityBrush;
11261126

11271127
}
1128+
1129+
private void OnLevelSaturationMouseDown(object sender, MouseButtonEventArgs e)
1130+
{
1131+
POINT cursor;
1132+
GetCursorPos(out cursor);
1133+
var c1 = Win32GetScreenPixel((int)cursor.X, (int)cursor.Y);
1134+
var c2 = new PixelColor();
1135+
c2.Alpha = c1.A;
1136+
c2.Red = c1.R;
1137+
c2.Green = c1.G;
1138+
c2.Blue = c1.B;
1139+
currentColor = c2;
1140+
rectCurrentColor.Fill = new SolidColorBrush(Color.FromArgb(c2.Alpha, c2.Red, c2.Green, c2.Blue));
1141+
}
11281142
} // class
11291143

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

0 commit comments

Comments
 (0)