For a while I had trouble with clipping but I never gave it the attention needed to figure it out. Now I really needed it and here my findings.
I had a Scene on top I was drawing a Rectangle represented in a Widget using resizeable Border, sitting in a LayerWidget on the Scene.
I wanted
A) The Scene not to extend into the negative numbers when the user dragged the Rectangle to the left (over the x=0 line)
B) The Rectangle to be clipped when exiting to the left
C) The Rectangle to be clipped when exiting to the right border of the Scene
The solution is
scene.setMaximumBounds(new Rectangle(0,0,width,height));
scene.setMaximumSize(new Dimension(width,height));
scene.validate();
scene.setCheckClipping(true);
In addition you have to set clipping on the LayerWidget holding the Widget representing the Rectangular
myLayerWidget.setCheckClipping(true);
This last line makes sure that the rectangle is still partly visible when it gets dragged over the edges of the defined scene size. If you would omit this last setting, the rectangle would be clipped in its total when outside the edge of the scene and you do not get the partly clipped image.
No comments:
Post a Comment