InputSystemJme missing implementation of inherited abstract method & MouseInvert

hello,





the Type com.jme3.niftygui.InputSystemJme implements the abstract Type de.lessvoid.nifty.spi.input.InputSystem and therefore has to implement the inherited abstract method forwardEvents(NiftyInputConsumer inputEventConsumer). It seems like the newest version I've got from the SVN (both: jME3 and Nifty) do not work together, because the jME3 in the Repository uses the Nifty-1.2-SNAPSHOTS-2.jar in which the class de.lessvoid.nifty.spi.input.InputSystem does not declare any abstract Method forwardEvents(NiftyInputConsumer inputEventConsumer). Using the newest versions of both (Nifty and jME3) will therefore give the following Error:



Application 11:38:34 Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.Error: Unresolved compilation problem:
The type InputSystemJme must implement the inherited abstract method InputSystem.forwardEvents(NiftyInputConsumer)

at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:17)
at de.lessvoid.nifty.Nifty.render(Nifty.java:156)
at com.jme3.niftygui.NiftyJmeDisplay.postQueue(NiftyJmeDisplay.java:96)
at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:456)
at com.jme3.renderer.RenderManager.render(RenderManager.java:477)


I found a quick solution to this problem by having a quick look at the jME2-InputSystem lessvoid provides in his Repository (https://nifty-gui.svn.sourceforge.net/svnroot/nifty-gui/nifty-jme-renderer). The following method would allow you two use the newest version of nifty which can be found in the SVN-Repository.


   @Override
   public void forwardEvents(final NiftyInputConsumer inputEventConsumer)
   {
      for(MouseInputEvent ev : mouseEvents)
      {
         inputEventConsumer.processMouseEvent(ev);
      }
      mouseEvents.clear();
      
      for(KeyboardInputEvent ev : keyEvents)
      {
         inputEventConsumer.processKeyboardEvent(ev);
      }
      keyEvents.clear();
   }



It does the trick. The error would disappear and your application would start again. I would just like you guys who know the most about jME have a quick look at it and maybe integrate it into the source-code.


Now... the next problem:

The Y-Axis of the mouse is inverted, meaning that when you press at the bottom of the Nifty-Interface a button at the top of the interface would be triggered.

It seems like Nifty defines the top of the screen to be y=0 whereas jME defines the bottom to be y=0. There is no right or wrong. It's just that the two systems have to use the same definition.

A simple patch to this would be the following modification in com.jme3.input.lwjgl.LwjglMouseInput:

    public void update() {
        while (Mouse.next()){
            int btn = Mouse.getEventButton();

            int wheelDelta = Mouse.getEventDWheel();
            int xDelta = Mouse.getEventDX();
            int yDelta = Mouse.getEventDY();
            int x = Mouse.getX();
            int y = Mouse.getY();

            y = Display.getDisplayMode().getHeight() - y; // Edit by Fellkneul

            curWheel += wheelDelta;
            if (cursorVisible){
                xDelta = x - curX;
                yDelta = y - curY;
                curX = x;
                curY = y;
            }else{
                x = curX + xDelta;
                y = curY + yDelta;
                curX = x;
                curY = y;
            }

            if (xDelta != 0 || yDelta != 0 || wheelDelta != 0){
                MouseMotionEvent evt = new MouseMotionEvent(x, y, xDelta, yDelta, curWheel, wheelDelta);
                listener.onMouseMotionEvent(evt);
            }
            if (btn != -1){
                MouseButtonEvent evt = new MouseButtonEvent(btn,
                                                            Mouse.getEventButtonState());
                listener.onMouseButtonEvent(evt);
            }
        }
    }




Actually, that is not such a good solution, because other devices that request MouseInput from jME3 might no longer work then any more. So people using a different GUI might face the same problem as I am doing now.

I think it should be Nifty to have a close look at its MouseInputHandlers or whatsoever in order to find a solution to this problem.

Well... Never mind :)

thanks in advance,
Fellkneul

The niftygui implementation of jme3 is very specialized and you are not supposed to use it with any other version of nifty than the supplied one. The difference in coordinate systems is one you will have to live with I guess but its a pretty common thing really.

Cheers,

Normen

okay right… thanks @ normen



so… now referring to lessvoid (I hope you read this):



could you manage to get the newest version of nifty to work with jME again??



i mean could you do something against the inverting of the mouse??

now… sorry for getting on your nerves with this… but this would be a simple solution:





com.jme3.niftygui.InputSystemJme:

package com.jme3.niftygui;


import java.util.ArrayList;
import java.util.List;

import org.lwjgl.opengl.Display;

import com.jme3.input.KeyInput;
import com.jme3.input.RawInputListener;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
import com.jme3.input.event.MouseButtonEvent;
import com.jme3.input.event.MouseMotionEvent;

import de.lessvoid.nifty.NiftyInputConsumer;
import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
import de.lessvoid.nifty.input.mouse.MouseInputEvent;
import de.lessvoid.nifty.spi.input.InputSystem;


public class InputSystemJme implements InputSystem, RawInputListener
{
   
