I’m creating my own look and feel method to draw my custom buttons and I need it to be pixel perfect because they will need to line up with other parts of the UI, but it’s not going well.
My (simplified) drawing code looks like this, which is almost directly lifted from the original L&F code:
void drawButtonBackground (Graphics& g, Button& button, const Colour& backgroundColour,
bool isMouseOverButton, bool isButtonDown) override
{
// outer shadow
outline.addRoundedRectangle (0.5f, 0.5f, getWidth() - 1.0f, getHeight() - 1.0f,
cornerSize, cornerSize,
! (flatOnLeft || flatOnTop),
! (flatOnRight || flatOnTop),
! (flatOnLeft || flatOnBottom),
! (flatOnRight || flatOnBottom));
g.setColour(Colour::fromFloatRGBA(0.0f, 0.0f, 0.0f, 0.25f));
g.fillPath(outline);
// the problem...
g.strokePath(outline, PathStrokeType(1.0f));
}
I’m creating a slight shadow around the button and I’m using a semi-transparent black so it will work with any background.
My test button is 50x21 pixels and on my retina screen with the standard L&F, it comes out exactly to 100x42 as expected. Without the last strokePath, my button comes out to 99x41. Not good. But if I add the strokePath, it comes out exactly to 100x42 as expected, but because of the now layered transparency, it’s slightly darker where the stroked path is. Not good either.
It seems like my choices are to have the correct size with incorrect shading, or the wrong size with correct shading. I don’t like either.
Anyone know how to correct this?