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:
parent
256c6dea74
commit
cf3bbd547c
@ -21,11 +21,12 @@ namespace RGB.NET.Core.Layout
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
[XmlElement("Shape")]
|
[XmlElement("Shape")]
|
||||||
[DefaultValue(Shape.Rectangle)]
|
[DefaultValue("Rectangle")]
|
||||||
public Shape Shape { get; set; } = Shape.Rectangle;
|
public string DescriptiveShape { get; set; } = "Rectangle";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the descriptive x-position of the <see cref="LedLayout"/>.
|
/// Gets or sets the descriptive x-position of the <see cref="LedLayout"/>.
|
||||||
@ -59,6 +60,18 @@ namespace RGB.NET.Core.Layout
|
|||||||
[DefaultValue("1.0")]
|
[DefaultValue("1.0")]
|
||||||
public string DescriptiveHeight { get; set; } = "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>
|
/// <summary>
|
||||||
/// Gets or sets the x-position of the <see cref="LedLayout"/>.
|
/// Gets or sets the x-position of the <see cref="LedLayout"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -94,6 +107,14 @@ namespace RGB.NET.Core.Layout
|
|||||||
/// <param name="lastLed">The <see cref="LedLayout"/> previously calculated.</param>
|
/// <param name="lastLed">The <see cref="LedLayout"/> previously calculated.</param>
|
||||||
public void CalculateValues(DeviceLayout device, LedLayout lastLed)
|
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);
|
Width = GetSizeValue(DescriptiveWidth, device.LedUnitWidth);
|
||||||
Height = GetSizeValue(DescriptiveHeight, device.LedUnitHeight);
|
Height = GetSizeValue(DescriptiveHeight, device.LedUnitHeight);
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,16 @@ namespace RGB.NET.Core
|
|||||||
set { SetProperty(ref _shape, value); }
|
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>
|
/// <summary>
|
||||||
/// Gets a rectangle representing the physical location of the <see cref="Led"/> relative to the <see cref="Device"/>.
|
/// Gets a rectangle representing the physical location of the <see cref="Led"/> relative to the <see cref="Device"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -9,14 +9,19 @@ namespace RGB.NET.Core
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public enum Shape
|
public enum Shape
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A custom shape defined by vector-data.
|
||||||
|
/// </summary>
|
||||||
|
Custom = 0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simple rectangle.
|
/// A simple rectangle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Rectangle = 0,
|
Rectangle = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A simple circle.
|
/// A simple circle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Circle = 1
|
Circle = 2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,6 +87,7 @@ namespace RGB.NET.Devices.Corsair
|
|||||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||||
|
|
||||||
led.Shape = layoutLed.Shape;
|
led.Shape = layoutLed.Shape;
|
||||||
|
led.ShapeData = layoutLed.ShapeData;
|
||||||
|
|
||||||
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
|
LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id);
|
||||||
led.Image = (!string.IsNullOrEmpty(image?.Image))
|
led.Image = (!string.IsNullOrEmpty(image?.Image))
|
||||||
|
|||||||
@ -41,6 +41,32 @@
|
|||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</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"
|
<Style x:Key="StyleLedVisualizer"
|
||||||
TargetType="{x:Type controls:LedVisualizer}">
|
TargetType="{x:Type controls:LedVisualizer}">
|
||||||
<Setter Property="Width" Value="{Binding Led.LedRectangle.Size.Width, RelativeSource={RelativeSource Self}}" />
|
<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">
|
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Circle">
|
||||||
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCircle}" />
|
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCircle}" />
|
||||||
</DataTrigger>
|
</DataTrigger>
|
||||||
|
|
||||||
|
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Custom">
|
||||||
|
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCustom}" />
|
||||||
|
</DataTrigger>
|
||||||
</Style.Triggers>
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
<Style TargetType="{x:Type controls:LedVisualizer}" BasedOn="{StaticResource StyleLedVisualizer}" />
|
<Style TargetType="{x:Type controls:LedVisualizer}" BasedOn="{StaticResource StyleLedVisualizer}" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user