Re: Slider Scale Graphics
Posted: Thu Aug 27, 2020 2:56 am
DaveyBoy wrote:difference between brush and pen
tulamide wrote:It seems that the rectangle calculations are slightly off
Out of curiosity, I went and had a look at the user guide for the underlying Windows GDI+ drawing routines - and I did discover something rather odd about them: The DrawRectangle (outline with a pen) function takes integer dimensions, but the FillRectangle (with a brush) function takes floating point dimensions.
So, I had a bit more of a play - and the weirdness gets even deeper...
This just does the pen outline, and doesn't have the width and height "correction". The width of the pen (in pixels) and its alignment (false = centred on outline, true = inside shape) can be changed.
With a two-pixel border, note how the outline is always symmetrical. If drawn "inside shape" you can see two pixels all around; and if drawn "centred", one pixel all around disappears outside the view. This is exactly as you'd expect - and using the size "correction" even throws it off, making it asymmetrical.
But with a one-pixel border, everything goes wrong. It doesn't matter whether you draw "inside shape" or "centred", you can't see the right and bottom of the outline. Now, if the border is being "rounded" to fall on integer pixels, this kind of makes sense for "centred" alignment - you can't draw on half pixels, so the whole border is offset by half a pixel from where it should be. However, "draw inside" alignment should be possible, as that would involve only drawing whole pixels. But it doesn't work - the rounding must be happening before the alignment is taken into account, and the right and bottom are now a whole pixel out from where you'd expect them to be!
The effect is analogous for other pen widths too - odd-numbered widths all have the half-pixel offset.
How much of this is FlowStone, and how much GDI+, I'm not sure. But those function definitions I linked above suggest that it may be inherent to GDI+.