noLoop and G4P library

jlbjlb
edited March 2015 in How To...

Hello,

I am trying to reduce the CPU used by a Processing application to nil. I use the G4P library to build a gui to setup a configuration on an Arduino board (I have also a program on the Arduino Board, the program drives servos. The goal is to change the min and max allowed positions using the gui). I used a trick I found on this forum : I call noLoop at the end of draw(). I setup 4 mouse handlers (Moved, Dragged, Pressed and Released) to call loop(). In the future I would like to remove mouseMoved. Most of the behavior is ok but 2 problems remain :

1 - G4P widget are not refreshed the first time : draw executes but the widgets are not displayed. Is there a way to force G4P to redraw the view ? 2 - G4P sliders seems to intercept the mousePressed and mouseReleased event. When I click in a slider (in the grayed area), the drawing is not refreshed until I move the mouse, so mousePressed is not called.

Thanks !

Answers

  • Is there a way to force G4P to redraw the view ?

    No

    The G4P library requires Processing to loop to refresh the controls.

  • edited March 2015

    I call noLoop() at the end of draw().

    • That is not necessarily the "obligatory" place.
    • We can issue noLoop() anywhere within setup() and it'll work the same.
    • Just take notice that draw() is always called once after setup().
    • And even noLoop() can't stop that!

    https://processing.org/reference/noLoop_.html

    P.S.: The warning: "If using noLoop() in setup(), it should be the last line inside the block." there is 100% FALSE!

  • edited March 2015

    I setup 4 mouse handlers (Moved, Dragged, Pressed and Released) to call loop().

    More correct approach is redraw(), which makes draw() be called once:
    https://processing.org/reference/redraw_.html

Sign In or Register to comment.