From b32341437ba3e66ca487b0685b352af59e4ad0f5 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 6 Feb 2018 14:03:45 +0200 Subject: Improved BrushStop Offset clipping. --- .../Converters/BrushStopToOffsetValueConverter.cs | 52 ++++++++++++++ .../Tango.MachineStudio.Developer.csproj | 1 + .../ViewModels/MainViewVM.cs | 8 ++- .../Views/MainView.xaml | 79 +++++++++++++++++++--- .../Views/MainView.xaml.cs | 5 -- 5 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs new file mode 100644 index 000000000..d8ac744a9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class BrushStopToOffsetValueConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + BrushStop stop = values[0] as BrushStop; + Segment segment = values[1] as Segment; + + if (stop != null && segment != null) + { + if (segment.BrushStops.IndexOf(stop) == segment.BrushStops.Count - 1) + { + return 100d; + } + else if (segment.BrushStops.IndexOf(stop) == 0) + { + return 0d; + } + else + { + return stop.OffsetPercent; + } + } + else + { + return 0d; + } + } + catch + { + return 0d; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 7a3e838cf..ee3295d45 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -94,6 +94,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4cf14a216..4e7c5ec12 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1015,11 +1015,17 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The dropped stop. public void OnDropBrushStop(BrushStop draggedStop, BrushStop droppedStop) { + SelectedSegment.BrushStops.Swap(draggedStop, droppedStop); + int tmpIndex = draggedStop.StopIndex; draggedStop.StopIndex = droppedStop.StopIndex; droppedStop.StopIndex = tmpIndex; - SelectedSegment.BrushStops.Swap(draggedStop, droppedStop); + if (SelectedSegment.BrushStops.Count > 1) + { + SelectedSegment.BrushStops.First().OffsetPercent = 0; + SelectedSegment.BrushStops.Last().OffsetPercent = 100; + } } /// diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index ae57c2d25..f716b6228 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -53,6 +53,7 @@ + @@ -806,21 +807,43 @@ - + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -956,13 +979,32 @@ - + - + + + + + + + + + + + + + + + + + + + + @@ -1232,8 +1274,22 @@ - - + + + + + + + + + @@ -1243,8 +1299,9 @@ - + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs index be24711c1..c8d37d9aa 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs @@ -110,11 +110,6 @@ namespace Tango.MachineStudio.Developer.Views } } - private void ColorPickerCombo_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs e) - { - - } - private void Offset_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { UpdateGradientBrushDisplay(); -- cgit v1.3.1