diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls')
4 files changed, 266 insertions, 77 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml index 2aa11c63c..d65bd5d8f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml @@ -6,46 +6,19 @@ xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls" xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls" mc:Ignorable="d" - d:DesignHeight="250" d:DesignWidth="550" Background="White"> + Height="250" Width="650" Background="White"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="235"/> <ColumnDefinition Width="1*"/> - <ColumnDefinition Width="50"/> </Grid.ColumnDefinitions> - <colorPicker:ColorCanvas SelectedColor="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=SelectedColor,Mode=TwoWay}" Background="Transparent" BorderThickness="0" UsingAlphaChannel="False" /> + <colorPicker:ColorCanvas x:Name="colorCanvas" SelectedColor="{x:Null}" SelectedColorChanged="ColorCanvas_SelectedColorChanged" Background="Transparent" BorderThickness="0" UsingAlphaChannel="False" /> - <Viewbox Stretch="Uniform" Grid.Column="1" Margin="5"> - <controls:HiveControl x:Name="hive" Height="250" HexagonSelected="hive_HexagonSelected" MaxSelections="1" Width="250" BorderThickness="1" /> - </Viewbox> - - <Grid Grid.Column="2"> - <Grid> - <Grid.RowDefinitions> - <RowDefinition Height="1*"/> - <RowDefinition Height="45"/> - <RowDefinition Height="1*"/> - </Grid.RowDefinitions> - <Button ToolTip="Increase Delta Resolution" Click="OnResolutionUpClicked" Style="{StaticResource MaterialDesignFlatButton}" Height="50" Padding="0" Foreground="#202020" VerticalAlignment="Bottom"> - <materialDesign:PackIcon Kind="ArrowUp" Width="24" Height="24" /> - </Button> - - <Grid Grid.Row="1"> - <shapes:Hexagon Stroke="#202020" StrokeThickness="1" Margin="5" /> - <TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" FontStyle="Italic" FontSize="10"> - <Run Text="Δ"></Run> - <Run Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Resolution,FallbackValue=1}"></Run> - </TextBlock> - </Grid> - - <Button ToolTip="Decrease Delta Resolution" Click="OnResolutionDownClicked" Grid.Row="2" Style="{StaticResource MaterialDesignFlatButton}" Height="50" Padding="0" Foreground="#202020" VerticalAlignment="Top"> - <materialDesign:PackIcon Kind="ArrowDown" Width="24" Height="24" /> - </Button> - </Grid> - </Grid> + <commonControls:HiveComboControl x:Name="hiveCombo" Grid.Column="1" SelectedHexagonChanged="hiveCombo_SelectedHexagonChanged" /> </Grid> </UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs index 7d1a1dc81..41b362889 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.SharedUI.Controls; namespace Tango.MachineStudio.Common.Controls { @@ -21,7 +23,12 @@ namespace Tango.MachineStudio.Common.Controls public partial class HiveColorPickerControl : UserControl { public event EventHandler<Color> SelectedColorChanged; - private bool _preventHiveSelectedColorChange; + public event EventHandler<Color> SelectedHiveColorChanged; + public event EventHandler<HexagonControl> SelectedHexagonChanged; + public event EventHandler<int> LAxisValueChanged; + public event EventHandler<int> ResolutionChanged; + + private bool _preventColorCanvasEvent; public bool DemoMode { @@ -39,93 +46,112 @@ namespace Tango.MachineStudio.Common.Controls public static readonly DependencyProperty ResolutionProperty = DependencyProperty.Register("Resolution", typeof(int), typeof(HiveColorPickerControl), new PropertyMetadata(1, (d, e) => (d as HiveColorPickerControl).OnResolutionChanged())); - public Color SelectedColor + public Color? SelectedColor { - get { return (Color)GetValue(SelectedColorProperty); } + get { return (Color?)GetValue(SelectedColorProperty); } set { SetValue(SelectedColorProperty, value); } } public static readonly DependencyProperty SelectedColorProperty = - DependencyProperty.Register("SelectedColor", typeof(Color), typeof(HiveColorPickerControl), new PropertyMetadata(Colors.Red, (d, e) => (d as HiveColorPickerControl).OnSelectedColorChanged())); + DependencyProperty.Register("SelectedColor", typeof(Color?), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedColorChanged())); + + public HexagonControl SelectedHexagon + { + get { return (HexagonControl)GetValue(SelectedHexagonProperty); } + set { SetValue(SelectedHexagonProperty, value); } + } + public static readonly DependencyProperty SelectedHexagonProperty = + DependencyProperty.Register("SelectedHexagon", typeof(HexagonControl), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedHexagonChanged())); - public Color SelectedHiveColor + public Color? SelectedHiveColor { - get { return (Color)GetValue(SelectedHiveColorProperty); } + get { return (Color?)GetValue(SelectedHiveColorProperty); } set { SetValue(SelectedHiveColorProperty, value); } } public static readonly DependencyProperty SelectedHiveColorProperty = - DependencyProperty.Register("SelectedHiveColor", typeof(Color), typeof(HiveColorPickerControl), new PropertyMetadata(Colors.Red)); + DependencyProperty.Register("SelectedHiveColor", typeof(Color?), typeof(HiveColorPickerControl), new PropertyMetadata(null, (d, e) => (d as HiveColorPickerControl).OnSelectedHiveColorChanged())); + + public int LAxisValue + { + get { return (int)GetValue(LAxisValueProperty); } + set { SetValue(LAxisValueProperty, value); } + } + public static readonly DependencyProperty LAxisValueProperty = + DependencyProperty.Register("LAxisValue", typeof(int), typeof(HiveColorPickerControl), new PropertyMetadata(0, (d, e) => (d as HiveColorPickerControl).OnLAxisValueChanged())); + public HiveColorPickerControl() { InitializeComponent(); - hive.Loaded += Hive_Loaded; + this.Bind(ResolutionProperty, hiveCombo, HiveComboControl.ResolutionProperty, BindingMode.TwoWay); + this.Bind(SelectedHexagonProperty, hiveCombo, HiveComboControl.SelectedHexagonProperty, BindingMode.OneWay); + this.Bind(LAxisValueProperty, hiveCombo, HiveComboControl.LAxisValueProperty, BindingMode.OneWay); + + + hiveCombo.HiveGenerated += HiveCombo_HiveGenerated; } - private void Hive_Loaded(object sender, RoutedEventArgs e) + private void HiveCombo_HiveGenerated(object sender, EventArgs e) { - OnSelectedColorChanged(); + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); + } + + private void OnSelectedHiveColorChanged() + { + //_preventColorCanvasEvent = true; + //colorCanvas.SelectedColor = SelectedHiveColor; + //_preventColorCanvasEvent = false; + + SelectedHiveColorChanged?.Invoke(this, SelectedHiveColor.Value); } private void OnSelectedColorChanged() { - if (DemoMode) + if (SelectedColor != null) { - if (!_preventHiveSelectedColorChange) + _preventColorCanvasEvent = true; + colorCanvas.SelectedColor = SelectedColor; + _preventColorCanvasEvent = false; + + if (DemoMode) { - GenerateDemoModeHiveColors(); + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); } - SelectedColorChanged?.Invoke(this, SelectedColor); + + SelectedColorChanged?.Invoke(this, SelectedColor.Value); } } - private void hive_HexagonSelected(object sender, SharedUI.Controls.HexagonControl hexagon) + private void OnSelectedHexagonChanged() { - SelectedHiveColor = (hexagon.Fill as SolidColorBrush).Color; - - _preventHiveSelectedColorChange = true; - SelectedColor = SelectedHiveColor; - _preventHiveSelectedColorChange = false; + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); + SelectedHiveColor = (SelectedHexagon.Fill as SolidColorBrush).Color; } - private void OnResolutionChanged() + private void OnLAxisValueChanged() { - GenerateDemoModeHiveColors(); + LAxisValueChanged?.Invoke(this, LAxisValue); } - private void GenerateDemoModeHiveColors() + private void OnResolutionChanged() { - if (hive.CenterHexagon != null) - { - Random rnd = new Random(); - - (hive.CenterHexagon.Fill as SolidColorBrush).Color = SelectedColor; - - int counter = 0; - - foreach (var hexagon in hive.Hexagons.Where(x => x != hive.CenterHexagon).OrderBy(x => rnd.Next())) - { - (hexagon.Fill as SolidColorBrush).Color = Color.FromRgb((byte)Math.Min(SelectedColor.R + counter++, 255), (byte)Math.Min((SelectedColor.G + counter++), 255), (byte)Math.Min((SelectedColor.B + counter++), 255)); - - counter += (int)(4d * ((double)Resolution / 4d)); - } - } + hiveCombo.GenerateDemoModeHiveColors(SelectedColor.Value); } - private void OnResolutionUpClicked(object sender, RoutedEventArgs e) + private void ColorCanvas_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color?> e) { - if (Resolution < 10) + if (!_preventColorCanvasEvent) { - Resolution++; + SelectedColor = e.NewValue.Value; + hiveCombo.SelectHeagon(hiveCombo.CenterHexagon); } } - private void OnResolutionDownClicked(object sender, RoutedEventArgs e) + private void hiveCombo_SelectedHexagonChanged(object sender, HexagonControl e) { - if (Resolution > 1) - { - Resolution--; - } + SelectedHexagon = e; + SelectedHiveColor = (SelectedHexagon.Fill as SolidColorBrush).Color; + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml new file mode 100644 index 000000000..692b3f818 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml @@ -0,0 +1,54 @@ +<UserControl x:Class="Tango.MachineStudio.Common.Controls.HiveComboControl" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" + xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" + xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls" + mc:Ignorable="d" + Height="250" Width="415"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"/> + <ColumnDefinition Width="70"/> + <ColumnDefinition Width="50"/> + </Grid.ColumnDefinitions> + + <Viewbox Stretch="Uniform" Grid.Column="0" Margin="5"> + <controls:HiveControl x:Name="hive" x:FieldModifier="public" Height="250" HexagonSelected="OnHexagonSelected" MaxSelections="1" Width="250" BorderThickness="1" /> + </Viewbox> + + <Grid Grid.Column="1" ClipToBounds="True"> + <Viewbox Stretch="Fill" Width="160" Height="200" HorizontalAlignment="Right" Margin="0 0 -20 0"> + <controls:HiveControl Height="290" HexagonSelected="OnRowHiveHexagonSelected" MaxSelections="1" Width="100" Margin="0 0 50 0" HiveWidth="1" HiveHeight="5" BorderThickness="1" /> + </Viewbox> + </Grid> + + <Grid Grid.Column="2"> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="1*"/> + <RowDefinition Height="45"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + <Button ToolTip="Increase Delta Resolution" Click="OnResolutionUpClicked" Style="{StaticResource MaterialDesignFlatButton}" Height="50" Padding="0" Foreground="#202020" VerticalAlignment="Bottom"> + <materialDesign:PackIcon Kind="ArrowUp" Width="24" Height="24" /> + </Button> + + <Grid Grid.Row="1"> + <shapes:Hexagon Stroke="#202020" StrokeThickness="1" Margin="5" /> + <TextBlock TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold" FontStyle="Italic" FontSize="10"> + <Run Text="Δ"></Run> + <Run Text="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=Resolution,FallbackValue=1}"></Run> + </TextBlock> + </Grid> + + <Button ToolTip="Decrease Delta Resolution" Click="OnResolutionDownClicked" Grid.Row="2" Style="{StaticResource MaterialDesignFlatButton}" Height="50" Padding="0" Foreground="#202020" VerticalAlignment="Top"> + <materialDesign:PackIcon Kind="ArrowDown" Width="24" Height="24" /> + </Button> + </Grid> + </Grid> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs new file mode 100644 index 000000000..342a1f1c9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Logging; +using Tango.SharedUI.Controls; + +namespace Tango.MachineStudio.Common.Controls +{ + /// <summary> + /// Interaction logic for HiveComboControl.xaml + /// </summary> + public partial class HiveComboControl : UserControl + { + public event EventHandler<Color> SelectedColorChanged; + public event EventHandler<HexagonControl> SelectedHexagonChanged; + public event EventHandler<int> LAxisValueChanged; + public event EventHandler<int> ResolutionChanged; + public event EventHandler HiveGenerated; + + public int Resolution + { + get { return (int)GetValue(ResolutionProperty); } + set { SetValue(ResolutionProperty, value); } + } + public static readonly DependencyProperty ResolutionProperty = + DependencyProperty.Register("Resolution", typeof(int), typeof(HiveComboControl), new PropertyMetadata(1, (d, e) => (d as HiveComboControl).OnResolutionChanged())); + + public HexagonControl SelectedHexagon + { + get { return (HexagonControl)GetValue(SelectedHexagonProperty); } + set { SetValue(SelectedHexagonProperty, value); } + } + public static readonly DependencyProperty SelectedHexagonProperty = + DependencyProperty.Register("SelectedHexagon", typeof(HexagonControl), typeof(HiveComboControl), new PropertyMetadata(null, (d, e) => (d as HiveComboControl).OnSelectedHexagonChanged())); + + public int LAxisValue + { + get { return (int)GetValue(LAxisValueProperty); } + set { SetValue(LAxisValueProperty, value); } + } + public static readonly DependencyProperty LAxisValueProperty = + DependencyProperty.Register("LAxisValue", typeof(int), typeof(HiveComboControl), new PropertyMetadata(0, (d, e) => (d as HiveComboControl).OnLAxisValueChanged())); + + public HexagonControl CenterHexagon + { + get { return hive.CenterHexagon; } + } + + + public HiveComboControl() + { + InitializeComponent(); + + hive.HiveGenerated += (x, e) => HiveGenerated?.Invoke(this, new EventArgs()); + } + + private void OnLAxisValueChanged() + { + LAxisValueChanged?.Invoke(this, LAxisValue); + } + + private void OnSelectedHexagonChanged() + { + SelectedHexagonChanged?.Invoke(this, SelectedHexagon); + } + + private void OnResolutionChanged() + { + ResolutionChanged?.Invoke(this, Resolution); + } + + public void GenerateDemoModeHiveColors(Color originalColor) + { + if (hive.CenterHexagon != null) + { + Random rnd = new Random(); + + (hive.CenterHexagon.Fill as SolidColorBrush).Color = originalColor; + + int counter = 0; + + foreach (var hexagon in hive.Hexagons.Where(x => x != hive.CenterHexagon).OrderBy(x => rnd.Next())) + { + (hexagon.Fill as SolidColorBrush).Color = Color.FromRgb((byte)Math.Min(originalColor.R + counter++, 255), (byte)Math.Min((originalColor.G + counter++), 255), (byte)Math.Min((originalColor.B + counter++), 255)); + + counter += (int)(4d * ((double)Resolution / 4d)); + } + } + } + + private void OnResolutionUpClicked(object sender, RoutedEventArgs e) + { + if (Resolution < 10) + { + Resolution++; + } + } + + private void OnResolutionDownClicked(object sender, RoutedEventArgs e) + { + if (Resolution > 1) + { + Resolution--; + } + } + + private void OnRowHiveHexagonSelected(object sender, HexagonControl hexagon) + { + int l = 2 - hexagon.Row; + LogManager.Default.Log("L ROW: " + l.ToString()); + } + + private void OnHexagonSelected(object sender, HexagonControl e) + { + SelectedHexagon = e; + } + + public void SelectHeagon(HexagonControl hexagon) + { + hive.SelectHexagon(hexagon); + SelectedHexagonChanged?.Invoke(this, hexagon); + } + } +} |
