G4P controls loose their positions in proscene while resizing the window!

Hello, im new in processing and i need your help. I want to manipulate a loaded object in proscene with a GUI. For my design are the g4p controls the best and i love the GUI builder.
But i have at the momet this problem: when i resize the window, the G4P controls loose their positions on the window. and they are then disabeld in the new position!
Could you explain please what am i missing here and how i can fix the controls in their Postions when i resize the window?! this is the code i have till now:

import g4p_controls.*;
import remixlab.proscene.*;

GButton btn1,btn2; 

Scene scene;

PMatrix3D currCameraMatrix;
PGraphics3D g3; 

void setup() {
  size(1200,800,P3D);
  
  //G4P Control
  btn1 = new GButton(this,25,60,70,25); // loose Position when i resize the window...
  btn1.setText("G4P_btn1");
  btn2 = new GButton(this,25,120,70,25); // loose Position when i resize the window...
  btn2.setText("G4P_btn2");
  
   scene = new Scene(this);
   g3 = (PGraphics3D)g;
}

void draw() {
  background(0);
  fill(255,0,0);
  noStroke();
  box(30);

  gui();
}


void gui() {
  hint(DISABLE_DEPTH_TEST);
  currCameraMatrix = new PMatrix3D(g3.modelview);
  float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
  perspective(PI/3.0, scene.camera().aspectRatio(), cameraZ/10.0, cameraZ*10.0);
  camera();
  
  strokeWeight(3);
  stroke(200); 
  noFill();
  rect(25, 35, 70, 110);

  g3.camera = currCameraMatrix;
  hint(ENABLE_DEPTH_TEST);
}

Thank you

1 Like

Unfortunately the proScene library is deprecated and the new library nub does not appear to be available in the contributions manager so I can’t test any possible solution but looking at the code I suggest the following change in the draw method

void draw() {
  pushMatrix();
  background(0);
  fill(255,0,0);
  noStroke();
  box(30);

  gui();
  popMatrix();
}

I think there is a very good chance that this will work, fingers crossed :smile:

Update - I have found the nub library in the contributions manager (I must have been blind LOL) but your code was created with the older proScene library and won’t work with nub.

Since proScene has been deprecated there will be no more updates or bug fixes so I strongly recommend you move to nub.

2 Likes

Hello Peter, thank you for your answer, i appreciate it. I tried the push/popMatrix() before and in many different ways but no luck :-).
I saw all the examples of the new nub library --> @Jean Pierre made a great work again. I will definitly move to nub and thank you for the recomondation

the push/popMatrix() doesnt work in nub too, this the code i tried:

import nub.processing.*;
import g4p_controls.*;

GButton btn1, btn2;
GCustomSlider sdr1;
GLabel lbl1;
GCheckbox checkbox1;
Scene scene;
PMatrix3D CameraMatrix;
PGraphics3D g3; 

void setup() {
  size(800, 800, P3D);
  g3 = (PGraphics3D)g;
  scene = new Scene(this);
  
 //G4P Control loose Position when i resize the window...
  btn1 = new GButton(this,25,60,70,25); 
  btn1.setText("G4P_btn1");
  btn2 = new GButton(this,25,120,70,25); 
  btn2.setText("G4P_btn2");
  sdr1 = new GCustomSlider(this, 25, 160, 100, 40, "grey_blue");
  lbl1 = new GLabel(this, 25, 250, 80, 20);
  lbl1.setText("My label");
  checkbox1 = new GCheckbox(this, 25, 210, 20, 20);
 
}

void draw() {
  
  pushMatrix();
  background(0);
  fill(0, 0, 255); rotateY(PI/4); rotateZ(PI/4);
  box(50);
  gui();
  popMatrix();
  
  //scene.beginHUD();  // it does not work
  //gui();
  //scene.endHUD();
}
void gui() {
  hint(DISABLE_DEPTH_TEST);
  CameraMatrix = new PMatrix3D(g3.modelview);
  float cameraZ = ((height/2.0) / tan(PI*60.0/360.0));
  perspective(PI/3.0, scene.aspectRatio(), cameraZ/10.0, cameraZ*10.0);
  camera();
  
  strokeWeight(3);
  stroke(200); 
  noFill();
  rect(25, 35, 70, 110);

  g3.camera = CameraMatrix;
  hint(ENABLE_DEPTH_TEST);
}

