GoogleCodeArchive / piccolo2d

Automatically exported from code.google.com/p/piccolo2d
0 stars 0 forks source link

PCanvas.setCamera() sets new Camera's bounds to Canvas bounds #227

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Consider this code that replaces the camera on a PCanvas:

PCanvas canvas = new PCanvas();
PCamera camera = PUtil.createBasicScenegraph();
canvas.setCamera(camera); //*
canvas.setPanEventHandler(new PPanEventHandler());
canvas.setZoomEventHandler(new PZoomEventHandler());

The new camera's bounds are set by the PCanvas.setCamera() method to be the 
bounds of the PCanvas. If PCanvas is a component of some JComponent, J, it may 
have bounds with (x,y) not equal to (0,0) (if J's layout manager repositions 
it.)

This seems to be undesirable behavior. (In a simple scenegraph the side effect 
is that after replacing the camera the camera renders the layer starting at 
some offset (whatever the PCanvas's (x,y) offset is)).

It seems that PCanvas.setCamera() should the camera's bounds to be 
(0,0,canvas.width,canvas.height). 

(Easy workaround: just set the camera's bounds yourself after replacing the 
camera.)

Original issue reported on code.google.com by atdi...@gmail.com on 29 Oct 2011 at 12:52

GoogleCodeExporter commented 9 years ago
Sounds like a bug to me, want to code a fix?

Original comment by heue...@gmail.com on 1 Nov 2011 at 7:43

GoogleCodeExporter commented 9 years ago
Sure, I'll put some thought into it.

Also wondering if PCanvas.setBounds() is correct wrt to the bounds it sets on 
the camera:

    public void setBounds(final int x, final int y, final int width, final int height) {
        camera.setBounds(camera.getX(), camera.getY(), width, height);
        super.setBounds(x, y, width, height);
    }

I suppose the fundamental question is, in what cases do clients want the 
canvas's camera to NOT be at (0,0)? Do you know any such use cases?

Original comment by atdi...@gmail.com on 2 Nov 2011 at 2:01

GoogleCodeExporter commented 9 years ago
Committed revision 1155.

Original comment by atdi...@gmail.com on 13 Nov 2011 at 7:01

GoogleCodeExporter commented 9 years ago
Committed revision 1156. (TRUNK, same fix as the earlier branch commit.)

Original comment by atdi...@gmail.com on 13 Nov 2011 at 7:12

GoogleCodeExporter commented 9 years ago

Original comment by heue...@gmail.com on 26 Nov 2013 at 8:47