drawVerticalLine request (scaling)

i draw frequency spectrums with drawVerticalLine, when i use this in a scaling context, the area isn't filled homogeneously.

So we need a variant which uses integer rounding on pixel level.

something like drawVerticalLineRoundXIntPixel

 

Current behavior 150% zoom (in this case the area isn't filled homogeneously, because the alpha-level isn't additive mixed, instead interpolated which is correct for the most use cases, but not in this use case)

line 1 src-position 1 dest-position 1.5 thickness 1.5

line 2 src-position 2 dest-position 3 thickness 1.5

line 3 src-position 3 dest-position 4.5 thickness 1.5

line 4 src-position 4 dest-position 6 thickness 1.5

 

New Behavior drawVerticalLineRoundXIntPixel

--> if we have a 150% zoom, the thickness of the line is 1 or 2, depending on the position

 

line 1 src-position 1 dest-position 1 thickness 1

line 2 src-position 2 dest-position 2 thickness 2

line 3 src-position 3 dest-position 4 thickness 1

line 4 src-position 4 dest-position 5 thickness 2

 

I'd really recommend avoiding that method these days - it pre-dates the scale factors and there's really no bulletproof way to make it work correctly when affine transforms are involved. Doing what you're suggesting could mess up existing code that relies on the way it works currently. I may even deprecate the method at some point.

There are two better alternative ways to render it:

1. Build a RectangleList and draw it. This operation will avoid scaling problems and runs faster than calling drawVerticalLine because it doesn't have to repeatedly call into the graphics classes or clip each line. This is how the juce thumbnail draws its waveforms.

2. Build a Path and draw it. This is surprisingly fast, and we've switched to drawing our waveforms as paths in tracktion now because it looks much better and has almost no noticeable performance hit.

mhh every line, can consist of different colour parts (because its a multi-channel display),  which uses a complex sorting alghorithm to calculate a specific colour on a specific position (dependend in which magnitude level and which order the channels are), not sure if a can do this with rectangleList. Then i need a rectangle list for every mixed colour.

Doing what you're suggesting could mess up existing code that relies on the way it works currently.

 

I need a extra method, not a replacement 

I can't think of how I could add an extra method that does exactly what you're asking for without it just looking like a bizarre hack. And the graphics stuff has to run on top of various rendering engines - with CoreGraphics for example, you can only draw rectangles. That's why the current drawVerticalLine code just basically draws a rectangle - it has no extra control over what it does on CoreGraphics.

Since drawVerticalLine is only a wrapper around fillRect, why not just call fillRect directly, and give it a float rectangle which when scaled ends up in the position that you really want it to be? By reversing the scale factor you could draw them at floating point coords which actually map onto physical pixels.