You are reading a single comment by @gerardwr and its replies. Click here to read the full conversation.
  • Changed my drawString override function to clearRect the area where the string is going to be displayed.

    Not extensively tested, but seems to work ok for me. It saves a lot of clearRects in my code :-)

    Comments and suggestions welcome!

    Code is like this:

    // override drawString function to:
    // - allocate proper line spacing between successive lines
    // - clear the area where the string will be displayed
    g._ds = g.drawString;
    g.drawString = function(s,x,y) {
      s=s.toString();
      sa=s.split("\n");
      spacing=5+g.getFontHeight();
      sa.forEach(function(line){
        // clear the area where the string will be written
        g.clearRect(x,y,x+g.stringWidth(line), y + spacing);
        // now call the original drawString
        g._ds(line,x,y);
        y+=spacing;
      });      
    };
    
    
About

Avatar for gerardwr @gerardwr started