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 › "undo" noStroke()
Page Index Toggle Pages: 1
"undo" noStroke() (Read 1347 times)
"undo" noStroke()
Sep 8th, 2008, 7:57pm
 
I am trying to write a reusable function to draw a texture mapped shape without the outline, and then restore to the state (color, width) before the call.  In other words I want to undo noStroke().  

Any suggestions on how to do this?
Thanks...
Re: "undo" noStroke()
Reply #1 - Sep 9th, 2008, 11:07am
 
A dirty way is to use:

 g.stroke = true;

It is the exact counterpart of noStroke() action.
It is dirty because this public variable is marked (in a comment) as "read-only"...
Not sure if there is a cleaner way (there should be a pushContext()/popContext(), perhaps, to save and restore stroke/fill/weight/etc. info).
Re: "undo" noStroke()
Reply #2 - Sep 9th, 2008, 3:33pm
 
Thanks very much.  Saving and restoring g.stroke does the trick.  The Javadoc fooled me into thinking it was read-only.

I'm trying to write a library; something like push/popContext() might be less vulnerable to changes in PGraphics.


Re: "undo" noStroke()
Reply #3 - Sep 9th, 2008, 7:03pm
 
nope, they *are* read-only, you'll get different results depending on the renderer. no foolin'. (now you behave, otherwise i'll take em away or make you use an accessor method.)

the proper method is to use:
Code:
boolean savedStroke = g.stroke;
int savedStrokeColor = g.strokeColor;


then to restore:
Code:
if (savedStroke) {
stroke(savedStrokeColor);
} else {
noStroke();
}


we're likely adding a push()/pop() like you describe, perhaps even in time for 0149, since it's generally useful and needed internally as well. the amount of state info is quite large.
Re: "undo" noStroke()
Reply #4 - Sep 9th, 2008, 9:55pm
 
Thanks, I'll follow your advice. Dire measures are unnecessary Smiley
Re: "undo" noStroke()
Reply #5 - Sep 10th, 2008, 7:22am
 
This may become redundant in the light of Fry's comment about version 149, but I have been using my own style stack for this purpose. I think it covers all the rendering style settings available, but I may have missed a few of the less common ones.
Re: "undo" noStroke()
Reply #6 - Sep 10th, 2008, 2:01pm
 
Thanks Jo, StyleStack looks pretty thorough; I could see myself (ab)using it just to call PeekStyle().  I'll be reading your mouse sensitive shapes and zoom/pan code for inspiration as well.
Re: "undo" noStroke()
Reply #7 - Feb 11th, 2009, 1:35am
 
Thanks for Style Stack!  I might give it a go to see how it works... I'm finding myself implementing a light scene graph in my latest processing project so i was looking around for something like pushMatrix/popMatrix.  

popStyle, popStyle!
Re: "undo" noStroke()
Reply #8 - Feb 11th, 2009, 1:23pm
 
ilazarte, I am not too sure on how to interpret your comment.

But for reference for this thread, I will point that fry followed up his comment and introduced indeed pushStyle() and popStyle().
Re: "undo" noStroke()
Reply #9 - Feb 12th, 2009, 2:33am
 
great, that was new to me... maybe i should read whats new in version 1,0 and save alot of time. table with all new commands? couldnt find one?
Re: "undo" noStroke()
Reply #10 - Feb 12th, 2009, 11:21am
 
Ah? Indeed, I couldn't find push/popStyle neither in the list of changes nor in the list of revisions linked from the download list. Perhaps a little involuntary omission?
Re: "undo" noStroke()
Reply #11 - Feb 12th, 2009, 1:33pm
 
I'll just take this opportunity to thank Fry for push/popStyle().  They make it so much easier to have objects, each with their own .draw() method.
--
Tom
Page Index Toggle Pages: 1