Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Slider Scale Graphics

Post any examples or modules that you want to share here

Re: Slider Scale Graphics

Postby trogluddite » 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...
outline_rounding.fsm
(615 Bytes) Downloaded 921 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+.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Slider Scale Graphics

Postby deraudrl » Thu Aug 27, 2020 6:55 am

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.)
I keep a pair of oven mitts next to my computer so I don't get a concussion from slapping my forehead while I'm reading the responses to my questions.
deraudrl
 
Posts: 239
Joined: Thu Nov 28, 2019 9:12 pm
Location: SoCal

Re: Slider Scale Graphics

Postby trogluddite » Thu Aug 27, 2020 2:05 pm

^^ 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
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Slider Scale Graphics

Postby kortezzzz » Fri Aug 28, 2020 10:52 am

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! :)
User avatar
kortezzzz
 
Posts: 763
Joined: Tue Mar 19, 2013 4:21 pm

Previous

Return to User Examples

Who is online

Users browsing this forum: No registered users and 26 guests