Complex Regions in Interactive Images

A major element, and a major problem, in many graphics applications is identifying the location within an image where an event, such as a mouse click, has occurred. If you’re interested in only the window coordinates where the event occurred, this information is supplied in the lParam argument accompanying a WM_xBUTTONxxxx message. Using MFC, the information is found in the point argument passed to the OnxButtonxxxx and OnMouseMove methods. However, determining where a mouse click has occurred in relation to a displayed bitmap or some other region defined on the screen is a more difficult matter, particularly when the region is not conveniently defined by a series of bounding coordinates.

For simple rectangular shapes, you can use the PtInRect method, as explained in Chapter 29. However, for any other shapes, this method fails, and a new approach is required.

For example, consider Figure 30.1, where three shapes are depicted representing possible screen areas:

Figure 30.1: Three bounded regions 

© 1998 SYBEX Inc. All rights reserved.