On Monday, February 15, 2010 at 11:50 PM Steve Christensen wrote:

While there could be a drawing but in the OS, it's probably best to rule out issues with your code first. How do you determine the OS version?

I've used a code from the Net, which adds a category to NSApplication. This code was tested in both 10.4, 10.5 and 10.6 and works perfectly. No problems here. Moreover, I've changed the drawing code to make it to be more clear. My initial goal was just to draw the upper part of background image (the same for several windows), whereas windows have different height. Therefore I calculate an offset value, which is used in setPatternPhase, as

[myView bounds].size.height - [myBgImage size].height

And I've tried to exclude version checking from the code. A person, who reported a bug in 10.6, now tells that all is OK. But I've tested this version in 10.6 and in 10.4 and in both versions there is a shift for 1 pixel down. It looks like my NSView is shifted for 1 pixel. But its frame top is zero. Its height is the same in every OS... Just a weird problem...

Best regards,
Alexander



----- Original Message ----- From: "Steve Christensen" <puns...@mac.com>
To: "Alexander Bokovikov" <openwo...@uralweb.ru>
Cc: <cocoa-dev@lists.apple.com>
Sent: Monday, February 15, 2010 11:50 PM
Subject: Re: NSView : Background bitmap drawing issue


While there could be a drawing but in the OS, it's probably best to rule out issues with your code first. How do you determine the OS version? I ask because that's the only version-specific test in your drawing code. I would do something like this to initialize the variables:

double majorOSVersionNumber = floor(NSAppKitVersionNumber);

isLeo = NO;
isSnowLeo = NO;
if (majorOSVersionNumber > NSAppKitVersionNumber10_4)
{
if (majorOSVersionNumber > NSAppKitVersionNumber10_5)
isSnowLeo = YES;
else
isLeo = YES;
}

You should not being doing tests like "if (NSAppKitVersionNumber == NSAppKitVersionNumber10_5)" since that will only be true for 10.5.0, but will fail for 10.5.1, 10.5.2, etc. The value of NSAppKitVersionNumber is incremented by an integer amount for 10.x releases and by a fractional amount for 10.x.x releases.


On Feb 15, 2010, at 1:26 AM, Alexander Bokovikov wrote:

I've written a subclass of NSView, which draws a NSImage, as the background. All is working, but the only problem is in different behavior on different Macs / OS versions. Here is the drawing code:

@interface BGSkinView : NSView {
NSImage *bg;
BOOL isLeo, isSnowLeo;
}
......................
- (void)drawRect:(NSRect)rect {
NSGraphicsContext *ctx;
CGFloat y;

ctx = [NSGraphicsContext currentContext];
[ctx saveGraphicsState];
y = [self bounds].size.height;
///////////////////////////////////////////////////////////////////////////////////////
       if (!isLeo)
y++;
///////////////////////////////////////////////////////////////////////////////////////
[ctx setPatternPhase:NSMakePoint(0, y)];
//
[[NSColor colorWithPatternImage:bg] set];
NSRectFill([self bounds]);
//
[ctx restoreGraphicsState];
}

isLeo is true on 10.5 and isSnowLeo is true on 10.6

I tested this code on my Mac with both 10.4, 10.5 and 10.6 and have got a shift of the image for one pixel down on 10.4 and 10.6. Therefore I've added the condition, selected above. But now I've got a report from another 10.6 Mac, where my code shifts the background for one pixel up. Thus, my patch with y++ should be disabled there.

As far as I understand, this effect is caused not by OS version, but by some graphic subsystem feature. Could anybody tell me, what is this one-pixel shift? Maybe it's some border, drawn outside of my view, which I don't see?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to