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 › Retrieving graphics attributes
Page Index Toggle Pages: 1
Retrieving graphics attributes? (Read 416 times)
Retrieving graphics attributes?
Jul 23rd, 2008, 1:44pm
 
Is it possible to retrieve the 'current' graphics attributes used by Processing at runtime? In particular, any of the following:

rectMode
ellipseMode
strokeWeight
strokeJoin
strokeCap
smooth/noSmooth

I need this because I would like to be able to temporarily modify these attributes for specific drawing operations but then return them to their previous values.

I realise that I could create my own variables that stored the state of each and then called the relevant Processing method in response to these variables, but I just wanted to check I wasn't missing something.

On a similar theme is it possible to detect which of  P2D,P3D,OPENGL is currently set? I need this because some operations fail at run-time in certain modes (e.g. smooth() in P3D). This is slightly more complicated because Processing insists that size() is the first line of setup(), so initialising a variable at run-time with this value is more difficult.

Thanks.
Re: Retrieving graphics attributes?
Reply #1 - Jul 23rd, 2008, 2:22pm
 
You can use something like if(g instanceof processing.opengl.PGraphicsOpenGL) (or processing.core.PGraphics3D etc) to check what mode you're in.
Re: Retrieving graphics attributes?
Reply #2 - Jul 23rd, 2008, 8:28pm
 
println("rectMode: " + g.rectMode);
println("ellipseMode: " + g.ellipseMode);
println("strokeWeight: " + g.strokeWeight);
println("strokeJoin: " + g.strokeJoin);
println("strokeCap: " + g.strokeCap);
println("smooth: " + g.smooth);

Looks like it works...
Re: Retrieving graphics attributes?
Reply #3 - Jul 23rd, 2008, 10:17pm
 
Great - thanks.

I hadn't realised that g was exposed. Does anyone know if using g in this way (and for the instanceof approach mentioned by JohnG) is 'officially' approved? I ask because I can't see any obvious documentation about using it and don't want go too far down that route if it later becomes deprecated or hidden.



Re: Retrieving graphics attributes?
Reply #4 - Jul 23rd, 2008, 10:48pm
 
While this is a question that only Ben can answer authoritatively, if I had to guess, the case will be that for the foreseeable future, g will continue to be exposed, however its use is not officially approved in the sense that a) bug reports relating to its use will not be very high priority, b) no efforts will be made to make it very easy, and c) if some compelling reason comes up in the future to limit access, that might happen.

However, the general approach up until now has been to leave most of this stuff accessible but undocumented for the handful of advanced users that know what to do with it, and I doubt that will change any time soon.
Re: Retrieving graphics attributes?
Reply #5 - Jul 24th, 2008, 4:31pm
 
As said by ewjordan...
I will add that if variables are made public in the code, it is voluntarily done to ease their access without multiplying the access functions. I mean, that's not a design flaw, so it is unlikely to change.
Page Index Toggle Pages: 1