Example #1
0
  /** Callback from RawInputListener. Do not use. */
  public void onMouseMotionEvent(MouseMotionEvent evt) {
    if (!eventsPermitted) {
      throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
    }

    cursorPos.set(evt.getX(), evt.getY());
    inputQueue.add(evt);
  }
  public void update() {
    if (!context.isRenderable()) return;

    while (Mouse.next()) {
      int btn = Mouse.getEventButton();

      int wheelDelta = Mouse.getEventDWheel();
      int xDelta = Mouse.getEventDX();
      int yDelta = Mouse.getEventDY();
      int x = Mouse.getX();
      int y = Mouse.getY();

      curWheel += wheelDelta;
      if (cursorVisible) {
        xDelta = x - curX;
        yDelta = y - curY;
        curX = x;
        curY = y;
      } else {
        x = curX + xDelta;
        y = curY + yDelta;
        curX = x;
        curY = y;
      }

      if (xDelta != 0 || yDelta != 0 || wheelDelta != 0) {
        MouseMotionEvent evt = new MouseMotionEvent(x, y, xDelta, yDelta, curWheel, wheelDelta);
        evt.setTime(Mouse.getEventNanoseconds());
        listener.onMouseMotionEvent(evt);
      }
      if (btn != -1) {
        MouseButtonEvent evt = new MouseButtonEvent(btn, Mouse.getEventButtonState(), x, y);
        evt.setTime(Mouse.getEventNanoseconds());
        listener.onMouseButtonEvent(evt);
      }
    }
  }
Example #3
0
  private void onMouseMotionEventQueued(MouseMotionEvent evt) {
    //        for (int i = 0; i < rawListeners.size(); i++){
    //            rawListeners.get(i).onMouseMotionEvent(evt);
    //        }

    if (evt.getDX() != 0) {
      float val = Math.abs(evt.getDX()) / 1024f;
      invokeAnalogsAndActions(
          MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_X, evt.getDX() < 0), val, false);
    }
    if (evt.getDY() != 0) {
      float val = Math.abs(evt.getDY()) / 1024f;
      invokeAnalogsAndActions(
          MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_Y, evt.getDY() < 0), val, false);
    }
    if (evt.getDeltaWheel() != 0) {
      float val = Math.abs(evt.getDeltaWheel()) / 100f;
      invokeAnalogsAndActions(
          MouseAxisTrigger.mouseAxisHash(MouseInput.AXIS_WHEEL, evt.getDeltaWheel() < 0),
          val,
          false);
    }
  }