mirror of
https://github.com/riegera2412/UVtools.git
synced 2026-07-09 01:52:32 +02:00
(Add) Layer slider debounce time to render the image [Configurable] (#343)
This commit is contained in:
@@ -216,6 +216,14 @@
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="TextBox.ValueLabel_ms, NumericUpDown.ValueLabel_ms /template/ TextBox">
|
||||
<Setter Property="InnerRightContent">
|
||||
<Template>
|
||||
<TextBox Classes="NumericUpDownValueLabel" Text="ms" ToolTip.Tip="Milliseconds" />
|
||||
</Template>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<Style Selector="NumericUpDown">
|
||||
<Setter Property="MinWidth" Value="130"/>
|
||||
|
||||
@@ -61,8 +61,11 @@ namespace UVtools.WPF
|
||||
|
||||
|
||||
private Timer _layerNavigationTooltipTimer = new(0.1) { AutoReset = false };
|
||||
private Timer _layerNavigationSliderDebounceTimer = new(25) { AutoReset = false };
|
||||
private uint _actualLayerSlider;
|
||||
private uint _actualLayer;
|
||||
|
||||
|
||||
private bool _showLayerImageRotated;
|
||||
private bool _showLayerImageRotateCwDirection = true;
|
||||
private bool _showLayerImageRotateCcwDirection;
|
||||
@@ -93,7 +96,6 @@ namespace UVtools.WPF
|
||||
private readonly List<Point[]> _maskPoints = new ();
|
||||
|
||||
|
||||
|
||||
public void InitLayerPreview()
|
||||
{
|
||||
LayerImageBox = this.FindControl<AdvancedImageBox>("LayerImage");
|
||||
@@ -174,6 +176,11 @@ namespace UVtools.WPF
|
||||
{
|
||||
Dispatcher.UIThread.InvokeAsync(() => RaisePropertyChanged(nameof(LayerNavigationTooltipMargin)));
|
||||
};
|
||||
_layerNavigationSliderDebounceTimer.Interval = Settings.LayerPreview.LayerSliderDebounce == 0 ? 1 : Settings.LayerPreview.LayerSliderDebounce;
|
||||
_layerNavigationSliderDebounceTimer.Elapsed += (sender, args) =>
|
||||
{
|
||||
Dispatcher.UIThread.InvokeAsync(ShowLayer);
|
||||
};
|
||||
}
|
||||
|
||||
private void LayerSliderOnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
|
||||
@@ -454,8 +461,8 @@ namespace UVtools.WPF
|
||||
}
|
||||
|
||||
public string MinimumLayerString => SlicerFile is null ? "???" : $"{SlicerFile.LayerHeight}mm\n0";
|
||||
public string MaximumLayerString => SlicerFile is null ? "???" : $"{SlicerFile.PrintHeight}mm\n{SlicerFile.LayerCount - 1}";
|
||||
public string ActualLayerTooltip => SlicerFile is null ? "???" : $"{Layer.ShowHeight(LayerCache.Layer?.PositionZ ?? 0)}mm\n" +
|
||||
public string MaximumLayerString => SlicerFile is null ? "???" : $"{SlicerFile.PrintHeight}mm\n{SlicerFile.LastLayerIndex}";
|
||||
public string ActualLayerTooltip => SlicerFile is null ? "???" : $"{Layer.ShowHeight(SlicerFile[_actualLayer]?.PositionZ ?? 0)}mm\n" +
|
||||
$"{ActualLayer}\n" +
|
||||
$"{(ActualLayer + 1) * 100 / SlicerFile.LayerCount}%";
|
||||
|
||||
@@ -562,6 +569,26 @@ namespace UVtools.WPF
|
||||
}
|
||||
}
|
||||
|
||||
public uint ActualLayerSlider
|
||||
{
|
||||
get => _actualLayerSlider;
|
||||
set
|
||||
{
|
||||
if (DataContext is null) return;
|
||||
if (!RaiseAndSetIfChanged(ref _actualLayerSlider, value)) return;
|
||||
if (Settings.LayerPreview.LayerSliderDebounce == 0)
|
||||
{
|
||||
ActualLayer = _actualLayerSlider;
|
||||
}
|
||||
else
|
||||
{
|
||||
_layerNavigationSliderDebounceTimer.Stop();
|
||||
_layerNavigationSliderDebounceTimer.Start();
|
||||
ActualLayer = _actualLayerSlider;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public uint ActualLayer
|
||||
{
|
||||
get => _actualLayer;
|
||||
@@ -569,7 +596,14 @@ namespace UVtools.WPF
|
||||
{
|
||||
if (DataContext is null) return;
|
||||
if (!RaiseAndSetIfChanged(ref _actualLayer, value)) return;
|
||||
ShowLayer();
|
||||
|
||||
|
||||
if (!_layerNavigationSliderDebounceTimer.Enabled) // Doesn't come from ActualLayerSlider timer
|
||||
{
|
||||
ActualLayerSlider = _actualLayer; // sync when required
|
||||
ShowLayer(); // Show layer only if timer is not present
|
||||
}
|
||||
|
||||
InvalidateLayerNavigation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1692,7 +1692,7 @@
|
||||
Name="Layer.Navigation.Slider"
|
||||
Minimum="0"
|
||||
Maximum="{Binding SliderMaximumValue}"
|
||||
Value="{Binding ActualLayer}"
|
||||
Value="{Binding ActualLayerSlider}"
|
||||
TickFrequency="1"
|
||||
TickPlacement="Outside"
|
||||
SmallChange="1"
|
||||
|
||||
@@ -23,7 +23,6 @@ using System.Net.Http;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Collections;
|
||||
using UVtools.AvaloniaControls;
|
||||
using UVtools.Core;
|
||||
using UVtools.Core.Extensions;
|
||||
@@ -1275,6 +1274,7 @@ namespace UVtools.WPF
|
||||
await settingsWindow.ShowDialog(this);
|
||||
if (settingsWindow.DialogResult == DialogResults.OK)
|
||||
{
|
||||
_layerNavigationSliderDebounceTimer.Interval = Settings.LayerPreview.LayerSliderDebounce == 0 ? 1 : Settings.LayerPreview.LayerSliderDebounce;
|
||||
RaisePropertyChanged(nameof(IssuesGridItems));
|
||||
}
|
||||
}
|
||||
@@ -1390,7 +1390,7 @@ namespace UVtools.WPF
|
||||
|
||||
if (IsFileLoaded)
|
||||
{
|
||||
title += $"File: {Path.GetFileName(SlicerFile.FileFullPath)} ({Math.Round(LastStopWatch.ElapsedMilliseconds / 1000m, 2)}s) ";
|
||||
title += $"File: {SlicerFile.Filename} ({Math.Round(LastStopWatch.ElapsedMilliseconds / 1000m, 2)}s) ";
|
||||
}
|
||||
|
||||
title += $"Version: {App.VersionStr} RAM: {SizeExtensions.SizeSuffix(Environment.WorkingSet)}";
|
||||
|
||||
@@ -257,7 +257,8 @@ namespace UVtools.WPF
|
||||
private bool _autoFlipLayerIfMirrored = true;
|
||||
private bool _layerZoomToFitOnLoad = true;
|
||||
private bool _showBackgroudGrid;
|
||||
|
||||
private ushort _layerSliderDebounce;
|
||||
|
||||
public Color TooltipOverlayBackgroundColor
|
||||
{
|
||||
get => _tooltipOverlayBackgroundColor;
|
||||
@@ -766,6 +767,12 @@ namespace UVtools.WPF
|
||||
set => RaiseAndSetIfChanged(ref _showBackgroudGrid, value);
|
||||
}
|
||||
|
||||
public ushort LayerSliderDebounce
|
||||
{
|
||||
get => _layerSliderDebounce;
|
||||
set => RaiseAndSetIfChanged(ref _layerSliderDebounce, value);
|
||||
}
|
||||
|
||||
public LayerPreviewUserSettings Clone()
|
||||
{
|
||||
return MemberwiseClone() as LayerPreviewUserSettings;
|
||||
|
||||
@@ -957,9 +957,29 @@
|
||||
|
||||
<CheckBox
|
||||
Margin="10,0,10,10"
|
||||
Content="Show square grid as background "
|
||||
IsChecked="{Binding Settings.LayerPreview.ShowBackgroudGrid}"
|
||||
/>
|
||||
Content="Show square grid as background"
|
||||
IsChecked="{Binding Settings.LayerPreview.ShowBackgroudGrid}"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" Spacing="10">
|
||||
<NumericUpDown
|
||||
Classes="ValueLabel ValueLabel_ms"
|
||||
Margin="10,0,0,10"
|
||||
VerticalAlignment="Center"
|
||||
Minimum="0"
|
||||
Maximum="1000"
|
||||
Increment="5"
|
||||
Value="{Binding Settings.LayerPreview.LayerSliderDebounce}"/>
|
||||
|
||||
<TextBlock
|
||||
Margin="0,0,0,10"
|
||||
VerticalAlignment="Center"
|
||||
Text="Layer slider debounce time to render the image"
|
||||
ToolTip.Tip="Time to wait in milliseconds to render the layer image after navigating on the layer slider while dragging.
|
||||

The timer resets every time the slider changes value.
|
||||

Use this option when layer images are heavy to load and you can't get a smooth navigation on the slider while dragging.
|
||||

Use 0 to disable the delay and instant render the layer."/>
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
@@ -151,6 +151,8 @@ namespace UVtools.WPF.Windows
|
||||
if (!RaiseAndSetIfChanged(ref _layerIndexEnd, value)) return;
|
||||
RaisePropertyChanged(nameof(LayerEndMM));
|
||||
RaisePropertyChanged(nameof(LayerRangeCountStr));
|
||||
|
||||
//App.MainWindow.ActualLayer = _layerIndexEnd;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user