diff --git a/RGB.NET.WPF/Controls/LedVisualizer.cs b/RGB.NET.WPF/Controls/LedVisualizer.cs new file mode 100644 index 0000000..82f2742 --- /dev/null +++ b/RGB.NET.WPF/Controls/LedVisualizer.cs @@ -0,0 +1,33 @@ +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace RGB.NET.WPF.Controls +{ + /// + /// Visualizes a in an wpf-application. + /// + public class LedVisualizer : Control + { + #region DependencyProperties + // ReSharper disable InconsistentNaming + + /// + /// Backing-property for the -property. + /// + public static readonly DependencyProperty LedProperty = DependencyProperty.Register( + "Led", typeof(Led), typeof(LedVisualizer), new PropertyMetadata(default(Led))); + + /// + /// Gets or sets the to visualize. + /// + public Led Led + { + get { return (Led)GetValue(LedProperty); } + set { SetValue(LedProperty, value); } + } + + // ReSharper restore InconsistentNaming + #endregion + } +} diff --git a/RGB.NET.WPF/Controls/RGBDeviceVisualizer.cs b/RGB.NET.WPF/Controls/RGBDeviceVisualizer.cs new file mode 100644 index 0000000..ad7500c --- /dev/null +++ b/RGB.NET.WPF/Controls/RGBDeviceVisualizer.cs @@ -0,0 +1,76 @@ +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace RGB.NET.WPF.Controls +{ + /// + /// Visualizes a in an wpf-application. + /// + [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 + + /// + /// Backing-property for the -property. + /// + public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register( + "Device", typeof(IRGBDevice), typeof(RGBDeviceVisualizer), new PropertyMetadata(default(IRGBDevice), DeviceChanged)); + + /// + /// Gets or sets the to visualize. + /// + public IRGBDevice Device + { + get { return (IRGBDevice)GetValue(DeviceProperty); } + set { SetValue(DeviceProperty, value); } + } + + // ReSharper restore InconsistentNaming + #endregion + + #region Methods + + /// + 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 + } +} diff --git a/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs b/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs new file mode 100644 index 0000000..1d4ef1c --- /dev/null +++ b/RGB.NET.WPF/Controls/RGBSurfaceVisualizer.cs @@ -0,0 +1,64 @@ +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace RGB.NET.WPF.Controls +{ + /// + /// Visualizes the in an wpf-application. + /// + [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 Canvas _canvas; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + public RGBSurfaceVisualizer() + { + RGBSurface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged; + foreach (IRGBDevice device in RGBSurface.Devices) + AddDevice(device); + } + + private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) + { + if (args.DeviceAdded) + foreach (IRGBDevice device in args.Devices) + AddDevice(device); + + _canvas.Width = RGBSurface.SurfaceRectangle.Size.Width; + _canvas.Height = RGBSurface.SurfaceRectangle.Size.Height; + } + + #endregion + + #region Methods + + /// + public override void OnApplyTemplate() + { + _canvas = (Canvas)GetTemplateChild(PART_CANVAS); + } + + private void AddDevice(IRGBDevice device) + { + _canvas.Children.Add(new RGBDeviceVisualizer { Device = device }); + } + + #endregion + } +} diff --git a/RGB.NET.WPF/Converter/ColorToSolidColorBrushConverter.cs b/RGB.NET.WPF/Converter/ColorToSolidColorBrushConverter.cs new file mode 100644 index 0000000..ef3a37f --- /dev/null +++ b/RGB.NET.WPF/Converter/ColorToSolidColorBrushConverter.cs @@ -0,0 +1,32 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace RGB.NET.WPF.Converter +{ + /// + /// Converts into . + /// + [ValueConversion(typeof(Core.Color), typeof(SolidColorBrush))] + public class ColorToSolidColorBrushConverter : IValueConverter + { + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Core.Color color = value as Core.Color; + return new SolidColorBrush(color == null + ? Color.FromArgb(0, 0, 0, 0) + : Color.FromArgb(color.A, color.R, color.G, color.B)); + } + + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + SolidColorBrush brush = value as SolidColorBrush; + return brush == null + ? Core.Color.Transparent + : new Core.Color(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B); + } + } +} diff --git a/RGB.NET.WPF/RGB.NET.WPF.csproj b/RGB.NET.WPF/RGB.NET.WPF.csproj index 5a2fe99..932f147 100644 --- a/RGB.NET.WPF/RGB.NET.WPF.csproj +++ b/RGB.NET.WPF/RGB.NET.WPF.csproj @@ -32,25 +32,48 @@ ..\bin\RGB.NET.WPF.XML + + ..\packages\RGB.NET.Core.1.0.0\lib\net45\RGB.NET.Core.dll True + + + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + + + + + + + + + + + + + + + + + + + +