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 › Trying to make a text box – how to erase text
Page Index Toggle Pages: 1
Trying to make a text box – how to erase text? (Read 2571 times)
Trying to make a text box – how to erase text?
Apr 4th, 2008, 10:41am
 
I am new to Processing and struggling to find information on what I think should be pretty basic stuff. I would appreciate help finding out how erase text on the screen.

A search turned up this thread: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1196575108;start=0#0 but I find it hard to believe there is no simpler mode for overwriting text

textMode(SCREEN) sounded promising but I could find little info on how to use it and the code I tried didn’t display anything.

I would really appreciate seeing some example code for writing, overwriting and clearing individual word or lines of text on the screen.


Thanks in advance.
Re: Trying to make a text box – how to erase text?
Reply #1 - Apr 5th, 2008, 4:07pm
 
You need to remove the last character in the string then completely redraw the text box. That's about as simple as it'll get. Here's the code I used for an acrostic. Hope it helps!

noLoop();

//adds text to the screen as it is being typed
void keyPressed() {

 //deletes a mistype or typo
 if (key == BACKSPACE) {
   if (typed.length() > 0) {
     typed = typed.substring(0, typed.length()-1);

     fill (0);//changes the fill to the background color

     rect(140, 100, 640, 480);//creates a rectangle fill the above fill
   
fill (255, 255, 255);//changes the fill back to white for the redraw
     redraw();
   }
 }

 //generates the new line if enter is presses
 else if (key == ENTER) {
   typed = typed+"\n";
 }

 //generates the text on screen
 else if (textWidth(typed+key) < width){
   typed = typed+key;
   redraw();
 }
Re: Trying to make a text box – how to erase text?
Reply #2 - Apr 5th, 2008, 4:46pm
 
It looks like that code still needs to explicitly erase the screen area and then redraw. For an environment that seems to have been around for a while, I was surprised I couldn’t find a processing library object that had the basic support for text caption functionality

Many thanks for taking the time to respond
Re: Trying to make a text box – how to erase text?
Reply #3 - Apr 6th, 2008, 3:33pm
 
I think you're confused about how processing works, you can't just simply add a text box or something and leave it to be rendered every loop, you have to draw everything to the screen every loop.

Thankfully with clever use of classes, it's not too hard to do.
Re: Trying to make a text box – how to erase text?
Reply #4 - Apr 7th, 2008, 11:15am
 
Manic, thanks for the reply. No, I do get what Processing does, I am only confused by the lack of a pre-existing class to do something that I would have thought would be generally useful. It’s no problem building a class for displaying a text box, just surprising to hear that its not in a standard Processing library.
Re: Trying to make a text box – how to erase text?
Reply #5 - Apr 7th, 2008, 7:09pm
 
aah sorry for the misunderstanding, well no its not a standard library, but there is the p5 control library, which is pretty much the accepted standard:

http://www.sojamo.de/libraries/controlP5/
Re: Trying to make a text box – how to erase text?
Reply #6 - Apr 7th, 2008, 10:05pm
 
Thanks for the link, I will have a look at that library

edit:
Had a look and its very impressive, just the kind of thing I was looking for.

Thanks again for the tip.
Page Index Toggle Pages: 1