mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Surface editor - Prevent LED overlaps
This commit is contained in:
parent
34bcfccb4c
commit
746c42e538
@ -17,9 +17,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
internal BitmapBrush(Scale scale, PluginSetting<int> sampleSizeSetting)
|
internal BitmapBrush(Scale scale, PluginSetting<int> sampleSizeSetting)
|
||||||
{
|
{
|
||||||
|
_disposeLock = new object();
|
||||||
_sampleSizeSetting = sampleSizeSetting;
|
_sampleSizeSetting = sampleSizeSetting;
|
||||||
Scale = scale;
|
Scale = scale;
|
||||||
_disposeLock = new object();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -121,7 +121,6 @@ namespace Artemis.UI.Screens.SurfaceEditor
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_surfaceService.AutoArrange();
|
_surfaceService.AutoArrange();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadWorkspaceSettings()
|
private void LoadWorkspaceSettings()
|
||||||
@ -405,9 +404,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
|
|||||||
device.SelectionStatus = SelectionStatus.None;
|
device.SelectionStatus = SelectionStatus.None;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
|
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
|
||||||
}
|
|
||||||
|
|
||||||
_mouseDragStatus = MouseDragStatus.None;
|
_mouseDragStatus = MouseDragStatus.None;
|
||||||
_rgbService.IsRenderPaused = false;
|
_rgbService.IsRenderPaused = false;
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
using SkiaSharp;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
using Point = System.Windows.Point;
|
using Point = System.Windows.Point;
|
||||||
|
|
||||||
@ -58,12 +61,25 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
|
|||||||
|
|
||||||
public void UpdateMouseDrag(Point mousePosition)
|
public void UpdateMouseDrag(Point mousePosition)
|
||||||
{
|
{
|
||||||
double roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
float roundedX = (float) Math.Round((mousePosition.X + _dragOffsetX) / 10d, 0, MidpointRounding.AwayFromZero) * 10f;
|
||||||
double roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
float roundedY = (float) Math.Round((mousePosition.Y + _dragOffsetY) / 10d, 0, MidpointRounding.AwayFromZero) * 10f;
|
||||||
Device.X = Math.Max(0, roundedX);
|
|
||||||
Device.Y = Math.Max(0, roundedY);
|
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
|
// ReSharper disable once UnusedMember.Global - Called from view
|
||||||
public void MouseEnter(object sender, MouseEventArgs e)
|
public void MouseEnter(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
@ -90,6 +106,23 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
|
|||||||
|
|
||||||
return MouseDevicePosition.Regular;
|
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
|
public enum MouseDevicePosition
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user