Re: Lock/unlock focus does not draw image in Snow Leopard
Avi Drissman <avi-wYYLmqtpiAJWk0Htik3J/[email protected]>
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
The intended use of -lockFocus is a message to an object that you are drawing into it. If you are using NSCustomImageRep, then it makes little sense to call -lockFocus on it, since that means that you're trying to modify the image by drawing into it. This code path may have accidentally worked in the past, but SL made major behind-the-scenes changes to how images worked. While those changes are invisible to most users of NSImages, I fear your code may have accidentally been working. I'm not sure what you're trying to do. Are you trying to draw the myImage image into a view? If so, send -lockFocus to the view in which you want to draw, and then send -drawAtPoint... to the image to get it to draw. Avi On Fri, Aug 28, 2009 at 6:38 PM, Michael McCulloch <[email protected]>wrote: > I have found that the following code works fine pre-Snow Leopard to draw > the contents of an image: > > myImage = [[NSImage alloc] initWithSize:aSize]; > [myImage addRepresentation:[[[NSCustomImageRep alloc] > initWithDrawSelector:@selector(drawMyImage:) delegate:self] > autorelease]]; > [myImage lockFocus]; > [myImage unlockFocus]; > > Apparently the above worked fine since the lock/unlock focus triggered the > call of the drawMyImage selector (exactly how is unknown). > > However, in Snow Leopard this does not work. The draw selector is NOT > called. The code has to be changed to: > > myImage = [[NSImage alloc] initWithSize:aSize]; > myImageRep = [[[NSCustomImageRep alloc] initWithDrawSelector:@selector(drawMyImage:) > delegate:self] autorelease]; > [myImage addRepresentation:myImageRep]; > [myImage lockFocus]; > [myImageRep draw]; > [myImage unlockFocus]; > > In Snow Leopard the draw has to be explicitly called. Why the change? > > Another question: Since I do not know what the details of the > implementations of lockFocus and unlockFocus are on any OS X version, if I > now go with the Snow Leopard code for all OS X versions, does the explicit > [myImageRep draw] cause pre-Snow Leopard versions to draw my image TWICE? > > --- > Michael McCulloch > _______________________________________________ > MacOSX-dev mailing list > [email protected] > http://www.omnigroup.com/mailman/listinfo/macosx-dev >