PointerPredictor 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
支援產生一組預測當前輸入 Pointer 最可能路徑的 PointerPoint 物件。
public ref class PointerPredictor sealed : IClosable
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class PointerPredictor final : IClosable
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class PointerPredictor : System.IDisposable
Public NotInheritable Class PointerPredictor
Implements IDisposable
- 繼承
- 屬性
- 實作
範例
以下範例中,我們展示如何透過背景執行緒中 SwapChainPanel 的輸入來消耗 PointerPredictor 物件。
class PointerPredictionRenderer : IDisposable
{
private DispatcherQueueController _queuecontroller;
private InputPointerSource _inputPointerSource;
private PointerPredictor _pointerPredictor;
private List<Point> _actualPoints = new List<Point>();
private List<Point> _predictedPoints = new List<Point>();
private SwapChainPanel _panel;
public PointerPredictionRenderer(SwapChainPanel panel)
{
_panel = panel;
_panel.Loaded += SwapChainPanel_Loaded;
}
private void SwapChainPanel_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
_queuecontroller = DispatcherQueueController.CreateOnDedicatedThread();
_queuecontroller.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.High,
() =>
{
// Set up the pointer input source to receive pen input for the swap chain panel.
_inputPointerSource = _panel.CreateCoreIndependentInputSource(InputPointerSourceDeviceKinds.Pen);
_inputPointerSource.PointerPressed += InputPointerSource_PointerPressed;
_inputPointerSource.PointerMoved += InputPointerSource_PointerMoved;
_inputPointerSource.PointerReleased += InputPointerSource_PointerReleased;
// Create the pointer predictor for the input pointer source. By default it will be configured
// to predict points 15ms into the future
_pointerPredictor = PointerPredictor.CreateForInputPointerSource(_inputPointerSource);
});
}
~PointerPredictionRenderer()
{
Dispose();
}
public void Dispose()
{
if (_pointerPredictor != null)
{
_pointerPredictor.Dispose();
_pointerPredictor = null;
}
_inputPointerSource.PointerPressed -= InputPointerSource_PointerPressed;
_inputPointerSource.PointerMoved -= InputPointerSource_PointerMoved;
_inputPointerSource.PointerReleased -= InputPointerSource_PointerReleased;
_inputPointerSource = null;
_queuecontroller = null;
}
private void InputPointerSource_PointerPressed(InputPointerSource sender, PointerEventArgs args)
{
// Store the new point in contact.
_actualPoints.Add(args.CurrentPoint.Position);
}
private void InputPointerSource_PointerMoved(InputPointerSource sender, PointerEventArgs args)
{
// Only render ink and query for predicted points when the pointer is in contact.
// There are no predicted points if the pointer is not in contact.
if (args.CurrentPoint.IsInContact)
{
// Store new points received in this event.
var intermediatePoints = args.GetIntermediatePoints();
foreach (var point in intermediatePoints)
{
_actualPoints.Add(point.Position);
}
// Query for the predicted points from the predictor.
var predictedPoints = _pointerPredictor.GetPredictedPoints(args.CurrentPoint);
if (predictedPoints != null)
{
foreach (var predictedPoint in predictedPoints)
{
_predictedPoints.Add(predictedPoint.Position);
}
}
// Render the new ink stroke and the predicted ink stroke.
RenderInk();
}
}
private void InputPointerSource_PointerReleased(InputPointerSource sender, PointerEventArgs args)
{
// Clear the stored ink points and erase the predicted ink rendered for this stroke.
_actualPoints.Clear();
ClearPredictedInk();
_predictedPoints.Clear();
}
private void RenderInk()
{
// Render the ink strokes defined by _actualPoints and _predictedPoints.
throw new NotImplementedException();
}
private void ClearPredictedInk()
{
// Clear the ink stroke defined by _predictedPoints.
throw new NotImplementedException();
}
}
備註
此物件通常用於降低墨水輸入的渲染延遲。 在某些情況下,當使用者快速繪製時,筆尖與渲染出的墨水之間可能會有明顯的空隙。
屬性
| 名稱 | Description |
|---|---|
| PredictionTime |
設定指標 預測 器物件應該嘗試預測指標輸入的時間點,距離當前時間點的未來距離。 |
方法
| 名稱 | Description |
|---|---|
| Close() |
關閉 PointerPredictor 並釋放系統資源。 |
| CreateForInputPointerSource(InputPointerSource) |
為指定的 InputPointerSource 建立一個 PointerPredictor 實例。 |
| Dispose() |
執行與釋放、釋放或重設非受控資源相關聯的應用程式定義工作。 |
| GetPredictedPoints(PointerPoint) |
取得指定 PointerPoint 的預測點集合。 |