1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Surface editor - Prevent LED overlaps

This commit is contained in:
Robert 2020-12-14 19:56:00 +01:00
parent 34bcfccb4c
commit 746c42e538
3 changed files with 39 additions and 9 deletions

View File

@ -17,9 +17,9 @@ namespace Artemis.Core
internal BitmapBrush(Scale scale, PluginSetting<int> sampleSizeSetting)
{
_disposeLock = new object();
_sampleSizeSetting = sampleSizeSetting;
Scale = scale;
_disposeLock = new object();
}
#endregion

View File

@ -119,9 +119,8 @@ namespace Artemis.UI.Screens.SurfaceEditor
bool confirmed = await _dialogService.ShowConfirmDialog("Auto-arrange layout", "Are you sure you want to auto-arrange your layout? Your current settings will be overwritten.");
if (!confirmed)
return;
_surfaceService.AutoArrange();
_surfaceService.AutoArrange();
}
private void LoadWorkspaceSettings()
@ -405,9 +404,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
device.SelectionStatus = SelectionStatus.None;
}
else
{
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
}
_mouseDragStatus = MouseDragStatus.None;
_rgbService.IsRenderPaused = false;

View File

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core;
using RGB.NET.Core;
using SkiaSharp;
using Stylet;
using Point = System.Windows.Point;
@ -58,12 +61,25 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
public void UpdateMouseDrag(Point mousePosition)
{
double roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
double roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
Device.X = Math.Max(0, roundedX);
Device.Y = Math.Max(0, roundedY);
float roundedX = (float) Math.Round((mousePosition.X + _dragOffsetX) / 10d, 0, MidpointRounding.AwayFromZero) * 10f;
float roundedY = (float) Math.Round((mousePosition.Y + _dragOffsetY) / 10d, 0, MidpointRounding.AwayFromZero) * 10f;
if (Fits(roundedX, roundedY))
{
Device.X = roundedX;
Device.Y = roundedY;
}
else if (Fits(roundedX, (float) Device.Y))
{
Device.X = roundedX;
}
else if (Fits((float) Device.X, roundedY))
{
Device.Y = roundedY;
}
}
// ReSharper disable once UnusedMember.Global - Called from view
public void MouseEnter(object sender, MouseEventArgs e)
{
@ -90,6 +106,23 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
return MouseDevicePosition.Regular;
}
private bool Fits(float x, float y)
{
if (x < 0 || y < 0)
return false;
List<SKRect> own = Device.Leds
.Select(l => SKRect.Create(l.Rectangle.Left + x, l.Rectangle.Top + y, l.Rectangle.Width, l.Rectangle.Height))
.ToList();
List<SKRect> others = Device.Surface.Devices
.Where(d => d != Device)
.SelectMany(d => d.Leds)
.Select(l => SKRect.Create(l.Rectangle.Left + (float) l.Device.X, l.Rectangle.Top + (float) l.Device.Y, l.Rectangle.Width, l.Rectangle.Height))
.ToList();
return !own.Any(o => others.Any(l => l.IntersectsWith(o)));
}
}
public enum MouseDevicePosition