From f2a49cc48b1868dd12c91ee22a6a20ca83a17c3d Mon Sep 17 00:00:00 2001 From: "louis.dufour" Date: Fri, 2 Feb 2024 08:45:03 +0100 Subject: [PATCH] Add(dev): Gestion de la couleur de l'ellipse --- Sources/Lib/KinectManager.cs | 78 +++++++++++++++++++--------------- Sources/WpfApp/MainWindow.xaml | 2 +- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs index ac50260..dbe75da 100644 --- a/Sources/Lib/KinectManager.cs +++ b/Sources/Lib/KinectManager.cs @@ -1,6 +1,7 @@ using Microsoft.Kinect; using System.ComponentModel; using System.Diagnostics; +using System.Windows.Media; namespace Lib { @@ -18,6 +19,17 @@ namespace Lib } } + private SolidColorBrush _kinectStatusColor = new SolidColorBrush(Colors.Red); // Couleur rouge par défaut, signifiant inactive + public SolidColorBrush KinectStatusColor + { + get { return _kinectStatusColor; } + set + { + _kinectStatusColor = value; + OnPropertyChanged(nameof(KinectStatusColor)); + } + } + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { @@ -27,21 +39,11 @@ namespace Lib public KinectManager() { sensor = KinectSensor.GetDefault(); - if (Sensor == null) - { - StatusText = "Kinect n'est pas connecté"; - } - else if (!Sensor.IsOpen) - { - StatusText = "Kinect n'est pas ouvert"; - } - else if (Sensor.IsAvailable) - { - StatusText = "Kinect est disponible"; - } - else + UpdateStatusProperties(); + // Abonnez-vous à l'événement IsAvailableChanged + if (sensor != null) { - StatusText = "Kinect n'est pas disponible"; + sensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; } } public void StartSensor() @@ -79,25 +81,33 @@ namespace Lib } } - private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args) - { - if (Sensor == null) - { - StatusText = "Kinect n'est pas connecté"; - } - else if (!Sensor.IsOpen) - { - StatusText = "Kinect n'est pas ouvert"; - } - else if (Sensor.IsAvailable) - { - StatusText = "Kinect est disponible"; - } - else - { - StatusText = "Kinect n'est pas disponible"; - } + private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e) + { + UpdateStatusProperties(); + } - } + private void UpdateStatusProperties() + { + if (Sensor == null) + { + StatusText = "Kinect n'est pas connecté"; + KinectStatusColor = new SolidColorBrush(Colors.Red); } - } \ No newline at end of file + else if (!Sensor.IsOpen) + { + StatusText = "Kinect n'est pas ouvert"; + KinectStatusColor = new SolidColorBrush(Colors.Yellow); + } + else if (Sensor.IsAvailable) + { + StatusText = "Kinect est disponible"; + KinectStatusColor = new SolidColorBrush(Colors.Green); + } + else + { + StatusText = "Kinect n'est pas disponible"; + KinectStatusColor = new SolidColorBrush(Colors.Orange); + } + } + } +} \ No newline at end of file diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index 88530fb..1772725 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -14,7 +14,7 @@ - +