Make 2nd PApplet window fullscreen

edited April 2014 in How To...

With the following code i have 2 windows. The default one get's fullscreen and the other one get's not. But for me it would be a lot easier if it would be the other way around. Is that possible? I tried some things but none of them worked.

import java.awt.Frame;

// run with command + r !!!
boolean sketchFullScreen = true;


// ----------------------------

PFrame f;
SecondApplet s;

void setup() {
  size(displayWidth, displayHeight);
  PFrame f = new PFrame(100, 100, 800, 600);
}

void draw() {
  background(255, 0, 0);
  fill(255);
  rect(10, 10, frameCount, 10);

  /*
  s.background(0, 0, 255);
   s.fill(100);
   s.rect(10, 20, frameCount, 10);
   s.redraw();
   */

  s.redraw();
}

public boolean sketchFullScreen() {
  return sketchFullScreen;
}

// . . . . . . . . . . . . . . . . . . .

public void mousePressed() {
  println("mousePressed window 1");
}

// . . . . . . . . . . . . . . . . . . .


public void mouseMoved() {
  println("mouseMoved window 1");
}

// . . . . . . . . . . . . . . . . . . .

public class PFrame extends Frame {

  public PFrame(int x, int y, int width, int height) {
    setBounds(x, y, width, height);
    s = new SecondApplet();
    add(s);
    s.init();
    show();
  }
}

// . . . . . . . . . . . . . . . . . . .


public class SecondApplet extends PApplet {
  public void setup() {
    //size(400, 300);
    //println(displayWidth);
    size(displayWidth, displayHeight);
    noLoop();
  }

  public void draw() {
    background(0, 0, 255);
    fill(100);
    rect(10, 20, frameCount, 10);
    redraw();
  }

  public void mousePressed() {
    println("mousePressed window 2");
  }

  public void mouseMoved() {
  println("mouseMoved window 2");
}
}
Tagged:

Answers

  • edited May 2014

    My experiment w/ 3 PApplet instances:

    /**
     * Cursor Keys (v2.40)
     * by  DebIanAddict (2014/Feb)
     * mod GoToLoop
     *
     * forum.processing.org/two/discussion/3231/
     * void-draw-unexpected-token
     *
     * forum.processing.org/two/discussion/4121/
     * make-2nd-papplet-window-fullscreen
     */
    
    static final int DIM = 56, CURVE = 8;
    static final color ON = #00FF00, OFF = 0;
    
    static boolean MakeFullScreenOnce;
    static int instantiationDelay;
    
    boolean north, south, east, west;
    int id;
    
    static final void main(String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      PApplet.main(splitTokens(sketch + " 0"));
    
      MakeFullScreenOnce = true;
      instantiationDelay = 2500;
      PApplet.main(splitTokens(sketch + " 1"));
    
      PApplet.main(splitTokens(sketch + " 2"));
    }
    
    boolean sketchFullScreen() {
      delay(instantiationDelay);
    
      return MakeFullScreenOnce
        ? !(MakeFullScreenOnce = false) : false;
    }
    
    void init() {
      id = int(args[args.length - 1]);
      super.init();
    }
    
    void setup() {
      size(
      id != 1? 400 : displayWidth, 
      id != 1? 400 : displayHeight, 
      JAVA2D);
    
      frameRate(30);
      noLoop();
      smooth(4);
    
      rectMode(CORNER);
      noStroke();
    
      background(id != 1? #0AF5E3 : #E3F50A);
      frame.setTitle(frame.getTitle() + " #" + id);
    
      if (id != 1)  thread("repositionCanvas");
    }
    
    void repositionCanvas() {
      while (!frame.isVisible())  delay(5);
    
      frame.setLocation(id == 0
        ? width>>1 : displayWidth - width*2
        , height>>1);
    }
    
    void draw() {
      fill(north? ON:OFF);
      rect(180, 120, DIM, DIM, CURVE);
    
      fill(south? ON:OFF);
      rect(180, 190, DIM, DIM, CURVE);
    
      fill(west? ON:OFF);
      rect(110, 190, DIM, DIM, CURVE);
    
      fill(east? ON:OFF);
      rect(250, 190, DIM, DIM, CURVE);
    }
    
    void keyPressed() {
      setDirection(keyCode, true);
      redraw();
    }
    
    void keyReleased() {
      setDirection(keyCode, false);
      redraw();
    }
    
    void setDirection(int k, boolean bool) {
      if      (k == UP    | k == 'W')   north = bool;
      else if (k == DOWN  | k == 'S')   south = bool;
      else if (k == LEFT  | k == 'A')   west  = bool;
      else if (k == RIGHT | k == 'D')   east  = bool;
    }
    
  • edited April 2014

    I only see 2 applets instead of 3. Anyway thanks, i saw the code when you posted 2 and i already was trying stuff with that. Your way of having multiple windows is so much easier to work with!

    O yeah, why do you have the delay? I have the same result without the delay (only faster).

    And how does your repositionCanvas work? Isn't there a change frame.getX() actually is 0 and therefor it hangs in a loop? and the >> ?

    while (frame.getX() == 0)  delay(5);
    
      frame.setLocation(id == 0
        ? width>>1 : displayWidth - width*2
        , height>>1);
    
  • I have a small monitor, and a big monitor which is my main one. I want fullscreen on the small one. This is really hard :( Specially since it's not possible to toggle fullscreen (that would be so handy).

    In preferences there is this option: Screen Shot 2014-04-04 at 11.03.33 PM

    I figured it get's ignored as soon as you use:

    static final void main(String[] args) {
      final String sketch = Thread.currentThread()
        .getStackTrace()[1].getClassName();
    
      PApplet.main(sketch, append(args, "0"));
    }
    

    So my guess is that it needs to be parsed on which window it should run.

    I found some code for it in here: https://github.com/processing/processing/blob/416f2e5b99f38f0c350e0f2bc4e39563cb5dbbaa/app/src/processing/app/Preferences.java

    But that's only for the preferences window. I have to sleep asap. Just dropping what i know so far in case someone can complete me.

  • edited April 2014

    O yeah, why do you have the delay()?

    That code is my testbed in researching how sketches are instantiated & initialized internally. :-B
    You can peruse it by yourself too:
    https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java

    Static field instantiationDelay is just a experiment and a way to be aware when each PApplet is created!
    Just comment out lines #26 and/or #33, so instantiationDelay keeps its initial 0 value or delay() never happens! :ar!

    Isn't there a change frame.getX() actually is 0 and therefore it hangs in a loop?

    Inside setup(), both getX() & getY() are 0. Function repositionCanvas() is invoked as a separate thread("").
    And awaits till Processing setLocation() by itself, hopefully setting both getX() & getY() to another non-0 coordinates!

    Of course, when (id == 1), which is the fullscreen PApplet, repositionCanvas() isn't called at all! :-j
    But then you've given me another idea. Method getX() isn't safe. Instead, method isVisible() is much more logic! :-bd

    And the >> ?

    It's the bitwise right-shift operator -> processing.org/reference/rightshift.html
    The effect of >> 1 is the same as /2 for whole values! :bz

  • edited April 2014

    I figured it gets ignored as soon as you use:

    Theoretically, since append() is used on args, no previous entries are lost:
    http://processing.org/reference/append_.html

    However, I dunno how to make passed arguments at command line to work at all.
    I've tried out "--location=100,300", which corresponds to constant field ARGS_LOCATION, but it got ignored! :o3
    That's why I've made my own repositionCanvas() function! :-w

    I want fullscreen on the small one.

    Theoretically, "--display=1", which corresponds to ARGS_DISPLAY, passed argument would work.
    But in my Processing v2.0.2, that is ignored as well! Try it out for yourself. Who knows?

    final String[] deviceArg = {
      "--display=1", "1"
    };
    
    MakeFullScreenOnce = true;
    
    PApplet.main(sketch, concat(args, deviceArg));
    
  • Thanks, The bitshift /2 is cool to know, i only used it for getting colors.

    I looked in the arguments yesterday as well. http://forum.processing.org/two/discussion/4140/use-displayn-command#Item_1 I have the same problem.

    Around line 10534 is where ARGS_DISPLAY get handled but i'm still looking for a way to get into it. I will give an update later. https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java

    Do you use mac or windows? (i'm on a mac 10.9.2).

    And why do you use Processing v.2.0.2?

  • Processing 2.0.2, Lubuntu 13.04, 64-bit OpenJDK 7.u51, GeForce 9800GT.

Sign In or Register to comment.