Android Java: Removing boundaries on the mouse - java

I have a special use case that requires a connected mouse to either wrap around the screen or to remove the boundaries on the mouse entirely. Pretty much what I need is to be able to see the physical change in mouse movement.
The MotionEvent for the mouse pointer does not provide how the mouse actually moves, but only how it moves on the screen itself. I have been using the onHover(View, MotionEvent) to get mouse data, and I can single out the mouse event by constraining the events to InputDevice.SOURCE_MOUSE, but it does not give any InputDevice.SOURCE_MOUSE_RELATIVE events, and I think that's the source I need to find out these relative mouse movements.
I am a beginner in Android development, so I don't know if I'm missing the obvious, but I've tried looking through the Android documentation. Is something like this even possible?

Related

Edit series by dragged mouse event Teechart in Java

I'm trying to move the curve of the graph by dragging the mouse,
is this possible?
Here's a visual example of what I'm attempting to do:
I'm using the Teechart library in java, to draw the series I use a Jpanel (Swing).
Is there a function that allows me to do this?
I'm not familiar with Teechart. Maybe it will handle mouse input. If not, add a MouseMotionListener to the component that's displaying the graph, and implement the mouseDragged method. The MouseEvent parameter has methods to tell you where the event occurred. Use that to decide whether to update the graph, and by how much, and call the appropriate Teechart methods. You might also want to add a MouseListener and implement mousePressed and mouseReleased. The sequence of events should be Pressed, Dragged, possibly more drags, Released.

How to constrain the mouse cursor within the bounds of the window in LibGDX?

This is a widely known issue that can even sometimes appear on even high-budget professional titles, that when you set the window type to "borderless" and you have an extended display your mouse can "slide off-screen" if the mouse is not constrained to the limits of the display the game is running on currently.
I was wondering how LibGDX can tackle this.
Is there some direct way to constraint mouse movement?
Or does one need to do continuous iterative calculations on mouse position or something?
Libgdx offers built-in function for trapping mouse cursor inside window. Function you are looking is Gdx.input.setCursorCatched(true).
Taken from the docs:
void setCursorCatched(boolean catched)
Only viable on the desktop. Will confine the mouse cursor location to the window and hide the mouse cursor. X and y coordinates are still reported as if the mouse was not catched.
Parameters:
catched - whether to catch or not to catch the mouse cursor
Or checkout documentation by yourself here.
LibGDX is built on top of LWJGL, so you should be able to use the Mouse.setGrabbed() method.
More info in the API: http://www.lwjgl.org/javadoc/org/lwjgl/input/Mouse.html#setGrabbed(boolean)
And here's a discussion on what changes when you call Mouse.setGrabbed(): http://lwjgl.org/forum/index.php?topic=5150.0

Does SWT Canvas Provide Tools For Mouse Move/Click Active Areas?

I'm creating an application with Java and SWT, and have a workspace generated on a Canvas. I need to make certain areas (controls) on the canvas trigger an event when mouseover-ed or clicked. Of course this could be done by listening to the MouseMoveEvent and checking the location of the mouse manually, but I would like to know if SWT provides an easier way to do this.
Thanks
As far as I know, there is no facility to automate this. You will need to register mouse listeners and investigate the x & y coordinates manually.
A different approach might be adding individual Canvas objects onto an enclosing Canvas. This way, you could add listeners to the individual controls. This will, however, use more memory (as the underlying object has a buffer, as well as the control on top) and redrawing will be more CPU intensive.
My personal preference goes to the first technique.
Thanks for the answer, Paul. I finally created an ArrayList of Rectangle objects for each control. Whenever the mousemove event triggers, I loop through each Rectangle and call Rectangle.contains() with the mouse coordinates. This solution turned out to be very organized.
In my case, the control events are homogenous (they all do the same thing), but if anyone has multiple control actions, Rectangle.data can be used to contain a Command object.

JGraph - overriding cell drag

This is quite a long shot, I know it's a question about a very specific package.
I'm trying to stop nodes from dragging into a certain area of the graph.
I have written code to detect when the mouse is dragged over a node, however it is a bit of a hack. I am trying to get the node that the mouse is dragging and its XY co-ordinates but have no idea how to do it.
I can't find any methods to override this, the marquee handler doesn't get called for a node drag. I'm looking at overriding the BasicUI class, but don't know
You would be better off posting at the JGraph forum.

How to generate events from graphics generated by Java2D

I have made an Ellipse with the help of java.awt.geom.Ellipse2D
Now, I want that whenever user clicks on that ellipse, an event is generated so that I can listen to that event and peform subsequent tasks based on the ellipse which generated that event.
Here is a simple example of an object drawing program that demonstrates click, drag and multiple selection. Also consider JGraph, which is a much more advanced library for graph visualization.
I'm going to assume this is a question asking a way to listen to mouse clicks which are made on an ellipse drawn on some Swing component using Graphics2D.draw.
The simple answer is, there is no way to generate mouse events from graphics drawn on a surface.
However, here's an alternative approach:
Store the Ellipse2D objects from which the ellipses were drawn from in a List.
Register a MouseListener on the Swing component where the user is to click on.
From the MouseEvents generated from the mouse clicks, determine the location at which the mouse was clicked (using MouseEvent.getPoint), and check if the mouse click occurred in any of the Ellipse2Ds contained in the aforementioned List, using the Ellipse2D.contains method.
I don't think this is possible without lots of handcoded stuff (letting the canvas or whatever, listen to mouse events, and calculating yourself if the ellipse was clicked on).
If you want to do more like that consider scenegraph. With that the ellipse would be an object in its own right and you can register event listeners.
Edit as response to comment:
Scenegraph: https://scenegraph.dev.java.net/
google for more resources: scenegraph java
And yes. Scenegraph ist part of the JavaFX stuff, but works nicely with pure Java (no FX)

Categories

Resources