我正在尝试使用 Anoto-Pen 作为TouchDevice
with SurfaceInkCanvas
。
笔使用打印在一张纸上的坐标系来推导出它的位置,然后这个位置数据被发送到我的应用程序。在那里,我尝试TouchInput
通过子类TouchDevice
化并将发送位置数据和事件转换为 .NET Touch-Events 使用TouchDevice.ReportDown();
,TouchDevice.ReportMove()
等来转换它ScatterViewItems
。到目前为止,四处移动和处理按钮“点击”有效。
现在的问题是,当我尝试写上InkCanvas
唯一的点时。观察触发的事件后,似乎InkCanvas
没有收到OnTouchMove
事件。
我注册了事件处理程序TouchDown
,TouchMove
并TouchUp
在我的SurfaceInkCanvas
. TouchDown
永远不会触发。只有当我从外面开始TouchMove
然后移动到里面的一个点时。TouchUp
SurfaceInkCanvas
这是我的代码TouchDevice
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Text.RegularExpressions;
using System.Windows;
using PaperDisplay.PenInput;
using System.Windows.Media;
using System.Windows.Threading;
namespace TouchApp
{
public class PenTouchDevice : TouchDevice
{
public Point Position { get; set; }
public Person Person { get; set; }
public PenTouchDevice(Person person)
: base(person.GetHashCode())
{
Person = person;
}
public override TouchPointCollection GetIntermediateTouchPoints(System.Windows.IInputElement relativeTo)
{
return new TouchPointCollection();
}
public override TouchPoint GetTouchPoint(System.Windows.IInputElement relativeTo)
{
Point point = Position;
if (relativeTo != null)
{
point = this.ActiveSource.RootVisual.TransformToDescendant((Visual)relativeTo).Transform(Position);
}
return new TouchPoint(this, point, new Rect(point, new Size(2.0, 2.0)), TouchAction.Move);
}
public void PenDown(PenPointInputArgs args, Dispatcher dispatcher)
{
dispatcher.BeginInvoke((Action)(() =>
{
SetActiveSource(PresentationSource.FromVisual(Person.Window));
Position = GetPosition(args);
if (!IsActive)
{
Activate();
}
ReportDown();
}));
}
public void PenUp(PenPointInputArgs args, Dispatcher dispatcher)
{
dispatcher.BeginInvoke((Action)(() =>
{
Position = GetPosition(args);
if (IsActive)
{
ReportUp();
Deactivate();
}
}));
}
public void PenMove(PenPointInputArgs args, Dispatcher dispatcher)
{
dispatcher.BeginInvoke((Action)(() =>
{
if (IsActive)
{
Position = GetPosition(args);
ReportMove();
}
}));
}
public Point GetPosition(PenPointInputArgs args)
{
double adaptedX = args.Y - 0.01;
double adaptedY = (1 - args.X) - 0.005;
return new Point(adaptedX * Person.Window.ActualWidth, adaptedY * Person.Window.ActualHeight);
}
}
}
我的代码中有以下代码,App.xaml.cs
每次出现笔输入时都会调用它:
public void HandleEvent(object sender, EventArgs args)
{
if (typeof(PointInputArgs).IsAssignableFrom(args.GetType()))
{
PenPointInputArgs pointArgs = (PenPointInputArgs)args;
switch (pointArgs.EventType)
{
case InputEvent.Down: touchDevice1.PenDown(pointArgs, this.Dispatcher); break;
case InputEvent.Up: touchDevice1.PenUp(pointArgs, this.Dispatcher); break;
case InputEvent.Move:
case InputEvent.MoveDown: touchDevice1.PenMove(pointArgs, this.Dispatcher); break;
}
}
}
先感谢您。