G4P GUI draw question


#1

Hi,
at which point of the program is the “draw” function of the GUI called?
I ask because there is no obvious

drawGUI();

similar to the

createGUI();

which is used in the setup.

I’m drawing an image which partly overlaps a border and I want to clean that up by drawing over it with white squares.

Is the GUI drawn at the end of the draw loop?
Maybe I’m just too stupid to read the description right…
Max.


#2

All G4P controls are draw immediately after the draw() method so they appear on top of everything. This is done automatically by the library.

The createGU() method is created by GUI Builder and creates all the G4P controls, this method should only be executed once which is why it appears in setup()


#3

@quark Is there a way I could change that, e.g. make the gui update right before draw(); ?


#4

The short answer is ‘No’. If that was possible G4P controls could be hidden under drawn graphics but still respond to mouse clicks - weird.

Perhaps you could explain more clearly what you are trying to do?


#5

@quark

I would like to be able to have graphics (say a gui widget of my own creation) be drawn above the G4P GUI,
Like have the library update the gui before the draw() loop executes, i.e. update gui then call draw();
as opposed to calling draw() and then updating the gui.

I could have my program register a mouse handler that overrides the G4P library when there is graphics over the G4P widgets.

I see in the library that this is the draw() method.

public void draw() {
		app.pushMatrix();
		if(orgMatrix != null)
			app.setMatrix(orgMatrix);
		for(GAbstractControl control : windowControls){
			if( (control.registeredMethods & DRAW_METHOD) == DRAW_METHOD )
				control.draw();
		}		
		app.popMatrix();
	}

Would modifying it like so:

public void draw() {
		
		for(GAbstractControl control : windowControls){
			if( (control.registeredMethods & DRAW_METHOD) == DRAW_METHOD )
				control.draw();
		}	
                app.pushMatrix();
		if(orgMatrix != null)
			app.setMatrix(orgMatrix);	
		app.popMatrix();
	}

make it do what I want?


#6

Thank you. That solves my problem.


#7

@madscientist
The code you provide above will not change when the G4P controls are drawn. It also contains redundant code and a logic error which will cause unpredictable results.

In fact the code inside the G4P draw() method does not and cannot determine when the method is executed. Rather G4P uses a Processing library callback to execute this method after its own draw() method.


#8

So how would I have to change it to make it execute afterwards?


#9

You would create a class to represent your widget. The class would need a method to draw/render itself and that method would have to be ‘registered’ with processing (usually done in the widget’s constructor. Finally to make it appear over the G4P controls the widget would have to be created after the G4P controls.

Personally I have not tried this but it should work. :smiley:


#10

But if G4P updates after the draw() loop, then if I update my widget inside the draw() loop, then the G4P widgets will still be on top.


#11

Use registerMethod(): https://Forum.Processing.org/two/discussions/tagged?Tag=registerMethod()


#12

Oh, so I can update my widget without having anything in the main draw() loop.

Thanks, @GoToLoop @quark :relieved: