mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 09:43:46 +00:00
Color picker - Remember last 18 picked colors
This commit is contained in:
parent
f646f64648
commit
12227b3530
@ -94,19 +94,20 @@
|
|||||||
StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
StaysOpen="{Binding StaysOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||||
PopupAnimation="Fade"
|
PopupAnimation="Fade"
|
||||||
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
|
IsOpen="{Binding PopupOpen, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}">
|
||||||
<materialDesign:Card Width="200" Height="230" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4">
|
<materialDesign:Card Width="200" Height="260" Margin="30" materialDesign:ShadowAssist.ShadowDepth="Depth4">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="160" />
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition />
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<materialDesign:ColorPicker Grid.Row="0"
|
<materialDesign:ColorPicker Grid.Row="0"
|
||||||
Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
Color="{Binding Color, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
|
||||||
MouseUp="ColorGradient_OnMouseUp"
|
MouseUp="ColorGradient_OnMouseUp"
|
||||||
PreviewMouseDown="Slider_OnMouseDown"
|
PreviewMouseDown="Slider_OnMouseDown"
|
||||||
PreviewMouseUp="Slider_OnMouseUp" />
|
PreviewMouseUp="Slider_OnMouseUp" />
|
||||||
<Slider Grid.Row="1" Margin="8"
|
<Slider Grid.Row="1" Margin="8 2 8 8"
|
||||||
IsMoveToPointEnabled="True"
|
IsMoveToPointEnabled="True"
|
||||||
Orientation="Horizontal"
|
Orientation="Horizontal"
|
||||||
Style="{DynamicResource MaterialDesignColorSlider}"
|
Style="{DynamicResource MaterialDesignColorSlider}"
|
||||||
@ -115,17 +116,34 @@
|
|||||||
PreviewMouseDown="Slider_OnMouseDown"
|
PreviewMouseDown="Slider_OnMouseDown"
|
||||||
PreviewMouseUp="Slider_OnMouseUp"
|
PreviewMouseUp="Slider_OnMouseUp"
|
||||||
Maximum="255" />
|
Maximum="255" />
|
||||||
|
|
||||||
|
<ItemsControl Grid.Row="2" x:Name="RecentColorsContainer" Margin="10 0" HorizontalAlignment="Left">
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Border CornerRadius="4" Background="{StaticResource Checkerboard}" Width="16" Height="16" Margin="2">
|
||||||
|
<Rectangle RadiusX="4" RadiusY="4" Cursor="Hand" MouseLeftButtonDown="SelectRecentColor" ToolTip="{Binding}">
|
||||||
|
<Rectangle.Fill>
|
||||||
|
<SolidColorBrush Color="{Binding}" />
|
||||||
|
</Rectangle.Fill>
|
||||||
|
</Rectangle>
|
||||||
|
</Border>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
<ItemsControl.ItemsPanel>
|
||||||
|
<ItemsPanelTemplate>
|
||||||
|
<WrapPanel Orientation="Horizontal"></WrapPanel>
|
||||||
|
</ItemsPanelTemplate>
|
||||||
|
</ItemsControl.ItemsPanel>
|
||||||
|
</ItemsControl>
|
||||||
|
|
||||||
<!-- Checkboxes don't work inside popups inside tree views, which is where the color picker is regularly used -->
|
<CheckBox Grid.Row="3"
|
||||||
<CheckBox Grid.Row="2"
|
|
||||||
x:Name="PreviewCheckBox"
|
x:Name="PreviewCheckBox"
|
||||||
Margin="10 0"
|
Margin="10 5 0 10"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Style="{StaticResource MaterialDesignCheckBox}"
|
Style="{StaticResource MaterialDesignCheckBox}"
|
||||||
Click="PreviewCheckBoxClick">
|
Click="PreviewCheckBoxClick">
|
||||||
Preview on devices
|
Preview on devices
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</materialDesign:Card>
|
</materialDesign:Card>
|
||||||
</Popup>
|
</Popup>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Shapes;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
|
|
||||||
namespace Artemis.UI.Shared
|
namespace Artemis.UI.Shared
|
||||||
@ -146,6 +148,12 @@ namespace Artemis.UI.Shared
|
|||||||
|
|
||||||
colorPicker._inCallback = true;
|
colorPicker._inCallback = true;
|
||||||
colorPicker.OnPropertyChanged(nameof(PopupOpen));
|
colorPicker.OnPropertyChanged(nameof(PopupOpen));
|
||||||
|
|
||||||
|
if ((bool) e.NewValue)
|
||||||
|
colorPicker.PopupOpened();
|
||||||
|
else
|
||||||
|
colorPicker.PopupClosed();
|
||||||
|
|
||||||
colorPicker._inCallback = false;
|
colorPicker._inCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,6 +238,22 @@ namespace Artemis.UI.Shared
|
|||||||
PreviewCheckBox.IsChecked = _colorPickerService.PreviewSetting.Value;
|
PreviewCheckBox.IsChecked = _colorPickerService.PreviewSetting.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PopupClosed()
|
||||||
|
{
|
||||||
|
_colorPickerService?.QueueRecentColor(Color);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PopupOpened()
|
||||||
|
{
|
||||||
|
RecentColorsContainer.ItemsSource = new ObservableCollection<Color>(_colorPickerService.RecentColors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectRecentColor(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
Color = (Color) ((Rectangle) sender).DataContext;
|
||||||
|
PopupOpen = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public event PropertyChangedEventHandler? PropertyChanged;
|
public event PropertyChangedEventHandler? PropertyChanged;
|
||||||
|
|
||||||
|
|||||||
@ -24,10 +24,35 @@ namespace Artemis.UI.Shared.Services
|
|||||||
|
|
||||||
PreviewSetting = settingsService.GetSetting("UI.PreviewColorPickerOnDevices", false);
|
PreviewSetting = settingsService.GetSetting("UI.PreviewColorPickerOnDevices", false);
|
||||||
PreviewSetting.AutoSave = true;
|
PreviewSetting.AutoSave = true;
|
||||||
|
RecentColorsSetting = settingsService.GetSetting("UI.ColorPickerRecentColors", new LinkedList<Color>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderColorPickerOverlay(object? sender, FrameRenderingEventArgs e)
|
||||||
|
{
|
||||||
|
if (_mustRenderOverlay)
|
||||||
|
_overlayOpacity += 0.2f;
|
||||||
|
else
|
||||||
|
_overlayOpacity -= 0.2f;
|
||||||
|
|
||||||
|
if (_overlayOpacity <= 0f)
|
||||||
|
{
|
||||||
|
_coreService.FrameRendering -= RenderColorPickerOverlay;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_overlayOpacity > 1f)
|
||||||
|
_overlayOpacity = 1f;
|
||||||
|
|
||||||
|
using SKPaint overlayPaint = new() {Color = new SKColor(0, 0, 0, (byte) (255 * _overlayOpacity))};
|
||||||
|
overlayPaint.Color = _overlayColor.WithAlpha((byte) (_overlayColor.Alpha * _overlayOpacity));
|
||||||
|
e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginSetting<bool> PreviewSetting { get; }
|
public PluginSetting<bool> PreviewSetting { get; }
|
||||||
|
public PluginSetting<LinkedList<Color>> RecentColorsSetting { get; }
|
||||||
|
|
||||||
|
public LinkedList<Color> RecentColors => RecentColorsSetting.Value;
|
||||||
|
|
||||||
public Task<object> ShowGradientPicker(ColorGradient colorGradient, string dialogHost)
|
public Task<object> ShowGradientPicker(ColorGradient colorGradient, string dialogHost)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(dialogHost))
|
if (!string.IsNullOrWhiteSpace(dialogHost))
|
||||||
@ -56,25 +81,16 @@ namespace Artemis.UI.Shared.Services
|
|||||||
_overlayColor = new SKColor(color.R, color.G, color.B, color.A);
|
_overlayColor = new SKColor(color.R, color.G, color.B, color.A);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RenderColorPickerOverlay(object? sender, FrameRenderingEventArgs e)
|
public void QueueRecentColor(Color color)
|
||||||
{
|
{
|
||||||
if (_mustRenderOverlay)
|
if (RecentColors.Contains(color))
|
||||||
_overlayOpacity += 0.2f;
|
RecentColors.Remove(color);
|
||||||
else
|
|
||||||
_overlayOpacity -= 0.2f;
|
|
||||||
|
|
||||||
if (_overlayOpacity <= 0f)
|
RecentColors.AddFirst(color);
|
||||||
{
|
while (RecentColors.Count > 18)
|
||||||
_coreService.FrameRendering -= RenderColorPickerOverlay;
|
RecentColors.RemoveLast();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_overlayOpacity > 1f)
|
RecentColorsSetting.Save();
|
||||||
_overlayOpacity = 1f;
|
|
||||||
|
|
||||||
using SKPaint overlayPaint = new() {Color = new SKColor(0, 0, 0, (byte) (255 * _overlayOpacity))};
|
|
||||||
overlayPaint.Color = _overlayColor.WithAlpha((byte) (_overlayColor.Alpha * _overlayOpacity));
|
|
||||||
e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
|
||||||
@ -9,8 +10,11 @@ namespace Artemis.UI.Shared.Services
|
|||||||
Task<object> ShowGradientPicker(ColorGradient colorGradient, string dialogHost);
|
Task<object> ShowGradientPicker(ColorGradient colorGradient, string dialogHost);
|
||||||
|
|
||||||
PluginSetting<bool> PreviewSetting { get; }
|
PluginSetting<bool> PreviewSetting { get; }
|
||||||
|
LinkedList<Color> RecentColors { get; }
|
||||||
|
PluginSetting<LinkedList<Color>> RecentColorsSetting { get; }
|
||||||
void StartColorDisplay();
|
void StartColorDisplay();
|
||||||
void StopColorDisplay();
|
void StopColorDisplay();
|
||||||
void UpdateColorDisplay(Color color);
|
void UpdateColorDisplay(Color color);
|
||||||
|
void QueueRecentColor(Color color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user