We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › fullscreen toggle on/off
Page Index Toggle Pages: 1
fullscreen toggle on/off (Read 929 times)
fullscreen toggle on/off
Jul 23rd, 2007, 3:30am
 
hi, i'd like to be able to toggle in and out of fullscreen at will. here is my code at the moment, which seems to work. but i'm clearly doing something wrong because eventually this eats up memory and gives a java heap error. so if someone could correct my ways, i would be most appreciative

Code:
import processing.core.PApplet;

public class Fullscreen extends PApplet {
 public static boolean FULL_SCREEN = false;
 public static final String[] OPTIONS_WINDOWED = { "Fullscreen" };
 public static final String[] OPTIONS_FULLSCREEN = { "--present", "Fullscreen" };

 public void setup() {
   size(800,600);
 }

 public void draw() {
   background(255);
   line(mouseX,mouseY,random(width),random(height));
 }

 public static void main(String[] args) {
   if(FULL_SCREEN) {
     PApplet.main(OPTIONS_FULLSCREEN);
   } else {
     PApplet.main(OPTIONS_WINDOWED);      
   }
 }
 
 public static void toggleFullscreen(PApplet papplet) {
   FULL_SCREEN = !FULL_SCREEN;
   papplet.frame.dispose();
   Fullscreen.main(null);
 }

 public void keyReleased() {
   if (key == 'f') { Fullscreen.toggleFullscreen(this); }
 }
}

Re: fullscreen toggle on/off
Reply #1 - Jul 23rd, 2007, 2:36pm
 
that's just gonna re-launch the applet in each mode whenever you call Fullscreen.main()... the dispose() isn't enough to shut things down properly, so you're running out of space since the other copies of the applet are still running.

your best bet is to call:

frame.setResizable(true);

and then call frame.setBounds(0, 0, screen.width, screen.height), or frame.setBounds(400, 400, 200, 200) to resize it smaller.
Re: fullscreen toggle on/off
Reply #2 - Jul 23rd, 2007, 4:21pm
 
thanks that works great.

just for the record here is the corrected code. it's a separate class that can just be called from the papplet like this:

  Fullscreen.toggle(this);

note there are a few things also to be aware of:

1) smooth seems to get undone by any resizing of the frame, so i also call smooth() once a second from within draw() -- i dont' think this costs anything to call frequently since it's just setting a boolean, but someone correct me if i'm wrong. (nothing happened if i called `papplet.smooth();` from the toggle method, so easier to just override it centrally.)

2) mac os has about 21 pixels of chrome on the top of of the screen, so it's also helpful to compensate for that in setLocation and setSize. i haven't tested this on Windows, so not sure how it works there..

Code:
import java.awt.Dimension;
import java.awt.Toolkit;
import processing.core.PApplet;

public class Fullscreen {
 private static boolean FULL_SCREEN = false;
 public static Dimension APP_SIZE = new Dimension(800, 600);
 
 private static void setChrome(PApplet papplet, boolean full) {
   papplet.frame.setUndecorated(full);
 }

 private static void setLocation(PApplet papplet, boolean full) {
   papplet.frame.setLocation(0, 0);      
 }

 private static void setSize(PApplet papplet, boolean full) {
   if (full) {
     papplet.frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
   } else {
     papplet.frame.setSize(APP_SIZE);
   }    
 }
   
 public static void toggle(PApplet papplet) {
   FULL_SCREEN = !FULL_SCREEN;
   papplet.frame.dispose();
   papplet.frame.setResizable(!FULL_SCREEN);
   setSize(papplet, FULL_SCREEN);
   setChrome(papplet, FULL_SCREEN);
   setLocation(papplet, FULL_SCREEN);
   papplet.frame.setVisible(true);
 }
}
Re: fullscreen toggle on/off
Reply #3 - Jul 23rd, 2007, 5:22pm
 
you can get that offset value via frame.getInsets(), so that it'll work consistently across other platforms.. or you can do the setUndecorated(true) hack that's found elsewhere on the board so that there isn't the extra stuff showing. to get rid of the macosx menubar check into the LSUIPresentationMode hack.

as for smooth(), any time that you call size(), you're gonna get a new renderer, so it'll obliterate any of your previous settings (smooth, strokeWeight, fill, etc). so just be sure to reset things as necessary. enabling smooth() isn't an expensive operation, so you're safe to just call it inside draw() or whatever. calling smooth() from the toggle won't work because the renderer won't yet be set up properly.
Page Index Toggle Pages: 1