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

Surface rearranging WIP

This commit is contained in:
SpoinkyNL 2019-08-24 23:24:13 +02:00
parent bc9dccef31
commit 5106195450
24 changed files with 308 additions and 648 deletions

View File

@ -29,11 +29,6 @@
Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Teal.xaml" />
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Teal.xaml" />
<!-- Artemis -->
<ResourceDictionary Source="Styles/Visualizers/RGBSurfaceVisualizer.xaml" />
<ResourceDictionary Source="Styles/Visualizers/RGBDeviceVisualizer.xaml" />
<ResourceDictionary Source="Styles/Visualizers/LedVisualizer.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- MahApps Brushes -->

View File

@ -147,9 +147,6 @@
</ApplicationDefinition>
<Compile Include="Adorners\BoundingBoxAdorner.cs" />
<Compile Include="Bootstrapper.cs" />
<Compile Include="Controls\Visualizers\LedVisualizer.cs" />
<Compile Include="Controls\Visualizers\RGBDeviceVisualizer.cs" />
<Compile Include="Controls\Visualizers\RGBSurfaceVisualizer.cs" />
<Compile Include="Converters\ColorToSolidColorBrushConverter.cs" />
<Compile Include="Extensions\RgbColorExtensions.cs" />
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
@ -157,7 +154,7 @@
<Compile Include="Services\Interfaces\IArtemisUIService.cs" />
<Compile Include="Stylet\ArtemisViewManager.cs" />
<Compile Include="Stylet\NinjectBootstrapper.cs" />
<Compile Include="ViewModels\Screens\EditorViewModel.cs" />
<Compile Include="ViewModels\Screens\SurfaceEditorViewModel.cs" />
<Compile Include="ViewModels\Interfaces\IEditorViewModel.cs" />
<Compile Include="ViewModels\Controls\RgbDevice\RgbDeviceViewModel.cs" />
<Compile Include="ViewModels\Controls\RgbDevice\RgbLedViewModel.cs" />
@ -172,19 +169,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ViewModels\Screens\SettingsViewModel.cs" />
<Compile Include="ViewModels\Controls\Editor\SurfaceEditorViewModel.cs" />
<Page Include="Styles\Visualizers\LedVisualizer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\Visualizers\RGBDeviceVisualizer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\Visualizers\RGBSurfaceVisualizer.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Screens\HomeView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -201,7 +185,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Screens\EditorView.xaml">
<Page Include="Views\Screens\SurfaceEditorView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
@ -213,10 +197,6 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Controls\Editor\SurfaceEditorView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
@ -260,8 +240,7 @@
<None Include="Resources\bow.svg" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controls\ColorPicker\" />
<Folder Include="Controls\GradientPicker\" />
<Resource Include="Resources\tile.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="FodyWeavers.xml" />

View File

@ -1,47 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using RGB.NET.Core;
namespace Artemis.UI.Controls.Visualizers
{
/// <inheritdoc />
/// <summary>
/// Visualizes a <see cref="T:RGB.NET.Core.Led" /> in an wpf-application.
/// </summary>
public class LedVisualizer : Control
{
public void Select()
{
BorderBrush = new SolidColorBrush(Colors.RoyalBlue);
}
public void Deselect()
{
BorderBrush = new SolidColorBrush(Colors.Black);
}
#region DependencyProperties
// ReSharper disable InconsistentNaming
/// <summary>
/// Backing-property for the <see cref="Led" />-property.
/// </summary>
public static readonly DependencyProperty LedProperty = DependencyProperty.Register(
"Led", typeof(Led), typeof(LedVisualizer), new PropertyMetadata(default(Led)));
/// <summary>
/// Gets or sets the <see cref="RGB.NET.Core.Led" /> to visualize.
/// </summary>
public Led Led
{
get => (Led) GetValue(LedProperty);
set => SetValue(LedProperty, value);
}
// ReSharper restore InconsistentNaming
#endregion
}
}

View File

