EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

getCurrentPoint method

Retrieves a PointerPoint object that provides basic info on the pointer associated with the event.

Use this method only when your app requires pointer details that are not intrinsically exposed by the event argument of the pointer event handler.

Important  This method is available to Windows Store apps only.

Syntax

var retval = MSPointerEvent.getCurrentPoint(element);

Parameters

element [in]

Type: Element

Provides the context for the pointer data.

Return value

Type: PointerPoint

The PointerPoint object corresponding to the pointer associated with the event.

Remarks

Additional pointer info can be obtained through the getCurrentPoint and getIntermediatePoints methods or the currentPoint and intermediatePoints properties of the event argument. We recommend using the getCurrentPoint and getIntermediatePoints methods as you can specify the context of the pointer data.

The object retrieved by this method provides access to extended pointer info through the properties property, which gets a PointerPointProperties object.

In the following example, we query various pointer properties directly from the event object and get extended properties through the PointerPoint and PointerPointProperties objects. (See Quickstart: Pointers for the complete example.)


// Get extended pointer data.
function queryPointer(e) {
    // We get the extended pointer info through the getCurrentPoint method
    // of the event argument. (We recommend using getCurrentPoint 
    // to ensure the coordinate space is in relation to the target.)
    // Note: getCurrentPoint and currentPoint are only available in the 
    // local compartment, they are not available in the web compartment.
    var ptTargetProperties = e.getCurrentPoint(e.currentTarget).properties;

    var details = "Pointer Id: " + e.pointerId;
    switch (e.pointerType) {
        case e.MSPOINTER_TYPE_MOUSE:
            details += "\nPointer type: mouse";
            details += "\nLeft button: " + ptTargetProperties.isLeftButtonPressed;
            details += "\nRight button: " + ptTargetProperties.isRightButtonPressed;
            details += "\nWheel button: " + ptTargetProperties.isMiddleButtonPressed;
            details += "\nX1 button: " + ptTargetProperties.isXButton1Pressed;
            details += "\nX2 button: " + ptTargetProperties.isXButton2Pressed;
            break;
        case e.MSPOINTER_TYPE_PEN:
            details += "\nPointer type: pen";
            if (ptProperties.isInContact) {
                details += "\nPressure: " + ptTargetProperties.pressure;
                details += "\nrotation: " + ptTargetProperties.rotation;
                details += "\nTilt X: " + ptTargetProperties.tiltX;
                details += "\nTilt Y: " + ptTargetProperties.tiltY;
                details += "\nBarrel button pressed: " + ptTargetProperties.isBarrelButtonPressed;
            }
            break;
        case e.MSPOINTER_TYPE_TOUCH:
            details += "\nPointer type: touch";
            details += "\nPressure: " + ptTargetProperties.pressure;
            details += "\nrotation: " + ptTargetProperties.rotation;
            details += "\nTilt X: " + ptTargetProperties.tiltX;
            details += "\nTilt Y: " + ptTargetProperties.tiltY;
            break;
        default:
            details += "\nPointer type: " + "n/a";
            break;
    }
    details += "\nPointer location (target): " + e.offsetX + ", " + e.offsetY;
    details += "\nPointer location (screen): " + e.screenX + ", " + e.screenY;

    return details;
}


Typically, the object returned by this method is used to feed pointer data to a GestureRecognizer as demonstrated here. (See Quickstart: Static gestures for the complete example.)

The gesture recognizer (inputManager) listens for and handles all pointer input and processes static gesture events (tap, double tap, press and hold, and right tap).


