FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Bugs
   Software Bugs
(Moderator: fry)
   error code
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: error code  (Read 261 times)
christian


error code
« on: Nov 15th, 2003, 4:47pm »

// Typing (Excerpt from the piece Textension)
// by Josh Nimoy <http://www.jtnimoy.com>
 
// Click in the window to give it focus.
// Type to add letters and press backspace to delete.
 
// Created 27 January 2003
 
BFont f;
int leftmargin = 10;
int rightmargin = 20;
String buff = "";
boolean didntTypeYet = true;
 
void setup()
{
  size(200, 200);
  // Load the font. Fonts are located within the  
  // main Processing directory/folder and they
  // must be placed within the data directory
  // of your sketch for them to load
  f = loadFont("Univers45.vlw.gz");
  textFont(f, 25);
}
 
void loop()
{
  background(176);
   
  if(millis()%500<250){  // Only fill cursor half the time
    noFill();
  }else{
    fill(255);
    stroke(0);
  }
  float rPos;
  // Store the cursor rectangle's position
  rPos = f.width(buff)+leftmargin;
  rect(rPos+1, 19, 10, 21);
 
  // Some instructions at first
  if(didntTypeYet){
    fill(0);
    text("Use the keyboard.", 22, 40);
  }
   
  fill(0);
  push();
  translate(rPos,10+25);
  char k;
 
  for(int i=0;i<buff.length();i++){
    k = buff.charAt(i);
    translate(-f.width(k),0);
    text(k,0,0);
    if(-f.width(k)<rightmargin){
     
    }
     
  }
  pop();
}
 
void keyPressed()
{
  char k;
  k = (char)key;
  switch(k){
    case 8:
    if(buff.length()>0){
 buff = buff.substring(1);
    }
    break;
    case 13:  // Avoid special keys
    case 10:
    case 65535:
    case 127:
    case 27:
    break;
    default:
    if(f.width(buff+k)+leftmargin < width-rightmargin){
 didntTypeYet = false;
 buff=k+buff;
    }
    break;
  }
}
 
mKoser

WWW Email
Re: error code
« Reply #1 on: Nov 15th, 2003, 5:23pm »

just debugged the code you posted, and commented out a few lines which caused the error!
 
Code:

// Typing (Excerpt from the piece Textension)
// by Josh Nimoy <http://www.jtnimoy.com>
 
// Click in the window to give it focus.
// Type to add letters and press backspace to delete.
 
// Created 27 January 2003
 
BFont f;
int leftmargin = 10;
int rightmargin = 20;
String buff = "";
boolean didntTypeYet = true;
 
void setup()
{
  size(200, 200);
  // Load the font. Fonts are located within the
  // main Processing directory/folder and they
  // must be placed within the data directory
  // of your sketch for them to load
  f = loadFont("Univers45.vlw.gz");
  textFont(f, 25);
}
 
void loop(){
  background(176);
 
  if(millis()%500<250){  // Only fill cursor half the time
    noFill();
  }else{
    fill(255);
    stroke(0);
  }
  float rPos;
  // Store the cursor rectangle's position
  rPos = f.width(buff)+leftmargin;
  rect(rPos+1, 19, 10, 21);
 
  // Some instructions at first
  if(didntTypeYet){
    fill(0);
    text("Use the keyboard.", 22, 40);
  }
 
   
  fill(0);
  push();
  translate(rPos,10+25);
  char k;
   
  for(int i=0;i<buff.length();i++){
    k = buff.charAt(i);
    translate(-f.width(k),0);
    text(k,0,0);
     
     
 
 
    // THIS WAS CAUSING THE ERROR!
    //if(-f.width(k)<rightmargin){    
    //}
     
 
     
  }  
  pop();  
}
 
void keyPressed()
{
  char k;
  k = (char)key;
  switch(k){
    case 8:
    if(buff.length()>0){
 buff = buff.substring(1);
    }
    break;
    case 13:  // Avoid special keys
    case 10:
    case 65535:
    case 127:
    case 27:
    break;
    default:
    if(f.width(buff+k)+leftmargin < width-rightmargin){
 didntTypeYet = false;
 buff=k+buff;
    }
    break;
  }
}

 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
fry


WWW
Re: error code
« Reply #2 on: Nov 23rd, 2003, 11:40pm »

i'm a little confused... is this a p5 bug or was it just something in the code?
 
Pages: 1 

« Previous topic | Next topic »