@ -1,78 +0,0 @@
using System.Windows;
using System.Windows.Controls;
using RGB.NET.Core;
namespace Artemis.UI.Controls.Visualizers
{
/// <inheritdoc />
/// <summary>
/// Visualizes a <see cref="T:RGB.NET.Core.IRGBDevice" /> in an wpf-application.
/// </summary>
[TemplatePart(Name = PART_CANVAS, Type = typeof(Canvas))]
public class RGBDeviceVisualizer : Control
{
#region Constants
private const string PART_CANVAS = "PART_Canvas";
#endregion
#region Properties & Fields
public Canvas Canvas { get; private set; }
#endregion
#region DependencyProperties
// ReSharper disable InconsistentNaming
/// <summary>
/// Backing-property for the <see cref="Device" />-property.
/// </summary>
public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register(
"Device", typeof(IRGBDevice), typeof(RGBDeviceVisualizer), new PropertyMetadata(default(IRGBDevice), DeviceChanged));
/// <summary>
/// Gets or sets the <see cref="IRGBDevice" /> to visualize.
/// </summary>
public IRGBDevice Device
{
get => (IRGBDevice) GetValue(DeviceProperty);
set => SetValue(DeviceProperty, value);
}
// ReSharper restore InconsistentNaming
#endregion
#region Methods
/// <inheritdoc />
public override void OnApplyTemplate()
{
Canvas = (Canvas) GetTemplateChild(PART_CANVAS);
LayoutLeds();
}
private static void DeviceChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
{
((RGBDeviceVisualizer) dependencyObject).LayoutLeds();
}
private void LayoutLeds()
{
if (Canvas == null) return;
Canvas.Children.Clear();
if (Device == null) return;
foreach (var led in Device)
Canvas.Children.Add(new LedVisualizer {Led = led});
}
#endregion
}
}

View File

@ -1,170 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.UI.Adorners;
using RGB.NET.Core;
using RGB.NET.Groups;
using Point = System.Windows.Point;
namespace Artemis.UI.Controls.Visualizers
{
/// <inheritdoc />
/// <summary>
/// Visualizes the <see cref="T:RGB.NET.Core.RGBSurface" /> in an wpf-application.
/// </summary>
[TemplatePart(Name = PART_CANVAS, Type = typeof(Canvas))]
public class RGBSurfaceVisualizer : Control
{
#region Constants
private const string PART_CANVAS = "PART_Canvas";
#endregion
#region Properties & Fields
private RGBSurface _surface;
private Canvas _canvas;
private BoundingBoxAdorner _boundingBox;
private Point _startingPoint;
//TODO DarthAffe 17.06.2017: This is ugly - redesign how device connect/disconnect is generally handled!
private readonly List<IRGBDevice> _newDevices = new List<IRGBDevice>();
#endregion
#region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.WPF.Controls.RGBSurfaceVisualizer" /> class.
/// </summary>
public RGBSurfaceVisualizer()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
_surface = RGBSurface.Instance;
_surface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
foreach (var device in _surface.Devices)
_newDevices.Add(device);
UpdateSurface();
}
private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs)
{
_surface.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
_canvas?.Children.Clear();
_newDevices.Clear();
}
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args)
{
if (args.DeviceAdded)
foreach (var device in args.Devices)
_newDevices.Add(device);
UpdateSurface();
}
#endregion
#region Methods
/// <inheritdoc />
public override void OnApplyTemplate()
{
// Detach any existing event handlers
if (_canvas != null)
{
_canvas.MouseLeftButtonDown -= ScrollViewerOnMouseLeftButtonDown;
_canvas.MouseLeftButtonUp -= ScrollViewerOnMouseLeftButtonUp;
}
_canvas?.Children.Clear();
_canvas = (Canvas) GetTemplateChild(PART_CANVAS);
UpdateSurface();
if (_canvas == null) return;
_canvas.MouseLeftButtonDown += ScrollViewerOnMouseLeftButtonDown;
_canvas.MouseLeftButtonUp += ScrollViewerOnMouseLeftButtonUp;
_canvas.MouseMove += ScrollViewerOnMouseMove;
}
private void ScrollViewerOnMouseLeftButtonDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
_canvas.CaptureMouse();
_startingPoint = mouseButtonEventArgs.GetPosition(_canvas);
_boundingBox = new BoundingBoxAdorner(_canvas, Colors.RoyalBlue);
var adornerLayer = AdornerLayer.GetAdornerLayer(_canvas);
adornerLayer.Add(_boundingBox);
}
private void ScrollViewerOnMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
_canvas.ReleaseMouseCapture();
var adornerLayer = AdornerLayer.GetAdornerLayer(_canvas);
var adorners = adornerLayer.GetAdorners(_canvas);
if (adorners == null) return;
foreach (var adorner in adorners)
adornerLayer.Remove(adorner);
_boundingBox = null;
}
private void ScrollViewerOnMouseMove(object sender, MouseEventArgs mouseEventArgs)
{
if (_boundingBox == null) return;
var currentPoint = mouseEventArgs.GetPosition(_canvas);
_boundingBox.Update(_startingPoint, currentPoint);
var ledStart = new RGB.NET.Core.Point(_startingPoint.X, _startingPoint.Y);
var ledEnd = new RGB.NET.Core.Point(currentPoint.X, currentPoint.Y);
var selection = new RectangleLedGroup(ledStart, ledEnd, 0.1);
// Deselect all LED of each device
var deviceLeds = new List<LedVisualizer>();
foreach (var rgbDeviceVisualizer in _canvas.Children.Cast<RGBDeviceVisualizer>())
deviceLeds.AddRange(rgbDeviceVisualizer.Canvas.Children.Cast<LedVisualizer>());
foreach (var ledVisualizer in deviceLeds)
ledVisualizer?.Deselect();
// Select all LEDs in the bounding box
foreach (var led in selection.GetLeds())
{
var ledVisualizer = deviceLeds.FirstOrDefault(l => l.Led == led);
ledVisualizer?.Select();
}
}
private void UpdateSurface()
{
if (_canvas == null || _surface == null) return;
if (_newDevices.Count > 0)
{
foreach (var device in _newDevices)
_canvas.Children.Add(new RGBDeviceVisualizer {Device = device});
_newDevices.Clear();
}
_canvas.Width = _surface.SurfaceRectangle.Size.Width;
_canvas.Height = _surface.SurfaceRectangle.Size.Height;
}
#endregion
}
}

