2013-10-27 59 views
1

在主要Java中,它支持「纏繞規則」,這可能有助於在形狀上打洞。如何在Piccolo2D中打洞?

不幸的是,這個概念在Piccolo2D忽略:

public class Try_Holes_01 { 

    @SuppressWarnings("serial") 
    public static void main(String[] args) { 

     final Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); 
     //final Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO); 

     path.append(new Ellipse2D.Double(100,100,200,200), false); 
     path.append(new Ellipse2D.Double(120,120,100,100), false); 

     JPanel panel = new JPanel() { 
      @Override 
      protected void paintComponent(Graphics g) { 
       super.paintComponent(g); 
       Graphics2D g2 = (Graphics2D) g; 

       g2.fill(path); 
      } 
     }; 

     final PPath path_p = new PPath(path); 
     path_p.setPaint(Color.BLACK); 

     JFrame frame = new JFrame(); 
     frame.setLayout(new BorderLayout()); 
     frame.add(panel, BorderLayout.CENTER); 
     frame.setSize(800, 600); 
     frame.setLocationRelativeTo(null); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setVisible(true); 

     new PFrame() { 
      @Override 
      public void initialize() { 
       getCanvas().getLayer().addChild(path_p); 
      } 
     }; 


    } 

} 

enter image description here

那麼如何讓Piccolo2D路徑內孔?

回答

2

PPath維護一個私人的GeneralPath成員的運作。它初始化爲WIND_NON_ZERO。幸運的是,它可以通過PPath.getPathReference()訪問。因此,這應該做的伎倆:

path_p.getPathReference().setWindingRule(Path2D.WIND_EVEN_ODD); 

這裏是一個結果:

enter image description here

+0

是的,我發現這個了。奇怪的是,他們忽視了原型的纏繞... –

+0

是的,很好的抓住雖然,+1 – tenorsax