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 › Detecting Present Mode
Page Index Toggle Pages: 1
Detecting Present Mode? (Read 1476 times)
Detecting Present Mode?
Aug 14th, 2007, 7:52pm
 
can i determine in the code if Present has been used?

i have code such as

static boolean FULLSCREEN = true;
if (FULLSCREEN) {
 size(screen.width, screen.height);
} else {
 size(640, 480);
}

then use 'width' and 'height' for scaling my output to fit. however, this requires me to manually set FULLSCREEN as required and i'd like it to just know.

yes, i'm a noob, please be friendly 8)

cheers
andy
Re: Detecting Present Mode?
Reply #1 - Aug 15th, 2007, 11:08pm
 
you might try using frame.isUndecorated(), since in present mode, that will be set to true.
Re: Detecting Present Mode?
Reply #2 - Aug 16th, 2007, 7:28pm
 
ok, thanks.

i added

void setup() {
 println("Undecorated " + frame.isUndecorated());
...

and got

Undecorated false
Undecorated true

as output when running in Present Mode, two 'falses' when running in windowed mode.

why does setup run twice like that?
Re: Detecting Present Mode?
Reply #3 - Aug 17th, 2007, 12:49am
 
it runs twice so that we can dynamically change the renderer on the fly.. it's messy to just switch from the default (Java 2D) to something like OpenGL.

but do this check *after size()* and you should be fine, because only things before size() will run more than once. this is why size() must always be first in setup().
Re: Detecting Present Mode?
Reply #4 - Aug 17th, 2007, 11:02am
 
but it's the size i'm trying to change 8) are you saying i should change it twice, once to just force it into opengl mode, the second time to get it to correct size (if necessary)? i will try it.

does nobody else do this? should i be doing something else? or should i be doing something like using normalising my coords (-1 to 1, say) and then one scale to (width, height) later on? (and how will handle different aspet ratios?)

questions questions, sorry 8)

andy
Re: Detecting Present Mode?
Reply #5 - Aug 17th, 2007, 11:25am
 
import processing.opengl.*;

void setup() {
 println("setup1");
 size(640, 480, OPENGL);
 println("setup2");
 if (frame.isUndecorated()) {
   // present mode
   println("setup3");
   size(screen.width, screen.height, OPENGL);
 }
 println("setup4");
}

void draw() {
 translate(width / 2, height / 2);
 rotateX(PI / 4);
 rotateZ(PI / 4);
 box(width / 4);
}

in windowed mode i get 1, 1, 2, and 4 and a nice cube in a window.

in present mode i get 1, 1, 2, 3 and 4 and a corrupted screen, the default grey background on left and top sides, bottom right is white with scatterings of black (the cube, diced?)

winxp, java 1.5.0_11, processing 0125, ati...
Re: Detecting Present Mode?
Reply #6 - Aug 17th, 2007, 2:56pm
 
yikes, no.. i wouldn't don't do that. i would strongly discourage changing the size of an opengl renderer while it's running. the others are designed to behave correctly, but opengl usually won't play nice, and you'll get different results for different graphics cards, machines, etc.
Re: Detecting Present Mode?
Reply #7 - Aug 17th, 2007, 5:14pm
 
yeah, i'd noticed 8) annoying but not the end of the world.

thanks for the help.

andy
Re: Detecting Present Mode?
Reply #8 - Aug 19th, 2007, 10:18am
 
ben,

i ran into this quite often, so it think it would be generally nice to have a variable that holds the type of mode the sketch is running in. like:

switch ( presentationMode )
{
 case ONLINE:  // i know "online" is there for that  ..
 case PROCESSING: // started from inside Processing
 case STANDALONE:  // application
}

F
Re: Detecting Present Mode?
Reply #9 - Aug 20th, 2007, 1:01pm
 
in ./app/src/processing/app/Runner.java, the startPresenting() method there is the following:

params.add(PApplet.ARGS_PRESENT);

so it does add a '--present' flag to the command line arguments when running the papplet in present mode.

it uses this to set present = true. present is local to PApplet.main().

er, what this means i'm not sure 8) will look into it.

andy
Re: Detecting Present Mode?
Reply #10 - Aug 22nd, 2007, 12:17am
 
With the next revision of Processing, it would really be great if we could eliminate this difficulty everyone is experiencing regarding these two things:  detecting the mode (processing, online, present) and setting the size() accordingly.

Ideally, in order for one Processing sketch to run properly (without modification) in all 3 modes, we'd like to be able to do the following:

if (present) {
get screen.width, screen.height
optionally set size to match the screen,
or to a smaller size
} else if (online) {
indicate the default width+height we would like to "Export" in INDEX.HTML, but at runtime, we'd like to get the ACTUAL width+height in <OBJECT> (or in <PARAM>)
so the HTML could be modified without needing to re-export the sketch just to update the size
} else if (processing) {
we just call size(w,h) for a desired width+height
}

I understand from fry's postings on this topic, this is not a trivial request.

Perhaps this logic could be included in a more sophisticated "size()" function.

For example, fancySize(w1,h1, w2,h2, w3,h3)
could mean:
if (processing) use size(w1,h1)
if (online) use size(w2,h2)
if (present) use size(w3,h3)
... with the additional logic that specifying w=0,h=0
asks to GET the width+height from the environment,
so that "online" the values come from the OBJECT/PARAM
and for "present" the values come from the screen.width,screen.height

I am not saying my suggestion is the best way.
I just mean to emphasize that a lot of people would appreciate a solution to this issue.
Perhaps someone else has a more elegant solution.

Better still, ... perhaps an expert Java coder out there could provide working example code to update Processing that Casey and Ben could consider for inclusion in the next release.

... just a wish,
 djones

fjen wrote on Aug 19th, 2007, 10:18am:
ben,

i ran into this quite often, so it think it would be generally nice to have a variable that holds the type of mode the sketch is running in. like:

switch ( presentationMode )
{
 case ONLINE:  // i know "online" is there for that  ..
 case PROCESSING: // started from inside Processing
 case STANDALONE:  // application
}

F

Re: Detecting Present Mode?
Reply #11 - Aug 22nd, 2007, 1:53pm
 
the best way to get things implemented is of course to write the code as you mention, but regardless of that, use the bugs db to file your request as an "enhancement", which will mean it will be in the queue for consideration/possible implementation.
Re: Detecting Present Mode?
Reply #12 - Aug 22nd, 2007, 9:00pm
 
FWIW, just a thought:  Perhaps it would be useful (?) if there were a "metatag" way of specifying the applet size in the absense of hardcoded values in size().  That way the applet-sizer-html-writer code could "know" the size for the export, but could still have a size() statement with discovered variable values.  Syntax could vary widely (and isn't important) but something like:

// the "//P5:" would be a special "hint" comment
// tag indicating special parsing is required
// (in its absense would continue as before to
// look for a real size(const,const) statement)

// specify desired dimensions:
//P5:  size(400,300);

// get actual dimensions:
w = blah.getWidth();
h = blah.getHeight();
size(w,h); // no constants, so not used by applet-exporter
Page Index Toggle Pages: 1