View File

@ -79,5 +79,15 @@ namespace Artemis.UI.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap tile {
get {
object obj = ResourceManager.GetObject("tile", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -124,4 +124,7 @@
<data name="logo_512" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\logo-512.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="tile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\tile.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

View File

@ -1,98 +0,0 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Artemis.UI.Controls.Visualizers"
xmlns:converters="clr-namespace:Artemis.UI.Converters">
<converters:ColorToSolidColorBrushConverter x:Key="ConverterColorToSolidColorBrush" />
<ControlTemplate x:Key="ControlTemplateLedRectangle" TargetType="{x:Type controls:LedVisualizer}">
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Rectangle VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Opacity="0.5"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"
Fill="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
<ControlTemplate x:Key="ControlTemplateLedCircle" TargetType="{x:Type controls:LedVisualizer}">
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Ellipse VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Opacity="0.5"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"
Fill="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
<ControlTemplate x:Key="ControlTemplateLedCustom" TargetType="{x:Type controls:LedVisualizer}">
<Border x:Name="Border" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Path Opacity="0.5"
Clip="{Binding Data, RelativeSource={RelativeSource Self}}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="2"
Fill="{TemplateBinding Background}">
<Path.Data>
<PathGeometry Figures="{Binding Led.ShapeData, RelativeSource={RelativeSource TemplatedParent}}">
<PathGeometry.Transform>
<ScaleTransform ScaleX="{Binding ActualWidth, ElementName=Border}"
ScaleY="{Binding ActualHeight, ElementName=Border}" />
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
</Path>
</Border>
</ControlTemplate>
<Style x:Key="StyleLedVisualizer" TargetType="{x:Type controls:LedVisualizer}">
<Setter Property="Width" Value="{Binding Led.LedRectangle.Size.Width, RelativeSource={RelativeSource Self}}" />
<Setter Property="Height" Value="{Binding Led.LedRectangle.Size.Height, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Left"
Value="{Binding Led.LedRectangle.Location.X, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Top"
Value="{Binding Led.LedRectangle.Location.Y, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderBrush" Value="#000000" />
<Setter Property="Background"
Value="{Binding Led.Color, RelativeSource={RelativeSource Self},
Converter={StaticResource ConverterColorToSolidColorBrush}}" />
<Setter Property="Template" Value="{StaticResource ControlTemplateLedRectangle}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#FFFFFF" />
</Trigger>
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Circle">
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCircle}" />
</DataTrigger>
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Custom">
<Setter Property="Template" Value="{StaticResource ControlTemplateLedCustom}" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type controls:LedVisualizer}" BasedOn="{StaticResource StyleLedVisualizer}" />
</ResourceDictionary>

