• 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: NSButtonCell darkened when state is NSOnState [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSButtonCell darkened when state is NSOnState [SOLVED]


  • Subject: Re: NSButtonCell darkened when state is NSOnState [SOLVED]
  • From: Stephan Burlot <email@hidden>
  • Date: Tue, 16 Nov 2004 10:20:24 +0100

To perpetuate my tradition of answering my own posts, this is what I found:

Didn't find an obvious solution, so what I did is to use the alternate image to display a darkened version of the button when state==NSONState.
The darkened image is calculated in awakeFromNib, using a modified version of some code by Chris Giordano found on cocoabuilder (search "Composing a darker image").


NSEnumerator *enumerator = [[cropButtonMatrix cells] objectEnumerator];

	while( aCell = [enumerator nextObject] )
	{
		darkenedImage = [NSImage highlightedImageForImage:[aCell image]];
		[aCell setAlternateImage:darkenedImage];
		[aCell setShowsStateBy:NSContentsCellMask];
		[aCell setHighlightsBy:NSNoCellMask];
	}

and highlightedImageForImage is in my NSImage Additions:
// ======================================================================== ===========
// creates copy of image, with highlighting applied
+ (NSImage *) highlightedImageForImage:(NSImage *)image
{
NSImage * newImage;
NSSize newSize;


	if (!image) return nil;

newSize = [image size];
newImage = [[[NSImage alloc] initWithSize:newSize] autorelease];
[newImage lockFocus];
[image drawAtPoint:NSZeroPoint fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) operation:NSCompositeSourceOver fraction:1.0];


[[[NSColor blackColor] colorWithAlphaComponent: .3] set];
NSRectFillUsingOperation(NSMakeRect(0, 0, newSize.width, newSize.height), NSCompositeSourceAtop);
[newImage unlockFocus];


	return newImage;
}

I'm thinking of starting my own mailing list, so I can ask questions and answer to myself. I'm looking for a moderator. ;-)

Stephan

Le 15 nov. 04, à 22:20, Stephan Burlot a écrit :

Hi,

I have a NSMatrix of buttons with image.
The NSMatrix is set to radio mode in IB.
Buttons are set to Square button, and behavior to "Push On/Push Off"

I want that when a button is selected, the image appears darkened.

Using trial and error, I achieved good result when the button is clicked by setting:
[[cropButtonMatrix cellWithTag:0] setShowsStateBy:NSNoCellMask];
[[cropButtonMatrix cellWithTag:0] setHighlightsBy:NSNoCellMask];


But the state of the button is not shown when the mouse is released, i.e. nothing is drawn in the cell to show its state.
I have tried all the constants available for setShowStateBy without success.


What is the magical incantation to tell the NSButtonCell to display its image darkened when it's on?

Any ideas?

Stephan Burlot

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


This email sent to email@hidden


_______________________________________________ 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
References: 
 >NSButtonCell darkened when state is NSOnState (From: Stephan Burlot <email@hidden>)

  • Prev by Date: Subclassing NSTextField and IB Custom Class
  • Next by Date: Re: How to embed a popup menu in an NSTextField
  • Previous by thread: Re: NSButtonCell darkened when state is NSOnState
  • Next by thread: NSURLHandle, proxies
  • Index(es):
    • Date
    • Thread