New Line in String Text

edited March 2015 in How To...

Hello. So the problem that I'm having is developing a text box. I was able to find codes to make the initial box, however when I type in it, the first line goes on forever. How do I make it so that when it reaches the end of the box the text will start to flow on a new line?

Here is my code for reference:

PFont font, font2, font3;

int currentString = 0;
String current = "";
String art1T = "";
String art1B = "";

color white   = color(255,255,255);
color black   = color(0,0,0);
color darkRed = color(100,0,0);
color orange  = color(255,165,0);
color yellow  = color(255,255,0);
color green   = color(0,200,0);
color cyan    = color(0,225,225);
color blue    = color(0,50,255);
color purple  = color(225,0,225);
color currentColor;
color art1Tc= 50;
color art1Bc= 50;

int art1Tp;
int art1Bp;
int a = 0;
int b = 0;
int c = 0;

float circleX, circleXB, circleXC;
float circleY, circleYB;

void setup(){
  size(600,750,P3D);
  background(0);
  font = loadFont("TrajanPro3-Regular-20.vlw");
  font2 = loadFont("TimesNewRomanPSMT-24.vlw");
  font3 = loadFont("TimesNewRomanPSMT-16.vlw");
  frameRate(24);
}

void draw() {
  float art1Tp = textWidth (art1T);
    float art1Bp = textWidth (art1B);
   stroke(50);
    if (mouseX >= 60 && mouseX <= 540 && mouseY >= 40 && mouseY <= 65) {
      if(mousePressed){
        currentString = 1;
        current = art1T;
      }
    }   
    fill(art1Tc);
    rect(50,35,500,30,10);

    if (mouseX >= 60 && mouseX <= 540 && mouseY >= 120 && mouseY <= 600) {
      if(mousePressed){
        currentString = 2;
        current = art1B;
      }
    }
    fill(art1Bc);
    rect(50,110,500,500,10);
    if(currentString == 1){
      line(art1Tp+50, 40, art1Tp+50, 65);
      art1T = current;
      art1Tc= 150;
      art1Bc= 50;
    }else if(currentString == 2){
      line(art1Bp+50, 115, art1Bp+50, 140);
      art1B = current;
      art1Tc= 50;
      art1Bc= 150;
      }
    textFont(font);
    fill(255,0,0,255);
    text("Story Title",50,30);
    text("Tell Me Your Story",50,100);

    textFont(font2);
    fill(currentColor);
    text(art1T, 60, 60);

    textFont(font3);
    fill(currentColor);
    text(art1B, 60, 130);
}

    void keyPressed() {
  if (keyCode == BACKSPACE) {
    if (current.length() > 0) {
      current = current.substring(0, current.length()-1);
    }
  } 
  else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT) {
    current = current + key;
  }
}

Thank you guys, in advance, for your help!

Tagged:

Answers

Sign In or Register to comment.