View File

@ -1,43 +0,0 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Artemis.UI.Controls.Visualizers">
<Style x:Key="StyleRGBDeviceVisualizer" TargetType="{x:Type controls:RGBDeviceVisualizer}">
<Setter Property="Width" Value="{Binding Device.Size.Width, RelativeSource={RelativeSource Self}}" />
<Setter Property="Height" Value="{Binding Device.Size.Height, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Left" Value="{Binding Device.Location.X, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Top" Value="{Binding Device.Location.Y, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="BorderBrush" Value="#202020" />
<!--<Setter Property="Background" Value="#3A3A3A" />-->
<Setter Property="Background">
<Setter.Value>
<ImageBrush AlignmentX="Left" AlignmentY="Top"
Stretch="Uniform"
ImageSource="{Binding Device.DeviceInfo.Image, RelativeSource={RelativeSource AncestorType=controls:RGBDeviceVisualizer}}" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:RGBDeviceVisualizer}">
<Grid VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Background="{TemplateBinding Background}">
<Canvas x:Name="PART_Canvas"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" />
<Border VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{x:Null}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type controls:RGBDeviceVisualizer}" BasedOn="{StaticResource StyleRGBDeviceVisualizer}" />
</ResourceDictionary>

View File

@ -1,46 +0,0 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:visualizers="clr-namespace:Artemis.UI.Controls.Visualizers">
<Style x:Key="StyleRGBSurfaceVisualizer" TargetType="{x:Type visualizers:RGBSurfaceVisualizer}">
<Setter Property="VerticalAlignment"
Value="Stretch" />
<Setter Property="HorizontalAlignment"
Value="Stretch" />
<Setter Property="VerticalContentAlignment"
Value="Top" />
<Setter Property="HorizontalContentAlignment"
Value="Left" />
<Setter Property="Background"
Value="{x:Null}" />
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="BorderBrush"
Value="{x:Null}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type visualizers:RGBSurfaceVisualizer}">
<ScrollViewer x:Name="PART_ScrollViewer"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Background="Transparent">
<Border VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<Canvas x:Name="PART_Canvas"
Background="Transparent" />
</Border>
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type visualizers:RGBSurfaceVisualizer}" BasedOn="{StaticResource StyleRGBSurfaceVisualizer}" />
</ResourceDictionary>

View File

@ -1,47 +0,0 @@
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.ViewModels.Controls.RgbDevice;
using RGB.NET.Core;
using Stylet;
namespace Artemis.UI.ViewModels.Controls.Editor
{
public class SurfaceEditorViewModel
{
private readonly IRgbService _rgbService;
public SurfaceEditorViewModel(IRgbService rgbService)
{
Devices = new ObservableCollection<RgbDeviceViewModel>();
_rgbService = rgbService;
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
_rgbService.Surface.Updated += SurfaceOnUpdated;
foreach (var surfaceDevice in _rgbService.Surface.Devices)
Devices.Add(new RgbDeviceViewModel(surfaceDevice));
}
public ObservableCollection<RgbDeviceViewModel> Devices { get; set; }
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
{
Execute.OnUIThread(() =>
{
if (Devices.All(d => d.Device != e.Device))
Devices.Add(new RgbDeviceViewModel(e.Device));
});
}
private void SurfaceOnUpdated(UpdatedEventArgs args)
{
foreach (var rgbDeviceViewModel in Devices)
{
rgbDeviceViewModel.Update();
}
}
}
}

View File

