Nifty - scrollpanel movement in android

Hi all,

I’ve noticed that in android there’s no confortable way to move a nftygui scroll panel, just by directly touching the arrows while in desktop you can use the mouse wheel over the scroll or dragging the scroll bar.

Checking jme code I found that in com.jme3.niftygui.InputSystemJme method onTouchEventQueued (the one forwarding touch events to nifty it’s only using TouchEvent.Type DOWN and UP, ignoring all other events like MOVE, SCROLL, HOVER_MOVE…:

......
        switch (evt.getType()) {
            case DOWN:
                if (inputPointerId != -1) {
                    // Another touch was done by the user
                    // while the other interacts with nifty, ignore.
                    break;
                }
                
                inputPointerId = evt.getPointerId();
                handleMouseEvent(0, true, nic, evt);
                
                break;
            case UP:
                if (inputPointerId != evt.getPointerId()) {
                    // Another touch was done by the user
                    // while the other interacts with nifty, ignore.
                    break;
                }
                
                inputPointerId = -1;
                handleMouseEvent(0, false, nic, evt);
                
                break;
......

So there’s no gesture converted in nifty into a mouse wheel event or any other allowing a better scrollpanel movement. I added the following case to onTouchEventQueued to translate SCROLL into mouse wheel:

......
            case SCROLL:
                // process scroll as wheel event should make scroll panels somehow work
                nic.processMouseEvent(x, y, (int)evt.getDeltaY(), -1, false);

                break;
......

And this way I was able to move the scroll panel dragging over scroll bar :partying_face: but not over the content because it was processed as a click event over them so although better, it’s still not the desired behaviour.

In adition to that, this only applies to vertical scrolls (I’m using deltaY) but a horizontal scroll bar would react to this also (all scrolls react to mouse wheel).

I’m trying to figure out how to make it better but I’m not sure how. Any ideas?

Thanks

2 Likes

May be you need this (ok, it’s too late, but i found this for my project)

private void onTouchEventQueued(TouchEvent evt, NiftyInputConsumer nic) {
		if (inputManager.isSimulateMouse()) {
			return;
		}

		x = (int) evt.getX();
		y = (int) (height - evt.getY());

		// Input manager will not convert touch events to mouse events,
		// thus we must do it ourselves..
		switch (evt.getType()) {
		case DOWN:
			if (inputPointerId != -1) {
				// Another touch was done by the user
				// while the other interacts with nifty, ignore.
				break;
			}

			inputPointerId = evt.getPointerId();
			handleMouseEvent(0, true, nic, evt);

			break;
		case UP:
			if (inputPointerId != evt.getPointerId()) {
				// Another touch was done by the user
				// while the other interacts with nifty, ignore.
				break;
			}

			inputPointerId = -1;
			handleMouseEvent(0, false, nic, evt);

			break;
		case MOVE:
			int wheelEmu = Math.round(Math.signum(evt.getDeltaY()));

			nic.processMouseEvent(x, y, wheelEmu, -1, false);

			break;
		default:
			Logger.getLogger(InputSystemJme.class.getName()).log(Level.INFO, "event type: {0}", evt.getType());
		}
	}

actually it is only move part:

		case MOVE:
			int wheelEmu = Math.round(Math.signum(evt.getDeltaY()));

			nic.processMouseEvent(x, y, wheelEmu, -1, false);

			break;

in jme3-niftygui project. maybe i have to create pull request if somebody interested in it. i understand that nifty it deprecated, but still.

p.s. i am not sure how to frame code here

3 Likes

if you mean on github , then select the line that you want to highlight from the lines bar → press on the 3dot menu → copy permalink & paste it.

It’s never too late @bukazoid, in fact I didn’t finish any fix to get it working. I really appreciate your comment. A PR for nifty would be great.

Nifty is not deprecated by itself but it seems that it’s not being developed and it’s maintained less than before. Also most people prefer other GUIs instead.

1 Like