Here is my code so far:
MouseDown(){
//if first mousedown
X1 = tempX; //tempX is for current positon
Y1 = tempY;
if (Input.style.display === "none") {
Input.value = "";
Input.style.top = tempX + 'px';
Input.style.left = tempY + 'px';
Input.size = 1;
Input.style.display = "block";
Draw();
}
}
Draw(){
var userInput = Input.value;
rectangledText(X1, Y1, 150, userInput, 12, 'verdana'); //code by markE
}
function rectangledText(x, y, width, text, fontsize, fontface) { //code by markE
self.TextWidth = ctx.measureText(Text).width;
var height = wrapText(x, y, text, fontsize, fontface, width)
ctx.strokeRect(x, y, width, height);
}
function wrapText(x, y, text, fontsize, fontface, maxwidth) {
var startingY = y;
var words = text.split(' ');
var line = '';
var space = '';
var lineHeight = fontsize * 1.286;
ctx.font = fontsize + "px " + fontface;
ctx.textAlign = 'left';
ctx.textBaseline = 'top'
for (var n = 0; n < words.length; n++) {
var testLine = line + space + words[n];
space = ' ';
if (ctx.measureText(testLine).width > maxwidth) {
ctx.fillText(line, x, y);
line = words[n] + ' ';
y += lineHeight;
space = '';
} else {
line = testLine;
}
}
ctx.fillText(line, x, y);
return (y + lineHeight - startingY);
}
This code will output the image below:
Basically what I want is to have the dynamic box and Wrapped text when I start to type the input or the mouseup after the first mousedown. Hopefully someone can help me with my problem.
Here is my other question, with regards to this post also.