On 12.5.2009, at 06:23, Graham Cox wrote:


On 12/05/2009, at 12:44 AM, Sahana A wrote:

We have a feature in our application wherein we have to draw a 1 pixel line. This drawing also varies relative to the zoom factor of our view. For example if we are drawing at a zoom factor of 200% we draw 0.5 pixel line. ( basically: 1/zoomfactor width of line; 1 if the zoomfactor < 100 ).

For most of the times we succeed in drawing the 1 pixel line. However after we change the zoom factor, our drawing fails. Our 1 pixel
line is now drawn in 2 pixels.
For example: On changing the zoom values from say 100% to 300% and back to 100% again, the single pixel line sometimes draw in 2 pixels. Even if the stroke width is set to 0.0 or 1.0, the stroked line will draw 2 pixels.


It's not just a case of setting the line width, but also of placing the line where you want it. Strokes are placed so that they are centred on the co-ordinate, so half the line is above and half below the integral co-ordinate position. This is true even if you suppress anti-aliasing, which make matters worse since the lightening of the line is disabled and it'll draw as a solid 2 pixel line.

You need to truncate the line's co-ordinates to a whole number then add or subtract 0.5 so that the line is drawn on the pixel, not on the co-ordinate.

This goes into the right direction, but things are a little more involved. Basically you need to convert to device coordinates first, to the correct rounding, convert the result back and then draw.

The 10.5-only NSView methods convertPointToBase: and friends are quite helpful for this.

For more details see Apples "Resolution Independence Guidelines".

Kai



--Graham


_______________________________________________

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/kai%40granus.net

This email sent to k...@granus.net

_______________________________________________

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 arch...@mail-archive.com

Reply via email to