Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cazador7907

macrumors newbie
Original poster
Nov 8, 2010
6
0
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 -
 
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

Cocoa - NSColor

QuickDraw (outdated Carbon) - RGBColor
 
Is this what you're needing?

Code:
#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

Code:
[UIColor whiteColor].CGColor

Hope this helps
 
Is this what you're needing?

Code:
#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

Code:
[UIColor whiteColor].CGColor

Hope this helps

That would only work on iOS...
 
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:

Code:
#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]
 
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?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.