1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Added custom shapes for leds

This commit is contained in:
Darth Affe 2017-02-11 10:24:15 +01:00
parent 256c6dea74
commit cf3bbd547c
5 changed files with 72 additions and 5 deletions

View File

@ -21,11 +21,12 @@ namespace RGB.NET.Core.Layout
public string Id { get; set; }
/// <summary>
/// Gets or sets the <see cref="RGB.NET.Core.Shape"/> of the <see cref="LedLayout"/>.
/// Gets or sets the descriptive <see cref="RGB.NET.Core.Shape"/> of the <see cref="LedLayout"/>.
/// This property is for XML-serialization only and should not be directly accessed.
/// </summary>
[XmlElement("Shape")]
[DefaultValue(Shape.Rectangle)]
public Shape Shape { get; set; } = Shape.Rectangle;
[DefaultValue("Rectangle")]
public string DescriptiveShape { get; set; } = "Rectangle";
/// <summary>
/// Gets or sets the descriptive x-position of the <see cref="LedLayout"/>.
@ -59,6 +60,18 @@ namespace RGB.NET.Core.Layout
[DefaultValue("1.0")]
public string DescriptiveHeight { get; set; } = "1.0";
/// <summary>
/// Gets or sets the <see cref="RGB.NET.Core.Shape"/> of the <see cref="LedLayout"/>.
/// </summary>
[XmlIgnore]
public Shape Shape { get; set; }
/// <summary>
/// Gets or sets the vecor-data representing a custom-shape of the <see cref="LedLayout"/>.
/// </summary>
[XmlIgnore]
public string ShapeData { get; set; }
/// <summary>
/// Gets or sets the x-position of the <see cref="LedLayout"/>.
/// </summary>
@ -94,6 +107,14 @@ namespace RGB.NET.Core.Layout
/// <param name="lastLed">The <see cref="LedLayout"/> previously calculated.</param>
public void CalculateValues(DeviceLayout device, LedLayout lastLed)
{
Shape shape;
if (!Enum.TryParse(DescriptiveShape, true, out shape))
{
shape = Shape.Custom;
ShapeData = DescriptiveShape;
}
Shape = shape;
Width = GetSizeValue(DescriptiveWidth, device.LedUnitWidth);
Height = GetSizeValue(DescriptiveHeight, device.LedUnitHeight);

View File

@ -33,6 +33,16 @@ namespace RGB.NET.Core
set { SetProperty(ref _shape, value); }
}
private string _shapeData;
/// <summary>
/// Gets or sets the data used for by the <see cref="Core.Shape.Custom"/>-<see cref="Core.Shape"/>.
/// </summary>
public string ShapeData
{
get { return _shapeData; }
set { SetProperty(ref _shapeData, value); }
}
/// <summary>
/// Gets a rectangle representing the physical location of the <see cref="Led"/> relative to the <see cref="Device"/>.
/// </summary>

View File

@ -9,14 +9,19 @@ namespace RGB.NET.Core
[Serializable]
public enum Shape
{
/// <summary>
/// A custom shape defined by vector-data.
/// </summary>
Custom = 0,
/// <summary>
/// A simple rectangle.
/// </summary>
Rectangle = 0,
Rectangle = 1,
/// <summary>
/// A simple circle.
/// </summary>
Circle = 1
Circle = 2,
}
}

View File

@ -87,6 +87,7 @@ namespace RGB.NET.Devices.Corsair
led.LedRectangle.Size.Height = layoutLed.Height;
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
led.Image = (!string.IsNullOrEmpty(image?.Image))

View File

@ -41,6 +41,32 @@
</Border>
</ControlTemplate>
<ControlTemplate x:Key="ControlTemplateLedCustom"
TargetType="{x:Type controls:LedVisualizer}">
<Border x:Name="Border" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Path Opacity="0.5"
Clip="{Binding Data, RelativeSource={RelativeSource Self}}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="2"
Fill="{TemplateBinding Background}">
<Path.Data>
<PathGeometry Figures="{Binding Led.ShapeData, RelativeSource={RelativeSource TemplatedParent}}">
<PathGeometry.Transform>
<ScaleTransform ScaleX="{Binding ActualWidth, ElementName=Border}"
ScaleY="{Binding ActualHeight, ElementName=Border}" />
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
<Style x:Key="StyleLedVisualizer"
TargetType="{x:Type controls:LedVisualizer}">
<Setter Property="Width" Value="{Binding Led.LedRectangle.Size.Width, RelativeSource={RelativeSource Self}}" />
@ -62,6 +88,10 @@
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Circle">
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCircle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Custom">
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCustom}" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type controls:LedVisualizer}" BasedOn="{StaticResource StyleLedVisualizer}" />