blob: 2e0a78df010ae26a3925bd7e7ba14dd3afeec587 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using System.Timers;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using UVtools.Core.Operations;
using UVtools.WPF.Controls.Tools;
using UVtools.WPF.Extensions;
using UVtools.WPF.Windows;
namespace UVtools.WPF.Controls.Calibrators
{
public class CalibrateLiftHeightControl : ToolControl
{
public OperationCalibrateLiftHeight Operation => BaseOperation as OperationCalibrateLiftHeight;
private readonly Timer _timer;
private Bitmap _previewImage;
public Bitmap PreviewImage
{
get => _previewImage;
set => RaiseAndSetIfChanged(ref _previewImage, value);
}
public CalibrateLiftHeightControl()
{
BaseOperation = new OperationCalibrateLiftHeight(SlicerFile);
if (!ValidateSpawn()) return;
InitializeComponent();
_timer = new Timer(20)
{
AutoReset = false
};
_timer.Elapsed += (sender, e) => Dispatcher.UIThread.InvokeAsync(UpdatePreview);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public override void Callback(ToolWindow.Callbacks callback)
{
if (App.SlicerFile is null) return;
switch (callback)
{
case ToolWindow.Callbacks.Init:
case ToolWindow.Callbacks.Loaded:
Operation.PropertyChanged += (sender, e) =>
{
_timer.Stop();
_timer.Start();
};
_timer.Stop();
_timer.Start();
break;
}
}
public void UpdatePreview()
{
var layers = Operation.GetLayers();
_previewImage?.Dispose();
PreviewImage = layers[0].ToBitmap();
foreach (var layer in layers)
{
layer.Dispose();
}
}
}
}
|