Temporarily disable Graphics antialiasing?


#1

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.

antialiased-note

This is actual size in my original app. With 2 selected notes.
antialiased-note-org


#2

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.


#3

Thanks for the quick response, I added a call to toNearestInt() on my rectangles and that did the trick. I would have never thought of trying that so it’s much appreciated.


#4

Wouldn’t it be best to just make int rectangles in the first place?

Rectangle<int>


#5

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.


#6

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’.


#7

…and yet they call a float method:

It is a horrible mess with logical and display pixels…
Just put your drawing on a system with a scale factor, and all your effort is gone (windows: 125% is standard IIRC)

I think the time when you could count pixels is gone. I hope one day there is a consistency (my preference would be all integer functions removed, since they are meaningless).

Having said that, I wonder how come that there seems to be a difference though (I haven’t tried, my GUIs are always scaling, but many users here say there is a difference)