Adding a tracking area

Discussion in 'Mac Programming' started by Miglu, Sep 28, 2010.

  1. macrumors member

    Joined:
    Jan 22, 2010
    Messages:
    74
    #1
    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:
    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?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    Messages:
    7,743
    #2
    What do you mean "does not work"? Are you not getting any mouseEntered or mouseExited calls? How are you calculating areaRect?
     
  3. macrumors member

    Joined:
    Jan 22, 2010
    Messages:
    74
    #3
    I am not getting MouseEntered or MouseExited calls.
    Code:
        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];
        }
    
     

Share This Page