Added UI elements borrowed from DarthAffe

Added a WIP of profile classes
This commit is contained in:
SpoinkyNL committed 2018-01-13 00:06:28 +01:00
1 parent 4f146865a4
commit 6eefa733b4
23 files changed
+847 -108

No files matched your search

@@ -0,0 +1,36 @@
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.Led" /> in an wpf-application.
/// </summary>
public class LedVisualizer : Control
{
#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
}
}
@@ -0,0 +1,78 @@
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
private Canvas _canvas;
#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 (Led led in Device)
_canvas.Children.Add(new LedVisualizer {Led = led});
}
#endregion
}
}
@@ -0,0 +1,99 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using RGB.NET.Core;
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;
//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()
{
this.Loaded += OnLoaded;
this.Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
_surface = RGBSurface.Instance;
_surface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
foreach (IRGBDevice 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 (IRGBDevice device in args.Devices)
_newDevices.Add(device);
UpdateSurface();
}
#endregion
#region Methods
/// <inheritdoc />
public override void OnApplyTemplate()
{
_canvas?.Children.Clear();
_canvas = (Canvas)GetTemplateChild(PART_CANVAS);
UpdateSurface();
}
private void UpdateSurface()
{
if ((_canvas == null) || (_surface == null)) return;
if (_newDevices.Count > 0)
{
foreach (IRGBDevice 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
}
}