mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Finalized client-side storage
This commit is contained in:
1 parent
6eefa733b4
commit
7773d377a2
29 files changed
+961
-434
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.UI.Controls.Visualizers
|
||||
@@ -32,5 +33,15 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
#endregion
|
||||
|
||||
public void Select()
|
||||
{
|
||||
BorderBrush = new SolidColorBrush(Colors.RoyalBlue);
|
||||
}
|
||||
|
||||
public void Deselect()
|
||||
{
|
||||
BorderBrush = new SolidColorBrush(Colors.Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,8 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private Canvas _canvas;
|
||||
|
||||
public Canvas Canvas { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
/// <inheritdoc />
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
_canvas = (Canvas) GetTemplateChild(PART_CANVAS);
|
||||
Canvas = (Canvas) GetTemplateChild(PART_CANVAS);
|
||||
|
||||
LayoutLeds();
|
||||
}
|
||||
@@ -63,14 +63,14 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
|
||||
private void LayoutLeds()
|
||||
{
|
||||
if (_canvas == null) return;
|
||||
if (Canvas == null) return;
|
||||
|
||||
_canvas.Children.Clear();
|
||||
Canvas.Children.Clear();
|
||||
|
||||
if (Device == null) return;
|
||||
|
||||
foreach (Led led in Device)
|
||||
_canvas.Children.Add(new LedVisualizer {Led = led});
|
||||
Canvas.Children.Add(new LedVisualizer {Led = led});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
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
|
||||
{
|
||||
@@ -22,6 +29,8 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
|
||||
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>();
|
||||
@@ -74,9 +83,70 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
/// <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);
|
||||
_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()
|
||||
@@ -86,7 +156,7 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
if (_newDevices.Count > 0)
|
||||
{
|
||||
foreach (IRGBDevice device in _newDevices)
|
||||
_canvas.Children.Add(new RGBDeviceVisualizer { Device = device });
|
||||
_canvas.Children.Add(new RGBDeviceVisualizer {Device = device});
|
||||
_newDevices.Clear();
|
||||
}
|
||||
|
||||
@@ -96,4 +166,4 @@ namespace Artemis.UI.Controls.Visualizers
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user