do you have an idea how i solve this now in nub :-)?

Thank you so much agian :muscle: :ok_hand:

OK I have been doing some experiments and the problem is based on the interaction between G4P and Processing, in particular the P3D renderer as it doesn’t occur in P2D and JAVA2D (default) renderers . It has nothing to do with nub. I have been using the code below to simulate the problem. The red oblong represents a G4P control and is unaffected by the window resize suggesting a bug in G4P but it might be some time before I get around to fixing it.

In the meantime you could have a second window (P2D or JAVA2D) for the controls, you can set this up in GUI Builder. If you have called the second window window then in the customGUI method add the line

window.setAlwaysOnTop(true);

to make sure it always appears above the 3D window.

import g4p_controls.*;

GButton btn1, btn2;
GCustomSlider sdr1;
GLabel lbl1;
GCheckbox checkbox1;
Scene scene;
PMatrix CameraMatrix;
PGraphics g3; 
Dummy dummy;

void setup() {
  size(600, 600, P3D); // Try changing the
  G4P.messagesEnabled(false);
  textSize(16);
  surface.setResizable(true);
  //G4P Control loose Position when i resize the window...
  btn1 = new GButton(this, 25, 60, 70, 25); 
  btn1.setText("G4P_btn1");
  btn2 = new GButton(this, 25, 120, 70, 25); 
  btn2.setText("G4P_btn2");
  sdr1 = new GCustomSlider(this, 25, 160, 100, 40, "grey_blue");
  lbl1 = new GLabel(this, 25, 250, 80, 20);
  lbl1.setText("My label");
  checkbox1 = new GCheckbox(this, 25, 210, 20, 20);
  dummy = new Dummy(this, width / 2, height / 2);
}

void draw() {
  pushMatrix();
  background(0);
  fill(255, 255, 0);
  text(width, 10, 20);
  text(height, 10, 40);
  fill(0, 255, 0);
  text(mouseX, 210, 20);
  text(mouseY, 210, 40);

  translate(width/2, height/2);
  fill(0, 0, 255); 

  ellipse(0, 0, 50, 50);
  popMatrix();
}

void keyTyped() {
  if (key == '2')
    surface.setSize(width + 20, height + 20);
  if (key == '1')
    surface.setSize(width - 20, height - 20);
}

// Use this to simulate a G4P control
public static class Dummy {

  int px, py;
  PApplet papp;

  Dummy(PApplet papp, int px, int py) {
    this.papp = papp;
    this.px = px;
    this.py = py;
    this.papp.registerMethod("draw", this);
  }

  public void draw() {
    println(papp.millis());
    papp.pushStyle();
    papp.pushMatrix();
    papp.translate(px, py);
    papp.fill(192, 0, 0, 128);
    papp.stroke(255, 0, 0, 128);
    papp.rectMode(CENTER);
    papp.rect(0, 0, 120, 120);
    papp.popMatrix();
    papp.popStyle();
  }
}
1 Like

I have raised a ticket on Sourceforge and will investigate further when I get the time.

1 Like

that is great :smiley: :ok_hand:
my project should have only one window so i will go on with one window with a fixed size until the ticket ist done.
Since i know now where the problem is :face_with_hand_over_mouth: i solved that with making a P3D (nub) on top of a 2D canvas. I placed than the G4P controls on 2D and it works. But there is a small issue with that: when i resize my fixed sketch size to a much more bigger screen, my objects loos visually (pixels)a little bit their original dimensions :thinking:
Please let me know when the ticket is done.
Thank you again and have a successful week :man_technologist:

1 Like

The fix is in :wink:

The problem is fixed with version 4.3.2 I have uploaded the new release but might take ~24hours before the Contribution Manager notices it and can install it.

1 Like

Thank you so much :laughing: :muscle:

I made a mistake and forgot to upload the new version for Processing to find. I have just discovered it an corrected the problem so it should be available in the contributions Manager in about 24hours.

thank you for the information :smile: i didn t check it yet, because im still having some problems without my sketch code. After i solve all the problems i will make a new GUI with G4P Builder with the new Version :hugs: