Re: Should I pixel align in a View subclass in method -initWithFrame:frame?
Re: Should I pixel align in a View subclass in method -initWithFrame:frame?
- Subject: Re: Should I pixel align in a View subclass in method -initWithFrame:frame?
- From: Kyle Sluder <email@hidden>
- Date: Tue, 08 May 2012 15:44:08 -0700
On May 8, 2012, at 3:16 PM, Peter Teeson wrote:
> This is a continuation of my previous issue stroking a bezier path.
> In my sub-class -initWithFrame:frame I do the following:
> self = [super initWithFrame:frame];
> if (self) {
> // Initialization code here.
> frame.size.width = 200.0;
> frame.size.height = 200.0;
> frame.origin.x = 50.0;
> frame.origin.y = 50.0;
>
> Should I be pixel aligning it? And is this the correct way?
No, you should treat the view coordinate system as abstract and only pixel align (using -centerScanRect:) when you need to.
Since Quartz coordinates refer to the infinitely-thin space between pixels, the area bounded by a rectangle defined by four points is already pixel aligned. You only need to shift your coordinates if you want a _line segment_ defined by two points to cover whole pixels. This is why you were having issues before, since strokes are applied to line segments while fills are applied to the area bounded by line segments.
This terminology starts to break down a bit when HiDPI gets involved. Where you see "pixel" in the above paragraph, think of an idealized "device-independent pixel" which maps directly to real device pixels at 1x (normal) scale factor. "Pixel" is actually a misnomer here, but there's no real good alternative term for "a unit square 1pt on each side," since the term "point" also refers to the infinitely-small location in the coordinate space that is identified by a coordinate.
And thankfully we only have 1x and 2x scale factors now. Previously we had 1.25x and 1.5x factors as well, which made dealing with fractional coordinates even more confusing.
--Kyle Sluder
_______________________________________________
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