다음을 통해 공유


RawStylusInput 클래스

정의

StylusDevice에서 StylusPlugIn으로 입력하는 방법에 대한 정보를 제공합니다.

public ref class RawStylusInput
public class RawStylusInput
type RawStylusInput = class
Public Class RawStylusInput
상속
RawStylusInput

예제

다음 예에서는 StylusPlugIn 를 확인 하는 Down 제스처입니다. StylusPlugIn 호출 NotifyWhenProcessed 에서 OnStylusUp 구독할 수는 OnStylusUpProcessed 는 애플리케이션 스레드에서만 호출 되는 메서드.

class RecognizerPlugin : StylusPlugIn
{
    GestureRecognizer recognizer;
    
    // StylusPointCollection that contains the stylus points of the current
    // stroke.
    StylusPointCollection points;

    // Keeps track of the stylus to check whether two styluses are used on the
    // digitizer.
    int currentStylus;

    public RecognizerPlugin()
        : base()
    {
        recognizer = new GestureRecognizer();
    }

    // Collect the points as the user draws the stroke.
    protected override void OnStylusDown(RawStylusInput rawStylusInput)
    {
        // If points is not null, there is already a stroke taking place
        // on the digitizer, so don't create a new StylusPointsCollection.
        if (points == null)
        {
            points = new StylusPointCollection(rawStylusInput.GetStylusPoints().Description);
            points.Add(rawStylusInput.GetStylusPoints());
            currentStylus = rawStylusInput.StylusDeviceId;
        }
    }

    // Collect the points as the user draws the stroke.
    protected override void OnStylusMove(RawStylusInput rawStylusInput)
    {
        // Check whether the stylus that started the stroke is the same, and
        // that the element hasn't lost focus since the stroke began.
            if (points != null && currentStylus == rawStylusInput.StylusDeviceId)
        {
            points.Add(rawStylusInput.GetStylusPoints());
        }
    }

    // Collect the points as the user draws the stroke.
    protected override void OnStylusUp(RawStylusInput rawStylusInput)
    {
        // Check whether the stylus that started the stroke is the same, and
        // that the element hasn't lost focus since the stroke began.
        if (points != null && currentStylus == rawStylusInput.StylusDeviceId)
        {
            points.Add(rawStylusInput.GetStylusPoints());

            // Subscribe to the OnStylusUpProcessed method.
            rawStylusInput.NotifyWhenProcessed(points);
        }

        points = null;
        currentStylus = 0;
    }
        
    // If the element loses focus, stop collecting the points and don't
    // perform gesture recognition.
    protected override void OnStylusLeave(RawStylusInput rawStylusInput, bool confirmed)
    {
        if (confirmed)
        {
            // Clear the StylusPointCollection
            points = null;
            currentStylus = 0;
        }
    }

