// "StartupMacros"

   // Global variables
   var pencilWidth=1, eraserWidth=10, leftClick=16, alt=8;
   var brushWidth = 10;
   var floodType = "8-connected"; 

   //macro "AutoRun" {print('AutoRun');}

   macro "Unused Tool -" {}
   macro "Unused Tool -" {}

   macro "Pencil Tool - C037L494fL4990L90b0Lc1c3L82a4Lb58bL7c4fDb4L5a5dL6b6cD7b" {
        getCursorLoc(x, y, z, flags);
        if (flags&alt!=0)
              setColorToBackgound();
        draw(pencilWidth);
   }

   macro "Paintbrush Tool - C037La077Ld098L6859L4a2fL2f4fL3f99L5e9bL9b98L6888L5e8dL888c" {
        getCursorLoc(x, y, z, flags);
        if (flags&alt!=0)
              setColorToBackgound();
        draw(brushWidth);
   }

    macro "Flood Fill Tool -C037B21P085373b75d0L4d1aL3135L4050L6166D57D77D68La5adLb6bcD09D94" {
        setupUndo();
        getCursorLoc(x, y, z, flags);
        if (flags&alt!=0) setColorToBackgound();
        floodFill(x, y, floodType);
     }


    macro "About ImageJ... Action Tool - C037T3e16?" {
        run("About ImageJ...");
    }

   function draw(width) {
        setupUndo();
        getCursorLoc(x, y, z, flags);
        setLineWidth(width);
        moveTo(x,y);
        x2=-1; y2=-1;
        while (true) {
            getCursorLoc(x, y, z, flags);
            if (flags&leftClick==0) exit();
            if (x!=x2 || y!=y2)
                lineTo(x,y);
            x2=x; y2 =y;
            wait(10);
        }
   }

   function setColorToBackgound() {
       savep = getPixel(0, 0);
       makeRectangle(0, 0, 1, 1);
       run("Clear");
       background = getPixel(0, 0);
       run("Select None");
       setPixel(0, 0, savep);
       setColor(background);
   }

  macro 'Pencil Tool Options...' {
       pencilWidth = getNumber("Pencil Width (pixels):", pencilWidth);
  }

  macro 'Paintbrush Tool Options...' {
      brushWidth = getNumber("Brush Width (pixels):", brushWidth);
   }

  macro 'Flood Fill Tool Options...' {
      Dialog.create("Flood Fill Tool");
      Dialog.addChoice("Flood Type:", newArray("4-connected", "8-connected"), floodType);
      Dialog.show();
      floodType = Dialog.getChoice();
  }


  



