aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-03-06 18:28:51 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-03-06 18:28:51 +0200
commit4e48c569f1cae820ffade8a786354b2ba79b50b4 (patch)
tree1bfbdf19f8c86cc1f1a1d8b900756b0cc2781d66 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs
parent7e6c673cc8b04086fa3c78cd1bf5e31085fd8cc8 (diff)
downloadTango-4e48c569f1cae820ffade8a786354b2ba79b50b4.tar.gz
Tango-4e48c569f1cae820ffade8a786354b2ba79b50b4.zip
Some improvements on hive.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs')
-rw-r--r--Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/HiveComboControl.xaml.cs136
1 files changed, 136 insertions, 0 deletions
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);
+ }
+ }
+}