    // This method is called on the application thread.
    protected override void OnStylusUpProcessed(object callbackData, bool targetVerified)
    {
        // Check that the element actually receive the OnStylusUp input.
        if (targetVerified && recognizer.IsRecognizerAvailable)
        {
            StylusPointCollection strokePoints = callbackData as StylusPointCollection;

            if (strokePoints == null)
            {
                return;
            }

            // Create a StrokeCollection to pass to the GestureRecognizer.
            Stroke newStroke = new Stroke(strokePoints);
            StrokeCollection strokes = new StrokeCollection();
            strokes.Add(newStroke);

            ReadOnlyCollection<GestureRecognitionResult> results = recognizer.Recognize(strokes);

            // If the GestureRecognizer recognizes the stroke as a Down
            // gesture with strong confidence, raise an event.
            if (results[0].ApplicationGesture == ApplicationGesture.Down &&
                results[0].RecognitionConfidence == RecognitionConfidence.Strong)
            {
                //raise event
            }
        }
    }
}
Class RecognizerPlugin
    Inherits StylusPlugIn
    Private recognizer As GestureRecognizer

    ' StylusPointCollection that contains the stylus points of the current
    ' stroke.
    Private points As StylusPointCollection

    ' Keeps track of the stylus to check whether two styluses are used on the
    ' digitizer.
    Private currentStylus As Integer

    Public Sub New()
        recognizer = New GestureRecognizer()

    End Sub


    ' Collect the points as the user draws the stroke.
    Protected Overrides Sub OnStylusDown(ByVal rawStylusInput As RawStylusInput)

        ' If points is not null, there is already a stroke taking place
        ' on the digitizer, so don't create a new StylusPointsCollection.
        If points Is Nothing Then
            points = New StylusPointCollection(rawStylusInput.GetStylusPoints().Description)
            points.Add(rawStylusInput.GetStylusPoints())
            currentStylus = rawStylusInput.StylusDeviceId
        End If

    End Sub

    ' Collect the points as the user draws the stroke.
    Protected Overrides Sub OnStylusMove(ByVal rawStylusInput As RawStylusInput)

        ' Check whether the stylus that started the stroke is the same, and
        ' that the element hasn't lost focus since the stroke began.
        If Not (points Is Nothing) AndAlso currentStylus = rawStylusInput.StylusDeviceId Then
            points.Add(rawStylusInput.GetStylusPoints())
        End If

    End Sub

    ' Collect the points as the user draws the stroke.
    Protected Overrides Sub OnStylusUp(ByVal rawStylusInput As RawStylusInput)

        ' Check whether the stylus that started the stroke is the same, and
        ' that the element hasn't lost focus since the stroke began.
        If Not (points Is Nothing) AndAlso currentStylus = rawStylusInput.StylusDeviceId Then
            points.Add(rawStylusInput.GetStylusPoints())

            ' Subscribe to the OnStylusUpProcessed method.
            rawStylusInput.NotifyWhenProcessed(points)
        End If

        points = Nothing
        currentStylus = 0

    End Sub

    ' If the element loses focus, stop collecting the points and don't
    ' perform gesture recognition.
    Protected Overrides Sub OnStylusLeave(ByVal rawStylusInput As RawStylusInput, ByVal confirmed As Boolean)

        If confirmed Then
            ' Clear the StylusPointCollection
            points = Nothing
            currentStylus = 0
        End If

    End Sub

    ' This method is called on the application thread.
    Protected Overrides Sub OnStylusUpProcessed(ByVal callbackData As Object, ByVal targetVerified As Boolean)

        ' Check that the element actually receive the OnStylusUp input.
        If targetVerified AndAlso recognizer.IsRecognizerAvailable Then

            Dim strokePoints As StylusPointCollection = callbackData

            If strokePoints Is Nothing Then
                Return
            End If

            ' Create a StrokeCollection to pass to the GestureRecognizer.
            Dim newStroke As New Stroke(strokePoints)
            Dim strokes As New StrokeCollection()
            strokes.Add(newStroke)

            Dim results As ReadOnlyCollection(Of GestureRecognitionResult) = recognizer.Recognize(strokes)

            ' If the GestureRecognizer recognizes the stroke as a Down
            ' gesture with strong confidence, raise an event.
            If results(0).ApplicationGesture = ApplicationGesture.Down AndAlso _
               results(0).RecognitionConfidence = RecognitionConfidence.Strong Then
                'raise event
            End If
        End If

    End Sub
End Class

설명

사용 합니다 RawStylusInput 입력에 대 한 정보는 StylusPlugIn 사용자가 스타일러스를 움직이면 수신 합니다.

속성

StylusDeviceId

현재 스타일러스 디바이스의 식별자를 가져옵니다.

TabletDeviceId

현재 태블릿 디바이스의 식별자를 가져옵니다.

Timestamp

입력이 발생한 시간을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetStylusPoints()

스타일러스에서 수집된 스타일러스 지점을 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
NotifyWhenProcessed(Object)

애플리케이션 스레드의 해당 스타일러스 메서드를 등록합니다.

SetStylusPoints(StylusPointCollection)

애플리케이션 스레드에 전달되는 스타일러스 지점을 설정합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상