mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 21:56:31 +00:00
97 lines
3.0 KiB
C#
97 lines
3.0 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using Azaion.Common.DTO;
|
|
using Azaion.Common.Extensions;
|
|
|
|
namespace Azaion.Common.Controls;
|
|
|
|
public class DetectionClassChangedEventArgs(DetectionClass detectionClass, int classNumber) : EventArgs
|
|
{
|
|
public DetectionClass DetectionClass { get; } = detectionClass;
|
|
public int ClassNumber { get; } = classNumber;
|
|
}
|
|
|
|
public partial class DetectionClasses
|
|
{
|
|
public event EventHandler<DetectionClassChangedEventArgs>? DetectionClassChanged;
|
|
private const int CaptionedMinWidth = 230;
|
|
ObservableCollection<DetectionClass> _detectionClasses = new();
|
|
|
|
public DetectionClasses()
|
|
{
|
|
InitializeComponent();
|
|
SizeChanged += (sender, args) =>
|
|
{
|
|
if (args.NewSize.Width < CaptionedMinWidth)
|
|
{
|
|
RegularModeButton.Text = "";
|
|
WinterModeButton.Text = "";
|
|
NightModeButton.Text = "";
|
|
}
|
|
else
|
|
{
|
|
RegularModeButton.Text = Constants.REGULAR_MODE_CAPTION;
|
|
WinterModeButton.Text= Constants.WINTER_MODE_CAPTION;
|
|
NightModeButton.Text= Constants.NIGHT_MODE_CAPTION;
|
|
}
|
|
};
|
|
}
|
|
|
|
public void Init(List<DetectionClass> detectionClasses)
|
|
{
|
|
foreach (var dClass in detectionClasses)
|
|
{
|
|
var cl = (DetectionClass)dClass.Clone();
|
|
cl.Color = cl.Color.ToConfidenceColor();
|
|
_detectionClasses.Add(cl);
|
|
}
|
|
|
|
DetectionDataGrid.ItemsSource = _detectionClasses;
|
|
DetectionDataGrid.SelectedIndex = 0;
|
|
}
|
|
|
|
public int CurrentClassNumber { get; private set; } = 0;
|
|
public DetectionClass? CurrentDetectionClass { get; set; }
|
|
|
|
private void DetectionDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e) =>
|
|
RaiseDetectionClassChanged();
|
|
|
|
private void ModeRadioButton_Checked(object sender, RoutedEventArgs e) =>
|
|
RaiseDetectionClassChanged();
|
|
|
|
private void RaiseDetectionClassChanged()
|
|
{
|
|
var detClass = (DetectionClass)DetectionDataGrid.SelectedItem;
|
|
if (detClass == null)
|
|
return;
|
|
|
|
var modeAmplifier = 0;
|
|
foreach (var child in ModeSwitcherPanel.Children)
|
|
if (child is RadioButton { IsChecked: true } rb)
|
|
if (int.TryParse(rb.Tag?.ToString(), out int modeIndex))
|
|
{
|
|
detClass.PhotoMode = (PhotoMode)modeIndex;
|
|
modeAmplifier += modeIndex;
|
|
}
|
|
|
|
CurrentDetectionClass = detClass;
|
|
CurrentClassNumber = detClass.Id + modeAmplifier;
|
|
|
|
DetectionClassChanged?.Invoke(this, new DetectionClassChangedEventArgs(detClass, CurrentClassNumber));
|
|
}
|
|
|
|
|
|
public void SelectNum(int keyNumber)
|
|
{
|
|
DetectionDataGrid.SelectedIndex = keyNumber;
|
|
}
|
|
|
|
private void OnKeyBanActivity(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.Key.In(Key.Enter, Key.Down, Key.Up, Key.PageDown, Key.PageUp))
|
|
e.Handled = true;
|
|
}
|
|
|
|
} |