Anoy-Pen을 TouchDevice
과 SurfaceInkCanvas
으로 사용하려고합니다.
펜은 용지에 인쇄 된 좌표계를 사용하여 위치를 파생시키고이 위치 데이터를 내 응용 프로그램에 전송합니다. 거기에 TouchInput
서브 클래 싱하여 TouchDevice
서브 클래 싱하고 TouchDevice.ReportDown();
, TouchDevice.ReportMove()
등을 사용하여 보내기 위치 데이터 및 이벤트를 변환하려고합니다. ScatterViewItems
을 이동하고 단추 "클릭"을 처리하는 것은 지금까지 작동합니다.Microsoft Surface Window에서 터치 입력 시뮬레이트
지금 문제는 내가 쓸 때 InkCanvas
에만 도트가 그려진다는 것입니다. 해고 된 이벤트를 관찰 한 후 InkCanvas
이벤트가 OnTouchMove
이벤트를 수신하지 못하는 것으로 보입니다.
나는 , 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;
}
}
}
미리 감사드립니다.