getting Color from NSColorInstance

Hi,
in the Example Projects folder (Cocoa declares) there is this line:

Var NSColorInstance As Ptr = colorWithDeviceRed(NSColorClassRef, RGB.red / 255, RGB.Green / 255, RGB.blue / 255, 1.0)

Now, how would I get a Xojo color from the pointer NSColorInstance?

As if I could write something like: var c as color = NScolorInstance

Thank you.

Declare Function getRedComponent Lib "AppKit" selector "redComponent"(ob_id As Ptr) As CGFloat
Declare Function getGreenComponent Lib "AppKit" selector "greenComponent"(ob_id As Ptr) As CGFloat
Declare Function getBlueComponent Lib "AppKit" selector "blueComponent"(ob_id As Ptr) As CGFloat
Declare Function getAlphaComponent Lib "AppKit" selector "alphaComponent"(ob_id As Ptr) As CGFloat

Dim xojoColor As Color = RGB(getRedComponent(c)*255, getGreenComponent(c)*255, getBlueComponent(c)*255, 256-getAlphaComponent(c)*255)

“c” is the NSColor Ptr

or just use NSColorMBS class if you use MBS Xojo Plugins.

@Thomas Eckert Thank you for the quick reply. Appreciated.

Still referring to the same example in Example Projects:

Am I guessing right that the following code is mixing up declares and Xojo functions?
I mean:
If Color.SelectedFromDialog(RGB, “Select a color”) Then

isn’t it the Xojo way to show the colorPanel? Because what I was hoping for, it was to get NSColorPanel to replace the Xojo one.
In other words, I thought the code below was creating the colorPanel by declares.
I suppose I’m out of luck (smiley).

Var RGB As Color
Soft Declare Sub setBackgroundColor Lib “Cocoa” selector “setBackgroundColor:” (windowRef As Integer, backColor As Ptr)

Soft Declare Function NSClassFromString Lib “Cocoa” (aClassName As CFStringRef) As Ptr
Soft Declare Function colorWithDeviceRed Lib “Cocoa” selector “colorWithDeviceRed:green:blue:alpha:”(classRef As Ptr, red As CGFloat, green As CGFloat, blue As CGFloat, alpha As CGFloat) As Ptr

// get the reference to the NSColor class so we can call one of the class methods
Var NSColorClassRef As Ptr = NSClassFromString(“NSColor”)

If Color.SelectedFromDialog(RGB, “Select a color”) Then
// now ask the NSColor class to create a new NSColor from the values we have
Var NSColorInstance As Ptr = colorWithDeviceRed(NSColorClassRef, RGB.red / 255, RGB.Green / 255, RGB.blue / 255, 1.0)

// and set the background
setBackgroundColor(Self.Handle, NSColorInstance)
End If