Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'UVtools.WPF/Controls/Tools/ToolLithophaneControl.axaml.cs')
-rw-r--r--UVtools.WPF/Controls/Tools/ToolLithophaneControl.axaml.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/UVtools.WPF/Controls/Tools/ToolLithophaneControl.axaml.cs b/UVtools.WPF/Controls/Tools/ToolLithophaneControl.axaml.cs
new file mode 100644
index 0000000..f75f7e7
--- /dev/null
+++ b/UVtools.WPF/Controls/Tools/ToolLithophaneControl.axaml.cs
@@ -0,0 +1,82 @@
+using System.Timers;
+using Avalonia.Controls;
+using Avalonia.Markup.Xaml;
+using Avalonia.Media.Imaging;
+using Avalonia.Threading;
+using UVtools.Core.Operations;
+using UVtools.WPF.Extensions;
+using UVtools.WPF.Windows;
+
+namespace UVtools.WPF.Controls.Tools
+{
+ public partial class ToolLithophaneControl : ToolControl
+ {
+ public OperationLithophane Operation => BaseOperation as OperationLithophane;
+
+ private readonly Timer _timer;
+
+ private Bitmap _previewImage;
+ public Bitmap PreviewImage
+ {
+ get => _previewImage;
+ set => RaiseAndSetIfChanged(ref _previewImage, value);
+ }
+
+ public ToolLithophaneControl()
+ {
+ BaseOperation = new OperationLithophane(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()
+ {
+ using var mat = Operation.GetTargetMat();
+ _previewImage?.Dispose();
+ PreviewImage = mat?.ToBitmap();
+ }
+
+ public async void SelectFile()
+ {
+ var dialog = new OpenFileDialog
+ {
+ AllowMultiple = false,
+ Filters = Helpers.ImagesFileFilter,
+ };
+
+ var files = await dialog.ShowAsync(ParentWindow);
+ if (files is null || files.Length == 0) return;
+
+ Operation.FilePath = files[0];
+ }
+ }
+}