[Ardor3D] SwtMouseWrapper

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

[Ardor3D] SwtMouseWrapper

Stefan
Hi,

whenever I click an "exotic" mouse button I get following RuntimeException:

java.lang.RuntimeException: unknown button: 8
        at com.ardor3d.input.swt.SwtMouseWrapper.getButtonForEvent(SwtMouseWrapper.java:172)
        at com.ardor3d.input.swt.SwtMouseWrapper.mouseDown(SwtMouseWrapper.java:98)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:192)
        at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
        at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4481)
        ...

The Exception is caused by following method in the SwtMouseWrapper:

private MouseButton getButtonForEvent(final MouseEvent e) {
        MouseButton button;
        switch (e.button) { // ordering is different than swt
            case 1:
                button = MouseButton.LEFT;
                break;
            case 3:
                button = MouseButton.RIGHT;
                break;
            case 2:
                button = MouseButton.MIDDLE;
                break;
            default:
                throw new RuntimeException("unknown button: " + e.button);
        }
        return button;
    }

What is the recommended way to prevent this exception? Subclassing the SwtMouseWrapper?

Thanks for your help!

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
Hi

I can fix this bug in about 7 hours when I am back home. I'll push the change on Git as soon as possible as usual.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
Great, thanks a lot!
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
You're welcome. I will extend the support so that you can use the 9 first buttons of a mouse, maybe 16 if necessary. Let me know your requirements. It's a trivial change. My main concern is that I don't know in which order SWT returns them, it's difficult to make something consistent.

In the future, I'd like to return the number of mouse buttons, it's supported by AWT but I don't know if it is supported by SWT and it's not supported by NEWT.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
In reply to this post by Stefan
Done:
https://github.com/gouessej/Ardor3D/commit/869c418ce87118e8d5a50739187bc5804916252f

I'm going to update the binaries and the Java documentation very soon.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
In reply to this post by Stefan
The binaries and the API documentation have been updated too.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
Thanks a lot for your effort! I will test it.
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
You're welcome. Your feedbacks are welcome.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
It is working - thanks!
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
You're welcome. I might plan to support a lot more mouse buttons when the NEWT Input API is ready.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
Hey Julien,

yesterday I accidentially hit a hidden mouse button of my mouse with ID 10.

I have a very simple mouse. It does not even have a middle mouse button. So, I think it is very likely that this exception will be thrown with more complex mouses out there.

I don't know the internals of the API but a constant for each button does not seem to be a good solution for arbitrarily complex input devices. Does the API support a way to intercept the exception? It just pops-up and I can't do anything about it.

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
I just extended the SWTMouseWrapper and overloaded the mouseUp and mouseDown methods to catch the exceptions. Just a workaround but for the moment it is OK.
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
In reply to this post by Stefan
Hi

Please can you indicate exactly which kind of mouse you use?

Actually, I have already done numerous breaking changes whereas JogAmp's Ardor3D Continuation will have its very first stable release next year, the mouse buttons will go on being managed that way even though it's not very flexible.

Maybe I can replace the RuntimeException by a simple warning but I'll have to modify all callers as they don't support receiving a null value :s

Keep in mind that the mice with an hidden mouse button using 10 as an identifier are probably very rare. I've found a mouse with 6 buttons, it's really difficult to find a mouse with more than 10 buttons, there are a few gamer's mice with 20 buttons.

It's very important to be able to wrap all events of the toolkit into events of the engine so that it's possible to write some code working on several toolkits without any major change.

I'll probably support mice with 32 buttons.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

Stefan
Hi,

I am using a Logitech M705. I am counting five buttons. The button on the left hand side that is pressed by the thumb causes the problem. It is not an obvious button.

I don't know whether there are rules for mouse device manufacturer to define those IDs. I guess not. So, it might be possible that there are devices that only have five buttons but one button has ID 501 or so. But I am not into this topic.

Regards,

Stefan
Reply | Threaded
Open this post in threaded view
|

Re: [Ardor3D] SwtMouseWrapper

gouessej
Administrator
I understand your position, I have just looked at this mouse and it is hardly believable that it has at least 10 buttons but the SWT documentation claims that the identifier matches with the button count:
http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/events/MouseEvent.html#button
" the button that was pressed or released; 1 for the first button, 2 for the second button, and 3 for the third button, etc."

However, the way the identifier is obtained isn't the same in SWT and in AWT/NEWT, we might have some surprises :s In the worst case, you can rely on me, I'll do the necessary changes if a mouse button really has something bigger than what is currently supported.
Julien Gouesse | Personal blog | Website