Page 2 of 2

Re: Slider Scale Graphics

Posted: Thu Aug 27, 2020 2:56 am
by trogluddite
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...
outline_rounding.fsm
(615 Bytes) Downloaded 1211 times

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

Re: Slider Scale Graphics

Posted: Thu Aug 27, 2020 6:55 am
by deraudrl
trogluddite wrote: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.
...
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+.

Don't read too much into that: there's also a DrawRectangle method in that class that takes floating point dimensions, and a FillRectangle method that uses integer dimensions. (Pretty much every method in that class has multiple versions depending on the type of the inputs, just normal C++ overloading.)

Re: Slider Scale Graphics

Posted: Thu Aug 27, 2020 2:05 pm
by trogluddite
^^ D'oh :oops: - I really should have thought of that - serves me right for being lazy and relying on Google's top hits! It's obviously been so long since I did any C/C++ coding that I'm getting very rusty! Thanks for the correction. :D

Re: Slider Scale Graphics

Posted: Fri Aug 28, 2020 10:52 am
by kortezzzz
Great demonstration. Thanks. I tried to add scaling feature for increasing \ decreasing size by dragging the image's window size in it but with a limited success (based on green). I'm sure Ruby can do it better, so I won't post it since it's a very naive attempt. Should be done easily with Ruby itself, don't it?

Thank you! :)