mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:46:30 +00:00
Add annotationResult and put them into json
This commit is contained in:
@@ -14,7 +14,8 @@ public class AnnotationControl : Border
|
||||
|
||||
private readonly Grid _grid;
|
||||
private readonly TextBlock _classNameLabel;
|
||||
|
||||
public TimeSpan Time { get; set; }
|
||||
|
||||
private AnnotationClass _annotationClass = null!;
|
||||
public AnnotationClass AnnotationClass
|
||||
{
|
||||
@@ -40,8 +41,9 @@ public class AnnotationControl : Border
|
||||
}
|
||||
}
|
||||
|
||||
public AnnotationControl(AnnotationClass annotationClass, Action<object, MouseButtonEventArgs> resizeStart)
|
||||
public AnnotationControl(AnnotationClass annotationClass, TimeSpan time, Action<object, MouseButtonEventArgs> resizeStart)
|
||||
{
|
||||
Time = time;
|
||||
_resizeStart = resizeStart;
|
||||
_classNameLabel = new TextBlock
|
||||
{
|
||||
@@ -104,5 +106,5 @@ public class AnnotationControl : Border
|
||||
return rect;
|
||||
}
|
||||
|
||||
public AnnotationInfo Info => new(AnnotationClass.Id, Canvas.GetLeft(this), Canvas.GetTop(this), Width, Height);
|
||||
public CanvasLabel Info => new(AnnotationClass.Id, Canvas.GetLeft(this), Canvas.GetTop(this), Width, Height);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
@@ -26,7 +25,8 @@ public class CanvasEditor : Canvas
|
||||
private AnnotationControl _curAnn = null!;
|
||||
|
||||
private const int MIN_SIZE = 20;
|
||||
|
||||
private readonly TimeSpan _viewThreshold = TimeSpan.FromMilliseconds(400);
|
||||
|
||||
public FormState FormState { get; set; } = null!;
|
||||
public IMediator Mediator { get; set; } = null!;
|
||||
|
||||
@@ -283,30 +283,28 @@ public class CanvasEditor : Canvas
|
||||
var height = Math.Abs(endPos.Y - _newAnnotationStartPos.Y);
|
||||
if (width < MIN_SIZE || height < MIN_SIZE)
|
||||
return;
|
||||
|
||||
var annotationControl = new AnnotationControl(CurrentAnnClass, AnnotationResizeStart)
|
||||
|
||||
var mainWindow = (MainWindow)((Window)((Grid)Parent).Parent).Owner;
|
||||
var time = TimeSpan.FromMilliseconds(mainWindow.VideoView.MediaPlayer.Time);
|
||||
CreateAnnotation(CurrentAnnClass, time, new CanvasLabel
|
||||
{
|
||||
Width = width,
|
||||
Height = height
|
||||
};
|
||||
annotationControl.MouseDown += AnnotationPositionStart;
|
||||
SetLeft(annotationControl, Math.Min(endPos.X, _newAnnotationStartPos.X));
|
||||
SetTop(annotationControl, Math.Min(endPos.Y, _newAnnotationStartPos.Y));
|
||||
Children.Add(annotationControl);
|
||||
CurrentAnns.Add(annotationControl);
|
||||
_newAnnotationRect.Fill = new SolidColorBrush(CurrentAnnClass.Color);
|
||||
Height = height,
|
||||
X = Math.Min(endPos.X, _newAnnotationStartPos.X),
|
||||
Y = Math.Min(endPos.Y, _newAnnotationStartPos.Y)
|
||||
});
|
||||
}
|
||||
|
||||
public AnnotationControl CreateAnnotation(AnnotationClass annClass, AnnotationInfo info)
|
||||
public AnnotationControl CreateAnnotation(AnnotationClass annClass, TimeSpan time, CanvasLabel canvasLabel)
|
||||
{
|
||||
var annotationControl = new AnnotationControl(annClass, AnnotationResizeStart)
|
||||
var annotationControl = new AnnotationControl(annClass, time, AnnotationResizeStart)
|
||||
{
|
||||
Width = info.Width,
|
||||
Height = info.Height
|
||||
Width = canvasLabel.Width,
|
||||
Height = canvasLabel.Height
|
||||
};
|
||||
annotationControl.MouseDown += AnnotationPositionStart;
|
||||
SetLeft(annotationControl, info.X );
|
||||
SetTop(annotationControl, info.Y);
|
||||
SetLeft(annotationControl, canvasLabel.X );
|
||||
SetTop(annotationControl, canvasLabel.Y);
|
||||
Children.Add(annotationControl);
|
||||
CurrentAnns.Add(annotationControl);
|
||||
_newAnnotationRect.Fill = new SolidColorBrush(annClass.Color);
|
||||
@@ -323,12 +321,17 @@ public class CanvasEditor : Canvas
|
||||
CurrentAnns.Remove(ann);
|
||||
}
|
||||
}
|
||||
public void RemoveAllAnns() => RemoveAnnotations(CurrentAnns.ToList());
|
||||
public void RemoveSelectedAnns() => RemoveAnnotations(CurrentAnns.Where(x => x.IsSelected).ToList());
|
||||
public void RemoveAllAnns() => RemoveAnnotations(CurrentAnns);
|
||||
public void RemoveSelectedAnns() => RemoveAnnotations(CurrentAnns.Where(x => x.IsSelected));
|
||||
|
||||
private void ClearSelections()
|
||||
{
|
||||
foreach (var ann in CurrentAnns)
|
||||
ann.IsSelected = false;
|
||||
}
|
||||
|
||||
public void ClearExpiredAnnotations(TimeSpan time)
|
||||
{
|
||||
RemoveAnnotations(CurrentAnns.Where(x => time - x.Time > _viewThreshold));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user