Sorry for the no response.
Let me explain: I need a list wich I can move with the scroll wheel. The list will clip the extra parts of the objects that are out of the panel and I will be able to click the items that contain the list. So… I need a viewport.
I need to reacomodate the size and position of that viewport acording to a layout too.
So I’m trying to create a custom Panel with a ViewPort inside, adapting the viewport to the size and position of the panel.
I tried to do a test case:
- Use a clone of the GuiViewport Camera.
- Use the RenderManager of the SimpleApp.
- Use the AppStateManager of the SimpleApp to get the BasePickState and add a new CollisionRoot.
- Create a viewPortNode in the Gui Bucket.
public class CustomViewPort extends Panel {
ViewPort viewport;
Node viewPortNode;
Container container;
Camera cam;
RenderManager renderManager;
AppStateManager stateManager;
public CustomViewPort(RenderManager rm, Camera cam, AppStateManager stateManager) {
viewPortNode = new Node("Root Node ViewPort Panel");
this.cam = cam.clone();
this.renderManager = rm;
this.stateManager = stateManager;
container = new Container();
container.setPreferredSize(new Vector3f(100, 100, 1));
container.setLocalTranslation(100, Display.getHeight() - 100, 0);
viewPortNode.attachChild(container);
viewPortNode.setQueueBucket(RenderQueue.Bucket.Gui);
float left = 0.1f;
float right = 0.5f;
float bottom = 0.2f;
float top = 0.9f;
this.cam.setViewPort(left, right, bottom, top);
container.setLocalScale(1/(right - left), 1/(top - bottom), 1);
addControl(new AbstractControl() {
@Override
protected void controlUpdate(float tpf) {
viewPortNode.updateLogicalState(tpf);
}
@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
viewPortNode.updateGeometricState();
}
});
MouseEventControl.addListenersToSpatial(container, new BasicMouseListener() {
@Override
public void mouseEntered(MouseMotionEvent event, Spatial target, Spatial capture) {
System.out.println("Mouse entered on CONTAINER");
}
@Override
public void mouseExited(MouseMotionEvent event, Spatial target, Spatial capture) {
System.out.println("Mouse exited of CONTAINER");
}
});
}
public void open() {
viewport = renderManager.createPostView("viewportPanel", cam);
viewport.setClearFlags(true, true, true);
viewport.attachScene(viewPortNode);
viewport.setBackgroundColor(ColorRGBA.Red);
stateManager.getState(BasePickState.class).addCollisionRoot(container, viewport);
}
public void close() {
renderManager.removePostView(viewport);
stateManager.getState(BasePickState.class).removeCollisionRoot(viewport);
}
}
Just for trying I create a class extending Panel. I give the cam viewport size a random value to test and a square size to the container.
I need to show and hide the panel so I create the functions open and close, creating and removing the viewport.
I’m adding this Panel to my UserInterface.
I scale the container to show it square shape but the collision shape doesn’t adjust to it.