ImageJ base code to get access to all the classes and their methods to test new Plugins. https://imagejdocu.tudor.lu/howto/plugins/the_imagej_eclipse_howto
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

3 years ago
  1. // Moves the selection left and down a specified distance in pixels.
  2. xy = split(getArgument());
  3. if (lengthOf(xy)!=2) {
  4. dx = 10;
  5. dy = 10;
  6. } else {
  7. dx = parseFloat(xy[0]);
  8. if (isNaN(dx)) dx = 10;
  9. dy = parseFloat(xy[1]);
  10. if (isNaN(dy)) dy = 10;
  11. }
  12. getPixelSize(unit, pixelWidth, pixelHeight);
  13. if (unit=="pixel") unit = "pixels";
  14. dxc = dx*pixelWidth;
  15. dyc = dy*pixelHeight;
  16. Dialog.create("Move");
  17. Dialog.addNumber("Delta_X ("+unit+"):", dxc);
  18. Dialog.addNumber("Delta_Y ("+unit+"):", dyc);
  19. Dialog.show();
  20. dx = Dialog.getNumber()/pixelWidth;
  21. dy = Dialog.getNumber()/pixelHeight;
  22. moveSelection(dx, dy);
  23. return toString(dx)+" "+toString(dy);
  24. function moveSelection(dx, dy) {
  25. getBoundingRect(x, y, width, height);
  26. if (selectionType==0)
  27. makeRectangle(x+dx, y+dy, width, height);
  28. else if (selectionType==1)
  29. makeOval(x+dx, y+dy, width, height);
  30. else {
  31. getSelectionCoordinates(xCoordinates, yCoordinates);
  32. for (i=0; i<xCoordinates.length; i++) {
  33. xCoordinates[i] += dx;
  34. yCoordinates[i] += dy;
  35. }
  36. makeSelection(selectionType, xCoordinates, yCoordinates);
  37. }
  38. }