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

**URL:** https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109
**Category:** Libraries
**Created:** [January 15, 2020, 10:37pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109 "2020-01-15T22:37:03Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![H\_Bacardi](https://avatars.discourse-cdn.com/v4/letter/h/6f9a4e/32.png) [@H\_Bacardi](https://discourse.processing.org/u/H_Bacardi)
#### Post date: [January 15, 2020, 10:37pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/1 "2020-01-15T22:37:03Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 16, 2020, 5:27pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/2 "2020-01-16T17:27:23Z")

</div>

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

```auto
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 😄

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 16, 2020, 5:38pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/3 "2020-01-16T17:38:37Z")

</div>

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**.

---

<div class="post-metadata">

### Author: ![H\_Bacardi](https://avatars.discourse-cdn.com/v4/letter/h/6f9a4e/32.png) [@H\_Bacardi](https://discourse.processing.org/u/H_Bacardi)
#### Post date: [January 17, 2020, 7:49pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/4 "2020-01-17T19:49:17Z")

</div>

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:

```auto
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 💪 👌

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 18, 2020, 1:02pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/5 "2020-01-18T13:02:53Z")

</div>

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.

```auto
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();
  }
}

```

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 18, 2020, 3:46pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/6 "2020-01-18T15:46:08Z")

</div>

I have raised a [ticket](https://sourceforge.net/p/g4p/tickets/37/) on Sourceforge and will investigate further when I get the time.

---

<div class="post-metadata">

### Author: ![H\_Bacardi](https://avatars.discourse-cdn.com/v4/letter/h/6f9a4e/32.png) [@H\_Bacardi](https://discourse.processing.org/u/H_Bacardi)
#### Post date: [January 21, 2020, 8:18pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/7 "2020-01-21T20:18:48Z")

</div>

that is great 😃 👌  
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 🤭 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 🤔  
Please let me know when the ticket is done.  
Thank you again and have a successful week 👨‍💻

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 22, 2020, 12:15pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/8 "2020-01-22T12:15:35Z")

</div>

The fix is in 😉

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.

---

<div class="post-metadata">

### Author: ![H\_Bacardi](https://avatars.discourse-cdn.com/v4/letter/h/6f9a4e/32.png) [@H\_Bacardi](https://discourse.processing.org/u/H_Bacardi)
#### Post date: [January 28, 2020, 10:06pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/9 "2020-01-28T22:06:01Z")

</div>

Thank you so much 😆 💪

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [February 5, 2020, 10:45am UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/10 "2020-02-05T10:45:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![H\_Bacardi](https://avatars.discourse-cdn.com/v4/letter/h/6f9a4e/32.png) [@H\_Bacardi](https://discourse.processing.org/u/H_Bacardi)
#### Post date: [February 7, 2020, 7:44pm UTC](https://discourse.processing.org/t/g4p-controls-loose-their-positions-in-proscene-while-resizing-the-window/17109/11 "2020-02-07T19:44:39Z")

</div>

thank you for the information 😄 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 🤗