// inputManager handles gesture recognition for this sample.
function inputManager(target) {
    var questionsStarted = false;
    var tapCount = 0;
    var questionTotal = _data.selectNodes("questions/question").length;
    var clueCount = 0;
    var doubleTap = false;
    var startTime;
    var clueTimer;
    var intervalTimerId;

    // Initialize the gesture recognizer.
    var gr = new Windows.UI.Input.GestureRecognizer();

    // Turn off visual feedback for gestures.
    // Visual feedback for pointer input is still displayed. 
    gr.showGestureFeedback = false;

    // Configure gesture recognizer to process the following:
    // double tap               - start questions and timer.
    // tap                      - move to next question.
    // right tap                - show answer.
    // hold and hold with mouse - start clues.
    gr.gestureSettings =
        Windows.UI.Input.GestureSettings.tap |
        Windows.UI.Input.GestureSettings.doubleTap |
        Windows.UI.Input.GestureSettings.rightTap |
        Windows.UI.Input.GestureSettings.hold |
        Windows.UI.Input.GestureSettings.holdWithMouse;

    // Register event listeners for these gestures.
    gr.addEventListener('tapped', tappedHandler);
    gr.addEventListener("holding", holdingHandler);
    gr.addEventListener("righttapped", rightTappedHandler);

    // Register event listeners for DOM pointer events.
    // The event pointer(s) are passed to the gesture recognizer
    // for further processing.
    target.addEventListener('MSPointerDown', pointerDown, false);
    target.addEventListener('MSPointerMove', pointerMove, false);
    target.addEventListener('MSPointerUp', pointerUp, false);
    target.addEventListener("MSPointerOver", pointerOver, true);
    target.addEventListener("MSPointerOut", pointerOut, true);

    // The following functions are registered to handle DOM pointer events

    // Basic pointer handling to highlight input area.
    function pointerOver(evt) {
        _eventLog.innerText += "pointer over || ";
        evt.target.style.backgroundColor = "DarkGray";
    }
    function pointerOut(evt) {
        _eventLog.innerText += "pointer out || ";
        evt.target.style.backgroundColor = "DimGray";
    }

    // Handle the pointer down event.
    function pointerDown(evt) {
        _eventLog.innerText += "pointer down || ";

        // Hide the floater if visible.
        _floater.style.visibility = "hidden";

        // Get the PointerPoint for the pointer event.
        var pp = evt.currentPoint;

        // Get whether this pointer down event is within
        // the time threshold for a double tap.
        doubleTap = gr.canBeDoubleTap(pp);

        // Pass the PointerPoint to the gesture recognizer.
        gr.processDownEvent(pp);
    };

    // Handle the pointer move event.
    // The holding gesture is routed through this event.
    // If pointer move is not handled, holding will not fire.
    function pointerMove(evt) {
        //_eventLog.innerText += "pointer move || ";

        // Get intermediate PointerPoints
        var pps = evt.intermediatePoints;

        // Pass the array of PointerPoints to the gesture recognizer.
        gr.processMoveEvents(pps);
    };

    // Handle the pointer up event.
    function pointerUp(evt) {
        _eventLog.innerText += "pointer up || ";

        // Get the current PointerPoint
        var pp = evt.currentPoint;

        // Pass the PointerPoint to the gesture recognizer.
        gr.processUpEvent(pp);
    };

    // The following functions are registered to handle gesture events.

    // This handler processes taps and double taps.
    // Potential double taps are identified in the pointer down handler.
    function tappedHandler(evt) {
        // Single tap and questions started: Display next question.
        if (!doubleTap && questionsStarted) {
            _eventLog.innerText += "tapped || ";
            _instructions.innerText = "Double tap to stop questions.";
            _clues.innerText = "";
            tapCount++;
            if (tapCount > questionTotal) {
                _questions.innerText = "No more questions.";
            } else {
                var xpath = "questions/question[" + (tapCount % (questionTotal + 1)) + "]/q";
                // Read data from a simple setting
                _questions.innerText = _data.selectSingleNode(xpath).innerText;
            }
        }
        // Single tap and questions not started: Don't do much.
        else if (!doubleTap && !questionsStarted) {
            _eventLog.innerText += "tapped || ";
            _instructions.innerText = "Double tap to start questions.";
        }
        // Double tap and questions not started: Display first question.
        else if (doubleTap && !questionsStarted) {
            _eventLog.innerText += "double-tapped || ";
            // Return if last question displayed.
            if (tapCount > questionTotal) {
                _questions.innerText = "No more questions.";
                return;
            }
            // Start questions.
            questionsStarted = true;
            _instructions.innerText = "Starting questions (double tap to stop questions).";

            // Question number is based on tap count.
            tapCount++;

            // Select question from XML data object.
            var xpath = "questions/question[" + (tapCount % (questionTotal + 1)) + "]/q";
            _questions.innerText = _data.selectSingleNode(xpath).innerText;

            // Display a basic timer once questions started.
            startTime = new Date().getTime();
            intervalTimerId = setInterval(displayTimer, 100);
        }
        // Double tap and questions started: Stop questions and timer.
        else if (doubleTap && questionsStarted) {
            _eventLog.innerText += "double-tapped || ";
            _instructions.innerText = "Questions stopped (double tap to start questions).";
            questionsStarted = false;
            clearInterval(intervalTimerId);
        }
    };

    // For this app, we display a basic timer once questions start.
    // In a more robust app, could be used for achievements.
    function displayTimer() {
        var x = new Date().getTime();
        timerBox.innerText = (x - startTime) / 1000;
    }

    // This handler processes right taps.
    // For all pointer devices a right tap is fired on
    // the release of a press and hold gesture.
    // For mouse devices, righttapped is also fired on a right button click.
    // For pen devices, 
    function rightTappedHandler(evt) {
        if (!questionsStarted) {
            return;
        }
        var transform = (new MSCSSMatrix()).
            translate(
            (window.innerWidth - _inputBox.clientWidth) / 2.0 + evt.position.x,
            (window.innerHeight - _inputBox.clientHeight) / 2.0 + evt.position.y);
        _floater.style.visibility = "visible";
        _floater.style.msTransform = transform;
        eventLog.innerText = "right-tap || ";
    }

    // A holding event is fired approximately one second after 
    // a pointer down if no subsequent movement is detected.
    // Handle the pointer move event.
    // The holding gesture is routed through this event.
    // If pointer move is not handled, holding will not fire.
    function holdingHandler(evt) {
        if (!questionsStarted)
            return;
        if (evt.holdingState == Windows.UI.Input.HoldingState.started) {
            _eventLog.innerText += "holding || ";
            clueManager.initialize(tapCount);
        } else if (evt.holdingState == Windows.UI.Input.HoldingState.completed) {
            clueManager.destroy();
            _eventLog.innerText += "holding completed || ";
        } else {
            _eventLog.innerText += "holding canceled || ";
        }
    }

};


See also

MSPointerEvent
Methods
Conceptual
Responding to user interaction
Quickstart: Pointers
Quickstart: DOM gestures and manipulations
Quickstart: Static gestures
Quickstart: Manipulation gestures
Developing Windows Store apps (JavaScript and HTML)
Touch interaction design
Reference
Windows.UI.Core
Windows.UI.Input
Samples (DOM)
Input: DOM pointer event handling sample
Samples (Windows Store app APIs)
Input: Manipulations and gestures (JavaScript) sample
Input: Windows 8 gestures sample

 

 

Send comments about this topic to Microsoft

Build date: 1/23/2013

커뮤니티 추가 항목

표시:
© 2014 Microsoft