Re: A pie analyzer
Re: A pie analyzer
- Subject: Re: A pie analyzer
- From: "Tony S. Wu" <email@hidden>
- Date: Fri, 25 Apr 2003 22:43:14 -0700
Thanks for you guys' help.
I am using the determine-by-math approach, by using atan and stuffs.
Here is what I do.
First, I use
- (NSToolTipTag)addToolTipRect:(NSRect)aRect owner:(id)anObject
userData:(void *)userData
to add a tool tip with the rect that covers my pie.
Then, in the method
- (NSString *)view:(NSView *)view stringForToolTip:(NSToolTipTag)tag
point:(NSPoint)point userData:(void *)userData
I find out which pie section the point is in, and return the tooltips
accordingly.
However, because all the pies are in the same tool tip rect, it won't
update unless the mouse moves out of the rect then moves back in, which
can be troublesome.
Is there anyway to tell NSView to update tooltip once mouse is moved?
Thanks :D
Tony S. Wu
email@hidden
"The world doesn't give us hope - it gives us chance."
http://homepage.mac.com/tonyswu/tonyswu - My web page.
On Sunday, April 20, 2003, at 10:13 PM, Shaun Wexler wrote:
On Saturday, April 19, 2003, at 01:23 PM, Scott Anguish wrote:
http://homepage.mac.com/tonyswu/temp/c1.gif
My problem is, NSView only allows me to add tooltip for a rect.
I thought about using NSBezierPath's containsPoint method.
But I am not sure if it's a good idea since i'll be calling this
method for average 5 to 8 times each time a user moves his mouse.
I'd suggest trying it and see if it bogs down. NSBezierPath may
very well be optimized to check the bounds of the shape before
actually checking the shape itself.
I would hope so!
Also, (being unfamiliar with non-IB tooltip handling), using a timer
to delay the tooltip calculation until its display was necessary would
be another optimization.
The other alternative is to figure it out mathematically (determine
the rotational angle of the point to see which 'slice' it would be
in, and then it's distance from the center to see if it is actually
within the slice). Good old geometry.. :-) That's pretty much an
atan, two squares and a square root (plus of course some add/sub
action)
He should compute the square of the diameter ONCE for comparison
purposes, rather than the sqrt (or fqsrte) of each cursor location,
which would eliminate that instruction. Correct? And I have a nice
fast_atan2f() function which can be used to save many cycles, as well.
Since you know the shape of the target area, this is probably the
best method to use.
Certainly the "cleanest" way to code it, IMO. After examining his
.gif, I see that he uses alpha, which would make it less than robust
and/or much harder to code.
I'd recommend against the testing the pixel color method.
I suggested the pixel color method, since he was interested in
performance, and that's used in some OpenGL app's, for efficiency.
Calculating an atan and a sqrt whenever the mouse moves is certainly
not a high-performance implementation. Granted, this would only be
when the cursor was in the view's rect, and hopefully then only upon a
MouseMoved event, but hey... ;-)
--
Shaun Wexler
MacFOH
http://www.macfoh.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.