gskinner/EaselJS — pull request #87 by alekstorm (2011-11-08 09:23:51+00:00)
Title: Add overridable DisplayObject.drawHitMask() to use an arbitrary object for hit detection

Currently, collision detection of an object with the mouse pointer is performed by drawing the object onto a temporary 1x1-pixel canvas, offset such that only the pixel under the mouse pointer on the main canvas is visible. If this pixel is not fully transparent, it is counted as a hit.

This patch lets `DisplayObject`s draw any object to the temporary canvas by overriding `drawHitMask()`; if they do not, `draw()` is called by the default implementation. This will allow for much cheaper hit detection of complex objects such as images or multi-layered graphics, since only a filled outline of the object's shape must be rendered, as well as allow objects to be "hit" in transparent areas.

However, if `cache()` is called on the object, then the custom hit masking is ignored, and the cached canvas used instead. If you feel that this is acceptable as long as users are informed, then the pull request is ready for inclusion in the mainline. If not, then another commit must be added to create a separate cached hit mask canvas in `cache()`, though it may have an entirely different size and position.