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

Bug-Creator

macrumors 68000
Original poster
May 30, 2011
1,864
4,786
Germany
Finally decided to go into OS X coding and struggling both with Objective-C (more an C++ guy) and the various APIs.

What I'm trying to achieve is drawing simple vector based GFX with the possibility to edit objects.

Found various names like Quartz, Core Graphics, Core Image ....

Examples I found use UIView, but are for iOS. Example for OS X has NSView and function names are slightly different.

Code:
- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    NSRect bound = [self bounds];
    [[NSColor greenColor] set];
    [NSBezierPath fillRect:bound];
    NSBezierPath *aPath = [NSBezierPath bezierPath];
    [[NSColor blueColor] set];
    // Set the starting point of the shape.
    [aPath moveToPoint:CGPointMake(100.0, 0.0)];
   
    // Draw the lines.
    [aPath lineToPoint:CGPointMake(200.0, 40.0)];
    [aPath lineToPoint:CGPointMake(160, 140)];
    [aPath lineToPoint:CGPointMake(40.0, 140)];
    [aPath lineToPoint:CGPointMake(0.0, 40.0)];
    [aPath closePath];
    [aPath stroke];
}
Is what I gobbled together and it does seem to work, but I'm not sure wether I'm on the road to HW accelerated GFX or just entering a dead end....
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.