@ -1,9 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using RGB.NET.Core;
using Stylet;
namespace Artemis.UI.ViewModels.Controls.RgbDevice
{
public class RgbDeviceViewModel
public class RgbDeviceViewModel : PropertyChangedBase
{
private readonly List<RgbLedViewModel> _leds;
@ -16,6 +20,9 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
_leds.Add(new RgbLedViewModel(led));
}
public Cursor Cursor { get; set; }
public SelectionStatus SelectionStatus { get; set; }
public IRGBDevice Device { get; }
public IReadOnlyCollection<RgbLedViewModel> Leds => _leds.AsReadOnly();
@ -24,5 +31,20 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
foreach (var rgbLedViewModel in _leds)
rgbLedViewModel.Update();
}
public void SetColorsEnabled(bool enabled)
{
foreach (var rgbLedViewModel in _leds)
rgbLedViewModel.ColorsEnabled = enabled;
}
public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
}
public enum SelectionStatus
{
None,
Hover,
Selected
}
}

View File

@ -1,5 +1,6 @@
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.UI.Extensions;
using PropertyChanged;
@ -14,7 +15,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public RgbLedViewModel(Led led)
{
Led = led;
Execute.OnUIThread(CreateLedGeometry);
Update();
}
@ -30,6 +31,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public Geometry DisplayGeometry { get; private set; }
public Geometry StrokeGeometry { get; private set; }
public Color DisplayColor { get; private set; }
public bool ColorsEnabled { get; set; } = true;
public string Tooltip => $"{Led.Id} - {Led.LedRectangle}";
@ -93,8 +95,11 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public void Update()
{
var newColor = Led.Color.ToMediaColor();
SetColor(newColor);
if (ColorsEnabled)
{
var newColor = Led.Color.ToMediaColor();
SetColor(newColor);
}
if (Math.Abs(Led.LedRectangle.X - X) > 0.1)
X = Led.LedRectangle.X;

View File

@ -1,6 +1,6 @@
namespace Artemis.UI.ViewModels.Interfaces
{
public interface IEditorViewModel : IScreenViewModel
public interface ISurfaceEditorViewModel : IScreenViewModel
{
}

View File

@ -1,18 +0,0 @@
using Artemis.Core.Services.Interfaces;
using Artemis.UI.ViewModels.Controls.Editor;
using Artemis.UI.ViewModels.Interfaces;
using Stylet;
namespace Artemis.UI.ViewModels.Screens
{
public class EditorViewModel : Screen, IEditorViewModel
{
public EditorViewModel(IRgbService rgbService)
{
SurfaceEditorViewModel = new SurfaceEditorViewModel(rgbService);
}
public SurfaceEditorViewModel SurfaceEditorViewModel { get; set; }
public string Title => "Editor";
}
}

View File

@ -102,8 +102,8 @@ namespace Artemis.UI.ViewModels.Screens
case "Workshop":
// ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(WorkshopViewModel)));
break;
case "Editor":
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(EditorViewModel)));
case "SurfaceEditor":
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(SurfaceEditorViewModel)));
break;
case "Settings":
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(SettingsViewModel)));

View File

