On p. 274, Hillegass has an aside about how to pick up the event when a mouse enters and exits a view, e.g. to highlight the view, as we'll do here. Not the most exciting screenshot in the world, I know. I tried to get the mouse, but couldn't figure it out. The mouse tracking code is set up in "viewDidMoveToWindow," which I gather is called when that happens during launch. If we do that then we get events sent as calls to "mouseEntered_" and "mouseExited_." The highlighting part is handled in "drawRect_", with an important clean-up method below that. The other thing in this code is a demo of how to get additional colors besides the standard Apple ones, from the color list called "Crayons." Here is the code:
class MyView(NSView): |