Page 1 of 2
Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 2:48 pm
by Nowhk
The schema is pretty simple:

- Immagine.png (13.56 KiB) Viewed 15359 times
every time I click with mouse on the work space, the counter increment itself: this means that draw function is called.
It is strange when working on the tools, since if I'm making graphic it messes with index/time line of processing.
That's normal? Can I avoid this? Thanks!
- Test.fsm
- (365 Bytes) Downloaded 807 times
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 8:43 pm
by Nowhk
This is another huge anomaly I reckon:
- Bug3.fsm
- (1.56 KiB) Downloaded 811 times
open the schema, and click the "Start" Button. Within the first Ruby script, it generates random value every 1/2 second, that I send to another Ruby "draw" script.
Even if the "input" value is at 0.5 sec, draw method is called many times, faster, and I see the first counter run very fast. Redraw should trigger "draw" on every input value.
The strange things is that on a Computer it works correctly (I see both counter go at same speed).
Here, at home (another PC) the first one is faster. Both with Windows 10 Professional.
Is that a bug or am I missing somethings fundamental?
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 8:57 pm
by tulamide
Here on the forums was a talk about it, if I remember correctly. You have to avoid sending to the output from within the draw method. Any output call lets Flowstone redraw the functional elements around the view (the circular inputs/outputs). For some reason, probably to take care the view itself stays intact, a draw call is also sent to Ruby.
Conclusion: Call the output method only from methods that are not connected to the draw method.
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 9:07 pm
by Nowhk
tulamide wrote:Conclusion: Call the output method only from methods that are not connected to the draw method.
But I can't: its on the draw method that I can "draw" element. So, it is drawing lines at a different time/speed than the inputs.
Can I draw inside custom methods? This can't work since "v" doesn't exist:
Code: Select all
def theMyDraw
@path = GraphicsPath.new
@pen = Pen.new (Color.new 200,0,200,0), 0.3
@path.addLine [1, 2],[10, 12]
v.drawPath @pen, @path
end

Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 9:56 pm
by MyCo
The standard method is to calculate any variable you need for drawing in event/mouseXYZ or a method called from there, and in draw you just draw to the view.
The multiple times redraw you see should only happen in the schematic (not on the frontpanel). Basically, FS forces a redraw for the green float box you've connected to the output, this redraw is sent to Ruby as well (maybe it shouldn't but there might be a reason for it)
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 10:48 pm
by Nowhk
Not sure if this is what happens in my case! This function for example:
Code: Select all
def draw v
if(@end == true)
return
end
if(@index == 10)
@path = GraphicsPath.new
@old_x = 0
@index = 0
end
@path.addLine [@old_x, @new_y],[@old_x + @lenght, @new_y]
@old_x = @old_x + @lenght
v.drawPath @pen, @path
@index = @index + 1
end
I haven't any "output" from the draw method here, but its called more times than the times I call "redraw 0" from another method.
Here the example:
- Bug4.fsm
- (1.67 KiB) Downloaded 835 times
as you can see, the step that it "draw" is longer than 5 points in the grid, that's because it is called more times.
Each step (i.e. every time I reckon a "value" inside the Ruby that draw) should be 5 points lenght (@lenght = 5); instead its longer, because draw is retriggered from others elements that I don't know (as I said, there is no output within draw here).
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 11:20 pm
by tulamide
There is no bug:
MyCo wrote:The standard method is to calculate any variable you need for drawing in event/mouseXYZ or a method called from there, and in draw you just draw to the view.
You should stick to this! The draw method is called whenever a redraw is needed - not just when
you call it. Calculations don't belong into the draw method.
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 11:25 pm
by MyCo
As long as you don't do anything it's 5 steps. Of course when you interact with FS, FS has to redraw more often.
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 11:28 pm
by Nowhk
MyCo wrote:As long as you don't do anything it's 5 steps. Of course when you interact with FS, FS has to redraw more often.
This is what happens on my other PC. On this, it redraw more ad I said. I do nothing in FS, I just click start
But on this computer it draw more.
Re: Why mouse click invoke draw?
Posted: Wed Nov 18, 2015 11:36 pm
by Nowhk
You can see it in this video:
http://www.fastswf.com/U8s2F4kevery time it got a value, draw has been processed two times (draw step is 10 points long, instead of see progression of 5 points drawf).
The significant draw as you can see happen (on the new 10 points lenght draft) after 5 point, betweem 5° and 10°.
So it seems that draw is called a little bit before the value is coming, drawing again a line with old values plus the new ones.
But the strange thing is that this happens "only" on pc A. If I try it on pc B, it works without any problem.