use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.
the class AwtMouseInput method update.
public void update() {
if (cursorMoved) {
int newX = location.x;
int newY = location.y;
int newWheel = wheelPos;
// invert actual Y and DY for motion events
int actualX = lastKnownLocation.x;
int actualY = component.getHeight() - lastKnownLocation.y;
MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY, newX - lastEventX, lastEventY - newY, wheelPos, lastEventWheel - wheelPos);
listener.onMouseMotionEvent(evt);
lastEventX = newX;
lastEventY = newY;
lastEventWheel = newWheel;
cursorMoved = false;
}
synchronized (eventQueue) {
eventQueueCopy.clear();
eventQueueCopy.addAll(eventQueue);
eventQueue.clear();
}
int size = eventQueueCopy.size();
for (int i = 0; i < size; i++) {
listener.onMouseButtonEvent(eventQueueCopy.get(i));
}
}
use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.
the class GlfwMouseInputVR method onWheelScroll.
private void onWheelScroll(long window, double xOffset, double yOffset) {
mouseWheel += yOffset;
final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(mouseX, mouseY, 0, 0, mouseWheel, (int) Math.round(yOffset));
mouseMotionEvent.setTime(getInputTimeNanos());
mouseMotionEvents.add(mouseMotionEvent);
}
use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.
the class GlfwMouseInputVR method onCursorPos.
private void onCursorPos(long window, double xpos, double ypos) {
int x = (int) Math.round(xpos);
int y = context.getSettings().getHeight() - (int) Math.round(ypos);
if (mouseX == 0) {
mouseX = x;
}
if (mouseY == 0) {
mouseY = y;
}
xDelta = x - mouseX;
yDelta = y - mouseY;
mouseX = x;
mouseY = y;
if (xDelta != 0 || yDelta != 0) {
final MouseMotionEvent mouseMotionEvent = new MouseMotionEvent(x, y, xDelta, yDelta, mouseWheel, 0);
mouseMotionEvent.setTime(getInputTimeNanos());
mouseMotionEvents.add(mouseMotionEvent);
}
}
use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.
the class AndroidTouchInput method generateMouseEvent.
// TODO: Ring Buffer for mouse events?
public InputEvent generateMouseEvent(TouchEvent event) {
InputEvent inputEvent = null;
int newX;
int newY;
int newDX;
int newDY;
// MouseEvents do not support multi-touch, so only evaluate 1 finger pointer events
if (!isSimulateMouse() || numPointers > 1) {
return null;
}
if (isMouseEventsInvertX()) {
newX = (int) (invertX(event.getX()));
newDX = (int) event.getDeltaX() * -1;
} else {
newX = (int) event.getX();
newDX = (int) event.getDeltaX();
}
if (isMouseEventsInvertY()) {
newY = (int) (invertY(event.getY()));
newDY = (int) event.getDeltaY() * -1;
} else {
newY = (int) event.getY();
newDY = (int) event.getDeltaY();
}
switch(event.getType()) {
case DOWN:
// Handle mouse down event
inputEvent = new MouseButtonEvent(0, true, newX, newY);
inputEvent.setTime(event.getTime());
break;
case UP:
// Handle mouse up event
inputEvent = new MouseButtonEvent(0, false, newX, newY);
inputEvent.setTime(event.getTime());
break;
case HOVER_MOVE:
case MOVE:
inputEvent = new MouseMotionEvent(newX, newY, newDX, newDY, (int) event.getScaleSpan(), (int) event.getDeltaScaleSpan());
inputEvent.setTime(event.getTime());
break;
}
return inputEvent;
}
use of com.jme3.input.event.MouseMotionEvent in project jmonkeyengine by jMonkeyEngine.
the class NewtMouseInput method update.
@Override
public void update() {
if (!component.hasFocus())
return;
if (cursorMoved) {
int newX = location.getX();
int newY = location.getY();
int newWheel = wheelPos;
// invert DY
int actualX = lastKnownLocation.getX();
int actualY = component.getSurfaceHeight() - lastKnownLocation.getY();
MouseMotionEvent evt = new MouseMotionEvent(actualX, actualY, newX - lastEventX, lastEventY - newY, wheelPos, lastEventWheel - wheelPos);
listener.onMouseMotionEvent(evt);
lastEventX = newX;
lastEventY = newY;
lastEventWheel = newWheel;
cursorMoved = false;
}
synchronized (eventQueue) {
eventQueueCopy.clear();
eventQueueCopy.addAll(eventQueue);
eventQueue.clear();
}
int size = eventQueueCopy.size();
for (int i = 0; i < size; i++) {
listener.onMouseButtonEvent(eventQueueCopy.get(i));
}
}
Aggregations