John Riselvato
John Riselvato

Reputation: 12904

CGContextRef with two frame

I have two frames with point and lines on them that i would like to do a fill with. Does CGContextRef work will with filling if the two point of lines are on different frames?

I am figuring if they contain the same CGContextRef it wouldn't matter would it?

Heres the idea:

    if(dp.gPoints == nil || dp.gPoints->size() < 1)
    return;
CGContextRef UserGraphBuff = UIGraphicsGetCurrentContext();
CGContextBeginPath(UserGraphBuff);
vector<CGPoint>::iterator k = dp.gPoints->begin();
CGContextMoveToPoint(UserGraphBuff, (*k).x, (*k).y);
++k;
CGContextSetStrokeColorWithColor(UserGraphBuff, [UIColor blackColor].CGColor);
while(k != dp.gPoints->end()){
    CGContextAddLineToPoint(UserGraphBuff, (*k).x, (*k).y);
    ++k;
}
vector<CGPoint>::iterator L = dp.dPoints->end();
while(L != dp.dPoints->begin()){
    CGContextAddLineToPoint(UserGraphBuff, (*L).x, (*L).y);
    --L;
}
CGContextAddLineToPoint(UserGraphBuff, (*k).x, (*k).y);
CGContextSetFillColor(UserGraphBuff, CGColorGetComponents([[UIColor greenColor] CGColor]));
CGContextClosePath(UserGraphBuff);
CGContextEOFillPath(UserGraphBuff);

Maybe there is an issue with my code, which explains why this isn't working. Any information would be great. Thanks.

Upvotes: 0

Views: 110

Answers (1)

rob mayoff
rob mayoff

Reputation: 385590

I don't know if it's your problem, bit your second loop is wrong. It dereferences dp.dPoints->end() and skips dp.dPoints->begin(). It needs to be this:

while (L != do.dPoints->begin()) {
    --L;
    CGContextAddLineToPoint(UserGraphBuff, (*L).x, (*L).y);
}

Upvotes: 1

Related Questions