PDA

View Full Version : Colorref




cazador7907
Nov 8, 2010, 07:13 PM
Evening!

I'm new to C++ programming in xCode and I've been trying to work my way through a couple of programs in an attempt to convert them to the Mac. So far, the process hasn't been too painful. Hopefully this won't change.

Anyway, one thing that I can't seem to find a work around for (I'm sure that I've jus suffering from a mental block here) is converting VC++ COLORREF (this is just a constant integer value that defines colors with the MFC).

Is there an equivalent in xCode? If not, what is the work around? Or, is this a case where I should be working with the OpenGL/GLUT frameworks?

Many thanks in advance!!

Larry -



Catfish_Man
Nov 8, 2010, 07:17 PM
Cocoa uses NSColor objects to refer to colors.

lloyddean
Nov 8, 2010, 08:35 PM
Someone's going to do it, and it might as well be me - that's Xcode, not xCode.

The answer to your question depends upon which of the many API you're using on the Mac to do your imaging.

Quartz - CGColorRef (http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGColor/Reference/reference.html)

Cocoa - NSColor (http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSColor_Class/Reference/Reference.html)

QuickDraw (outdated Carbon) - RGBColor (http://serenity.uncc.edu/web/ADC/2005/Developer_DVD_Series/April/ADC%20Reference%20Library/documentation/Carbon/Reference/QuickDraw_Ref/qdref_main/function_group_24.html)

bbarnhart
Nov 9, 2010, 09:46 AM
Is this what you're needing?


#define RGB(r, g, b)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]


You can also get a CGColorRef from UIColor


[UIColor whiteColor].CGColor


Hope this helps

Catfish_Man
Nov 9, 2010, 09:52 AM
Is this what you're needing?


#define RGB(r, g, b)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]


You can also get a CGColorRef from UIColor


[UIColor whiteColor].CGColor


Hope this helps

That would only work on iOS...

bbarnhart
Nov 9, 2010, 10:00 AM
My bad. I just assumed UIColor would also be available in the Mac API.

kainjow
Nov 9, 2010, 10:20 AM
My bad. I just assumed UIColor would also be available in the Mac API.

Anything prefixed with UI* is iOS only :)

The OS X equivalent would be:

#define RGB(r, g, b)
[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a)
[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

cazador7907
Nov 9, 2010, 06:20 PM
Thanks for all the great replies! I don't think though that I provided enough data. In coding this simple game, I'm using a simple two dimensional array to store color values. In a separate four cell array, I define each color. Within the MFC for VC++, the declarations are pretty simple:

COLORREF m_arrColors[4]; //Hold the RGB color definition that will be used to fill the game board.

COLORREF GetBoardCell(int x, int y) //Returns a single cell from

I understand that NSColor is the object that I will use, I'm just not sure how to use it. Thoughts?

Catfish_Man
Nov 9, 2010, 07:16 PM
Make a 2D array of pointers to NSColors or CGColorRefs.

lloyddean
Nov 9, 2010, 07:18 PM
I don't think though that I provided enough data.

An understatement still as well. How do you intend to draw, render or image these color values?