2012-05-12 9 views
2

Anoy-Pen을 TouchDeviceSurfaceInkCanvas으로 사용하려고합니다.
펜은 용지에 인쇄 된 좌표계를 사용하여 위치를 파생시키고이 위치 데이터를 내 응용 프로그램에 전송합니다. 거기에 TouchInput 서브 클래 싱하여 TouchDevice 서브 클래 싱하고 TouchDevice.ReportDown();, TouchDevice.ReportMove() 등을 사용하여 보내기 위치 데이터 및 이벤트를 변환하려고합니다. ScatterViewItems을 이동하고 단추 "클릭"을 처리하는 것은 지금까지 작동합니다.Microsoft Surface Window에서 터치 입력 시뮬레이트

지금 문제는 내가 쓸 때 InkCanvas에만 도트가 그려진다는 것입니다. 해고 된 이벤트를 관찰 한 후 InkCanvas 이벤트가 OnTouchMove 이벤트를 수신하지 못하는 것으로 보입니다.

나는 , TouchMoveTouchUp에 등록 된 이벤트 처리기를 SurfaceInkCanvas에 등록했습니다. TouchDown이 실행되지 않습니다. TouchMoveTouchUp을 입력하고 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; 
      } 

     } 
    } 

미리 감사드립니다.

답변

-1

GetIntermediateTouchPoints 빈 배열을 반환하지 않아야합니다, 그것은 포함해야합니다 적어도 하나의 점

public override TouchPointCollection GetIntermediateTouchPoints(System.Windows.IInputElement relativeTo) 
{ 
    TouchPointCollection refCollection = new TouchPointCollection(); 
    refCollection.Add(GetTouchPoint(relativeTo)); 
    return refCollection; 
} 
관련 문제