mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Brushes - Added brush presets
ColorGradient - Refactored so it implements IList
This commit is contained in:
1 parent
e32b181d9f
commit
3d38461bdd
18 files changed
+722
-419
No files matched your search
@@ -38,7 +38,7 @@
|
||||
<Rectangle Stroke="{DynamicResource NormalBorderBrush}" Cursor="Hand" MouseUp="UIElement_OnMouseUp">
|
||||
<Rectangle.Fill>
|
||||
<LinearGradientBrush
|
||||
GradientStops="{Binding ColorGradient.Stops, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorGradientToGradientStopsConverter}}"
|
||||
GradientStops="{Binding ColorGradient, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorGradientToGradientStopsConverter}}"
|
||||
EndPoint="1,0"
|
||||
StartPoint="0,0" />
|
||||
</Rectangle.Fill>
|
||||
|
||||
@@ -14,18 +14,18 @@ namespace Artemis.UI.Shared
|
||||
/// Converts <see cref="T:Artemis.Core.Models.Profile.ColorGradient" /> into a
|
||||
/// <see cref="T:System.Windows.Media.GradientStopCollection" />.
|
||||
/// </summary>
|
||||
[ValueConversion(typeof(List<ColorGradientStop>), typeof(GradientStopCollection))]
|
||||
[ValueConversion(typeof(ColorGradient), typeof(GradientStopCollection))]
|
||||
public class ColorGradientToGradientStopsConverter : IValueConverter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
List<ColorGradientStop> colorGradients = (List<ColorGradientStop>) value;
|
||||
ColorGradient? colorGradient = value as ColorGradient;
|
||||
GradientStopCollection collection = new();
|
||||
if (colorGradients == null)
|
||||
if (colorGradient == null)
|
||||
return collection;
|
||||
|
||||
foreach (ColorGradientStop c in colorGradients.OrderBy(s => s.Position))
|
||||
foreach (ColorGradientStop c in colorGradient.OrderBy(s => s.Position))
|
||||
collection.Add(new GradientStop(Color.FromArgb(c.Color.Alpha, c.Color.Red, c.Color.Green, c.Color.Blue), c.Position));
|
||||
return collection;
|
||||
}
|
||||
@@ -33,8 +33,8 @@ namespace Artemis.UI.Shared
|
||||
/// <inheritdoc />
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
GradientStopCollection collection = (GradientStopCollection) value;
|
||||
List<ColorGradientStop> colorGradients = new();
|
||||
GradientStopCollection? collection = value as GradientStopCollection;
|
||||
ColorGradient colorGradients = new();
|
||||
if (collection == null)
|
||||
return colorGradients;
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
{
|
||||
_gradientEditorViewModel = gradientEditorViewModel;
|
||||
ColorStop = colorStop;
|
||||
ColorStop.PropertyChanged += ColorStopOnPropertyChanged;
|
||||
}
|
||||
|
||||
public ColorGradientStop ColorStop { get; }
|
||||
@@ -58,12 +57,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
get => _willRemoveColorStop;
|
||||
set => SetAndNotify(ref _willRemoveColorStop, value);
|
||||
}
|
||||
|
||||
private void ColorStopOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
_gradientEditorViewModel.ColorGradient.OnColorValuesUpdated();
|
||||
}
|
||||
|
||||
|
||||
#region Movement
|
||||
|
||||
public void StopMouseDown(object sender, MouseButtonEventArgs e)
|
||||
@@ -102,7 +96,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
|
||||
double minValue = 0.0;
|
||||
double maxValue = _gradientEditorViewModel.PreviewWidth;
|
||||
List<ColorGradientStop> stops = _gradientEditorViewModel.ColorGradient.Stops.OrderBy(s => s.Position).ToList();
|
||||
List<ColorGradientStop> stops = _gradientEditorViewModel.ColorGradient.ToList();
|
||||
ColorGradientStop? previous = stops.IndexOf(ColorStop) >= 1 ? stops[stops.IndexOf(ColorStop) - 1] : null;
|
||||
ColorGradientStop? next = stops.IndexOf(ColorStop) + 1 < stops.Count ? stops[stops.IndexOf(ColorStop) + 1] : null;
|
||||
if (previous != null)
|
||||
@@ -111,7 +105,6 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
maxValue = next.Position * _gradientEditorViewModel.PreviewWidth;
|
||||
|
||||
Offset = Math.Max(minValue, Math.Min(maxValue, position.X));
|
||||
_gradientEditorViewModel.ColorGradient.OnColorValuesUpdated();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
<Rectangle x:Name="Preview" Height="40" shared:SizeObserver.Observe="True" shared:SizeObserver.ObservedWidth="{Binding PreviewWidth, Mode=OneWayToSource}">
|
||||
<Rectangle.Fill>
|
||||
<LinearGradientBrush
|
||||
GradientStops="{Binding ColorGradient.Stops, Converter={StaticResource ColorGradientToGradientStopsConverter}}"
|
||||
GradientStops="{Binding ColorGradient, Converter={StaticResource ColorGradientToGradientStopsConverter}}"
|
||||
EndPoint="1,0"
|
||||
StartPoint="0,0" />
|
||||
</Rectangle.Fill>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
@@ -6,6 +7,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
@@ -21,12 +23,24 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
ColorGradient = colorGradient;
|
||||
ColorStopViewModels = new BindableCollection<ColorStopViewModel>();
|
||||
|
||||
_originalStops = ColorGradient.Stops.Select(s => new ColorGradientStop(s.Color, s.Position)).ToList();
|
||||
_originalStops = ColorGradient.Select(s => new ColorGradientStop(s.Color, s.Position)).ToList();
|
||||
|
||||
PropertyChanged += UpdateColorStopViewModels;
|
||||
ColorGradient.CollectionChanged += ColorGradientOnCollectionChanged;
|
||||
}
|
||||
|
||||
public BindableCollection<ColorStopViewModel> ColorStopViewModels { get; set; }
|
||||
#region Overrides of DialogViewModelBase
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDialogClosed(object sender, DialogClosingEventArgs e)
|
||||
{
|
||||
ColorGradient.CollectionChanged -= ColorGradientOnCollectionChanged;
|
||||
base.OnDialogClosed(sender, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public BindableCollection<ColorStopViewModel> ColorStopViewModels { get; }
|
||||
|
||||
public ColorStopViewModel? SelectedColorStopViewModel
|
||||
{
|
||||
@@ -48,15 +62,19 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
set => SetAndNotify(ref _previewWidth, value);
|
||||
}
|
||||
|
||||
public ColorGradient Stops
|
||||
{
|
||||
get => ColorGradient;
|
||||
}
|
||||
|
||||
public void AddColorStop(object sender, MouseEventArgs e)
|
||||
{
|
||||
Canvas? child = VisualTreeUtilities.FindChild<Canvas>((DependencyObject) sender, null);
|
||||
float position = (float) (e.GetPosition(child).X / PreviewWidth);
|
||||
ColorGradientStop stop = new(ColorGradient.GetColor(position), position);
|
||||
ColorGradient.Stops.Add(stop);
|
||||
ColorGradient.OnColorValuesUpdated();
|
||||
ColorGradient.Add(stop);
|
||||
|
||||
int index = ColorGradient.Stops.OrderBy(s => s.Position).ToList().IndexOf(stop);
|
||||
int index = ColorGradient.IndexOf(stop);
|
||||
ColorStopViewModel viewModel = new(this, stop);
|
||||
ColorStopViewModels.Insert(index, viewModel);
|
||||
|
||||
@@ -69,8 +87,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
return;
|
||||
|
||||
ColorStopViewModels.Remove(colorStopViewModel);
|
||||
ColorGradient.Stops.Remove(colorStopViewModel.ColorStop);
|
||||
ColorGradient.OnColorValuesUpdated();
|
||||
ColorGradient.Remove(colorStopViewModel.ColorStop);
|
||||
|
||||
SelectColorStop(null);
|
||||
}
|
||||
@@ -97,9 +114,9 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
public override void Cancel()
|
||||
{
|
||||
// Restore the saved state
|
||||
ColorGradient.Stops.Clear();
|
||||
ColorGradient.Stops.AddRange(_originalStops);
|
||||
ColorGradient.OnColorValuesUpdated();
|
||||
ColorGradient.Clear();
|
||||
foreach (ColorGradientStop colorGradientStop in _originalStops)
|
||||
ColorGradient.Add(colorGradientStop);
|
||||
|
||||
base.Cancel();
|
||||
}
|
||||
@@ -107,8 +124,13 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
||||
private void UpdateColorStopViewModels(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName != nameof(PreviewWidth)) return;
|
||||
foreach (ColorGradientStop colorStop in ColorGradient.Stops.OrderBy(s => s.Position))
|
||||
foreach (ColorGradientStop colorStop in ColorGradient)
|
||||
ColorStopViewModels.Add(new ColorStopViewModel(this, colorStop));
|
||||
}
|
||||
|
||||
private void ColorGradientOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(ColorGradient));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
@@ -86,7 +87,7 @@ namespace Artemis.UI.Shared.Services
|
||||
{
|
||||
if (_currentTime.Equals(value)) return;
|
||||
_currentTime = value;
|
||||
UpdateProfilePreview();
|
||||
Tick();
|
||||
OnCurrentTimeChanged();
|
||||
}
|
||||
}
|
||||
@@ -180,16 +181,9 @@ namespace Artemis.UI.Shared.Services
|
||||
|
||||
public void UpdateProfilePreview()
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
if (Playing)
|
||||
return;
|
||||
|
||||
// Stick to the main segment for any element that is not currently selected
|
||||
foreach (Folder folder in SelectedProfile.GetAllFolders())
|
||||
folder.Timeline.Override(CurrentTime, folder.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||
foreach (Layer layer in SelectedProfile.GetAllLayers())
|
||||
layer.Timeline.Override(CurrentTime, (layer != SelectedProfileElement || layer.Timeline.Length < CurrentTime) && layer.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||
|
||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
Tick();
|
||||
}
|
||||
|
||||
public bool UndoUpdateProfile()
|
||||
@@ -357,6 +351,20 @@ namespace Artemis.UI.Shared.Services
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
if (SelectedProfile == null)
|
||||
return;
|
||||
|
||||
// Stick to the main segment for any element that is not currently selected
|
||||
foreach (Folder folder in SelectedProfile.GetAllFolders())
|
||||
folder.Timeline.Override(CurrentTime, folder.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||
foreach (Layer layer in SelectedProfile.GetAllLayers())
|
||||
layer.Timeline.Override(CurrentTime, (layer != SelectedProfileElement || layer.Timeline.Length < CurrentTime) && layer.Timeline.PlayMode == TimelinePlayMode.Repeat);
|
||||
|
||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
}
|
||||
|
||||
#region Copy/paste
|
||||
|
||||
public ProfileElement? DuplicateProfileElement(ProfileElement profileElement)
|
||||
|
||||
Reference in new issue
Block a user