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 › Get current ellipse mode
Page Index Toggle Pages: 1
Get current ellipse mode? (Read 550 times)
Get current ellipse mode?
Mar 10th, 2009, 9:15pm
 
So I can set the ellipse mode with ellipseMode(), but is there any way to _get_ the current mode?

This would be nice so that classes which need to do drawing in a particular mode can avoid having side-effects on later code.  What I want is:

Class foo {
 void someMethod()
 {
   mode = GetCurrentEllipseMode();  // remember the current mode
   ellipseMode(CENTER); // set the mode I want
   ellipse(...); // draw something.
   ellipseMode(mode); // restore the old mode before returning.
 }
}

Any way to do this?
Re: Get current ellipse mode?
Reply #1 - Mar 10th, 2009, 9:52pm
 
From PGraphics.java:

 /** The current rect mode (read-only) */
 public int rectMode;
 /** The current ellipse mode (read-only) */
 public int ellipseMode;
 /** The current shape alignment mode (read-only) */
 public int shapeMode;
 /** The current image alignment (read-only) */
 public int imageMode = CORNER;

Of course, if all classes set the mode before drawing, it is unnecessary. Except for code that you don't own (libraries...).
Re: Get current ellipse mode?
Reply #2 - Mar 10th, 2009, 10:28pm
 
Hm.  "int curEllipse = PGraphics.ellipseMode;" gives me "cannot make a static reference to the non-static field PGraphics.ellipseMode."  Sorry if this is a dumb question, but should I be accessing it differently?  

And yes, the class will (if I go that far) become part of a library which is why I'm worried about it.

Similarly, what about getting the current fill and stroke values?
Re: Get current ellipse mode?
Reply #3 - Mar 10th, 2009, 11:46pm
 
try:

Code:
int curEllipse=g.ellipseMode;
Re: Get current ellipse mode?
Reply #4 - Mar 11th, 2009, 7:42am
 
Actually, I come here thinking of a better solution, answering your second question as well: fry recently added pushStyle() and popStyle() to Processing, it addresses nicely and in a complete way your concerns of isolation of modes/states.
Re: Get current ellipse mode?
Reply #5 - Mar 11th, 2009, 5:32pm
 
Oh, yes, that's just the ticket.  I love it when people get these features implemented before I even ask for them.  :)
Page Index Toggle Pages: 1