UIObjects doesn't like beeing attached to Nodes

It seems like UIButtons (and probably all other UIObjects) doesn’t work well when attached to Nodes that has local translations that != 0. Their hit area seem to be in stuck in the original location.



I made this test scenario:

import com.jme.app.SimpleGame;

import com.jme.input.*;

import com.jme.ui.UIButton;

import com.jme.scene.Node;



public class UIBug extends SimpleGame {

   private UIButton button;

   private Node uiNode;

   private Node cursor;

   

   public void simpleInitGame() {

      input = new MyInputHandler();

      

        button = new UIButton(“button”,

            input,

            “jmetest/data/images/buttonup.png”,

            “jmetest/data/images/buttonover.png”,

            “jmetest/data/images/buttondown.png”,

            100,

            100,

            1.0f);

       

        uiNode = new Node(“UI Node”);

       

        // Here’s where it goes wrong, try to outcomment…

        uiNode.getLocalTranslation().x += 200;

      

        uiNode.attachChild(button);

       

        rootNode.attachChild(uiNode);

        rootNode.attachChild(input.getMouse());

      

      rootNode.setRenderQueueMode(com.jme.renderer.Renderer.QUEUE_ORTHO);

   }

   

   public void simpleUpdate() {

      button.update();

   }

   

   public static void main(String[] args) {

      UIBug app = new UIBug();

      app.setDialogBehaviour(UIBug.ALWAYS_SHOW_PROPS_DIALOG);

      app.start();

   }

   

   private class MyInputHandler extends InputHandler {

      MyInputHandler() {

           keyboard = KeyBindingManager.getKeyBindingManager();

           keyboard.setKeyInput(InputSystem.getKeyInput());

           mouse = new AbsoluteMouse(“Mouse Input”, display.getWidth(),

                 display.getHeight());

           mouse.setMouseInput(InputSystem.getMouseInput());

           setMouse(mouse);

      }

   }

}





And a screenshot that says it all :stuck_out_tongue:



(the white block beeing the cursor)



/Per



PS: Noticed the same problem when applying RenderStates.

Oh and another thing: if not extending the InputManager and doing:

           keyboard = KeyBindingManager.getKeyBindingManager();

           keyboard.setKeyInput(InputSystem.getKeyInput());



a NullPointerException is thrown. Is it supposed to be that way?

I can’t comment on the UIObject, but I can comment on the keyboard thing, have you initialised the InputSystem?



InputSystem.createInputSystem(properties.getRenderer());



DP

Yeah, that’s done in SimpleGame

I’ve had the same issue on my own game. Really the only current solution is to draw your GUIs at a top level for now. We’ll get that fixed in a later GUI push / consolidation effort.

Ok, going with the temp fix then.



Thanks



/Per

I’ll look into this as I ‘push’ :wink:

After taking a look at what you are doing… I’d say that you are correct. The code in ActiveArea does a strait correlation b/t the mouse and the active area. So if you only translate the active area, but not the mouse then you will see strange behaviour.



The hitTest for ActiveArea is based on the hotSpotPosition of the mouse which is compared against the screen coordinate x and y position of the active area. This is a totally separate value from the ‘graphics’ the quad which you can do local translates.



As a general rule of thumb, I keep my UI in a separate node from the mouse, and them both in separate nodes from anything 3D.



I’ll be checking in extensive changes soon, UIObject will now be derrived from Node, not Quad. So I’m sure I’ll put new and different bugs in place, so keep testing. But I’d say this one is a ‘works as designed’ deal.

Remember that people are currently using GUI so make sure you spend a little time going through the code review process (I understand GUI is a work in progress…) or at least detailing the changes on this board somewhere.

So says Mojo :slight_smile: too… sorry about the flippant commit yesterday. All new changes hit the Review board first.