23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Method<br />

msSetPointerCapture<br />

Description<br />

Captures the pointerId for the element so that pointer events come to it and are not<br />

raised for other elements (even if you move outside the first element and into another).<br />

MSGotPointerCapture will be fired on the element as well.<br />

msReleasePointerCapture<br />

Ends capture, triggering an MSLostPointerCapture event.<br />

msGetPointerCapture<br />

Returns the element with the capture, if any (otherwise null).<br />

We see this in the Input DOM pointer event handling sample, where it sets capture within its<br />

MSPointerDown handler and releases it in MSPointerUp:<br />

this.MSPointerDown = function (evt) {<br />

canvas.msSetPointerCapture(evt.pointerId);<br />

// ...<br />

};<br />

this.MSPointerUp = function (evt) {<br />

canvas.msReleasePointerCapture(evt.pointerId);<br />

// ...<br />

};<br />

Gesture Events<br />

The first thing to know about all MSGesture* events is that they don’t just fire automatically like click<br />

and MSPointer* events, and you don’t just add a listener and be done with it (that’s what click is for!).<br />

Instead, you need to do a little bit of configuration first to tell the system how exactly you want gestures<br />

to occur, and you need to use MSPointerDown to associate the gesture configurations with a particular<br />

pointerId. This small added bit of complexity makes it possible for apps to work with multiple<br />

concurrent gestures and keep them all independent just as you can do with pointer events. Imagine, for<br />

example, a jigsaw puzzle app (as presented in a small way in one of the samples in “The Gesture<br />

Samples” below) that allows multiple people sitting around a table-size touch screen to work with<br />

individual pieces as they will. Using gestures, each person can be manipu-lating an individual piece (or<br />

two!), moving it around, rotating it, perhaps zooming in to see a larger view, and, of course, testing out<br />

placement. For Windows Store apps written in JavaScript, it’s also helpful that manipulation deltas for<br />

configured elements—which include translation, rotation, and scaling—are given in the coordinate<br />

space of the parent element, meaning that it’s fairly straightforward to translate the manipulation into<br />

<strong>CSS</strong> transforms and such to make the manipulation visible. In short, there is a great deal of flexibility<br />

here when you need it; if you don’t, you can use gestures in a simple manner as well. Let’s see how it all<br />

works.<br />

Tip If you’re observant, you’ll notice that everything in this section has no dependency on WinRT APIs.<br />

As a result, the gesture events described here work in both the local and web contexts.<br />

378

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!