Re: NSMomentaryLightButton vs. NSMomentaryPushInButton and NSPushOnPushOffButton vs. NSOnOffButton
Re: NSMomentaryLightButton vs. NSMomentaryPushInButton and NSPushOnPushOffButton vs. NSOnOffButton
- Subject: Re: NSMomentaryLightButton vs. NSMomentaryPushInButton and NSPushOnPushOffButton vs. NSOnOffButton
- From: Jeff Johnson <email@hidden>
- Date: Thu, 28 Oct 2010 11:09:05 -0500
Hi Ken.
Thank you very much for the explanation.
I agree that using showsStateBy and highlightsBy directly seems to make more sense. These settings are not available in Interface Builder, unfortunately, only the button type.
By using setHighlightsBy: directly, I was able to see a difference between NSChangeGrayCellMask and NSChangeBackgroundCellMask. The documentation seems to be a bit lacking:
"NSChangeGrayCellMask: The button cell swaps the “control color” (the controlColor method of NSColor) and white pixels on its background and icon.
NSChangeBackgroundCellMask: Same as NSChangeGrayCellMask, but only background pixels are changed."
In my testing NSChangeBackgroundCellMask doesn't do anything to the background, it only changes the pixels of the icon. Maybe it's referring to the background of the icon? Also, the documentation for setHighlightsBy: seems wrong:
"If both NSChangeGrayCellMask and NSChangeBackgroundCellMask are specified, both are recorded, but which behavior is used depends on the button cell’s image. If the button has no image, or if the image has no alpha (transparency) data, NSChangeGrayCellMask is used. If the image does have alpha data, NSChangeBackgroundCellMask is used"
In my testing, I can't get NSChangeBackgroundCellMask to be used, it always behaves as NSChangeGrayCellMask. I'm near certain that some of my test images had alpha data.
As for NSChangeGrayCellMask vs. NSPushInCellMask, I can't see any difference, at least not with the configurations I tested.
Would you recommend that we use NSPushInCellMask / NSMomentaryPushInButton and simply ignore NSChangeGrayCellMask / NSChangeBackgroundCellMask / NSMomentaryLightButton as historical artifacts? It might be nice if the latter were re-deprecated, to clear up confusion. On the other hand, NSChangeBackgroundCellMask does seem genuinely useful.
-Jeff
On Oct 28, 2010, at 12:53 AM, Ken Ferry wrote:
> Hi Quincey, Jeff,
>
> -[NSButtonCell setButtonType:] is (mostly) a cover for certain combinations
> of -[NSButtonCell setHighlightsBy:] and -[NSButtonCell setShowsStateBy:].
>
> For a button, highlighted is synonymous with "pressed". setHighlightsBy:
> controls how a button draws to communicate that it is pressed. It takes an
> NSCellMask describing the look.
>
> showsStateBy: describes how a button should draw to show that it's "on".
> _All_ buttons change from on to off and back when clicked, it's just that
> many do not show it. This is also described with an NSCellMask.
>
> NSCellMask is a combination of NSContentsCellMask, NSPushInCellMask,
> NSChangeGrayCellMask, and NSChangeBackgroundCellMask. 0 is also a
> possibility, which would mean "do not draw differently".
>
> NSContentsCellMask means "use alternate contents", i.e. -[NSButtonCell
> alternateImage] and -[NSButtonCell alternateTitle].
>
> NSPushInCellMask means "look pushed in".
>
> NSChangeGrayCellMask and NSChangeBackgroundCellMask are rather historical
> names (the first comes from the NeXT's four color display - it refers to
> swapping one of the two gray colors with the other one!). They basically
> mean, uh, draw the bezel differently in some fashion.
>
> Anyway, NSMomentaryLightButton sets highlightsBy to
> NSChangeGrayCellMask|NSChangeBackgroundCellMask
> and showsStateBy to 0.
>
> NSMomentaryPushInButton sets highlightsBy to NSPushInCellMask and
> showsStateBy to 0.
>
> NSPushOnPushOffButton sets highlightsBy to NSPushInCellMask |
> NSChangeGrayCellMask|NSChangeBackgroundCellMask and showsStateBy to
> NSChangeGrayCellMask|NSChangeBackgroundCellMask.
>
> NSOnOffButton sets highlightsBy to
> NSChangeGrayCellMask|NSChangeBackgroundCellMask
> and showsStateBy to NSChangeGrayCellMask|NSChangeBackgroundCellMask.
>
> I find direct use of showsStateBy and highlightsBy to mostly make more sense
> than setButtonType.
>
> -Ken
>
> On Wed, Oct 27, 2010 at 9:13 PM, Quincey Morris <email@hidden
>> wrote:
>
>> On Oct 27, 2010, at 20:04, Jeff Johnson wrote:
>>
>>> I was aware of the documentation, and you appear to have it backwards:
>>>
>>> NSMomentaryLightButton
>>> While the button is held down it’s shown as “lit,” and also “pushed in”
>> to the screen if the button is bordered.
>>>
>>> NSMomentaryPushInButton
>>> While the button is held down it’s shown as “lit.”
>>>
>>> Nonetheless, one would expect that NSMomentaryPushInButton would also be
>> pushed in, given its name. And as I said, there seems to be no difference in
>> behavior.
>>
>> You're right, I read it according my expectation, not according to the
>> actual words. :)
>>
>> This is very strange, though. According to this document,
>> NSMomentaryPushInButton is the behavior of a normal push-button, and we know
>> it *is* shown as pushed-in (for at least some of the bordered button types).
>> Also, here's what the Leopard release notes had to say about it:
>>
>>> The constants NSMomentaryPushButton and NSMomentaryLight where reversed.
>> If you called [NSButtonCell setButtonType:] with these constants, they would
>> do the wrong thing. For compatability, these constant names have been kept
>> but new ones with the correct naming have been introduced:
>> NSMomentaryLightButton and NSMomentaryPushInButton.
>>
>> After playing around with IB's simulator for a bit, I couldn't find a case
>> where the two non-deprecated constants made any visual difference, either --
>> regardless of the presence of a template image. I have a vague recollection
>> of finding a difference between them, in the past, but it's possible that
>> I'm just remembering reading the documentation and believing what it said.
>>
>> It's possible that there's technically a difference between the two types,
>> but that no bezel formats currently show the difference visually.
>>
>> Very strange.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden