Corbin's Treehouse - Corbin Dunn, Santa Cruz, CA
Plug Bug
Treehouse
Photography
Videos
Projects
Unicycling
About

Cocoa: modal NSColorPanel dialog.


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];    

}



One Response to “Cocoa: modal NSColorPanel dialog.”

  1. corbin says:

    Note that the starting of modal session isn’t really required…


(c) 2008-2017 Corbin Dunn

Corbin's Treehouse is powered by WordPress. Made on a Mac.

Subscribe to RSS feeds for entries and comments.

38 queries. 0.424 seconds.