mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Gradient editor - Added stops creation
Core - ColorGradient can now return a color at a certain position
This commit is contained in:
parent
f95aaf2443
commit
0ccc1fed3d
@ -44,6 +44,31 @@ namespace Artemis.Core.Models.Profile
|
|||||||
{
|
{
|
||||||
OnPropertyChanged(nameof(Colors));
|
OnPropertyChanged(nameof(Colors));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SKColor GetColor(float position)
|
||||||
|
{
|
||||||
|
var point = Colors.SingleOrDefault(f => f.Position == position);
|
||||||
|
if (point != null) return point.Color;
|
||||||
|
|
||||||
|
var before = Colors.First(w => w.Position == Colors.Min(m => m.Position));
|
||||||
|
var after = Colors.First(w => w.Position == Colors.Max(m => m.Position));
|
||||||
|
|
||||||
|
foreach (var gs in Colors)
|
||||||
|
{
|
||||||
|
if (gs.Position < position && gs.Position > before.Position)
|
||||||
|
before = gs;
|
||||||
|
|
||||||
|
if (gs.Position >= position && gs.Position < after.Position)
|
||||||
|
after = gs;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SKColor(
|
||||||
|
(byte) ((position - before.Position) * (after.Color.Red - before.Color.Red) / (after.Position - before.Position) + before.Color.Red),
|
||||||
|
(byte) ((position - before.Position) * (after.Color.Green - before.Color.Green) / (after.Position - before.Position) + before.Color.Green),
|
||||||
|
(byte) ((position - before.Position) * (after.Color.Blue - before.Color.Blue) / (after.Position - before.Position) + before.Color.Blue),
|
||||||
|
(byte) ((position - before.Position) * (after.Color.Alpha - before.Color.Alpha) / (after.Position - before.Position) + before.Color.Alpha)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ColorGradientColor : INotifyPropertyChanged
|
public class ColorGradientColor : INotifyPropertyChanged
|
||||||
|
|||||||
@ -19,12 +19,14 @@ namespace Artemis.UI.Shared.Screens.Dialogs
|
|||||||
|
|
||||||
public void Confirm()
|
public void Confirm()
|
||||||
{
|
{
|
||||||
Session.Close(true);
|
if (!Session.IsEnded)
|
||||||
|
Session.Close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cancel()
|
public void Cancel()
|
||||||
{
|
{
|
||||||
Session.Close(false);
|
if (!Session.IsEnded)
|
||||||
|
Session.Close(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,43 +41,41 @@
|
|||||||
<TextBlock Margin="15 15 0 0">Gradient</TextBlock>
|
<TextBlock Margin="15 15 0 0">Gradient</TextBlock>
|
||||||
<Separator Margin="15 5" />
|
<Separator Margin="15 5" />
|
||||||
|
|
||||||
<ItemsControl ItemsSource="{Binding ColorGradient.Colors}" ClipToBounds="False" Margin="15 0">
|
<Grid>
|
||||||
<ItemsControl.ItemsPanel>
|
<ItemsControl ItemsSource="{Binding ColorGradient.Colors}" ClipToBounds="False" Margin="15 0" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp" Cursor="Cross">
|
||||||
<ItemsPanelTemplate>
|
<ItemsControl.ItemsPanel>
|
||||||
<Canvas Height="60" Width="437" x:Name="PreviewCanvas">
|
<ItemsPanelTemplate>
|
||||||
<Canvas.Background>
|
<Canvas Height="60" Width="437" x:Name="PreviewCanvas">
|
||||||
<VisualBrush Stretch="None" AlignmentY="Top">
|
<Canvas.Background>
|
||||||
<VisualBrush.Visual>
|
<VisualBrush Stretch="None" AlignmentY="Top">
|
||||||
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Margin="15">
|
<VisualBrush.Visual>
|
||||||
<Rectangle x:Name="Preview"
|
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Margin="15">
|
||||||
VerticalAlignment="Stretch"
|
<Rectangle x:Name="Preview" Width="{Binding ActualWidth, ElementName=PreviewCanvas}">
|
||||||
HorizontalAlignment="Stretch"
|
<Rectangle.Fill>
|
||||||
Width="{Binding ActualWidth, ElementName=PreviewCanvas}"
|
<LinearGradientBrush GradientStops="{Binding ColorGradient.Colors, Converter={StaticResource ColorGradientToGradientStopsConverter}}" />
|
||||||
Height="35">
|
</Rectangle.Fill>
|
||||||
<Rectangle.Fill>
|
</Rectangle>
|
||||||
<LinearGradientBrush GradientStops="{Binding ColorGradient.Colors, Converter={StaticResource ColorGradientToGradientStopsConverter}}" />
|
</materialDesign:Card>
|
||||||
</Rectangle.Fill>
|
</VisualBrush.Visual>
|
||||||
</Rectangle>
|
</VisualBrush>
|
||||||
</materialDesign:Card>
|
</Canvas.Background>
|
||||||
</VisualBrush.Visual>
|
</Canvas>
|
||||||
</VisualBrush>
|
</ItemsPanelTemplate>
|
||||||
</Canvas.Background>
|
</ItemsControl.ItemsPanel>
|
||||||
</Canvas>
|
<ItemsControl.ItemContainerStyle>
|
||||||
</ItemsPanelTemplate>
|
<Style TargetType="ContentPresenter">
|
||||||
</ItemsControl.ItemsPanel>
|
<Setter Property="Canvas.Top" Value="40" />
|
||||||
<ItemsControl.ItemContainerStyle>
|
</Style>
|
||||||
<Style TargetType="ContentPresenter">
|
</ItemsControl.ItemContainerStyle>
|
||||||
<Setter Property="Canvas.Top" Value="40" />
|
<ItemsControl.ItemTemplate>
|
||||||
</Style>
|
<DataTemplate>
|
||||||
</ItemsControl.ItemContainerStyle>
|
<local:GradientEditorColor
|
||||||
<ItemsControl.ItemTemplate>
|
ColorGradient="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:MaterialWindow}, Path=ColorGradient}"
|
||||||
<DataTemplate>
|
GradientColor="{Binding}" />
|
||||||
<local:GradientEditorColor
|
</DataTemplate>
|
||||||
ColorGradient="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=controls:MaterialWindow}, Path=ColorGradient}"
|
</ItemsControl.ItemTemplate>
|
||||||
GradientColor="{Binding}" />
|
</ItemsControl>
|
||||||
</DataTemplate>
|
</Grid>
|
||||||
</ItemsControl.ItemTemplate>
|
|
||||||
</ItemsControl>
|
|
||||||
|
|
||||||
<TextBlock Margin="15 15 0 0">Stops</TextBlock>
|
<TextBlock Margin="15 15 0 0">Stops</TextBlock>
|
||||||
<Separator Margin="15 5" />
|
<Separator Margin="15 5" />
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ColorGradient = colorGradient;
|
ColorGradient = colorGradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorGradient ColorGradient
|
public ColorGradient ColorGradient
|
||||||
{
|
{
|
||||||
get => (ColorGradient) GetValue(ColorGradientProperty);
|
get => (ColorGradient) GetValue(ColorGradientProperty);
|
||||||
@ -57,5 +57,14 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
|||||||
editor.OnPropertyChanged(nameof(ColorGradient));
|
editor.OnPropertyChanged(nameof(ColorGradient));
|
||||||
editor._inCallback = false;
|
editor._inCallback = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Rectangle_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
var position = e.GetPosition((IInputElement) sender);
|
||||||
|
// Position ranges from 0.0 to 1.0
|
||||||
|
var newPosition = (float) Math.Min(1, Math.Max(0, Math.Round((position.X) / 435.0, 3, MidpointRounding.AwayFromZero)));
|
||||||
|
|
||||||
|
ColorGradient.Colors.Add(new ColorGradientColor(ColorGradient.GetColor(newPosition), newPosition));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,6 +99,7 @@ namespace Artemis.UI.Shared.Screens.GradientEditor
|
|||||||
}
|
}
|
||||||
|
|
||||||
((IInputElement) sender).ReleaseMouseCapture();
|
((IInputElement) sender).ReleaseMouseCapture();
|
||||||
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ColorStop_MouseMove(object sender, MouseEventArgs e)
|
private void ColorStop_MouseMove(object sender, MouseEventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user