Re: NSButton sensing mouse over?
Re: NSButton sensing mouse over?
- Subject: Re: NSButton sensing mouse over?
- From: email@hidden
- Date: Wed, 23 Jan 2002 08:44:24 -0800
I have mine working pretty well (not exactly the same behavior, but
close) with 382 lines of code... 233 for an NSWindow subclass and 149
for an NSButtonCell subclass. I didn't have to touch NSView. Most of
the code in the nswindow subclass is for resizing at the four edges and
the four corners like windows...
I think the only thing mine does wrong is always bring the window to the
front when you click the buttons in the background. It tracks the mouse
exactly the same as the Appearance one. Oh, and I'm having some
difficulty getting my window's name into the Window menu. I jammed it
in there in validateMenu: but that seemed like a hack.
setShowsBorderOnlyWhileMouseInside causes the button to call my cell's
mouseEnter and mouseExit methods so i can display mouse over feedback.
I'm sure it does something different with regular NSButtons, but since
i'm overriding drawWithFrame:inView: none of the standard drawing takes
place. I did it this way so you can still place the button using IB...
and then I just take it and whack it to become my button, preserving the
position and autoposition stuff from ib.
As far as the tracking rects issue goes... I set the bounds of the
button to all three balls, and that takes care of the hover image
between spaces. Then inside in my tracking loop that I fire off in
mouse down, I do the right partial image copy to show the darkened
single ball during click-drags.
I still could use cleaner looking traffic light images.
On Wednesday, January 23, 2002, at 08:05 AM, Darrin Filer wrote:
>
I accomplished the same thing via a brute force technique but am still
>
looking for something more elegant. I ended up using tracking rects
>
since the behavior is more complicated than I anticipated. All three
>
buttons should display their hover images not only when the mouse is
>
hovering above them, but also when it is hovering between them. You can
>
actually drag the window from between the window widgets.
>
>
It took 400 lines of code to subclass NSView into something that
>
behaves exactly like the window widgets. However, this includes the
>
ability to draw the widgets over any type of background and still have
>
their 'shadows' look right. Also, note intricacies like preventing
>
window ordering when using the widgets in a background window.
>
>
In regards to this line of code:
>
[cell setShowsBorderOnlyWhileMouseInside:YES];
>
How does this effect how its drawn? (Doesn't this just effect the
>
border?)
>
>
>
>
On Wednesday, January 23, 2002, at 12:11 AM, email@hidden wrote:
>
>
i just responded privately that this doesn't work, then figured it
>
out... when i tried moving my call to
>
setShowsBorderOnlyWhileMouseInside: till *after* i added the button to
>
the window... then it works... (it might be good to document that this
>
is the case someplace.)
>
>
thanks chuck.
>
>
here's the code for the curious:
>
>
NSButton *button = [[NSButton alloc] initWithFrame:NSMakeRect(4,
>
335, 68, 24)];
>
NSButtonCell *cell = [[TrafficLightCell alloc] init];
>
[button setButtonType:NSMomentaryChangeButton];
>
[button setCell:cell];
>
>
[[window contentView] addSubview:button];
>
>
// if this next line is moved above the addSubview line above, then
>
TrafficLightCell's mouseEnter/Exit methods aren't called.
>
>
[cell setShowsBorderOnlyWhileMouseInside:YES];
>
>
>
Now I have a button that implements the red/yellow/green buttons of
>
NSWindow for use in borderless windows! (like iPhoto)
>
(if only i could find the nice images Appearance uses, i wouldn't have
>
to use my imperfect screengrabbed versions...)
>
I'm assuming that apps like iPhoto and iTunes create their windows
>
using carbon and then use DrawThemeTitleBarWidget(...)
>
>
>
On Tuesday, January 22, 2002, at 07:55 PM, Chuck Pisula wrote:
>
>
You'd have to do it yourself by looking for mouseEntered, and
>
mouseExited messages, and then doing your own drawing.
>
>
-c
>
>
On Tuesday, January 22, 2002, at 07:29 PM, email@hidden wrote:
>
>
Is there a way to have a custom NSButtonCell subclass draw differently
>
if the mouse has entered/exited the button, without being pressed? All
>
I can find is isHighlighted... which tracks when the button is pressed.
>
_______________________________________________
>
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.