Corbin Dunn
Redwood Monkey

Cocoa: modal NSColorPanel dialog.

Apple, Cocoa, General

Hi all,
I’ve seen some people request how to do a modal color panel. Well, carbon has GetColor(..) which ultimately uses the same NSColorPanel. So, you can set it to begin a modal session before you call GetColor(..). Here’s a code snippet:

#import <Carbon/Carbon.h>

– (IBAction)buttonClick:(id)sender

{

    NSColorPanel *colorPanel = [NSColorPanel sharedColorPanel];

    NSModalSession session = [NSApp beginModalSessionForWindow:colorPanel];

    

    RGBColor inColor = {128, 128, 128};

    RGBColor outColor = {0, 0, 0};

    Point point = {0, 0};

    if (GetColor(point, “\p”, &inColor, &outColor)) {

        NSColor *color = [NSColor colorWithCalibratedRed:(float)outColor.red / (float)UINT16_MAX green:(float)outColor.green / (float)UINT16_MAX blue:(float)outColor.blue / (float)UINT16_MAX alpha:1.0];

        [colorWell setColor:color];        

    }

    

    [NSApp endModalSession:session];    

}

Previous Post
no_thumbnail
Hi there...I'm poison oak!
Next Post
no_thumbnail
Muddy Coker Muni ride from April 2nd

1
Leave a Reply

avatar
500
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
corbin Recent comment authors
  Subscribe  
Notify of

(c) 2008-2018 Corbin Dunn

Privacy Policy

Subscribe to RSS feeds for entries.

74 queries. 0.407 seconds.

Log in