It is currently 05 Jun 2020, 21:47
   
Text Size

FMouseAdapter == more responsive/reliable clicking

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, friarsol, Blacksmith, KrazyTheFox, Agetian, CCGHQ Admins

FMouseAdapter == more responsive/reliable clicking

Postby nash39619 » 29 Nov 2019, 04:29

My biggest issue with Java, which I've discovered through working with Forge, is that the mouseClick event is only raised if the mouse doesn't move even a single pixel between mouse down and mouse up. As a result, any component that uses this event to trigger some action has usability problems where clicking it seemingly fails half the time. We've solved this for some components by using mousePressed or mouseReleased instead, but some places that use mousePressed really shouldn't, since the action should be cancelable by dragging the mouse away (which may itself do some drag action), and those using mouseReleased are triggered incorrectly if you mouse down outside the component and release inside.

Another issue I've noticed with our own code is that many mouse event handlers don't bother to check the button clicked, so the left, right, and middle mouse buttons all do the same thing when really only the left button should. I've fixed a few of these since I started on Forge, but there are still many others, and it's easy to forget to check the button.

My solution to these problems was to create FMouseAdapter, a new class that extends MouseAdapter and raises more specific events for each mouse button, including a more forgiving click event, as well as a specific double click event that's fired on the second mouse down if the first mouse down and up was a click. Note that a click in this case is defined as a mouse down and mouse up both inside the same component, regardless of the path the mouse takes in between.

For components that have special drag handling, an optional boolean parameter can be passed to the constructor to indicate such, which then tweaks it so the click events aren't raised if the mouse moves more than a couple pixels, which would start a drag. There's also a new DragDrop event that fires for such components if the mouse moves too much to be a click, which should replace mouseReleased for handling ending a drag operation.
nash39619
 
Posts: 1
Joined: 29 Nov 2019, 04:26
Has thanked: 0 time
Been thanked: 0 time

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 8 guests


Who is online

In total there are 8 users online :: 0 registered, 0 hidden and 8 guests (based on users active over the past 10 minutes)
Most users ever online was 1371 on 09 Feb 2020, 16:22

Users browsing this forum: No registered users and 8 guests

Login Form