3

Historically, one has simply done a floor() after any calculations, to make sure all coordinates, heights and widths align properly to the pixel boundary.

However, this clearly won't work anymore on the retina display, because 0.5 point is now perfectly valid.

How should coders now code pixel perfect things to make their code properly support both standard and retina displays?

NoobOverflow
  • 1,208
  • 3
  • 14
  • 19
  • uh... will `round()` work? Or does it support 0.2 and others? – TheAmateurProgrammer Sep 02 '12 at 13:33
  • round() still returns a whole integer, right? But on the retina, 0.5, 1.5, 2.5, etc. are valid for pixel-perfect drawling, as far as I understand. – NoobOverflow Sep 02 '12 at 13:39
  • Here, happened to found how to round a number to .5 http://stackoverflow.com/questions/752817/rounding-numbers-in-objective-c – TheAmateurProgrammer Sep 02 '12 at 14:05
  • You often wouldn't want whole-number coordinates even on a non-retina display, since it'll cause a 1-point straight-horizontal or straight-vertical stroke to be blurred. – Peter Hosey Sep 02 '12 at 18:09
  • @PeterHosey Why would 1-point straight lines get blurred at whole-number coordinates? – NoobOverflow Sep 02 '12 at 22:04
  • 1
    @NoobOverflow: Because the stroke is painted on either side of the line, and whole-number coordinates are between pixels (assuming no translation to the contrary—indeed, a half-point translation is common workaround). Thus, the stroke paints half of the pixel on each side of the line. Since that isn't physically possible, the stroke instead paints both pixels at 50% opacity. The result is both washed-out (red on white will appear pink, for example) and blurred. – Peter Hosey Sep 02 '12 at 22:51

1 Answers1

2

Convert the rect to backing-aligned coordinates. You'll probably be doing this in the view, but windows can do it and screens can do it as well.

You may also need to convert back, since the release notes suggest that the backing coordinate spaces are in pixels, so those spaces will obviously be twice as big on a Retina display. If I had one, I'd test it. If everything looks twice as big when you use the backing coordinates in view space, that means you do need to convert them back to view coordinates.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
  • If only retinas were easy and cheap to come by :) – NoobOverflow Sep 02 '12 at 21:50
  • I found out that one can simulate a retina display on a non-retina one, which is great. Instructions here: http://stackoverflow.com/questions/12124576/how-to-simulate-a-retina-display-hidpi-mode-in-mac-os-x-10-8-mountain-lion-on – NoobOverflow Sep 03 '12 at 08:35
  • @NoobOverflow: It depends on the display's capabilities. Neither my MBA's built-in display nor my desktop display can do HiDPI resolutions. – Peter Hosey Sep 03 '12 at 10:42