g4p new window

edited January 2016 in Library Questions

Hello I am looking for the best way how to create a new window in processing. I search for many solution and I find using g4p. I tried a little code to find out how does it work but I don't know what I am doing wrong. Later I would like to make 2 windows. In one sliders on the other changing graphic. But for now it seems I cant handle the first window. in this code the cursor should change on rect but it just blinking or doing nothing.

import g4p_controls.*;
GWindow Screen;

void setup() {
  size(400, 320, P2D);
  Screen =  GWindow.getWindow(this, "Fullscreen", 100, 50, 480, 320, P2D);
}
void draw() {
  background(230);
  rectMode(CENTER);
  rect(100, 100, 100, 100);

  if (dist(100, 100, mouseX, mouseY) < 50) {
    cursor(HAND);
  } else {
    cursor(ARROW);
  }
  Screen.addDrawHandler(this, "windowDraw");
}
public void windowDraw(PApplet app, GWinData data) {
  app.background(255);
  app.strokeWeight(2);
  app.stroke(0);
  app.line(app.width / 2, app.height/2, app.mouseX, app.mouseY);
}

Answers

  • I have correctly formatted your original post so we can see the code. The single apostrophe is for single line or in-line code, for multiple lines of code it should be indented by 4 paces. Check this post to find out how to format your code.

    The G4P library takes control over cursor image so it can change it when the mouse passes over a control such as a slider, which explains why you can't change it.

    In your code there is a mistake, line 18 should be in the setup method like this.

    import g4p_controls.*;
    GWindow Screen;
    
    void setup() {
      size(400, 320, P2D);
      Screen =  GWindow.getWindow(this, "Fullscreen", 100, 50, 480, 320, P2D);
      Screen.addDrawHandler(this, "windowDraw");
    }
    
    void draw() {
      background(230);
      rectMode(CENTER);
      rect(100, 100, 100, 100);
    }
    
    public void windowDraw(PApplet app, GWinData data) {
      app.background(255);
      app.strokeWeight(2);
      app.stroke(0);
      app.line(app.width / 2, app.height/2, app.mouseX, app.mouseY);
    }
    

    If you want to create GUIs with G4P then I strongly recommend that you install the G4P GUI Builder tool from the Tools menu. This tool is a visual GUI designer tool for G4P. My website has a number of video guides showing how to use it.

Sign In or Register to comment.