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()
|
||||
{
|
||||
var geometryRectangle = new Rect(0, 0, 1, 1);
|
||||
Geometry geometry;
|
||||
|
||||
switch (Led.Shape)
|
||||
{
|
||||
case Shape.Custom:
|
||||
try
|
||||
{
|
||||
geometry = Geometry.Parse(Led.ShapeData);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
geometry = new RectangleGeometry(geometryRectangle);
|
||||
}
|
||||
|
||||
CreateCustomGeometry();
|
||||
break;
|
||||
case Shape.Rectangle:
|
||||
geometry = new RectangleGeometry(geometryRectangle);
|
||||
if (Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
|
||||
CreateKeyCapGeometry();
|
||||
else
|
||||
CreateRectangleGeometry();
|
||||
break;
|
||||
case Shape.Circle:
|
||||
geometry = new EllipseGeometry(geometryRectangle);
|
||||
CreateCircleGeometry();
|
||||
break;
|
||||
default:
|
||||
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
|
||||
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();
|
||||
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()
|
||||
{
|
||||
var newColor = Led.Color.ToMediaColor();
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
|
||||
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.25" />
|
||||
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.333" />
|
||||
</Path.Fill>
|
||||
</Path>
|
||||
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user