Skip to content

Commit

Permalink
Add touch feedback to color buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
AmitJayant committed Apr 13, 2016
1 parent e45501b commit 577a674
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
2 changes: 1 addition & 1 deletion MaterialColors/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="About Material Colors" Height="300" Width="350" WindowStartupLocation="CenterOwner" ResizeMode="NoResize" Background="WhiteSmoke" Icon="Resources/icon.ico">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Image Source="/Resources/MaterialColors.png" Width="128" Height="128"/>
<TextBlock FontSize="11" Text="Version 1.0.1" HorizontalAlignment="Center"/>
<TextBlock FontSize="11" Text="Version 1.0.2" HorizontalAlignment="Center"/>
<TextBlock Tag="0" FontSize="11" Text="by Amit Jayant" HorizontalAlignment="Center" MouseDown="TextBlock_MouseDown" Cursor="Hand"/>
<TextBlock Tag="1" FontSize="11" Text="Source Code on Github" HorizontalAlignment="Center" Margin="0,16,0,0" MouseDown="TextBlock_MouseDown" Cursor="Hand"/>
<TextBlock Tag="2" FontSize="11" Text="Design inpired by Roman Nurik's Material Colors App for Mac" Margin="0,16,0,0" MouseDown="TextBlock_MouseDown" Cursor="Hand"/>
Expand Down
98 changes: 84 additions & 14 deletions MaterialColors/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@
<Button Grid.Row="1" x:Name="btn50" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="0" Fill="#FFEBEE" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="0" Fill="#FFEBEE" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="50" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#FFEBEE" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -217,8 +222,13 @@
<Button Grid.Row="2" x:Name="btn100" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="1" Fill="#FFCDD2" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="1" Fill="#FFCDD2" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="100" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#FFCDD2" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -228,8 +238,13 @@
<Button Grid.Row="3" x:Name="btn200" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="2" Fill="#EF9A9A" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="2" Fill="#EF9A9A" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="200" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#EF9A9A" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -239,8 +254,13 @@
<Button Grid.Row="4" x:Name="btn300" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="3" Fill="#E57373" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="3" Fill="#E57373" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="300" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#E57373" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -250,8 +270,13 @@
<Button Grid.Row="5" x:Name="btn400" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="4" Fill="#EF5350" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="4" Fill="#EF5350" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="400" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#EF5350" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -261,8 +286,13 @@
<Button Grid.Row="6" x:Name="btn500" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="5" Fill="#F44336" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="5" Fill="#F44336" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="500" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#F44336" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -272,8 +302,13 @@
<Button Grid.Row="7" x:Name="btn600" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="6" Fill="#E53935" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="6" Fill="#E53935" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="600" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#E53935" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -283,8 +318,13 @@
<Button Grid.Row="8" x:Name="btn700" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="7" Fill="#D32F2F" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="7" Fill="#D32F2F" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="700" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#D32F2F" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -294,8 +334,13 @@
<Button Grid.Row="9" x:Name="btn800" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="8" Fill="#C62828" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="8" Fill="#C62828" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="800" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#C62828" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -305,8 +350,13 @@
<Button Grid.Row="10" x:Name="btn900" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="9" Fill="#B71C1C" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="9" Fill="#B71C1C" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="900" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#B71C1C" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -316,8 +366,13 @@
<Button Grid.Row="11" x:Name="btnA100" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="10" Fill="#FF8A80" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="10" Fill="#FF8A80" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="A100" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#FF8A80" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -327,8 +382,13 @@
<Button Grid.Row="12" x:Name="btnA200" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="11" Fill="#FF5252" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="11" Fill="#FF5252" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="A200" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#FF5252" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -338,8 +398,13 @@
<Button Grid.Row="13" x:Name="btnA400" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="12" Fill="#FF1744" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="12" Fill="#FF1744" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="A400" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#FF1744" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand All @@ -349,8 +414,13 @@
<Button Grid.Row="14" x:Name="btnA700" Margin="8,2,24,2" Click="ColorSwatch_ButtonClick">
<Button.Template>
<ControlTemplate>
<ControlTemplate.Triggers>
<Trigger Property="Button.IsPressed" Value="True">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
<Grid>
<Rectangle Tag="13" Fill="#D50000" Stroke="Gray" Cursor="Hand" />
<Rectangle Tag="13" Fill="#D50000" Stroke="Gray" StrokeThickness="0.2" Cursor="Hand" />
<Label Content="A700" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Left" Cursor="Hand"/>
<Label Content="#D50000" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Right" Cursor="Hand"/>
</Grid>
Expand Down
2 changes: 2 additions & 0 deletions MaterialColors/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ private void ColorGroup_ButtonClick(object sender, RoutedEventArgs e)

private void ColorSwatch_ButtonClick(object sender, RoutedEventArgs e)
{
// Copy color hex to clipboard
grid = (Grid)VisualTreeHelper.GetChild((Button)sender, 0);
Label labelHex = (Label)VisualTreeHelper.GetChild(grid, 2);
Clipboard.SetText(labelHex.Content.ToString());
}

private void labelAbout_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// Show about dialog
About about = new About();
about.Owner = Window.GetWindow(this);
about.ShowDialog();
Expand Down
4 changes: 2 additions & 2 deletions MaterialColors/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]

0 comments on commit 577a674

Please sign in to comment.