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

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

One (more) question about draw/redraw

For general discussion related FlowStone

One (more) question about draw/redraw

Postby Nowhk » Wed Jan 20, 2016 3:12 pm

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 9663 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 809 times
Nowhk
 
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: One (more) question about draw/redraw

Postby tulamide » Wed Jan 20, 2016 4:30 pm

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 768 times
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: One (more) question about draw/redraw

Postby Nowhk » Wed Jan 20, 2016 4:39 pm

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 783 times
Nowhk
 
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm

Re: One (more) question about draw/redraw

Postby tulamide » Wed Jan 20, 2016 4:55 pm

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.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: One (more) question about draw/redraw

Postby Nowhk » Wed Jan 20, 2016 5:39 pm

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
Nowhk
 
Posts: 275
Joined: Mon Oct 27, 2014 6:45 pm


Return to General

Who is online

Users browsing this forum: No registered users and 59 guests