mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Simplified geometry generation, added some extra logic for keycaps
This commit is contained in:
parent
5f10627345
commit
aa1cd70fd1
@ -32,46 +32,69 @@ namespace Artemis.UI.ViewModels.Controls.ProfileEditor
|
|||||||
|
|
||||||
private void CreateLedGeometry()
|
private void CreateLedGeometry()
|
||||||
{
|
{
|
||||||
var geometryRectangle = new Rect(0, 0, 1, 1);
|
|
||||||
Geometry geometry;
|
|
||||||
|
|
||||||
switch (Led.Shape)
|
switch (Led.Shape)
|
||||||
{
|
{
|
||||||
case Shape.Custom:
|
case Shape.Custom:
|
||||||
try
|
CreateCustomGeometry();
|
||||||
{
|
|
||||||
geometry = Geometry.Parse(Led.ShapeData);
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
geometry = new RectangleGeometry(geometryRectangle);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Shape.Rectangle:
|
case Shape.Rectangle:
|
||||||
geometry = new RectangleGeometry(geometryRectangle);
|
if (Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
|
||||||
|
CreateKeyCapGeometry();
|
||||||
|
else
|
||||||
|
CreateRectangleGeometry();
|
||||||
break;
|
break;
|
||||||
case Shape.Circle:
|
case Shape.Circle:
|
||||||
geometry = new EllipseGeometry(geometryRectangle);
|
CreateCircleGeometry();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayGeometry = Geometry.Combine(
|
|
||||||
Geometry.Empty,
|
|
||||||
geometry,
|
|
||||||
GeometryCombineMode.Union,
|
|
||||||
new ScaleTransform(Led.LedRectangle.Width, Led.LedRectangle.Height)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Stroke geometry is the display geometry excluding the inner geometry
|
// Stroke geometry is the display geometry excluding the inner geometry
|
||||||
StrokeGeometry = DisplayGeometry.GetWidenedPathGeometry(new Pen(null, Led.Shape == Shape.Rectangle ? 2.0 : 1.0), 0.1, ToleranceType.Absolute);
|
StrokeGeometry = DisplayGeometry.GetWidenedPathGeometry(new Pen(null, 1.0), 0.1, ToleranceType.Absolute);
|
||||||
|
|
||||||
DisplayGeometry.Freeze();
|
DisplayGeometry.Freeze();
|
||||||
StrokeGeometry.Freeze();
|
StrokeGeometry.Freeze();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateRectangleGeometry()
|
||||||
|
{
|
||||||
|
DisplayGeometry = new RectangleGeometry(new Rect(0.5, 0.5, Led.LedRectangle.Width - 1, Led.LedRectangle.Height - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateCircleGeometry()
|
||||||
|
{
|
||||||
|
DisplayGeometry = new EllipseGeometry(new Rect(0.5, 0.5, Led.LedRectangle.Width - 1, Led.LedRectangle.Height - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateKeyCapGeometry()
|
||||||
|
{
|
||||||
|
DisplayGeometry = new RectangleGeometry(new Rect(1, 1, Led.LedRectangle.Width - 2, Led.LedRectangle.Height - 2), 1.6, 1.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateCustomGeometry()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DisplayGeometry = Geometry.Combine(
|
||||||
|
Geometry.Empty,
|
||||||
|
Geometry.Parse(Led.ShapeData),
|
||||||
|
GeometryCombineMode.Union,
|
||||||
|
new TransformGroup
|
||||||
|
{
|
||||||
|
Children = new TransformCollection
|
||||||
|
{
|
||||||
|
new ScaleTransform(Led.LedRectangle.Width - 1, Led.LedRectangle.Height - 1),
|
||||||
|
new TranslateTransform(0.5, 0.5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
CreateRectangleGeometry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
var newColor = Led.Color.ToMediaColor();
|
var newColor = Led.Color.ToMediaColor();
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False">
|
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False">
|
||||||
<Path.Fill>
|
<Path.Fill>
|
||||||
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.25" />
|
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.333" />
|
||||||
</Path.Fill>
|
</Path.Fill>
|
||||||
</Path>
|
</Path>
|
||||||
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False">
|
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user