(Graphics g, int tool, int x, int y)
| 524 | } |
| 525 | |
| 526 | void drawIcon(Graphics g, int tool, int x, int y) { |
| 527 | if (null==g) return; |
| 528 | icon = icons[tool]; |
| 529 | if (icon==null) return; |
| 530 | int x1, y1, x2, y2; |
| 531 | pc = 0; |
| 532 | if (icon.trim().startsWith("icon:")) { |
| 533 | String path = IJ.getDir("macros")+"toolsets/icons/"+icon.substring(icon.indexOf(":")+1); |
| 534 | try { |
| 535 | BufferedImage bi = ImageIO.read(new File(path)); |
| 536 | if (scale==1) |
| 537 | g.drawImage(bi,x-5,y-5,null); |
| 538 | else { |
| 539 | int size = Math.max(bi.getWidth(),bi.getHeight()); |
| 540 | g.drawImage(bi,x-5*scale,y-5*scale, size*scale,size*scale,null); |
| 541 | } |
| 542 | } catch (Exception e) { |
| 543 | IJ.error("Toolbar", "Error reading tool icon:\n"+path); |
| 544 | } |
| 545 | } else { |
| 546 | while (true) { |
| 547 | char command = icon.charAt(pc++); |
| 548 | if (pc>=icon.length()) break; |
| 549 | switch (command) { |
| 550 | case 'B': x+=v(); y+=v(); break; // adjust base |
| 551 | case 'N': x-=v(); y-=v(); break; // adjust base negatively |
| 552 | case 'R': g.drawRect(x+v(), y+v(), v(), v()); break; // rectangle |
| 553 | case 'F': g.fillRect(x+v(), y+v(), v(), v()); break; // filled rectangle |
| 554 | case 'O': g.drawOval(x+v(), y+v(), v(), v()); break; // oval |
| 555 | case 'V': case 'o': g.fillOval(x+v(), y+v(), v(), v()); break; // filled oval |
| 556 | case 'C': // set color |
| 557 | int saveScale = scale; |
| 558 | scale = 1; |
| 559 | int v1=v(), v2=v(), v3=v(); |
| 560 | int red=v1*16, green=v2*16, blue=v3*16; |
| 561 | if (red>255) red=255; if (green>255) green=255; if (blue>255) blue=255; |
| 562 | Color color = v1==1&&v2==2&&v3==3?foregroundColor:new Color(red,green,blue); |
| 563 | g.setColor(color); |
| 564 | scale = saveScale; |
| 565 | break; |
| 566 | case 'L': g.drawLine(x+v(), y+v(), x+v(), y+v()); break; // line |
| 567 | case 'D': g.fillRect(x+v(), y+v(), scale, scale); break; // dot |
| 568 | case 'P': // polyline |
| 569 | Polygon p = new Polygon(); |
| 570 | p.addPoint(x+v(), y+v()); |
| 571 | while (true) { |
| 572 | x2=v(); if (x2==0) break; |
| 573 | y2=v(); if (y2==0) break; |
| 574 | p.addPoint(x+x2, y+y2); |
| 575 | } |
| 576 | g.drawPolyline(p.xpoints, p.ypoints, p.npoints); |
| 577 | break; |
| 578 | case 'G': case 'H':// polygon or filled polygon |
| 579 | p = new Polygon(); |
| 580 | p.addPoint(x+v(), y+v()); |
| 581 | while (true) { |
| 582 | x2=v(); y2=v(); |
| 583 | if (x2==0 && y2==0 && p.npoints>2) |
no test coverage detected