Hit testing is a generic term for any procedure that determines whether a mouse click occurs inside a shape or area. Quartz provides two solutions for hit testing:
A path-oriented solution, which checks to see if the area enclosed by a path contains the hit point. See “Using a Path for Hit Testing.”
A pixel-oriented solution, which involves drawing into a 1x1 bitmap context with the appropriate transform. This solution is used in the CarbonSketch sample application that’s available in /Developer/Examples/Quartz. See “Using a 1x1 Bitmap Context for Hit Testing.”
When you are hit-testing, you may need to know the transform that Quartz uses to map between user and device space. The function CGContextGetUserSpaceToDeviceSpaceTransform, introduced in Mac OS X v10.4, returns the affine transform that maps user space to device space in a graphics context. There are other convenience functions for transforming points, sizes, and rectangles between these two coordinate spaces. For example, CGContextConvertPointToUserSpace transforms a point from the device space of a context to its user space.
Using a Path for Hit Testing
Using a 1x1 Bitmap Context for Hit Testing
Relevant Resources
Last updated: 2006-09-05