@@ -2607,34 +2607,41 @@ public void backgroundImpl() {
2607
2607
clearPixels (backgroundColor );
2608
2608
2609
2609
} else {
2610
- Color bgColor = new Color (backgroundColor );
2611
- // seems to fire an additional event that causes flickering,
2612
- // like an extra background erase on OS X
2613
- // if (canvas != null) {
2614
- // canvas.setBackground(bgColor);
2615
- // }
2616
- //new Exception().printStackTrace(System.out);
2617
- // in case people do transformations before background(),
2618
- // need to handle this with a push/reset/pop
2619
- Composite oldComposite = g2 .getComposite ();
2620
- g2 .setComposite (defaultComposite );
2610
+ backgroundRect ();
2611
+ }
2612
+ }
2621
2613
2622
- pushMatrix ();
2623
- resetMatrix ();
2624
- g2 .setColor (bgColor ); //, backgroundAlpha));
2625
- // g2.fillRect(0, 0, width, height);
2626
- // On a hi-res display, image may be larger than width/height
2627
- if (image != null ) {
2628
- // image will be null in subclasses (i.e. PDF)
2629
- g2 .fillRect (0 , 0 , image .getWidth (null ), image .getHeight (null ));
2630
- } else {
2631
- // hope for the best if image is null
2632
- g2 .fillRect (0 , 0 , width , height );
2633
- }
2634
- popMatrix ();
2635
2614
2636
- g2 .setComposite (oldComposite );
2615
+ protected void backgroundRect () {
2616
+ Color bgColor = new Color (backgroundColor );
2617
+
2618
+ // While more complete, this seems to fire an additional event that
2619
+ // causes flickering, like an extra background erase on OS X.
2620
+ //if (canvas != null) {
2621
+ // canvas.setBackground(bgColor);
2622
+ //}
2623
+
2624
+ // If there are transformations or blending changes at the top of
2625
+ // draw() (before background() is called) or still in place from
2626
+ // the last trip through draw(), need to store and re-apply after.
2627
+ Composite oldComposite = g2 .getComposite ();
2628
+ g2 .setComposite (defaultComposite );
2629
+ pushMatrix ();
2630
+ resetMatrix ();
2631
+
2632
+ g2 .setColor (bgColor );
2633
+ // On a hi-res display, image may be larger than width/height
2634
+ if (image != null ) {
2635
+ // image will be null in subclasses (i.e. PDF)
2636
+ g2 .fillRect (0 , 0 , image .getWidth (null ), image .getHeight (null ));
2637
+ } else {
2638
+ // hope for the best if image is null
2639
+ g2 .fillRect (0 , 0 , width , height );
2637
2640
}
2641
+
2642
+ // Reset the drawing state (see above)
2643
+ popMatrix ();
2644
+ g2 .setComposite (oldComposite );
2638
2645
}
2639
2646
2640
2647
0 commit comments