RawStylusInput Classe
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Fornece informações sobre a entrada de um StylusDevice para um StylusPlugIn.
public ref class RawStylusInput
public class RawStylusInput
type RawStylusInput = class
Public Class RawStylusInput
- Herança
-
RawStylusInput
Exemplos
O exemplo a seguir cria um StylusPlugIn que verifica o Down gesto. As StylusPlugIn chamadas NotifyWhenProcessed OnStylusUp para assinar o OnStylusUpProcessed método, que é chamado do thread do aplicativo.
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
Comentários
Use para RawStylusInput obter informações sobre a entrada que recebe StylusPlugIn quando o usuário move a caneta.
Propriedades
StylusDeviceId |
Obtém o identificador do dispositivo de caneta atual. |
TabletDeviceId |
Obtém o identificador do dispositivo de tablet atual. |
Timestamp |
Obtém a hora em que o processo foi iniciado. |
Métodos
Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
GetHashCode() |
Serve como a função de hash padrão. (Herdado de Object) |
GetStylusPoints() |
Obtém os pontos de caneta que são coletados da caneta. |
GetType() |
Obtém o Type da instância atual. (Herdado de Object) |
MemberwiseClone() |
Cria uma cópia superficial do Object atual. (Herdado de Object) |
NotifyWhenProcessed(Object) |
Assina os métodos de caneta correspondentes do thread do aplicativo. |
SetStylusPoints(StylusPointCollection) |
Define os pontos de caneta que são passados para o thread de aplicativo. |
ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual. (Herdado de Object) |