views:

102

answers:

0

in my previous code, I changed the coordinate system in my view's drawRect, so that the rectangle had 0,0 in the centre, 0,1 at the top centre and 1,0 in the centre of the right edge. I.e. a normalised Cartesian system.

    {
    // SCALE so that we range from TL(0, 0) - BR(2, -2)
    CGContextScaleCTM (X, 0.5 * bitmapSize.width, -0.5 * bitmapSize.height);

    // TRANSLATE so that we range from TL(-1, 1) - BR(1, -1)
    //   ie: a cartesian coordinate system, centred on (0, 0) with: 
    //       x increasing to the right
    //       y increasing upwards
    //       x&y each ranging from -1 to 1
    CGContextTranslateCTM(X, 1, -1);

    T = CGContextGetCTM (X);
}

in this box I create a wheel with 12 custom drawn buttons arranged around it. The buttons glow before gradually fading when pressed.

now I am redesigning the code, as the animation was rendering far too slowly

in my view's Load event I create a wheel object, which draws the wheel onto its own CALayer. this is then added as a sublayer to the view's Layer.

( the wheel object will in turn create the buttons which will each draw onto their own CALayer, and these layers will be added as sub layers to the wheels layer )

anyway, I would very much like to perform the drawing of the wheel and the buttons using my normalised Cartesian system. But I can't quite see how to implement it.

I could change the views transform. But this changes the boundary rectangle of the view. One solution would be to have a view within a view, but I discovered by chance testing that clipping to a circular path and drawing within that path will substantially slower than drawing without the clip. So I am hesitant to do this. I am looking for optimal efficiency (without going to GL, just yet -- I'm not ready for that -- I need to understand this stuff first, I think)

alternatively I could change the transform of the layer. but this is a 3D transform! I am having a lot of trouble getting my head around the logic of this. IPhone is a 2D screen. On it is represented a 2D interface. views and layers I conceptualise as flat rectangles sitting on top of one another. Is this wrong? Is this 3-D business just to do funky flip effects?

what if the layer has been set to rasterize, and it has a weird transform? How can it rasterize if it doesn't know what pixel resolution it is running? what if we have 10 nested layers each with a funky transform? And the innermost one needs to be rasterised? Does it somehow go all the way down the chain and figure out what pixels it is to overlay? What if the base layer is within a view within a view within a view and these views have 2D transforms on them? Does it really go all the way until it gets to pixel?

I want to rasterize my buttons -- that's why I'm asking. They are very complex drawing objects. It would save a lot of CPU GPU if they were prerendered dead and alive, and the fading would simply consist of compositing x*dead plus (1-x)*alive. so really I want bitmaps for both.

could someone slay my confusion?

many thanks,

Ohmu