1

I would like to draw some infinite object in Piccolo2D, like endless rectangular (cartesian) grid. It would be greate to have some geometric object on this grid, like in graphics editor.

Unfortunately, Piccolo somehow determines, whether it is required to call paint and does not do this appropriatedly for me.

The program below contains yellow object, which I want to make endless. It's type is PEndless. I am adding circle to it as a child.

package tests.endless;

import java.awt.Color;
import java.awt.geom.Rectangle2D;

import org.piccolo2d.PNode;
import org.piccolo2d.extras.PFrame;
import org.piccolo2d.nodes.PPath;
import org.piccolo2d.util.PPaintContext;

public class Try_PGrid {

    public static class PEndless extends PNode {

        @Override
        protected void paint(PPaintContext paintContext) {

            Rectangle2D localClip = paintContext.getLocalClip();
            paintContext.getGraphics().setColor(Color.yellow);
            paintContext.getGraphics().fill(localClip);

        }

    }

    public static void main(String[] args) {

        new PFrame() {

            @Override
            public void initialize() {

                PPath circle = PPath.createEllipse(0, 0, 100, 100);

                PEndless grid = new PEndless();
                grid.addChild(circle);
                //grid.setBounds(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); // not working at all
                //grid.setBounds(-10, -10, 50, 50); // yellow until circle visible
                grid.setBounds(-1000, -1000, 2000, 2000); // yellow until bounds

                getCanvas().getLayer().addChild(grid);


            }



        };

    }

}

Unfortunately, I found that:

1) if bounds are default (empty) then yellow paints only if circle is visible

2) if bounds are big and finite, then yellow paints withing bounds

3) it is not supporting infinite doubles, although this is legal in principle; if set infinite, it does no draw anything at all.

How to implement?

Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385

1 Answers1

0

It's part of how Java handles the drawing.

Look here for more information on this and a guide on how to prevent this issue.

Community
  • 1
  • 1
Remcoder
  • 215
  • 2
  • 12