• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSView : Background bitmap drawing issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView : Background bitmap drawing issue


  • Subject: Re: NSView : Background bitmap drawing issue
  • From: "Alexander Bokovikov" <email@hidden>
  • Date: Tue, 16 Feb 2010 01:34:34 +0500

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" <email@hidden>
To: "Alexander Bokovikov" <email@hidden>
Cc: <email@hidden>
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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >NSView : Background bitmap drawing issue (From: Alexander Bokovikov <email@hidden>)
 >Re: NSView : Background bitmap drawing issue (From: Steve Christensen <email@hidden>)

  • Prev by Date: Re: Null value from NSMutableArray
  • Next by Date: Embedded web server
  • Previous by thread: Re: NSView : Background bitmap drawing issue
  • Next by thread: Re: Debugging auto_zone_resurrection_error in Core Data using GCD
  • Index(es):
    • Date
    • Thread