Getting Cocoa system colors...
Posted: Thu Aug 01, 2013 3:19 am
I am new to using CocoaMessage() and the Objective-C style functions... I am also new to OSX's API...
My goal is to get the Mac's system colors in PB's RGB format, starting for example with "windowBackgroundColor".
This is what I've come up with so far, and I've tried many things, but Line 6 (the last CocoaMessage) gives me an error that the object is nil, and I always get a result of $000000. (I know the first NSColor is being created, but I guess I am using the ColorSpace wrong?)
My goal is to get the Mac's system colors in PB's RGB format, starting for example with "windowBackgroundColor".
This is what I've come up with so far, and I've tried many things, but Line 6 (the last CocoaMessage) gives me an error that the object is nil, and I always get a result of $000000. (I know the first NSColor is being created, but I guess I am using the ColorSpace wrong?)
Code: Select all
Procedure.i GetCocoaColor(ColorName.s)
Protected NSColor.i = CocoaMessage(#Null, #Null, "NSColor " + ColorName)
If (NSColor)
Protected.CGFloat R, G, B, A
NSColor = CocoaMessage(#Null, NSColor, "colorUsingColorSpaceName:$", @"deviceRGBColorSpace")
CocoaMessage(#Null, NSColor, "getRed:@", @R, "green:@", @G, "blue:@", @B, "alpha:@", @A)
ProcedureReturn (RGB(Int(R*255), Int(G*255), Int(B*255)))
Else
ProcedureReturn (-1)
EndIf
EndProcedure
Debug Hex(GetCocoaColor("windowBackgroundColor"))
Delay(1000)