1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Surface editor - Contain devices to the max texture size

Surface editor - Show a bounding box indicating the max texture size
This commit is contained in:
Robert 2021-08-13 22:38:03 +02:00
parent aace06b6cc
commit dfdc28760e
4 changed files with 31 additions and 8 deletions

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using Artemis.Core.DeviceProviders;

View File

@ -63,9 +63,8 @@
<Border BorderBrush="{DynamicResource MaterialDesignDivider}" BorderThickness="0 0 0 1" Margin="0 10" />
</StackPanel>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Grid.Column="0"
VerticalAlignment="Stretch" Margin="0,0,5,0">
<Grid ClipToBounds="True"
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch" Margin="0,0,5,0">
<Grid ClipToBounds="False"
Focusable="True"
FocusVisualStyle="{StaticResource FocusVisual}"
KeyUp="{s:Action EditorGridKeyUp}"
@ -188,8 +187,16 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Canvas>
<Rectangle ClipToBounds="False"
Width="{Binding MaxTextureSize}"
Height="{Binding MaxTextureSize}"
Stroke="{DynamicResource SecondaryHueMidBrush}"
StrokeThickness="{Binding MaxTextureSizeIndicatorThickness}"
StrokeDashArray="2 2" />
</Canvas>
</Grid>
<!-- Multi-selection rectangle -->
<Path Data="{Binding SelectionRectangle}" Opacity="0"
Stroke="{DynamicResource PrimaryHueLightBrush}"

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
@ -106,6 +107,9 @@ namespace Artemis.UI.Screens.SurfaceEditor
set => SetAndNotify(ref _colorFirstLedOnly, value);
}
public double MaxTextureSize => 4096 / _settingsService.GetSetting("Core.RenderScale", 0.5).Value;
public double MaxTextureSizeIndicatorThickness => 2 / PanZoomViewModel.Zoom;
public void OpenHyperlink(object sender, RequestNavigateEventArgs e)
{
Core.Utilities.OpenUrl(e.Uri.AbsoluteUri);
@ -155,7 +159,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
protected override void OnInitialActivate()
{
LoadWorkspaceSettings();
SurfaceDeviceViewModels.AddRange(_rgbService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => new SurfaceDeviceViewModel(d, _rgbService)));
SurfaceDeviceViewModels.AddRange(_rgbService.EnabledDevices.OrderBy(d => d.ZIndex).Select(d => new SurfaceDeviceViewModel(d, _rgbService, _settingsService)));
ListDeviceViewModels.AddRange(_rgbService.EnabledDevices.OrderBy(d => d.ZIndex * -1).Select(d => new ListDeviceViewModel(d, this)));
List<ArtemisDevice> shuffledDevices = _rgbService.EnabledDevices.OrderBy(d => Guid.NewGuid()).ToList();
@ -168,7 +172,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
}
_coreService.FrameRendering += CoreServiceOnFrameRendering;
PanZoomViewModel.PropertyChanged += PanZoomViewModelOnPropertyChanged;
base.OnInitialActivate();
}
@ -179,10 +183,17 @@ namespace Artemis.UI.Screens.SurfaceEditor
ListDeviceViewModels.Clear();
_coreService.FrameRendering -= CoreServiceOnFrameRendering;
PanZoomViewModel.PropertyChanged -= PanZoomViewModelOnPropertyChanged;
base.OnClose();
}
private void PanZoomViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(PanZoomViewModel.Zoom))
NotifyOfPropertyChange(nameof(MaxTextureSizeIndicatorThickness));
}
#endregion
#region Context menu actions

View File

@ -14,15 +14,17 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
public class SurfaceDeviceViewModel : PropertyChangedBase
{
private readonly IRgbService _rgbService;
private readonly ISettingsService _settingsService;
private Cursor _cursor;
private double _dragOffsetX;
private double _dragOffsetY;
private SelectionStatus _selectionStatus;
public SurfaceDeviceViewModel(ArtemisDevice device, IRgbService rgbService)
public SurfaceDeviceViewModel(ArtemisDevice device, IRgbService rgbService, ISettingsService settingsService)
{
Device = device;
_rgbService = rgbService;
_settingsService = settingsService;
}
public ArtemisDevice Device { get; }
@ -101,6 +103,10 @@ namespace Artemis.UI.Screens.SurfaceEditor.Visualization
if (x < 0 || y < 0)
return false;
double maxTextureSize = 4096 / _settingsService.GetSetting("Core.RenderScale", 0.5).Value;
if (x + Device.Rectangle.Width > maxTextureSize || y + Device.Rectangle.Height > maxTextureSize)
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();