cocoa - What do lockFocus and unlockFocus actually do? -
warning: i'm cocoa newbie.
i'm reading "cocoa programming mac os x" hillegass.
on p.301 it's written:
to make drawing appear on image instead of on screen, must first lock focus on image. when drawing complete, must unlock focus.
the code have, inside -(void)mousedragged:(nsevent *)theevent
of nsview
follows:
[resizedimage lockfocus]; [sourceimage drawinrect: nsmakerect(0, 0, resizewidth, resizeheight) fromrect: nsmakerect(0, 0, originalsize.width, originalsize.height) operation: nscompositesourceover fraction: 1.0]; [resizedimage unlockfocus];
without lock/unlock, not work, still don't understand going on.
i see 2nd line of code has no mention of resizedimage
mean when use lockfocus
makes sure 'drawing' happens takes place there? explain better?
drawing requires 'graphics context'. you'll notice that, unlike core graphics, none of appkit drawing methods take parameter specifies drawing ends up. instead, destination stored globally [nsgraphicscontext currentcontext]
. appkit drawing methods affect current context.
the main purpose of -lockfocus
(on images , views alike) set graphics context drawing ends going want to.
Comments
Post a Comment