FengGui + JME Handling Events

Hello,



I'm currently using JME and FengGui on a project. In the game, the user can use the mouse to control the camera movement and for picking objects, and as well for opening widgets from the menu bar.

My problem comes when user opens a widget, I want to make it so that when the user clicks on the widget or moves mouse on top of the widget then the controls for the game are destroy and the reactivated back again if the user clicks on the game.

For example:

  If user opens a widget and user moves mouse on top of the widget, then controls for moving the camera and picking objects with the mouse and keyboard are destroy so user can type on the widget and use wheel for scrolling down on scroll bar. Otherwise if controls are not destroy, the keyboard and mouse controls are still active and pressing keys would move camera around instead of typing in the text area. 

  If user then click back on the game, then controls for camera and picking objects are re-activated.



Any help would be appreciated. Thanks.

You want to detect if the mouse is inside a component using entered/exited.



I use this,



public class FocusManager implements IMouseEnteredListener, IMouseExitedListener  {

   public static FocusManager focusManager;
   
   public FocusManager() {
      focusManager = this;
   }
   
   public boolean guiInFocus = false;
   
   public void mouseEntered(MouseEnteredEvent mouseEnteredEvent)
   {
      guiInFocus = true;
   }
   
   public void mouseExited(MouseExitedEvent mouseExitedEvent)
   {
      guiInFocus = false;
   }
}

Then just add this line to widgets

myButtonOrWidget.addMouseEnteredListener(FocusManager.focusManager);
myButtonOrWidget.addMouseExitedListener(FocusManager.focusManager);



You will then need to test to see if the FocusManager.focusManager.guiInFocus == true before doing jme scene actions


Thanks for your quick reply. I'm currently trying to implement it this way, but I'm getting a NullPointerException that seems to point to Display.java and ObservableWidget.java which are both classes inside the FengGui.jar.

After I add the:

      myButtonOrWidget.addMouseEnteredListener(FocusManager.focusManager);

      myButtonOrWidget.addMouseExitedListener(FocusManager.focusManager);

lines to my code in the Button and Widget, I run the code and once my mouse enters either the widget or the button my project crashes, exits and prints out a Null Pointer Exception. From what I read on the code of those two classes, it doesn't seem to be anything wrong with FengGui, anyone has had the same or similar experience?



Thanks


theprism said:

You want to detect if the mouse is inside a component using entered/exited.

I use this,


public class FocusManager implements IMouseEnteredListener, IMouseExitedListener  {

   public static FocusManager focusManager;
   
   public FocusManager() {
      focusManager = this;
   }
   
   public boolean guiInFocus = false;
   
   public void mouseEntered(MouseEnteredEvent mouseEnteredEvent)
   {
      guiInFocus = true;
   }
   
   public void mouseExited(MouseExitedEvent mouseExitedEvent)
   {
      guiInFocus = false;
   }
}

Then just add this line to widgets

myButtonOrWidget.addMouseEnteredListener(FocusManager.focusManager);
myButtonOrWidget.addMouseExitedListener(FocusManager.focusManager);



You will then need to test to see if the FocusManager.focusManager.guiInFocus == true before doing jme scene actions