From e66f1bad3aad6de7f63aa9c277b87d8416c08488 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 5 Feb 2018 17:13:36 +0200 Subject: Implemented HiveColorPicker mock on developer module. --- .../Controls/HiveColorPickerControl.xaml | 23 +++++ .../Controls/HiveColorPickerControl.xaml.cs | 102 +++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml new file mode 100644 index 000000000..6a9bf9cc9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + 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 new file mode 100644 index 000000000..9432ae9ef --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +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; + +namespace Tango.MachineStudio.Common.Controls +{ + /// + /// Interaction logic for HiveColorPickerControl.xaml + /// + public partial class HiveColorPickerControl : UserControl + { + public event EventHandler SelectedColorChanged; + private bool _preventHiveSelectedColorChange; + + public bool DemoMode + { + get { return (bool)GetValue(DemoModeProperty); } + set { SetValue(DemoModeProperty, value); } + } + public static readonly DependencyProperty DemoModeProperty = + DependencyProperty.Register("DemoMode", typeof(bool), typeof(HiveColorPickerControl), new PropertyMetadata(false)); + + public Color SelectedColor + { + 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())); + + public Color SelectedHiveColor + { + 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)); + + public HiveColorPickerControl() + { + InitializeComponent(); + + hive.Loaded += Hive_Loaded; + } + + private void Hive_Loaded(object sender, RoutedEventArgs e) + { + OnSelectedColorChanged(); + } + + private void OnSelectedColorChanged() + { + if (DemoMode) + { + if (!_preventHiveSelectedColorChange) + { + GenerateDemoModeHiveColors(); + } + SelectedColorChanged?.Invoke(this, SelectedColor); + } + } + + private void hive_HexagonSelected(object sender, SharedUI.Controls.HexagonControl hexagon) + { + SelectedHiveColor = (hexagon.Fill as SolidColorBrush).Color; + + _preventHiveSelectedColorChange = true; + SelectedColor = SelectedHiveColor; + _preventHiveSelectedColorChange = false; + } + + private void GenerateDemoModeHiveColors() + { + 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 += 4; + } + } + } + } +} -- cgit v1.3.1