   private final ArrayList<MouseInputEvent> mouseEvents = new ArrayList<MouseInputEvent>();
   private final ArrayList<MouseInputEvent> mouseEventsCopy = new ArrayList<MouseInputEvent>();
   
   private final ArrayList<KeyboardInputEvent> keyEvents = new ArrayList<KeyboardInputEvent>();
   private final ArrayList<KeyboardInputEvent> keyEventsCopy = new ArrayList<KeyboardInputEvent>();
   
   private boolean pressed = false;
   private int x, y;
   
   private boolean shiftDown = false;
   private boolean ctrlDown = false;
   
   public InputSystemJme()
   {
   }
   
   public List<MouseInputEvent> getMouseEvents()
   {
      synchronized (mouseEvents)
      {
         mouseEventsCopy.clear();
         mouseEventsCopy.addAll(mouseEvents);
         mouseEvents.clear();
         return mouseEventsCopy;
      }
   }
   
   public List<KeyboardInputEvent> getKeyboardEvents()
   {
      synchronized (keyEvents)
      {
         keyEventsCopy.clear();
         keyEventsCopy.addAll(keyEvents);
         keyEvents.clear();
         return keyEventsCopy;
      }
   }
   
   public void onJoyAxisEvent(JoyAxisEvent evt)
   {
   }
   
   public void onJoyButtonEvent(JoyButtonEvent evt)
   {
   }
   
   public void onMouseMotionEvent(MouseMotionEvent evt)
   {
      synchronized (mouseEvents)
      {
         x = evt.getX();
         y = evt.getY();
         mouseEvents.add(new MouseInputEvent(x, y, pressed));
      }
   }
   
   public void onMouseButtonEvent(MouseButtonEvent evt)
   {
      if (evt.getButtonIndex() == 0)
      {
         synchronized (mouseEvents)
         {
            pressed = evt.isPressed();
            mouseEvents.add(new MouseInputEvent(x, y, pressed));
         }
      }
   }
   
   public void onKeyEvent(KeyInputEvent evt)
   {
      int code = evt.getKeyCode();
      
      synchronized (keyEvents)
      {
         if ((code == KeyInput.KEY_LSHIFT) || (code == KeyInput.KEY_RSHIFT))
         {
            shiftDown = evt.isPressed();
         }
         else if ((code == KeyInput.KEY_LCONTROL) || (code == KeyInput.KEY_RCONTROL))
         {
            ctrlDown = evt.isPressed();
         }
         KeyboardInputEvent keyEvt = new KeyboardInputEvent(code, evt.getKeyChar(), evt.isPressed(), shiftDown, ctrlDown);
         

         keyEvents.add(keyEvt);
      }
   }
   
   @Override
   public void forwardEvents(NiftyInputConsumer inputEventConsumer)
   {
      for (MouseInputEvent ev : mouseEvents)
      {
         ev = new MouseInputEvent(ev.getMouseX(), Display.getDisplayMode().getHeight() - ev.getMouseY(), ev.isLeftButton());
         
         inputEventConsumer.processMouseEvent(ev);
      }
      mouseEvents.clear();
      
      for (KeyboardInputEvent ev : keyEvents)
      {
         inputEventConsumer.processKeyboardEvent(ev);
      }
      keyEvents.clear();
   }
}



It would just add the missing method forwardEvents(NiftyInputConsumer inputEventConsumer). The bug about the inverted Y-Axis is also fixed here.

This is very usefull, because it only changes the InputSystemJme which was written for Nifty. It would also keep the old methods so older versions of Nifty would work with this file as well.


@Normen:
You could add this file to the jME source code. Both, old and new versions of Nifty will work with this version of the InputSystemJme. Moreover, it will only affect the Nifty-MouseInput.

Thanks :) :),
Fellkneul

Ok, let me clearify some things :slight_smile:



It's all momoko_fan's "fault" :lol:



Nah, not really his fault :wink: more like his - helpful (!) - suggestion. He suggested that Niftys InputSystem lacks a very important feature: If you want to overlay a Nifty GUI over your, let's say, jme rendered awesome 3d terrain of your awesome realtime strategy game :smiley: it was up until now not possible to send all mouse events that Nifty has not handled (f.i. because the mouse was over the terrain and not the GUI panel) to the terrain or to something else that is part of the game.



So he suggested that Nifty needs to provide that information and that got me thinking and it led to the change of Niftys InputSystem Interface.



This also explains your second problem: The change in the InputSystem Interface and the availability of more implementations for different systems (f.i. Java2d) now requires that mouse events will be send to Nifty with y=0 representing the top of the screen instead the bottom.



So there have been some changes to Nifty that influence existing and new Rendering- and InputSystem implementations. The current svn of Nifty should now be stable (in respect of the InputSystem) and with the upcoming Nifty 1.2 release those issues will disapear.



Besides all of this Normen is right, when using Nifty with any implementation like the jme3 one, it's best to use the Nifty version that the renderer was written for.



Please be patient … :slight_smile:

Okay … Thanks a lot :slight_smile: :slight_smile: