@NebbishHacker
Your suggestion on using getModified was "spot on", shame on me ;-)
Here's my latest code including a random 'drawString` to check that the override is now OK. Seems that it's perfect for me now.
Ofcourse it requires some bookkeeping of the m variable if you change to a complete different screen.
var m=0;
// override drawString function to:
// - allocate proper line spacing between successive lines (here 5 pixels)
// - clear the area where the previous drawString was displayed
g._ds = g.drawString;
g.drawString = function(s,x,y) {
s=s.toString();
sa=s.split("\n");
spacing=5+g.getFontHeight();
g.clearRect(m.x1, m.y1, m.x2, m.y2); // Will clear the precise area affected by the previous drawString calls
g.getModified(true); // Reset modified area
sa.forEach(function(line){
//call the original drawString
g._ds(line,x,y);
y+=spacing;
});
m=g.getModified(); // save modified area for clearing on next drawString
};
// write a random string of random size at random x and y positions
setInterval(function () {
g.setFontVector(80*Math.random());
g.setColor(1,0,0);
getal=1000*Math.random();
getal=getal.toFixed(0);
g.drawString(getal,Math.random()*239,Math.random()*239);
}, 1000);
g.clear();
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@NebbishHacker
Your suggestion on using
getModified
was "spot on", shame on me ;-)Here's my latest code including a random 'drawString` to check that the override is now OK. Seems that it's perfect for me now.
Ofcourse it requires some bookkeeping of the m variable if you change to a complete different screen.