@ -0,0 +1,126 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.Core.Events;
using Artemis.Core.Services.Interfaces;
using Artemis.UI.ViewModels.Controls.RgbDevice;
using Artemis.UI.ViewModels.Interfaces;
using RGB.NET.Core;
using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.ViewModels.Screens
{
public class SurfaceEditorViewModel : Screen, ISurfaceEditorViewModel
{
private readonly IRgbService _rgbService;
public SurfaceEditorViewModel(IRgbService rgbService)
{
Devices = new ObservableCollection<RgbDeviceViewModel>();
SelectionRectangle = new RectangleGeometry();
_rgbService = rgbService;
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
_rgbService.Surface.Updated += SurfaceOnUpdated;
foreach (var surfaceDevice in _rgbService.Surface.Devices)
{
var device = new RgbDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
device.SetColorsEnabled(false);
Devices.Add(device);
}
}
public RectangleGeometry SelectionRectangle { get; set; }
public ObservableCollection<RgbDeviceViewModel> Devices { get; set; }
public string Title => "Surface Editor";
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
{
Execute.OnUIThread(() =>
{
if (Devices.All(d => d.Device != e.Device))
{
var device = new RgbDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
device.SetColorsEnabled(false);
Devices.Add(device);
}
});
}
private void SurfaceOnUpdated(UpdatedEventArgs args)
{
foreach (var rgbDeviceViewModel in Devices)
rgbDeviceViewModel.Update();
}
#region Selection
private bool _editorSelecting;
private Point _selectionStartPoint;
private void StartSelection(Point position)
{
_selectionStartPoint = position;
_editorSelecting = true;
SelectionRectangle.Rect = new Rect();
Mouse.OverrideCursor = Cursors.Arrow;
}
private void StopSelection(Point position)
{
_editorSelecting = false;
Mouse.OverrideCursor = null;
var selectedRect = new Rect(_selectionStartPoint, position);
foreach (var device in Devices)
{
if (device.DeviceRectangle.IntersectsWith(selectedRect))
device.SelectionStatus = SelectionStatus.Selected;
else
device.SelectionStatus = SelectionStatus.None;
}
}
private void UpdateSelection(Point position)
{
var selectedRect = new Rect(_selectionStartPoint, position);
SelectionRectangle.Rect = selectedRect;
foreach (var device in Devices)
{
if (device.DeviceRectangle.IntersectsWith(selectedRect))
device.SelectionStatus = SelectionStatus.Selected;
else
device.SelectionStatus = SelectionStatus.None;
}
}
public void EditorGridMouseClick(object sender, MouseEventArgs e)
{
var position = e.GetPosition((IInputElement) sender);
if (e.LeftButton == MouseButtonState.Pressed)
StartSelection(position);
else
StopSelection(position);
}
public void EditorGridMouseMove(object sender, MouseEventArgs e)
{
if (!_editorSelecting)
return;
var position = e.GetPosition((IInputElement) sender);
UpdateSelection(position);
}
#endregion
}
}

View File

@ -1,33 +0,0 @@
<UserControl x:Class="Artemis.UI.Views.Controls.Editor.SurfaceEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:editor="clr-namespace:Artemis.UI.ViewModels.Controls.Editor"
xmlns:xaml="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800"
d:DataContext="{d:DesignInstance editor:SurfaceEditorViewModel}">
<StackPanel>
<TextBlock>Surface editor view</TextBlock>
<ItemsControl ItemsSource="{Binding Devices}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Device.Location.X}" />
<Setter Property="Canvas.Top" Value="{Binding Device.Location.Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Width="{Binding Device.Size.Width}" Height="{Binding Device.Size.Height}" xaml:View.Model="{Binding }"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>

View File

@ -7,9 +7,11 @@
xmlns:xaml="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance rgbDevice:RgbDeviceViewModel}"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="450" d:DesignWidth="800"
Cursor="{Binding Cursor}">
<UserControl.Resources></UserControl.Resources>
<Grid>
<Image Source="{Binding Device.DeviceInfo.Image}"></Image>
<Image Source="{Binding Device.DeviceInfo.Image}" />
<ItemsControl ItemsSource="{Binding Leds}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
@ -24,9 +26,50 @@
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Width="{Binding Width}" Height="{Binding Height}" xaml:View.Model="{Binding}" ToolTip="{Binding Tooltip}" />
<ContentControl Width="{Binding Width}" Height="{Binding Height}" xaml:View.Model="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Rectangle Width="Auto" Height="Auto" StrokeThickness="1">
<Rectangle.Style>
<Style TargetType="Rectangle">
<Style.Triggers>
<DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static rgbDevice:SelectionStatus.Hover}">
<Setter Property="Rectangle.Fill">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource IdealForegroundColor}" Opacity="0.25" />
</Setter.Value>
</Setter>
<Setter Property="Rectangle.Stroke" Value="{DynamicResource IdealForegroundColorBrush}"/>
</DataTrigger>
<DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static rgbDevice:SelectionStatus.Selected}">
<Setter Property="Rectangle.Fill">
<Setter.Value>
<SolidColorBrush Color="{DynamicResource Primary400}" Opacity="0.25" />
</Setter.Value>
</Setter>
<Setter Property="Rectangle.Stroke" Value="{DynamicResource PrimaryHueLightBrush}" />
</DataTrigger>
<DataTrigger Binding="{Binding SelectionStatus}" Value="{x:Static rgbDevice:SelectionStatus.None}">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.25" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.25" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Rectangle.Style>
</Rectangle>
</Grid>
</UserControl>

