Joe, thank you. That page helps. I succeeded, but I had to set the width to
0.01 because if I set it to zero I get a 2 pixels thick line when the scale
is different than 1.0. Don't know why. Please follow me.

After scaling the view with

  scale = 1.33;
  [self setBoundsSize:NSMakeSize((int)([self frame].size.width  / scale),
                                 (int)([self frame].size.height / scale))];

I get these logs in the drawRect method

    scale 1.33
    frame {{0, 0}, {1166, 1253}},
    bounds {{-140, -50}, {875, 941}}

As you can see the frame and bounds values are all integers now.
Now I draw a vertical line

    [NSBezierPath setDefaultLineWidth:0.0];
    bot = NSMakePoint(0.5, 0.5);
    top = NSMakePoint(0.5, 9.5);
    [NSBezierPath strokeLineFromPoint:bot toPoint:top];

And the lines looks 2 pixels thick. Dam! So I tried to set

    [NSBezierPath setDefaultLineWidth:0.01 / scale];
    
And it worked at any scale. Can't guess why! With 0.001 I don't see any
line. Strange story, it works with zero, with 0.01/1.33 and it doesn't work
with 0.001 / 1.33. Any idea?


Best Regards
-- 
Lorenzo
email: [EMAIL PROTECTED]

> From: Joe Goh <[EMAIL PROTECTED]>
> Date: Fri, 25 Apr 2008 17:31:17 +0800
> To: cocoa-dev@lists.apple.com, Lorenzo <[EMAIL PROTECTED]>
> Subject: Re: One pixel width. One.
> 
> On 4/25/08, Lorenzo <[EMAIL PROTECTED]> wrote:
>>  I am trying to draw a line with 1 pixel width. No matter whether the view is
>>  scaled or scrolled, I want to see a 1 pixel thick line.
> 
> I highly, highly recommend reading this article:
> http://wincent.com/a/about/wincent/weblog/archives/2007/01/offbyone.php
> 
> I wanted to do the exact same thing in my app last year and this
> article saved the day for me.
> 
> HTH,
> Joe Goh
> FunkeeMonk Technology
> http://www.funkeemonk.com/

_______________________________________________

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 [EMAIL PROTECTED]

Reply via email to