Re: Lock/unlock focus does not draw image in Snow Leopard

Ken Ferry <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hi Michael,
> I do not understand the reason for this change in the behavior of
lockFocus -- if it was intentional or is a bug.

Please always file a bug if you are asking this question.

I think this arises from your NSCustomImageRep having size NSZeroSize.  When
the draw selector is called, the region to be drawn into is {NSZeroPoint,
[customRep size]}.  That doesn't make sense when the custom rep's size is
NSZeroSize.

The behavior change arises because NSImage used to end up doing

if ([rep size] is NSZeroSize]) [rep setSize:[self size]];

So please file a bug.

-Ken
Cocoa Frameworks

On Fri, Aug 28, 2009 at 7:26 PM, Michael McCulloch
<[email protected]>wrote:

>
> On Aug 28, 2009, at 9:38 PM, I 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?
>>
>
> My initial investigations indicate that on pre-Snow Leopard machines, the
> [myImage lockFocus] call initiates the draw selector. It does NOT do so on
> Snow Leopard.
>
> Therefore, I apparently have to make the [myImageRep draw] specific to Snow
> Leopard or else I will draw the image twice on earlier OS X versions.
>
> I do not understand the reason for this change in the behavior of lockFocus
> -- if it was intentional or is a bug. Seems like this could bite a lot of
> folks.
>
>
> ---
> Michael McCulloch
>
> _______________________________________________
> MacOSX-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.