Re: Changing the "on" color of an NSButton
Re: Changing the "on" color of an NSButton
- Subject: Re: Changing the "on" color of an NSButton
- From: Esteban <email@hidden>
- Date: Sun, 27 Jan 2002 22:51:30 -0800
Hi Eric,
thanks for the great example.
Unfortunately, the cocoa dev mailing list removed the two attachments
you sent for the source code and header of ColoredButtonCell subclass of
NSButtonCell.
Could you please e-mail me the two files, or e-mail back with a link to
where i can get them.
Your method seems pretty solid way to go, and I would like to get this
source code into my source code "toolbox", in case i need it :-)
As far as the throbbing of default buttons that might require setting up
an NSTimer to execute an update method which changes the image of the
button a bit (from light to dark, then dark to light, then light to
dark, etc), a certain number of times per second? Of course you'd have
to add some "sleep time" so the user can see that its throbbing and not
flicking.
-Esteban
On Sunday, January 27, 2002, at 10:05 PM, Eric Ridge wrote:
On Saturday, January 19, 2002, at 02:17 PM, Eric Ridge wrote:
Question:
Is it possible to change the "on" color of a Round On/Off (or any)
Button?
Hi! I asked the above last week, and didn't receive the easy answer I
was hoping for. So, attached is what I hope will be an easy answer for
others that want colored buttons.
I've spent a few hours here and there working on an NSButtonCell
subclass (ColoredButtonCell) that allows you to create colored buttons
(Round, Square, Push, On/Off, Toggle, etc. Everything 'cept check and
radio buttons). It's not perfect, but it's pretty damn good, if I do
say so myself. :) The great thing is that it doesn't require external
images. However, it does not support "throbbing" of default buttons,
but it does everything else (as far as I can tell).
1) create your buttons as usual in InterfaceBuilder
2) connect them to a controller outlet
3) In the controller (awakeFromNib), do this on each button you want to
colorize:
[myButton
setCell: [ColoredButtonCell
cellForButton:myButton
withColor:[NSColor xxxColor]
]
];
Since you can't specify the cell type in IB (and since I couldn't get IB
to understand the NSButton subclass I started with), I tried to make
using the cell as easy as possible.
So here it is. Use it if you like, free of charge and warranty! Please
feel free to pass constructive criticism back my way.
thanks!
eric
ps, the .tiff is an example of what some small round buttons look like
with color.
/* ColoredButtonCell */
#import <Cocoa/Cocoa.h>
/**
* 1) create your buttons as usual in InterfaceBuilder
* 2) connect them to a controller outlet
* 3) In the controller (awakeFromNib), do this on each button you want
to colorize:
*
* [myButton
* setCell: [ColoredButtonCell
* cellForButton:myButton
* withColor:[NSColor xxxColor]
* ]
* ];
*/
@interface ColoredButtonCell : NSButtonCell
{
@private
NSImage *_button, *_overlay, *_result, *_mask, *_shadowMask;
NSSize _sourceSize;
NSRect _sourceFrame, _imageRect;
NSColor *_color;
NSButtonCell *_dummy;
int _currentState;
BOOL _mouseDown;
BOOL _colorizeWhenDeselected;
}
/**
* simple factory method for creating a ColoredButtonCell
* that is configured to work with the specified button. Also
* sets the color.
*/
+ (id)cellForButton:(NSButton *)button withColor:(NSColor *)color;
/** the color of the cell */
- (NSColor *)color;
/** change the color of the button */
- (void)setColor:(NSColor *)color;
/** should the cell colorize itself even when not selected */
- (BOOL)colorizeWhenDeselected;
/** change the state of the "colorizeWhenDeselected" flag */
- (void)setColorizeWhenDeselected:(BOOL)colorize;
@end
[demime 0.98b removed an attachment of type application/octet-stream
which had a name of ColoredButtonCell.m]
[demime 0.98b removed an attachment of type image/tiff which had a name
of ColoredButtonCell.tiff]
_______________________________________________
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.