aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-02-05 17:13:36 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-02-05 17:13:36 +0200
commite66f1bad3aad6de7f63aa9c277b87d8416c08488 (patch)
tree0fa147e0ffb968d7d3588e2cffddb81132f14456 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls
parent7228d8ffc60ee07fdc3532f9a6c06719a7f352a8 (diff)
downloadTango-e66f1bad3aad6de7f63aa9c277b87d8416c08488.tar.gz
Tango-e66f1bad3aad6de7f63aa9c277b87d8416c08488.zip
Implemented HiveColorPicker mock on developer module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml23
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml.cs102
2 files changed, 125 insertions, 0 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
new file mode 100644
index 000000000..6a9bf9cc9
--- /dev/null
+++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveColorPickerControl.xaml
@@ -0,0 +1,23 @@
+<UserControl x:Class="Tango.MachineStudio.Common.Controls.HiveColorPickerControl"
+ 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:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker"
+ xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
+ xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls"
+ mc:Ignorable="d"
+ d:DesignHeight="250" d:DesignWidth="500" >
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="235"/>
+ <ColumnDefinition Width="43*"/>
+ </Grid.ColumnDefinitions>
+
+ <colorPicker:ColorCanvas SelectedColor="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=SelectedColor,Mode=TwoWay}" 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>
+</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
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
+{
+ /// <summary>
+ /// Interaction logic for HiveColorPickerControl.xaml
+ /// </summary>
+ public partial class HiveColorPickerControl : UserControl
+ {
+ public event EventHandler<Color> 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;
+ }
+ }
+ }
+ }
+}