1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Colorref

Discussion in 'Mac Programming' started by cazador7907, Nov 8, 2010.

  1. macrumors newbie

    #1
    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 -
     
  2. macrumors 68030

    Catfish_Man

    #2
    Cocoa uses NSColor objects to refer to colors.
     
  3. macrumors 6502a

    #3
    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
     
  4. macrumors 6502a

    bbarnhart

    #4
    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
     
  5. macrumors 68030

    Catfish_Man

    #5
    That would only work on iOS...
     
  6. macrumors 6502a

    bbarnhart

    #6
    My bad. I just assumed UIColor would also be available in the Mac API.
     
  7. Moderator emeritus

    kainjow

    #7
    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]
     
  8. macrumors newbie

    #8
    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?
     
  9. macrumors 68030

    Catfish_Man

    #9
    Make a 2D array of pointers to NSColors or CGColorRefs.
     
  10. macrumors 6502a

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

Share This Page