View File

@ -6,18 +6,20 @@
xmlns:rgbDevice="clr-namespace:Artemis.UI.ViewModels.Controls.RgbDevice"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance rgbDevice:RgbLedViewModel}"
d:DesignHeight="450" d:DesignWidth="800">
d:DesignHeight="25" d:DesignWidth="25"
ToolTip="{Binding Tooltip}"
ToolTipService.IsEnabled="{Binding ColorsEnabled}">
<Grid Width="{Binding Width}" Height="{Binding Height}">
<Grid.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center" Stretch="Fill" ImageSource="{Binding Led.Image}" />
</Grid.Background>
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False">
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False" Visibility="{Binding ColorsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<Path.Fill>
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.25" />
</Path.Fill>
</Path>
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False">
<Path Data="{Binding StrokeGeometry}" ClipToBounds="False" Visibility="{Binding ColorsEnabled, Converter={StaticResource BoolToVisibilityConverter}}">
<Path.Fill>
<SolidColorBrush Color="{Binding DisplayColor}" />
</Path.Fill>

View File

@ -1,23 +0,0 @@
<UserControl x:Class="Artemis.UI.Views.Screens.EditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:screens="clr-namespace:Artemis.UI.ViewModels.Screens"
xmlns:xaml="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance screens:EditorViewModel}"
d:DesignHeight="600" d:DesignWidth="600">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel Margin="16">
<TextBlock>In the editor you can either edit your surface layout or edit a profile.</TextBlock>
<ContentControl xaml:View.Model="{Binding SurfaceEditorViewModel}"/>
</StackPanel>
</UserControl>

View File

@ -104,11 +104,11 @@
<TextBlock>Workshop</TextBlock>
</StackPanel>
</ListBoxItem>
<ListBoxItem x:Name="Editor">
<ListBoxItem x:Name="SurfaceEditor">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Edit"
Margin="0,0,8,0" />
<TextBlock>Editor</TextBlock>
<TextBlock>Surface Editor</TextBlock>
</StackPanel>
</ListBoxItem>
<ListBoxItem x:Name="Settings">

View File

@ -0,0 +1,78 @@
<UserControl x:Class="Artemis.UI.Views.Screens.SurfaceEditorView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:screens="clr-namespace:Artemis.UI.ViewModels.Screens"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance screens:SurfaceEditorViewModel}"
d:DesignHeight="600" d:DesignWidth="600">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock>The surface is a digital representation of your LED setup. Set this up accurately and effects will seamlessly move from one device to the other.</TextBlock>
<Grid Name="EditorDisplayGrid"
Grid.Row="1"
Margin="0 5 0 0"
MouseUp="{s:Action EditorGridMouseClick}"
MouseDown="{s:Action EditorGridMouseClick}"
MouseMove="{s:Action EditorGridMouseMove}">
<Grid.Triggers>
<EventTrigger RoutedEvent="Grid.MouseDown">
<BeginStoryboard>
<Storyboard TargetName="MultiSelectionPath" TargetProperty="Opacity">
<DoubleAnimation From="0" To="1" Duration="0:0:0.1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Grid.MouseUp">
<BeginStoryboard>
<Storyboard TargetName="MultiSelectionPath" TargetProperty="Opacity">
<DoubleAnimation From="1" To="0" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Grid.Background>
<ImageBrush TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,15,15" ImageSource="/Artemis.UI;component/Resources/tile.png" />
</Grid.Background>
<ItemsControl ItemsSource="{Binding Devices}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Device.Location.X}" />
<Setter Property="Canvas.Top" Value="{Binding Device.Location.Y}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ContentControl Width="{Binding Device.Size.Width}" Height="{Binding Device.Size.Height}" s:View.Model="{Binding }" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- Multi-selection rectangle -->
<Path Data="{Binding SelectionRectangle}" Opacity="0" Stroke="{DynamicResource PrimaryHueLightBrush}" StrokeThickness="1" Name="MultiSelectionPath">
<Path.Fill>
<SolidColorBrush Color="{DynamicResource Primary400}" Opacity="0.25" />
</Path.Fill>
</Path>
</Grid>
</Grid>
</UserControl>