开发者

How can I change the brush images used within the GLPaint sample application?

I have downloaded the GLPaint example that Apple has provided, and am trying to understand its structure.

I want to change the brushImage used within the application, so that I can vary the type of brush used when drawing. I tried 开发者_JS百科to reload the view in order to find a way to reinitialize just the stuff related to setting brushImage, but I couldn't get anything to work.

Does anyone know how to modify this property in this code sample?


You can abstract the brush image code from initWithCoder:(NSCoder*)coder into it's own method, and change the brushImage dynamically eg,

I have

- (void)setBrushType:(kBrushType)bType {
    CGImageRef      brushImage; 

    ...

    if (bType == kBrushTypeEraser) {
        brushImage = [UIImage imageNamed:@"Particle-solid.png"].CGImage;
    } else if (bType == kBrushTypeSolid) {
        brushImage = [UIImage imageNamed:@"Particle-solid.png"].CGImage;
    } else if (bType == kBrushTypeSoft) {
        brushImage = [UIImage imageNamed:@"Particle-soft.png"].CGImage;
    } else {
        NSAssert1(FALSE, @"Invalid brush type: %d", bType);
    }   

    ...

    if(brushImage) {    
    ...
    }
}

where kBrushType is a enumeration of all the different brush types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