I'm writing a library to launch operating system dialogs such as file open/save, message dialogs, and prompts from C applications. I can't figure out how to launch a color picker on Mac, for selecting a RGB(A) color value.
This is as far as I've gotten in the Mac implementation of my library in Objective C. I assume I need to launch a NSColorPanel
, but I can't find an example of how to do this online.
int launchColorPicker(float* r, float* g, float* b, float* a) {
@autoreleasepool {
NSColorPanel* panel = [NSColorPanel sharedColorPanel];
// ???
*r = ...;
*g = ...;
*b = ...;
*a = ...;
return succeeded;
} // @autoreleasepool
}
The following is an example of a programmatic NSColorPanel in objc. It may be run in Xcode by replacing main.m with the following code and deleting the pre-existing AppDelegate to avoid duplicate symbols.