title: What do lockFocus and unlockFocus actually do?
body: <p><em>Warning: I'm a Cocoa newbie.</em></p>
  
  <p>I'm reading "Cocoa Programming For Mac OS X" by Hillegass.</p>
  
  <p>On p.301 it's written:</p>
  
  <blockquote>
    <p>To make the drawing appear on the image instead of on the screen, you must first lock focus on the image. When the drawing is complete, you must unlock focus.</p>
  </blockquote>
  
  <p>The code I have, inside <code>-(void)mouseDragged:(NSEvent *)theEvent</code> of an <code>NSView</code> is as follows:</p>
  
  <pre><code>[resizedImage lockFocus];
  [sourceImage drawInRect: NSMakeRect(0, 0, resizeWidth, resizeHeight) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];
  [resizedImage unlockFocus];
  </code></pre>
  
  <p>Without the lock/unlock, this does not work, but I still don't understand exactly what is going on.</p>
  
  <p>I see that the 2nd line of code has no mention of <code>resizedImage</code> so does that mean when I use <code>lockFocus</code> it makes sure any 'drawing' that happens takes place there? Could someone explain this better?</p>