line width canvas retina


I have a TextField and Canvas, side by side. Both have the same height and I draw in the canvas a rectangle from 0,0 to the whole width and height.

g.DrawRect 0, 0, Me.Width, Me.Height

On a non-retina mac the height of the canvas and the textfield looks the same, while on a retina mac the canvas looks 2 pixels higher. Moreover it looks like that the line width used to draw the rectangle is 2 pixels instead of one. Am I missing something?


Try changing the PenWidth to 1 on Retina screens and see if that helps.
I’m not so sure on the height issue. Are you doing me.height = textfield.height and seeing this behavior?

Hi Tim,

thank you for replying. I had already tried to set PenWidth to 1 but with no luck. About the height, I set the in IDE the height of the canvas to match the textfield (i.e. 22 pixels)

On a current Desktop Retina screen, each point you draw is represented by 4 pixels (2x2). So in effect when you go


It draws a rectangle made of 100x100 points at 0,0. Actually 200x200 pixels.

Recent versions of Xojo ( >= 2016R1) allow you to address this. See HiDPI Support.pdf in the Documentation folder next to the Xojo executable.

Hi Michel,

thank you. I was not aware of that. I will take a look at the documentation then.

Ok, also after reading the documentation I did not find how to solve the my issue.
Any ideas? Thanks.

[quote=264892:@Davide Pagano]Ok, also after reading the documentation I did not find how to solve the my issue.
Any ideas? Thanks.[/quote]

Difficult to help without no more than a description to go on. Could you come up with a project that demonstrate the issue ?

ScaleXY scales PenWidth just like it scales coordinates. So in retina, where scaleXY is 2 a line width of 1 is 2 pixels wide. To get 1 pixel wide in retina you’ll need to change ScaleXY to 1, then PenWidth of 1 is 1 pixel wide.

Note that changing ScaleXY changes the Width/Height of the Graphics. So before you were drawing the rect to Me.Width, Me.Height. Me.Width is the Canvas.Width and that doesn’t change, but g.Width does. Make sure to use g.Width, g.Height.

g.ScaleX = 1 g.ScaleY = 1 g.DrawRect 0, 0, g.Width, g.Height

And you might want to set ScaleXY back to 2 (or ScaleFactor) if there’s more drawing.

Thank you. That solved the issue.