예제 #1
0
        private void ProcessMouseEvent(MouseEventArgs e, [CallerMemberName] string callerName = null)
        {
            DebugMessage($"{callerName}");

            if (strokeStylus != null)
            {
                return;
            }

            strokeMouse = callerName == nameof(HandleEventSignaturePadCanvasPreviewMouseDown) ? new InkStroke(InkSource.Mouse) : strokeMouse;
            if (strokeMouse == null)
            {
                return;
            }

            var point = e.GetPosition(canvasSignaturePad);
            var ip    = new InkPoint(point, 0f, null, GetCurrentTimestamp());

            DebugInkPoint(callerName, strokeMouse.Points.Count, ip);

            if (ip.Position.X < 0 || ip.Position.X > Width || ip.Position.Y < 0 || ip.Position.Y > Height)
            {
                borderTouch = true;
                return;
            }

            if (lStroke?.Count == 0 && strokeMouse?.Points.Count == 0)
            {
                RecordingStarted?.Invoke();
            }

            strokeMouse.Points.Add(ip);

            if (callerName == nameof(HandleEventSignaturePadCanvasPreviewMouseUp))
            {
                DebugMessage($"StrokeCaptured: #{lStroke.Count} Src = {strokeMouse.Source}, Count = {strokeMouse.Points.Count} @ {strokeMouse.Timestamp}");
                lStroke.Add(strokeMouse);
                strokeMouse = null;
            }
        }
예제 #2
0
 private static void DebugInkPoint(string source, int index, InkPoint point)
 {
     DebugMessage($"{source} => #{index}: {point.Position.X} x {point.Position.Y} x {point.Pressure} @ {point.Timestamp.Ticks}");
 }
예제 #3
0
        private void ProcessStylusEvent(StylusEventArgs e, [CallerMemberName] string callerName = null)
        {
            DebugMessage($"{callerName}");

            if (strokeMouse != null)
            {
                return;
            }

            if (callerName == nameof(HandleEventSignaturePadCanvasPreviewStylusDown))
            {
                if (lStroke?.Count == 0)
                {
                    RecordingStarted?.Invoke();
                }

                strokeStylus = new InkStroke(InkSource.Stylus);
                foreach (var sp in e.GetStylusPoints(canvasSignaturePad))
                {
                    var ip = new InkPoint(sp.ToPoint(), sp.PressureFactor, null, GetCurrentTimestamp());
                    DebugInkPoint(callerName, strokeStylus.Points.Count, ip);

                    if (ip.Position.X < 0 || ip.Position.X > Width || ip.Position.Y < 0 || ip.Position.Y > Height)
                    {
                        borderTouch = true;
                        return;
                    }

                    strokeStylus.Points.Add(ip);
                }
            }
            else if (strokeStylus != null)
            {
                var tsNow = GetCurrentTimestamp();
                var sps   = e.GetStylusPoints(canvasSignaturePad);
                if (sps.Count > 1)
                {
                    var tsLast = strokeStylus.Points.Last().Timestamp;

                    for (var idxSp = 0; idxSp < sps.Count; idxSp++)
                    {
                        var sp            = sps[idxSp];
                        var tsPointApprox = TimeSpan.FromTicks((tsNow.Ticks - tsLast.Ticks) * (idxSp + 1) / sps.Count + tsLast.Ticks);
                        var ip            = new InkPoint(sp.ToPoint(), sp.PressureFactor, null, tsPointApprox);
                        DebugInkPoint(callerName, strokeStylus.Points.Count, ip);

                        if (ip.Position.X < 0 || ip.Position.X > Width || ip.Position.Y < 0 || ip.Position.Y > Height)
                        {
                            borderTouch = true;
                            return;
                        }

                        strokeStylus.Points.Add(ip);
                    }
                }
                else if (sps.Count > 0)
                {
                    var ip = new InkPoint(sps[0].ToPoint(), sps[0].PressureFactor, null, tsNow);
                    DebugInkPoint(callerName, strokeStylus.Points.Count, ip);

                    if (ip.Position.X < 0 || ip.Position.X > Width || ip.Position.Y < 0 || ip.Position.Y > Height)
                    {
                        BorderTouch?.Invoke();
                        return;
                    }

                    strokeStylus.Points.Add(ip);
                }

                if (callerName == nameof(HandleEventSignaturePadCanvasPreviewStylusUp))
                {
                    DebugMessage($"StrokeCaptured: #{lStroke.Count} Src = {strokeStylus.Source}, Count = {strokeStylus.Points.Count} @ {strokeStylus.Timestamp}");
                    lStroke.Add(strokeStylus);
                    strokeStylus = null;
                }
            }
        }