diff --git a/src/Artemis.Core/Plugins/Settings/PluginSetting.cs b/src/Artemis.Core/Plugins/Settings/PluginSetting.cs
index a9b1d7f4b..ba2b62fc2 100644
--- a/src/Artemis.Core/Plugins/Settings/PluginSetting.cs
+++ b/src/Artemis.Core/Plugins/Settings/PluginSetting.cs
@@ -48,12 +48,14 @@ namespace Artemis.Core
get => _value;
set
{
- if (!Equals(_value, value))
- {
- _value = value;
- OnSettingChanged();
- NotifyOfPropertyChange(nameof(Value));
- }
+ if (Equals(_value, value)) return;
+
+ _value = value;
+ OnSettingChanged();
+ NotifyOfPropertyChange(nameof(Value));
+
+ if (AutoSave)
+ Save();
}
}
@@ -62,6 +64,12 @@ namespace Artemis.Core
///
public bool HasChanged => JsonConvert.SerializeObject(Value) != _pluginSettingEntity.Value;
+ ///
+ /// Gets or sets whether changes must automatically be saved
+ /// Note: When set to true is always false
+ ///
+ public bool AutoSave { get; set; }
+
///
/// Resets the setting to the last saved value
///
diff --git a/src/Artemis.UI.Shared/Bootstrapper.cs b/src/Artemis.UI.Shared/Bootstrapper.cs
new file mode 100644
index 000000000..a4535542e
--- /dev/null
+++ b/src/Artemis.UI.Shared/Bootstrapper.cs
@@ -0,0 +1,22 @@
+using Artemis.UI.Shared.Services;
+using Ninject;
+
+namespace Artemis.UI.Shared
+{
+ public static class Bootstrapper
+ {
+ public static bool Initialized { get; private set; }
+
+ public static void Initialize(IKernel kernel)
+ {
+ if (Initialized)
+ return;
+
+ var colorPickerService = kernel.Get();
+ GradientPicker.ColorPickerService = colorPickerService;
+ ColorPicker.ColorPickerService = colorPickerService;
+
+ Initialized = true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI.Shared/Controls/ColorPicker.xaml b/src/Artemis.UI.Shared/Controls/ColorPicker.xaml
index 20c03d4e3..e4ce9f773 100644
--- a/src/Artemis.UI.Shared/Controls/ColorPicker.xaml
+++ b/src/Artemis.UI.Shared/Controls/ColorPicker.xaml
@@ -94,17 +94,18 @@
StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
PopupAnimation="Fade"
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
-
+
+
-
+ PreviewMouseUp="Slider_OnMouseUp" />
+
+
+
+ Preview on devices
+
+
diff --git a/src/Artemis.UI.Shared/Controls/ColorPicker.xaml.cs b/src/Artemis.UI.Shared/Controls/ColorPicker.xaml.cs
index c2ebd7b07..bf0cc3527 100644
--- a/src/Artemis.UI.Shared/Controls/ColorPicker.xaml.cs
+++ b/src/Artemis.UI.Shared/Controls/ColorPicker.xaml.cs
@@ -5,6 +5,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
+using Artemis.UI.Shared.Services;
namespace Artemis.UI.Shared
{
@@ -13,6 +14,8 @@ namespace Artemis.UI.Shared
///
public partial class ColorPicker : UserControl, INotifyPropertyChanged
{
+ private static IColorPickerService _colorPickerService;
+
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(nameof(Color), typeof(Color), typeof(ColorPicker),
new FrameworkPropertyMetadata(default(Color), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, ColorPropertyChangedCallback));
@@ -44,6 +47,21 @@ namespace Artemis.UI.Shared
public ColorPicker()
{
InitializeComponent();
+ Loaded += OnLoaded;
+ Unloaded += OnUnloaded;
+ }
+
+ ///
+ /// Used by the gradient picker to load saved gradients, do not touch or it'll just throw an exception
+ ///
+ internal static IColorPickerService ColorPickerService
+ {
+ set
+ {
+ if (_colorPickerService != null)
+ throw new AccessViolationException("This is not for you to touch");
+ _colorPickerService = value;
+ }
}
public Color Color
@@ -87,6 +105,7 @@ namespace Artemis.UI.Shared
colorPicker.SetCurrentValue(ColorOpacityProperty, ((Color) e.NewValue).A);
colorPicker.OnPropertyChanged(nameof(Color));
+ _colorPickerService.UpdateColorDisplay(colorPicker.Color);
colorPicker._inCallback = false;
}
@@ -126,6 +145,7 @@ namespace Artemis.UI.Shared
color = Color.FromArgb(opacity, color.R, color.G, color.B);
colorPicker.SetCurrentValue(ColorProperty, color);
colorPicker.OnPropertyChanged(nameof(ColorOpacity));
+ _colorPickerService.UpdateColorDisplay(colorPicker.Color);
colorPicker._inCallback = false;
}
@@ -135,7 +155,7 @@ namespace Artemis.UI.Shared
PopupOpen = !PopupOpen;
e.Handled = true;
}
-
+
private void ColorGradient_OnMouseUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
@@ -144,13 +164,39 @@ namespace Artemis.UI.Shared
private void Slider_OnMouseDown(object sender, MouseButtonEventArgs e)
{
OnDragStarted();
+
+ if (_colorPickerService.PreviewSetting.Value)
+ _colorPickerService.StartColorDisplay();
}
private void Slider_OnMouseUp(object sender, MouseButtonEventArgs e)
{
OnDragEnded();
+ _colorPickerService.StopColorDisplay();
}
+ private void PreviewCheckBoxClick(object sender, RoutedEventArgs e)
+ {
+ _colorPickerService.PreviewSetting.Value = PreviewCheckBox.IsChecked.Value;
+ }
+
+ private void OnLoaded(object sender, RoutedEventArgs e)
+ {
+ PreviewCheckBox.IsChecked = _colorPickerService.PreviewSetting.Value;
+ _colorPickerService.PreviewSetting.SettingChanged += PreviewSettingOnSettingChanged;
+ }
+
+ private void OnUnloaded(object sender, RoutedEventArgs e)
+ {
+ _colorPickerService.PreviewSetting.SettingChanged -= PreviewSettingOnSettingChanged;
+ }
+
+ private void PreviewSettingOnSettingChanged(object sender, EventArgs e)
+ {
+ PreviewCheckBox.IsChecked = _colorPickerService.PreviewSetting.Value;
+ }
+
+
#region Events
public event EventHandler DragStarted;
@@ -167,6 +213,5 @@ namespace Artemis.UI.Shared
}
#endregion
-
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs b/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs
index c1ee8b929..78c481c1f 100644
--- a/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs
+++ b/src/Artemis.UI.Shared/Controls/GradientPicker.xaml.cs
@@ -16,7 +16,7 @@ namespace Artemis.UI.Shared
///
public partial class GradientPicker : UserControl, INotifyPropertyChanged
{
- private static IGradientPickerService _gradientPickerService;
+ private static IColorPickerService _colorPickerService;
private bool _inCallback;
public GradientPicker()
@@ -27,14 +27,13 @@ namespace Artemis.UI.Shared
///
/// Used by the gradient picker to load saved gradients, do not touch or it'll just throw an exception
///
- public static IGradientPickerService GradientPickerService
+ internal static IColorPickerService ColorPickerService
{
- private get => _gradientPickerService;
set
{
- if (_gradientPickerService != null)
+ if (_colorPickerService != null)
throw new AccessViolationException("This is not for you to touch");
- _gradientPickerService = value;
+ _colorPickerService = value;
}
}
@@ -93,7 +92,7 @@ namespace Artemis.UI.Shared
Execute.OnUIThread(async () =>
{
OnDialogOpened();
- await GradientPickerService.ShowGradientPicker(ColorGradient, DialogHost);
+ await _colorPickerService.ShowGradientPicker(ColorGradient, DialogHost);
OnDialogClosed();
});
}
diff --git a/src/Artemis.UI.Shared/Controls/TreeViewPopupCompatibleCheckBox.cs b/src/Artemis.UI.Shared/Controls/TreeViewPopupCompatibleCheckBox.cs
new file mode 100644
index 000000000..42952c013
--- /dev/null
+++ b/src/Artemis.UI.Shared/Controls/TreeViewPopupCompatibleCheckBox.cs
@@ -0,0 +1,22 @@
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace Artemis.UI.Shared
+{
+ // Workaround for https://developercommunity.visualstudio.com/content/problem/190202/button-controls-hosted-in-popup-windows-do-not-wor.html
+ ///
+ public class TreeViewPopupCompatibleCheckBox : CheckBox
+ {
+ ///
+ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
+ {
+ base.OnMouseLeftButtonDown(e);
+ }
+
+ ///
+ protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
+ {
+ base.OnMouseLeftButtonUp(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI.Shared/Services/ColorPickerService.cs b/src/Artemis.UI.Shared/Services/ColorPickerService.cs
new file mode 100644
index 000000000..843cf4adb
--- /dev/null
+++ b/src/Artemis.UI.Shared/Services/ColorPickerService.cs
@@ -0,0 +1,80 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using System.Windows.Media;
+using Artemis.Core;
+using Artemis.Core.Services;
+using Artemis.UI.Shared.Screens.GradientEditor;
+using SkiaSharp;
+
+namespace Artemis.UI.Shared.Services
+{
+ internal class ColorPickerService : IColorPickerService
+ {
+ private readonly ICoreService _coreService;
+ private readonly IDialogService _dialogService;
+
+ private bool _mustRenderOverlay;
+ private SKColor _overlayColor;
+ private float _overlayOpacity;
+
+ public ColorPickerService(IDialogService dialogService, ICoreService coreService, ISettingsService settingsService)
+ {
+ _dialogService = dialogService;
+ _coreService = coreService;
+
+ PreviewSetting = settingsService.GetSetting("UI.PreviewColorPickerOnDevices", false);
+ PreviewSetting.AutoSave = true;
+ }
+
+ public PluginSetting PreviewSetting { get; }
+
+ public Task