With help from stack overflow i am getting familiar with quartz drawing in iPhone. I want to make code that clips crescent moon pattern, this what i have so far, but its not working quite as i expect:
contextRef = UIGraphicsGetCurrentContext();
CGContextSaveGState(contextRef);
onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 128, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextClipToRect(contextRef, clipRect);
CGContextRestoreGState(contextRef);
onlyDrawTopHalf = YES;
halfMultiplier = onlyDrawTopHalf ? -1.0 : 1.0;
ellipse = CGRectMake(50, 50, 100, 128);
clipRect = CGRectOffset(ellipse, halfMultiplier * ellipse.size.width / 2, 0);
CGContextAddEllipseInRect(contextRef, clipRect);
CGContextEOClip(contextRef);
CGContextFillEllipseInRect(contextRef, ellipse);
To be precise, first paragraph of code draws circle (this works), second one should clip ellipse from it, but this is not working as intended.