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: Corbin Dunn <email@hidden>
- Date: Tue, 08 May 2012 15:26:46 -0700
On May 8, 2012, at 3:16 PM, Peter Teeson <email@hidden> wrote:
> This is a continuation of my previous issue stroking a bezier path.
Hi Peter, I'm not sure what issue you were having.
WRT:
> 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?
Your code above is already point aligned, there for it is pixel aligned. If the frame was say 200.2 or 200.5, then you should pixel align it.
> And is this the correct way?
> frame = [self convertRectToBacking: frame];
> frame = [self convertRectFromBacking: frame];
The above code doesn't do anything except convert back and forth. Say you have a frame origin of 200.5 that you want to be pixel aligned, you would do this:
> frame = [self convertRectToBacking: frame];
Floor in "pixel space".
frame.origin.x = floor(frame.origin.x);
> frame = [self convertRectFromBacking: frame];
Now frame is pixel aligned and is back in "point space".
corbin
>
> [self setFrame:frame];
> [self setNeedsDisplay:YES];
> … ….
>
>
> Thanks….
>
> _______________________________________________
>
> 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
_______________________________________________
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