I am porting an app from macOS/Swift to JUCE and I have a few places where I need precise drawing. For example I have a piano-roll style note editor where each notes rectangle has a border that renders black or highlighted to show selection state. In CoreGraphics I just temporarily set antialiasing off. I searched the JUCE source and can’t seem to find a way to do this. Any suggestions would be appreciated. Hopefully this zoomed JUCE image clarifies.
This is actual size in my original app. With 2 selected notes.
I don’t think there’s a way to turn antialiasing off. The JUCE way to do it (I think) would be to round to always nearest whole pixel coordinates when drawing - that should keep everything pixel-aligned so you don’t need to worry about antialiasing.
I think I’ve had cleaner results, when using Graphics::drawVerticalLine() and Graphics::drawHorizontalLine(). But of course these only help in the very specific case of drawing 1-pixel-thickness lines.
drawVerticalLine and drawHorizontalLine take ints for their x and y positions respectively - therefore they’ll always be pixel-perfect for that axis. However, they both take floats for their start/end positions so the start and end of the lines could potentially be ‘anti-aliased’.