diff --git a/src/Artemis.Core/RGB.NET/DirectBitmap.cs b/src/Artemis.Core/RGB.NET/DirectBitmap.cs
index 40b286242..e328a7df3 100644
--- a/src/Artemis.Core/RGB.NET/DirectBitmap.cs
+++ b/src/Artemis.Core/RGB.NET/DirectBitmap.cs
@@ -43,10 +43,14 @@ namespace Artemis.Core.RGB.NET
public Color GetPixel(int x, int y)
{
var index = x + y * Width;
- var col = Bits[index];
- var result = Color.FromArgb(col);
+ if (index >= 0 && index - 1 <= Bits.Length)
+ {
+ var col = Bits[index];
+ var result = Color.FromArgb(col);
- return result;
+ return result;
+ }
+ return Color.Black;
}
}
}
\ No newline at end of file
diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj
index 3daec2b82..15eb1c41e 100644
--- a/src/Artemis.UI/Artemis.UI.csproj
+++ b/src/Artemis.UI/Artemis.UI.csproj
@@ -148,16 +148,19 @@
+
+
+
+
+
-
-
@@ -169,15 +172,23 @@
Code
+
+ MSBuild:Compile
+ Designer
+
+
+ MSBuild:Compile
+ Designer
+
Designer
MSBuild:Compile
-
+
Designer
MSBuild:Compile
-
+
Designer
MSBuild:Compile
@@ -248,6 +259,9 @@
+
+
+
diff --git a/src/Artemis.UI/Converters/NullToVisibilityConverter.cs b/src/Artemis.UI/Converters/NullToVisibilityConverter.cs
new file mode 100644
index 000000000..9b40824a9
--- /dev/null
+++ b/src/Artemis.UI/Converters/NullToVisibilityConverter.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace Artemis.UI.Converters
+{
+ public class NullToVisibilityConverter : IValueConverter
+ {
+ private enum Parameters
+ {
+ Normal,
+ Inverted
+ }
+
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ var direction = (Parameters) Enum.Parse(typeof(Parameters), (string) parameter ?? throw new InvalidOperationException());
+ if (direction == Parameters.Normal)
+ {
+ if (value == null)
+ return Visibility.Hidden;
+ return Visibility.Visible;
+ }
+ if (value == null)
+ return Visibility.Visible;
+ return Visibility.Hidden;
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileDeviceViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileDeviceViewModel.cs
new file mode 100644
index 000000000..4f81e64af
--- /dev/null
+++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileDeviceViewModel.cs
@@ -0,0 +1,29 @@
+using System.Collections.Generic;
+using RGB.NET.Core;
+using Stylet;
+
+namespace Artemis.UI.ViewModels.Controls.ProfileEditor
+{
+ public class ProfileDeviceViewModel : PropertyChangedBase
+ {
+ private readonly List _leds;
+
+ public ProfileDeviceViewModel(IRGBDevice device)
+ {
+ Device = device;
+ _leds = new List();
+
+ foreach (var led in Device)
+ _leds.Add(new ProfileLedViewModel(led));
+ }
+
+ public IRGBDevice Device { get; }
+ public IReadOnlyCollection Leds => _leds.AsReadOnly();
+
+ public void Update()
+ {
+ foreach (var ledViewModel in _leds)
+ ledViewModel.Update();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs
similarity index 94%
rename from src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs
rename to src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs
index 051b0993f..7e776b7e5 100644
--- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Controls/ProfileEditor/ProfileLedViewModel.cs
@@ -1,18 +1,16 @@
using System;
using System.Windows;
-using System.Windows.Input;
using System.Windows.Media;
using Artemis.UI.Extensions;
-using PropertyChanged;
using RGB.NET.Core;
using Stylet;
using Color = System.Windows.Media.Color;
-namespace Artemis.UI.ViewModels.Controls.RgbDevice
+namespace Artemis.UI.ViewModels.Controls.ProfileEditor
{
- public class RgbLedViewModel : PropertyChangedBase
+ public class ProfileLedViewModel : PropertyChangedBase
{
- public RgbLedViewModel(Led led)
+ public ProfileLedViewModel(Led led)
{
Led = led;
diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs b/src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceDeviceViewModel.cs
similarity index 71%
rename from src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs
rename to src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceDeviceViewModel.cs
index 00020adf3..3d7e2ba07 100644
--- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbDeviceViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceDeviceViewModel.cs
@@ -6,40 +6,29 @@ using RGB.NET.Core;
using Stylet;
using Point = System.Windows.Point;
-namespace Artemis.UI.ViewModels.Controls.RgbDevice
+namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
{
- public class RgbDeviceViewModel : PropertyChangedBase
+ public class SurfaceDeviceViewModel : PropertyChangedBase
{
- private readonly List _leds;
private double _dragOffsetX;
private double _dragOffsetY;
+ private readonly List _leds;
- public RgbDeviceViewModel(IRGBDevice device)
+ public SurfaceDeviceViewModel(IRGBDevice device)
{
Device = device;
- _leds = new List();
+ _leds = new List();
foreach (var led in Device)
- _leds.Add(new RgbLedViewModel(led));
+ _leds.Add(new SurfaceLedViewModel(led));
}
- public Cursor Cursor { get; set; }
- public SelectionStatus SelectionStatus { get; set; }
-
public IRGBDevice Device { get; }
- public IReadOnlyCollection Leds => _leds.AsReadOnly();
+ public SelectionStatus SelectionStatus { get; set; }
+ public Cursor Cursor { get; set; }
- public void Update()
- {
- foreach (var rgbLedViewModel in _leds)
- rgbLedViewModel.Update();
- }
-
- public void SetColorsEnabled(bool enabled)
- {
- foreach (var rgbLedViewModel in _leds)
- rgbLedViewModel.ColorsEnabled = enabled;
- }
+ public IReadOnlyCollection Leds => _leds.AsReadOnly();
+ public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
public void StartMouseDrag(Point mouseStartPosition)
{
@@ -51,7 +40,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
{
var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
- this.Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
+ Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
}
public void FinishMouseDrag(Point mouseEndPosition)
@@ -78,8 +67,6 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
Cursor = Cursors.Arrow;
}
}
-
- public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
}
public enum SelectionStatus
diff --git a/src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceLedViewModel.cs
new file mode 100644
index 000000000..4afd874b2
--- /dev/null
+++ b/src/Artemis.UI/ViewModels/Controls/SurfaceEditor/SurfaceLedViewModel.cs
@@ -0,0 +1,37 @@
+using System;
+using RGB.NET.Core;
+using Stylet;
+
+namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
+{
+ public class SurfaceLedViewModel : PropertyChangedBase
+ {
+ public SurfaceLedViewModel(Led led)
+ {
+ Led = led;
+ Update();
+ }
+
+ public Led Led { get; }
+
+ public double X { get; private set; }
+ public double Y { get; private set; }
+ public double Width { get; private set; }
+ public double Height { get; private set; }
+
+ public void Update()
+ {
+ if (Math.Abs(Led.LedRectangle.X - X) > 0.1)
+ X = Led.LedRectangle.X;
+
+ if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1)
+ Y = Led.LedRectangle.Y;
+
+ if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1)
+ Width = Led.LedRectangle.Width;
+
+ if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1)
+ Height = Led.LedRectangle.Height;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
index 2dcdadd7d..6fe13a358 100644
--- a/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
+++ b/src/Artemis.UI/ViewModels/Screens/SurfaceEditorViewModel.cs
@@ -1,4 +1,5 @@
-using System.Collections.ObjectModel;
+using System;
+using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
@@ -8,7 +9,7 @@ using Artemis.Core.Events;
using Artemis.Core.Models.Surface;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage;
-using Artemis.UI.ViewModels.Controls.RgbDevice;
+using Artemis.UI.ViewModels.Controls.SurfaceEditor;
using Artemis.UI.ViewModels.Interfaces;
using RGB.NET.Core;
using Stylet;
@@ -23,26 +24,23 @@ namespace Artemis.UI.ViewModels.Screens
public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService)
{
- Devices = new ObservableCollection();
+ Devices = new ObservableCollection();
SurfaceConfigurations = new ObservableCollection();
SelectionRectangle = new RectangleGeometry();
_rgbService = rgbService;
_surfaceService = surfaceService;
_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);
-
+ var device = new SurfaceDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
Devices.Add(device);
}
}
public RectangleGeometry SelectionRectangle { get; set; }
- public ObservableCollection Devices { get; set; }
+ public ObservableCollection Devices { get; set; }
public SurfaceConfiguration SelectedSurfaceConfiguration { get; set; }
public ObservableCollection SurfaceConfigurations { get; set; }
@@ -56,47 +54,32 @@ namespace Artemis.UI.ViewModels.Screens
{
if (Devices.All(d => d.Device != e.Device))
{
- var device = new RgbDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
- device.SetColorsEnabled(false);
+ var device = new SurfaceDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
Devices.Add(device);
}
});
}
- private void SurfaceOnUpdated(UpdatedEventArgs args)
- {
- foreach (var rgbDeviceViewModel in Devices)
- rgbDeviceViewModel.Update();
- }
-
- #region Overrides of Screen
-
- protected override void OnActivate()
- {
- Task.Run(LoadSurfaceConfigurations);
- base.OnActivate();
- }
-
- #endregion
-
private async Task LoadSurfaceConfigurations()
{
- SurfaceConfigurations.Clear();
+ Execute.OnUIThread(async () =>
+ {
+ SurfaceConfigurations.Clear();
- // Get surface configs
- var configs = await _surfaceService.GetSurfaceConfigurations();
- // Populate the UI collection
- foreach (var surfaceConfiguration in configs)
- SurfaceConfigurations.Add(surfaceConfiguration);
- // Select either the first active surface or the first available surface
- SelectedSurfaceConfiguration = SurfaceConfigurations.FirstOrDefault(s => s.IsActive) ?? SurfaceConfigurations.FirstOrDefault();
+ // Get surface configs
+ var configs = await _surfaceService.GetSurfaceConfigurations();
+ // Populate the UI collection
+ foreach (var surfaceConfiguration in configs)
+ SurfaceConfigurations.Add(surfaceConfiguration);
+ // Select either the first active surface or the first available surface
+ SelectedSurfaceConfiguration = SurfaceConfigurations.FirstOrDefault(s => s.IsActive) ?? SurfaceConfigurations.FirstOrDefault();
- // Create a default if there is none
- if (SelectedSurfaceConfiguration == null)
- SelectedSurfaceConfiguration = AddSurfaceConfiguration("Default");
+ // Create a default if there is none
+ if (SelectedSurfaceConfiguration == null)
+ SelectedSurfaceConfiguration = AddSurfaceConfiguration("Default");
+ });
}
-
-
+
public SurfaceConfiguration AddSurfaceConfiguration(string name)
{
var config = new SurfaceConfiguration(name);
@@ -111,9 +94,34 @@ namespace Artemis.UI.ViewModels.Screens
var newConfig = AddSurfaceConfiguration(NewConfigurationName);
SelectedSurfaceConfiguration = newConfig;
}
+
NewConfigurationName = null;
}
+ #region Context menu actions
+
+ public void BringToFront(SurfaceDeviceViewModel surfaceDeviceViewModel)
+ {
+ Console.WriteLine("Bring to front");
+ }
+
+ public void BringForward(SurfaceDeviceViewModel surfaceDeviceViewModel)
+ {
+ Console.WriteLine("Bring forward");
+ }
+
+ public void SendToBack(SurfaceDeviceViewModel surfaceDeviceViewModel)
+ {
+ Console.WriteLine("Send to back");
+ }
+
+ public void SendBackward(SurfaceDeviceViewModel surfaceDeviceViewModel)
+ {
+ Console.WriteLine("Send backward");
+ }
+
+ #endregion
+
#region Mouse actions
private MouseDragStatus _mouseDragStatus;
@@ -215,6 +223,16 @@ namespace Artemis.UI.ViewModels.Screens
}
#endregion
+
+ #region Overrides of Screen
+
+ protected override void OnActivate()
+ {
+ Task.Run(LoadSurfaceConfigurations);
+ base.OnActivate();
+ }
+
+ #endregion
}
internal enum MouseDragStatus
diff --git a/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileDeviceView.xaml b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileDeviceView.xaml
new file mode 100644
index 000000000..95576a614
--- /dev/null
+++ b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileDeviceView.xaml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml
similarity index 83%
rename from src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml
rename to src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml
index e1b3cb6c1..91dde4813 100644
--- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml
+++ b/src/Artemis.UI/Views/Controls/ProfileEditor/ProfileLedView.xaml
@@ -1,11 +1,11 @@
-
diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml b/src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceDeviceView.xaml
similarity index 65%
rename from src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml
rename to src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceDeviceView.xaml
index 971a7ff17..48245d358 100644
--- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml
+++ b/src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceDeviceView.xaml
@@ -1,18 +1,35 @@
-
+
+
+
+
+
+
+
@@ -20,7 +37,7 @@
-
@@ -31,39 +48,40 @@
+
-
+
-
+
-
-
\ No newline at end of file
diff --git a/src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceLedView.xaml b/src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceLedView.xaml
new file mode 100644
index 000000000..80a274ac9
--- /dev/null
+++ b/src/Artemis.UI/Views/Controls/SurfaceEditor/SurfaceLedView.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml
index 2fa308297..027888b69 100644
--- a/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml
+++ b/src/Artemis.UI/Views/Screens/SurfaceEditorView.xaml
@@ -39,14 +39,14 @@
MouseDown="{s:Action EditorGridMouseClick}"
MouseMove="{s:Action EditorGridMouseMove}">
-
+
-
+
@@ -71,13 +71,48 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -117,7 +152,7 @@
- Add a new surface layout.
+ Add a new surface layout.
@@ -153,16 +188,16 @@
+ Grid.Row="0"
+ Style="{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
+ PlacementMode="LeftAndAlignMiddles"
+ UnfurlOrientation="Horizontal"
+ ToolTip="Manage surface layouts"
+ Margin="0 0 10 10"
+ HorizontalAlignment="Right"
+ VerticalAlignment="Bottom">
+ Orientation="Horizontal">