• 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: Steve Christensen <email@hidden>
  • Date: Mon, 15 Feb 2010 10:50:55 -0800

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


  • Follow-Ups:
    • Re: NSView : Background bitmap drawing issue
      • From: "Alexander Bokovikov" <email@hidden>
References: 
 >NSView : Background bitmap drawing issue (From: Alexander Bokovikov <email@hidden>)

  • Prev by Date: Freelance Cocoa job- SF Bay Area
  • Next by Date: Re: Null value from NSMutableArray
  • Previous by thread: NSView : Background bitmap drawing issue
  • Next by thread: Re: NSView : Background bitmap drawing issue
  • Index(es):
    • Date
    • Thread