Page 1 of 1

One (more) question about draw/redraw

Posted: Wed Jan 20, 2016 3:12 pm
by Nowhk
Hi all guys! I hope you can help me again ;)

I don't understand why I'm not able to call a redrawing of my View clicking on the Trigger button:

Immagine.png
Immagine.png (20.69 KiB) Viewed 10945 times

this should be pretty easy. Every Trigger click, a new Background color (notice the rand() function). But instead, only time in the "watch" zone change.

trigger redraw 0.fsm
(441 Bytes) Downloaded 868 times

Re: One (more) question about draw/redraw

Posted: Wed Jan 20, 2016 4:30 pm
by tulamide
It does redraw the view. You just need to go to the toplevel to see it. It's better if you have the trigger button one layer higher, so you can observe it better, like here:
trigger redraw 0 [tula].fsm
(456 Bytes) Downloaded 824 times

Re: One (more) question about draw/redraw

Posted: Wed Jan 20, 2016 4:39 pm
by Nowhk
tulamide wrote:It does redraw the view. You just need to go to the toplevel to see it. It's better if you have the trigger button one layer higher, so you can observe it better, like here:
The attachment trigger redraw 0 [tula].fsm is no longer available

I see. Thanks! My problem seems that I can't "prevent" redraw:

Code: Select all

def init
   @doRedraw = false
end

def draw i,v
   if(!@doRedraw)
      return
   end
   rc = [0,0,v.width,v.height]   
   brushBackground = Brush.new Color.new(0,80,rand(256))
   v.drawRectangle brushBackground,rc
end

def event i,v
   if(i == "trigger_redraw")
      @doRedraw = true
      redraw 0
      @doRedraw = false
   end
end

I'd like to "draw" only when I got a trigger (or an array Ruby input, for example) as input, not every time FlowStone invoke a general "redraw". Waste of resources for a controlled Area...

For example here, I'd like to change color every time I click on the Trigger button, not when I click on FlowStone workarea (that will invoke redraw inside Ruby).

trigger redraw 0_when_I_want.fsm
(494 Bytes) Downloaded 833 times

Re: One (more) question about draw/redraw

Posted: Wed Jan 20, 2016 4:55 pm
by tulamide
The draw method is not intended to be used for any programming/claculations/etc. It is just for drawing. The view just needs to be redrawn, when Flowstone demands it, else it would give strange results (for example when moving another view partly over the first one, then move it back. The first one would now be partly non-existent because of the missing redraw.

So, do your calculations in a seperate method, not in the draw method. For example, you could randomize the blue value in the event method (using instance variables), just before calling redraw. The result is the same: Color only changes on trigger, not on internal redraw.

Re: One (more) question about draw/redraw

Posted: Wed Jan 20, 2016 5:39 pm
by Nowhk
tulamide wrote:The draw method is not intended to be used for any programming/claculations/etc. It is just for drawing. The view just needs to be redrawn, when Flowstone demands it, else it would give strange results (for example when moving another view partly over the first one, then move it back. The first one would now be partly non-existent because of the missing redraw.

So, do your calculations in a seperate method, not in the draw method. For example, you could randomize the blue value in the event method (using instance variables), just before calling redraw. The result is the same: Color only changes on trigger, not on internal redraw.

I know, you teach to me this some topics ago. But my trouble is that I need to manage a huge arrays of values, and redraw it every time is so heavy. I thought to these solutions:

1 - prevent draw and draw only when I need (but seems not possible with Ruby/Draw in general);
2 - make a static bitmap once I draw it first time. Than avoid draw and use the generated bitmap instead;

I'm trying the point 2 with some difficults, but I'm almost done. Sooner a topic wih some questions! Thanks