feat/estimate #50

Merged
notazof merged 27 commits from feat/estimate into main 2026-09-04 22:07:17 +01:00
2 changed files with 54 additions and 2 deletions
Showing only changes of commit e987f215bb - Show all commits

bug fix painting the signature

Paul Schneider 2026-08-30 21:05:43 +01:00
Signed by: notazof
GPG key ID: 1DD5D838E5343B06

View file

@ -68,21 +68,38 @@ public class SignaturePadControl : TemplatedControl
public event EventHandler? RedrawRequested;
private readonly List<int> _strokes = new(capacity: 256);
private InputElement? _wiredCaptureArea;
private int _pendingPoints; // number of (x, y) pairs awaiting a length prefix
private bool _capturing;
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
RewireCaptureArea();
}
if (CaptureArea is { } previous)
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);
if (change.Property == CaptureAreaProperty)
{
RewireCaptureArea();
}
}
private void RewireCaptureArea()
{
if (_wiredCaptureArea is { } previous)
{
previous.PointerPressed -= OnCapturePressed;
previous.PointerMoved -= OnCaptureMoved;
previous.PointerReleased -= OnCaptureReleased;
}
if (CaptureArea is { } area)
_wiredCaptureArea = CaptureArea;
if (_wiredCaptureArea is { } area)
{
area.PointerPressed += OnCapturePressed;
area.PointerMoved += OnCaptureMoved;
@ -97,12 +114,14 @@ public class SignaturePadControl : TemplatedControl
_capturing = true;
_pendingPoints = 0;
AppendPoint(e.GetPosition(CaptureArea));
RedrawRequested?.Invoke(this, EventArgs.Empty);
}
private void OnCaptureMoved(object? sender, PointerEventArgs e)
{
if (!_capturing) return;
AppendPoint(e.GetPosition(CaptureArea));
RedrawRequested?.Invoke(this, EventArgs.Empty);
}
private void OnCaptureReleased(object? sender, PointerReleasedEventArgs e)
@ -169,6 +188,16 @@ public class SignaturePadControl : TemplatedControl
/// </summary>
public SignaturePadData Snapshot() => new(_strokes.ToArray());
/// <summary>
/// Copy of the current in-progress stroke, without the length
/// prefix used for sealed strokes. The view can render this as a
/// live preview while the user is still drawing.
/// </summary>
internal IReadOnlyList<int> PendingStroke
=> _capturing && _pendingPoints > 0
? _strokes.GetRange(_strokes.Count - 2 * _pendingPoints, 2 * _pendingPoints)
: Array.Empty<int>();
// --- Test-only surface (visible to PostIt.Tests) -------------------
/// <summary>

View file

@ -87,5 +87,28 @@ public partial class SignaturePage : ContentPage
poly.Points = pts;
InkLayer.Children.Add(poly);
}
var pending = _control.PendingStroke;
if (pending.Count > 0)
{
var poly = new Polyline
{
Stroke = StrokeBrush,
StrokeThickness = StrokeThickness,
StrokeLineCap = PenLineCap.Round,
StrokeJoin = PenLineJoin.Round,
};
var pts = new List<Point>(pending.Count / 2);
for (int p = 0; p < pending.Count; p += 2)
{
int nx = pending[p];
int ny = pending[p + 1];
pts.Add(new Point(nx / CoordinateMax * w, ny / CoordinateMax * h));
}
poly.Points = pts;
InkLayer.Children.Add(poly);
}
}
}