2

Anoto-Pen をTouchDevicewithとして使用しようとしていSurfaceInkCanvasます。
ペンは、紙に印刷された座標系を使用して位置を取得し、この位置データをアプリケーションに送信します。などを使用して、送信位置データとイベントを .NET Touch-Events にTouchInputサブクラス化し、変換して変換しようとしています。TouchDeviceTouchDevice.ReportDown();TouchDevice.ReportMove()ScatterViewItems

今の問題は、私が書き込もうとするとInkCanvasドットだけが描かれることです。発生したイベントを観察したところ、 はイベントをInkCanvas受信して​​いないようOnTouchMoveです。

と のイベント ハンドラを に登録TouchDownTouchMoveましTouchUpSurfaceInkCanvasTouchDownトリガーされることはありません。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;
            }

        }
    }

前もって感謝します。

4

1 に答える 1

-1

GetIntermediateTouchPoints空の配列を返してはなりません。少なくとも 1 つの点が含まれている必要があります

public override TouchPointCollection GetIntermediateTouchPoints(System.Windows.IInputElement relativeTo)
{
    TouchPointCollection refCollection = new TouchPointCollection();
    refCollection.Add(GetTouchPoint(relativeTo));
    return refCollection;
}
于 2012-06-21T16:36:36.500 に答える