diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopViewModel.cs b/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopViewModel.cs index 7629a9899..60080f009 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopViewModel.cs +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/ColorStopViewModel.cs @@ -32,6 +32,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor ColorStop.Position = (float) Math.Round(value / _gradientEditorViewModel.PreviewWidth, 3, MidpointRounding.AwayFromZero); NotifyOfPropertyChange(nameof(Offset)); NotifyOfPropertyChange(nameof(OffsetPercent)); + NotifyOfPropertyChange(nameof(OffsetFloat)); } } @@ -43,6 +44,20 @@ namespace Artemis.UI.Shared.Screens.GradientEditor ColorStop.Position = Math.Min(100, Math.Max(0, value)) / 100f; NotifyOfPropertyChange(nameof(Offset)); NotifyOfPropertyChange(nameof(OffsetPercent)); + NotifyOfPropertyChange(nameof(OffsetFloat)); + } + } + + // Functionally similar to Offset Percent, but doesn't round on get in order to prevent inconsistencies (and is 0 to 1) + public float OffsetFloat + { + get => ColorStop.Position; + set + { + ColorStop.Position = Math.Min(1, Math.Max(0, value)); + NotifyOfPropertyChange(nameof(Offset)); + NotifyOfPropertyChange(nameof(OffsetPercent)); + NotifyOfPropertyChange(nameof(OffsetFloat)); } } diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorView.xaml b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorView.xaml index 64e084204..2d8a50a73 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorView.xaml +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorView.xaml @@ -12,9 +12,9 @@ Background="{DynamicResource MaterialDesignPaper}" FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto" Width="400" - Height="400" - d:DesignHeight="450" - d:DesignWidth="800" + Height="425" + d:DesignHeight="425" + d:DesignWidth="400" d:DataContext="{d:DesignInstance local:GradientEditorViewModel}"> @@ -90,8 +90,43 @@ - - Selected stop + + + + + + + Selected stop: @@ -122,8 +157,12 @@ Margin="8,0,0,0" IsEnabled="{Binding HasSelectedColorStopViewModel}" Command="{s:Action RemoveColorStop}" - CommandParameter="{Binding SelectedColorStopViewModel}"> - DELETE + CommandParameter="{Binding SelectedColorStopViewModel}" + ToolTip="Delete Selected Stop"> + + + Delete + diff --git a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs index 497d81963..fb170cc33 100644 --- a/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs +++ b/src/Artemis.UI.Shared/Screens/GradientEditor/GradientEditorViewModel.cs @@ -27,6 +27,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor PropertyChanged += UpdateColorStopViewModels; ColorGradient.CollectionChanged += ColorGradientOnCollectionChanged; + ColorStopViewModels.CollectionChanged += ColorStopViewModelsOnCollectionChanged; } #region Overrides of DialogViewModelBase @@ -53,6 +54,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor } public bool HasSelectedColorStopViewModel => SelectedColorStopViewModel != null; + public bool HasMoreThanOneStop => ColorStopViewModels.Count > 1; public ColorGradient ColorGradient { get; } @@ -79,6 +81,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor ColorStopViewModels.Insert(index, viewModel); SelectColorStop(viewModel); + NotifyOfPropertyChange(nameof(HasMoreThanOneStop)); } public void RemoveColorStop(ColorStopViewModel colorStopViewModel) @@ -90,6 +93,38 @@ namespace Artemis.UI.Shared.Screens.GradientEditor ColorGradient.Remove(colorStopViewModel.ColorStop); SelectColorStop(null); + NotifyOfPropertyChange(nameof(HasMoreThanOneStop)); + } + + public void SpreadColorStops() + { + var stops = ColorStopViewModels.OrderBy(x => x.OffsetFloat); + int index = 0; + foreach (ColorStopViewModel stop in stops) + { + stop.OffsetFloat = index / ((float)stops.Count() - 1); + index++; + } + } + + public void RotateColorStops() + { + var stops = ColorStopViewModels.OrderByDescending(x => x.OffsetFloat); + float lastStopPosition = stops.Last().OffsetFloat; + foreach (ColorStopViewModel stop in stops) + { + float tempStop = stop.OffsetFloat; + stop.OffsetFloat = lastStopPosition; + lastStopPosition = tempStop; + } + } + + public void FlipColorStops() + { + foreach (ColorStopViewModel stop in ColorStopViewModels) + { + stop.OffsetFloat = 1 - stop.OffsetFloat; + } } public Point GetPositionInPreview(object sender, MouseEventArgs e) @@ -127,10 +162,15 @@ namespace Artemis.UI.Shared.Screens.GradientEditor foreach (ColorGradientStop colorStop in ColorGradient) ColorStopViewModels.Add(new ColorStopViewModel(this, colorStop)); } - + private void ColorGradientOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) { NotifyOfPropertyChange(nameof(ColorGradient)); } + + private void ColorStopViewModelsOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e) + { + NotifyOfPropertyChange(nameof(HasMoreThanOneStop)); + } } } \ No newline at end of file