Share via


PointerPredictor 클래스

정의

현재 입력 포인터의 가장 가능성이 높은 경로를 예측하는 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
상속
Object Platform::Object IInspectable PointerPredictor
특성
구현

예제

다음 예제에서는 백그라운드 스레드에서 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();
    }
}

설명

이 개체는 일반적으로 잉크 입력에 대한 렌더링 대기 시간을 줄이는 데 사용됩니다. 경우에 따라 사용자가 매우 빠르게 그릴 때 펜 팁과 렌더링된 잉크 사이에 눈에 띄는 간격이 있을 수 있습니다.

속성

PredictionTime

PointerPredictor 개체가 포인터 입력을 예측하려고 시도하는 현재 시간부터 미래까지의 시간을 가져오거나 설정합니다.

메서드

Close()

PointerPredictor를 닫고 시스템 리소스를 해제합니다.

CreateForInputPointerSource(InputPointerSource)

지정한 InputPointerSource에 대한 PointerPredictor의 instance 만듭니다.

Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

GetPredictedPoints(PointerPoint)

지정된 PointerPoint에 대해 예측된 점의 컬렉션을 검색합니다.

적용 대상