PDA

View Full Version : Adding a tracking area




Miglu
Sep 28, 2010, 12:46 PM
Adding an NSTrackingArea does not work if I add it from another object than the view that I am adding it to, using this code: NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:areaRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) owner:gameView userInfo:nil];
[gameView addTrackingArea: area];

It works if I do the same in gameView, with "gameView" replaced by "self" in the code. What is the problem?



kainjow
Sep 28, 2010, 10:00 PM
What do you mean "does not work"? Are you not getting any mouseEntered or mouseExited calls? How are you calculating areaRect?

Miglu
Sep 30, 2010, 01:55 PM
I am not getting MouseEntered or MouseExited calls. for (float i = 0; i < 5; i++) {
NSRect areaRect;
areaRect.origin.x = INDENT*bounds.size.width;
areaRect.origin.y = (1 - (GAP + LENGTH)*i)*bounds.size.height;
areaRect.size.width = LENGTH*bounds.size.height;
areaRect.size.height = LENGTH*bounds.size.height;
NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:areaRect options:(NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow) owner:self userInfo:nil];
[self addTrackingArea: track];
}