Page 1 of 1

[Ruby] defaultGridStep without a view

Posted: Thu Mar 24, 2016 3:03 pm
by tulamide
Sometimes the simplest things turn out to be the most complicated. For a conversion pixel => grid I need to access defaultGridStep from within a mouse state method. There is no view accessible, but the defaultGridStep method is an instance method of a view.

How do you solve such an issue? I'm not running out of ideas (I store the value in a variable from within the draw method), but I would hope to find the most elegant way to deal with it. For some reason it doesn't feel right to use resources by calling that rather constant value (the default grid step won't change at all in an exported plugin, and only rarely while editing in Flowstone) x times per second in the draw routine, just to be able to use it in another method.

So I hope there's something I didn't see, that enables me to call this exactly once when needed, without misusing the draw method.

Re: [Ruby] defaultGridStep without a view

Posted: Thu Mar 24, 2016 3:33 pm
by TheOm
You can use the Grid to Pixel or the Pixel to Grid primitive, feed it with a 1 and connect it to an input.
But out of interest, why do you need this value in a mouse method?

Re: [Ruby] defaultGridStep without a view

Posted: Thu Mar 24, 2016 3:49 pm
by tulamide
TheOm wrote:You can use the Grid to Pixel or the Pixel to Grid primitive, feed it with a 1 and connect it to an input.
But out of interest, why do you need this value in a mouse method?

Thank you. I hoped for a Ruby-only solution, but this is ok as well.

The script's database is pixel-based, since all elements shall have specific pixel values. Those database values may change during development, which makes it neccessary to convert on-the-fly.