• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Tracking Rect problem.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tracking Rect problem.


  • Subject: Re: Tracking Rect problem.
  • From: Eric Morand <email@hidden>
  • Date: Sat, 10 Sep 2005 14:07:24 +0200

About this :

    [ self addTrackingRect:[self visibleRect] owner:self userData:nil

assumeInside:NO];


I think you forgot something here : you have to store the result of addTracking... into your a_trackingRect variable. If you don't, you're [ self removeTrackingRect:a_trackingRect]; will not remove anything...

This will probably not solve your problem but will make sure you always have one and only one tracking rect for your button.



Anyway, I don't like to have tracking rects being created in drawRect (which should, well, only perform drawing). I personally register my custom controls to frame changes notification and remove/add the tracking rect when the frame changes.

Here is what I do personnaly :


- (id)init { self = [super init];

    if ( self )
    {
        // ...whatever you wand to initiliaz

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frameDidChange:) name:NSViewFrameDidChangeNotification object:self];
[self setPostsFrameChangedNotifications:YES];
}


    return self;
}

// ...


- (void)viewDidMoveToWindow { [self resetTrackingRect]; }

- (void)frameDidChange:(NSNotification *)aNotification
{
    [self resetTrackingRect];
}

- (void)resetTrackingRect
{
    // Tracking

    if ( trackingRectTag )
    {
        [self removeTrackingRect:trackingRectTag];
    }

    NSRect trackingRect = [self bounds];

    // Optional : Check if the mouse is already in the tracking rect

NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream];
NSRect boundsInWindow = [self convertRect:[self bounds] toView:nil];


    BOOL mouseInView = NSPointInRect(mouseLocation, boundsInWindow);

trackingRectTag = [self addTrackingRect:trackingRect owner:self userData:nil assumeInside:mouseInView];

    if ( mouseInView )
    {
        [self mouseEntered:[NSApp currentEvent]];
    }
}


I also add the following methods to ensure the tracking rect is removed when the control is removed :


- (void)removeFromSuperview
{
    if ( trackingRectTag )
    {
        [self removeTrackingRect:trackingRectTag];
    }

    [super removeFromSuperview];
}

- (void)removeFromSuperviewWithoutNeedingDisplay
{
    if ( trackingRectTag )
    {
        [self removeTrackingRect:trackingRectTag];
    }

    [super removeFromSuperviewWithoutNeedingDisplay];
}





Anyway, not sure if all of this will solve your problem. I'll try to add one of mu custom control to a scroll view to this how it behaves...





Eric.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Simple little question
  • Next by Date: How To Design A Queue of Messages?
  • Previous by thread: Re: Tracking Rect problem.
  • Next by thread: NSView to NSBitmapRep Without an NSWindow?
  • Index(es):
    • Date
    • Thread