Bug in DropShadow::drawForRectangle


#1

When using a DropShadow object with the DropShadow::drawForRectangle function, there are visible gaps between the corner segments.

dropshadow_gap

It seems this line here:

const float radiusInset = (radius + 1) / 2.0f;

right at the start of the drawForRectangle function is to blame.

If I change it to

const float radiusInset = radius / 2.0f;

the gaps go away. No overlap or anything was noticed, it looks simply perfect.

Should I open an issue on GitHub or does this suffice?

Regards,
Mike


#2

It seems this is platform specific. On Windows you get the gap, on macOS you don’t. Maybe some weird compiler / rounding issue?


#3

Is this on a Retina (or hi res.) display?

I haven’t noticed that in our plug-in on either platform.

Rail


#4

On macOS with a retina display, it works fine. On Windows with a non-retina display you get the gap.

MSVC 2017, latest update etc.


#5

This is with the tip and VS2015 on Windows 10 and Parallels 13:


This is with:

void CLoadTemplateDlg::paint (Graphics& g)
{
    g.setColour (Colours::darkgrey);

    g.setOpacity (0.85f);

    g.fillAll();

    DropShadow ds;
    ds.colour = Colours::white;

    Rectangle<int>  workArea;

    workArea.setWidth (m_pWorkArea->getWidth() + 6);
    workArea.setHeight (m_pWorkArea->getHeight() + 6);
    workArea.setCentre (getLocalBounds().getCentre());

    ds.drawForRectangle (g, workArea);
}

where m_pWorkArea is the Component of the dialog with the dropShadow. The screen res. is 2560x1353.

Are you using OpenGL? What’s your graphic card and screen res.?

Rail


#6

That’s because you set neither a radius nor an offset.

Can you try a radius of 30 and an offset of 0, 10, please?

ds.radius = 30;
ds.offset = { 0, 10 };

I’ve just tested all combinations and only when there is a radius set AND and offset, then the bug appears.

No, I’m not using OpenGL. My screen-res is 3440 x 1440.


#7

With those I see this on both platforms…

Rail


#8

I’ve just tried again on the retina mac and there it does NOT happen for me. I even took a screenshot and zoomed in, in case I missed the 1 pixel gap, because on a retina screen it’s so tiny, but there was no gap there. It seems as if the transform got rid of it there?


#9

It has something to do with the following calculation at juce_DropShadowEffect.cpp:139:

const float radiusInset = (radius + 1) / 2.0f;
const float expandedRadius = radius + radiusInset;

If the resulting expandedRadius*nativeScaleFactor is not an integral number (where nativeScaleFactor is the scale factor of your monitor - so 2 for retina) then the gap seems to appear.

It’s odd because the drawShadowSection class use removeFromLeft/removeFromRight which shouldn’t result in there being a gap.


#10

Any idea how to fix this?


#11

Removing the + 1 in the code works for me but I have a feeling that Jules put it in there for a very good reason. He’s on Holiday at the moment but will be back on Monday. I’ll need to discuss this with him once he is back.


#12

Thanks for the update.