Anoto-Pen をTouchDevice
withとして使用しようとしていSurfaceInkCanvas
ます。
ペンは、紙に印刷された座標系を使用して位置を取得し、この位置データをアプリケーションに送信します。などを使用して、送信位置データとイベントを .NET Touch-Events にTouchInput
サブクラス化し、変換して変換しようとしています。TouchDevice
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;
}
}
}
前もって感謝します。