One quick question about xcode

Discussion in 'Mac Programming' started by swimlikehell, Aug 31, 2006.

  1. macrumors member

    Joined:
    Aug 31, 2006
    Messages:
    46
    #1
    I know you will probaly thing i am stupid but i am just starting out so please help. I am trying to do multiple image functions using carbon and they all need CGContectRef. what was wondering was how i can go about finding that i am making a basic sketch program. any help will be much appreciated. Thanks
     
  2. macrumors regular

    Joined:
    Jan 11, 2006
    Messages:
    110
    #2
    I'm not entirely sure what you're trying to do. Your description isn't totally clear. But you say you're just starting out. Writing graphics programs can be quite complex to start out with. Did you already try writing console applications, or just simple GUI applications?
     
  3. macrumors member

    Joined:
    Aug 31, 2006
    Messages:
    46
    #3
    i have done a little of both, the start of my code is this, im trying to find out what i need to do to call this function:


    void MyColoredPatternPainting (CGContextRef myContext, CGRect rect)
    {
    CGPatternRef pattern;
    CGColorSpaceRef patternSpace;
    float alpha = 1,
    width, height;
    static const CGPatternCallbacks callbacks = {0, &MyDrawPattern, NULL};

    CGContextSaveGState (myContext);
    patternSpace = CGColorSpaceCreatePattern (NULL);
    CGContextSetFillColorSpace (myContext, patternSpace);
    CGColorSpaceRelease (patternSpace);

    pattern = CGPatternCreate (NULL,
    CGRectMake (0, 0, H_PSIZE, V_PSIZE),
    CGAffineTransformMake (1, 0, 0, 1, 0, 0),
    H_PATTERN_SIZE,
    V_PATTERN_SIZE,
    kCGPatternTilingConstantSpacing,
    true,
    &callbacks);

    CGContextSetFillPattern (myContext, pattern, &alpha);
    CGPatternRelease (pattern);
    CGContextFillRect (myContext, rect);
    CGContextRestoreGState (myContext);
    }*/
     
  4. macrumors 6502

    Joined:
    Jul 25, 2006
    Messages:
    294
    #4
    Sounds like you're trying to do some lower level stuff, which is fine, but not to be attempted without some consulting the docs.

    I suggest you search for "Graphics Context" within Xcode and look at the both the Cocoa and Quartz 2D references.

    To answer your immediate question though, a CGContextRef for display on the screen cannot be created from the Quartz/CG APIs. You can either obtain the current graphics context from a Cocoa app using the following code:

    Code:
    CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
    ... or you can obtain it from a Carbon HIView, but that code is too complicated to post here. You can find it in the documentation though.

    Alternatively, you can create a bitmap image, OpenGL, or printing CGContextRef if that's what you intend to do. Again, look to the docs for those.
     

Share This Page