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 › Handle to screen object
Page Index Toggle Pages: 1
Handle to screen object? (Read 306 times)
Handle to screen object?
Jul 9th, 2009, 9:45am
 
In a processing app that I'm writing, I have a function that does a bunch of drawing to the screen.  However, I also want to be able to draw to a PGraphics object.  I can have a function parameter that is the graphics object to draw to, but the problem I'm running into is in the syntax.  Specifically, I have to have code like:

if (canvas==null) {
   //draw to screen
   line(...);
} else {
  //draw to PGraphics object
  canvas.line(...);
}

When, really, it would be nice to just have at the top of the function
if (canvas==null) { canvas = screenHandle; }
and then everywhere I could just draw to the canvas as normal.

But, is there a way to get this handle to the screen to draw to?

Thanks!
Re: Handle to screen object?
Reply #1 - Jul 9th, 2009, 4:56pm
 
You can find it in the Developer's reference to Processing. It's really pretty simple: you'll find it in the PApplet member "g".

Code:

void setup () {}
void draw () {
 drawCoolStuff(g); // draws cool stuff to the screen
}

void drawCoolStuff (PGraphics context)
{
 context.beginDraw();
 // draw some stuff
 context.endDraw();
}
Re: Handle to screen object?
Reply #2 - Jul 10th, 2009, 10:40am
 
Perfect!  Thanks, I would never have found that on my own.
Page Index Toggle Pages: 1