Ok here is a start.
I guess I need to add a few steps for it to do what I want.
1. add mouse pressed code so text can be entered for each box
2. no typing will display unless mouse is pressed in that field.
3. need blinking cursor where text is to be entered.
4. need to convert lastInput to a value.
This code is just an experiment to test the display of the time. That part works. Now I just need to convert the input to a value, plug in a formula for it to display the time.
I going to try to enter a number, and when that number is equal to the seconds, then display the time.
Basically if(dis_s=lastInput){
text(...time..., float,float);
}
so if I enter 20, at 20 seconds, "00:20" should print on the adjacent box. But as it is now, the lastInput is not a value.
Code:
int dis_m, dis_s;
boolean startcount = false;
PFont font10;
PFont font24;
int TimeLapse = 0;
int StartTime;
float String;
String lastInput = new String();
String currentInput = new String();
void setup()
{
//setup fonts for use throughout the application
font10 = loadFont("Verdana-10.vlw");
font24 = loadFont("Verdana-24.vlw");
size(600,200);
background(255,255,255);
}
void draw()
{
textFont(font10);
stroke(0);
fill(255);
rect(10,18,50,15);// temp input rect
textAlign(LEFT);
stroke(255);
rect(10,34,50,15);// gives background to input field
stroke(0); // resets stroke to black
fill(0);
text(lastInput,25,30);
text("F",50,30);
fill(255,0,0);
text(currentInput,25,45);
noFill();
rect(65,18,50,15); // creates frame for temp display
drawbuttons();
if(mousePressed && rectSTART())
{
StartTime = millis();
startcount = true;
}
if(mousePressed && rectSTOP())
{
startcount = false;
}
if(mousePressed && rectRESET())
{
dis_m = 0;
dis_s = 0;
}
calculate();
display();
}
void drawbuttons()
{
fill(6,203,27); rect(400,45,50,20); // green start
fill(250,0,17); rect(400,70,50,20); // red stop
fill(250,122,30); rect(400,95,50,20); //orange reset
fill(0);
textFont(font10);
textAlign(CENTER);
text("Start", 425,59);
text("Stop", 425, 84);
text("Reset", 425, 109);
}
boolean rectSTART()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 45 && mouseY <= 65) return true;
else return false;
}
boolean rectSTOP()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 70 && mouseY <= 90) return true;
else return false;
}
boolean rectRESET()
{
if(mouseX >= 400 && mouseX <= 450 && mouseY >= 95 && mouseY <= 115) return true;
else return false;
}
void calculate()
{
if(startcount)
{
TimeLapse += millis() - StartTime;
int seconds = (millis() - StartTime) / 1000;
int minutes = seconds/60;
int hours = minutes/60;
seconds -=minutes * 60;
minutes -= hours*60;
dis_m = minutes;
dis_s = seconds;
}
}
void display()
{
stroke(0);
fill(255,255,255);
rect(460,50,100,60); // stopwatch
fill(0);
textFont(font24);
textAlign(LEFT);
text(nf(dis_m,2)+":"+nf(dis_s,2),477,88);
}
void keyPressed()
{
if(key == ENTER)
{
lastInput = currentInput = currentInput + key;
currentInput = "";
stroke(255);
fill(255);
rect(10,33,50,15);// covers old data for type field
stroke(0);
fill(255);
rect(10,18,50,15); // covers old data for temp field
rect(65,18,50,15); // covers old data for time field
fill(0);
textFont(font10);
text(nf(dis_m,2)+":"+nf(dis_s,2),75,30); // displays time of enter
}
else if(key == BACKSPACE && currentInput.length() > 0)
{
currentInput = currentInput.substring(0, currentInput.length() - 1);
}
else
{
currentInput = currentInput + key;
}
}