1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Gradient picker - Properly react to gradient changes once again

This commit is contained in:
Robert 2021-04-06 20:56:12 +02:00
parent b342eabe4d
commit 2bc882c814
4 changed files with 40 additions and 19 deletions

View File

@ -37,10 +37,7 @@
Background="{StaticResource Checkerboard}">
<Rectangle Stroke="{DynamicResource NormalBorderBrush}" Cursor="Hand" MouseUp="UIElement_OnMouseUp">
<Rectangle.Fill>
<LinearGradientBrush
GradientStops="{Binding ColorGradient, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource ColorGradientToGradientStopsConverter}}"
EndPoint="1,0"
StartPoint="0,0" />
<LinearGradientBrush x:Name="GradientPreview" EndPoint="1,0" StartPoint="0,0" />
</Rectangle.Fill>
</Rectangle>
</Border>

View File

@ -1,8 +1,10 @@
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core;
using Artemis.UI.Shared.Properties;
using Artemis.UI.Shared.Services;
@ -17,12 +19,14 @@ namespace Artemis.UI.Shared
{
private static IColorPickerService? _colorPickerService;
private bool _inCallback;
private ColorGradientToGradientStopsConverter _gradientConverter;
/// <summary>
/// Creates a new instance of the <see cref="GradientPicker" /> class
/// </summary>
public GradientPicker()
{
_gradientConverter = new ColorGradientToGradientStopsConverter();
InitializeComponent();
}
@ -99,10 +103,27 @@ namespace Artemis.UI.Shared
return;
gradientPicker._inCallback = true;
if (e.OldValue is ColorGradient oldGradient)
oldGradient.CollectionChanged -= gradientPicker.GradientChanged;
if (e.NewValue is ColorGradient newGradient)
newGradient.CollectionChanged += gradientPicker.GradientChanged;
gradientPicker.UpdateGradientStops();
gradientPicker.OnPropertyChanged(nameof(ColorGradient));
gradientPicker._inCallback = false;
}
private void GradientChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
Dispatcher.Invoke(UpdateGradientStops);
}
private void UpdateGradientStops()
{
GradientPreview.GradientStops = (GradientStopCollection)_gradientConverter.Convert(ColorGradient, null!, null!, null!);
}
private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
{
if (_colorPickerService == null)

View File

@ -132,16 +132,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions.Abstract
DisposeRightSideDynamicViewModel();
if (RightSideInputViewModel == null)
CreateRightSideInputViewModel();
Type preferredType = DataModelConditionPredicate.GetPreferredRightSideType();
// Ensure the right static value is never null when the preferred type is a value type
if (preferredType.IsValueType && DataModelConditionPredicate.RightStaticValue == null)
RightSideInputViewModel.Value = preferredType.GetDefault();
else
RightSideInputViewModel.Value = DataModelConditionPredicate.RightStaticValue;
if (RightSideInputViewModel.TargetType != preferredType)
if (preferredType != null && RightSideInputViewModel.TargetType != preferredType)
RightSideInputViewModel.UpdateTargetType(preferredType);
RightSideInputViewModel.Value = DataModelConditionPredicate.RightStaticValue;
}
}
@ -294,6 +290,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Conditions.Abstract
private void RightSideSelectionViewModelOnSwitchToStaticRequested(object sender, EventArgs e)
{
DataModelConditionPredicate.PredicateType = ProfileRightSideType.Static;
// Ensure the right static value is never null when the preferred type is a value type
Type preferredType = DataModelConditionPredicate.GetPreferredRightSideType();
if (DataModelConditionPredicate.RightStaticValue == null && preferredType != null && preferredType.IsValueType)
DataModelConditionPredicate.UpdateRightSideStatic(preferredType.GetDefault());
Update();
}

View File

@ -73,7 +73,7 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
Modifier.DirectDataBinding.RemoveModifier(Modifier);
_profileEditorService.UpdateSelectedProfileElement();
}
private void ParameterSelectionViewModelOnPropertySelected(object sender, DataModelInputDynamicEventArgs e)
{
Modifier.UpdateParameterDynamic(e.DataModelPath);
@ -139,13 +139,8 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
// Parameter
if (DynamicSelectionViewModel != null)
DynamicSelectionViewModel.ChangeDataModelPath(Modifier.ParameterPath);
else if (StaticInputViewModel != null)
{
// Ensure the right static value is never null when the preferred type is a value type
else if (StaticInputViewModel != null)
StaticInputViewModel.Value = Modifier.ParameterStaticValue;
if (SelectedModifierType.ParameterType.IsValueType && StaticInputViewModel.Value == null)
StaticInputViewModel.Value = SelectedModifierType.ParameterType.GetDefault();
}
}
private void ExecuteSelectModifierTypeCommand(object context)
@ -197,6 +192,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa
private void DynamicSelectionViewModelOnSwitchToStaticRequested(object sender, EventArgs e)
{
Modifier.ParameterType = ProfileRightSideType.Static;
// Ensure the right static value is never null when the preferred type is a value type
if (SelectedModifierType.ParameterType != null &&
SelectedModifierType.ParameterType.IsValueType && Modifier.ParameterStaticValue == null)
Modifier.UpdateParameterStatic(SelectedModifierType.ParameterType.GetDefault());
Update();
}