Login  Register

Problems with Overlay.show

Posted by Stein Rørvik on Jul 12, 2018; 3:10pm
URL: http://imagej.273.s1.nabble.com/Problems-with-Overlay-show-tp5020948.html

Here is another overlay issue:

It seems that text added with Overlay.drawString is lost when text is added using Overlay.addSelection,
_unless_ Overlay.show is called before the first instance of Overlay.addSelection.

If Overlay.show is called after Overlay.addSelection, the text added with Overlay.addSelection is lost instead.
So combining Overlay.drawString and Overlay.addSelection only works if Overlay.show is called at the right place.

Being able to combine Overlay.drawString and Overlay.addSelection is useful
because the former is bottom adjusted and the latter is top adjusted.

See this example macro.
The three functions are identical except for the code line position of Overlay.show;

close("boats*");
run("Boats (356K)");
TextStr1 = "This is test text 1";
TextStr2 = "This is test text 2";
TextStr3 = "This is test text 3";
TextStr4 = "This is test text 4";
xPos = getWidth/2;
yPos = round(getHeight/7);
setFont("SansSerif", 28, "antialiased");
setColor("red");

OverlayTest1();
OverlayTest2();
OverlayTest3();
run("Tile");

function OverlayTest1() {
                run("Boats (356K)");

                //draw text using Overlay.drawString
                Overlay.drawString(TextStr1, xPos, yPos*1);

                //draw text using Overlay.addSelection
                makeText(TextStr2, xPos, yPos*2);
                Overlay.addSelection("yellow");

                //repeat the above
                Overlay.drawString(TextStr3, xPos, yPos*3);
                makeText(TextStr4, xPos, yPos*4);
                Overlay.addSelection("yellow");

                Overlay.show;
                run("Select None");
                //problem: only TextStr1 is shown
}

function OverlayTest2() {
                run("Boats (356K)");

                //draw text using Overlay.drawString
                Overlay.drawString(TextStr1, xPos, yPos*1);

                //draw text using Overlay.addSelection
                makeText(TextStr2, xPos, yPos*2);
                Overlay.addSelection("yellow");

                //draw text using Overlay.drawString
                Overlay.drawString(TextStr1, xPos, yPos*3);

                //repeat the above
                Overlay.drawString(TextStr3, xPos, yPos*3);
                makeText(TextStr4, xPos, yPos*4);
                Overlay.addSelection("yellow");

                run("Select None");
                //problem: TextStr1 is not shown
}

function OverlayTest3() {
                run("Boats (356K)");

                //draw text using Overlay.drawString
                Overlay.drawString(TextStr1, xPos, yPos*1);
                Overlay.show;

                //draw text using Overlay.addSelection
                makeText(TextStr2, xPos, yPos*2);
                Overlay.addSelection("yellow");

                //draw text using Overlay.drawString
                Overlay.drawString(TextStr1, xPos, yPos*3);

                //repeat the above
                Overlay.drawString(TextStr3, xPos, yPos*3);
                makeText(TextStr4, xPos, yPos*4);
                Overlay.addSelection("yellow");

                run("Select None");
                //now all strings are shown
}

I am using daily build ImageJ 1.52e with Java 1.6 on Windows 7/64-bit.

Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html