2012-05-12 9 views
2

SurfaceInkCanvasTouchDeviceとしてAnoto-Penを使用しようとしています。
ペンは、用紙上に印刷された座標系を使用してその位置を導出し、この位置データをアプリケーションに送ります。ここでは、をサブクラス化してTouchDeviceにサブクラス化し、TouchDevice.ReportDown();,TouchDevice.ReportMove()などを使用して送信位置データとイベントを変換するようにしようとしています。ScatterViewItemsを移動し、ボタンのクリックを処理しています。Microsoft Surfaceウィンドウでタッチ入力をシミュレートする

今問題は、私がInkCanvasに書き込もうとすると、点だけが描画されるということです。解雇されたイベントを観察した後、InkCanvasはイベントOnTouchMoveを受け取っていないようです。

私はSurfaceInkCanvasTouchDownTouchMoveTouchUpのイベントハンドラを登録。 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; 
} 
関連する問題