org.lwjgl.input.Mouse类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.lwjgl.input.Mouse类的一些代码示例,展示了Mouse类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mouse类的具体详情如下:
包路径:org.lwjgl.input.Mouse
类名称:Mouse

Mouse介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

public boolean isTouched () {
  boolean button = Mouse.isButtonDown(0) || Mouse.isButtonDown(1) || Mouse.isButtonDown(2);
  return button;
}

代码示例来源:origin: libgdx/libgdx

void updateMouse () {
  justTouched = false;
  if (Mouse.isCreated()) {
    int events = 0;
    while (Mouse.next()) {
      events++;
      int x = (int)(Mouse.getEventX() * Display.getPixelScaleFactor());
      int y = Gdx.graphics.getHeight() - (int)(Mouse.getEventY() * Display.getPixelScaleFactor()) - 1;
      int button = Mouse.getEventButton();
      int gdxButton = toGdxButton(button);
      if (button != -1 && gdxButton == -1) continue; // Ignore unknown button.
      event.button = gdxButton;
      event.pointer = 0;
      event.timeStamp = Mouse.getEventNanoseconds();
        if (Mouse.getEventDWheel() != 0) {
          event.type = TouchEvent.TOUCH_SCROLLED;
          event.scrollAmount = (int)-Math.signum(Mouse.getEventDWheel());
        } else if (pressedButtons.size > 0) {
          event.type = TouchEvent.TOUCH_DRAGGED;
        if (Mouse.getEventButtonState()) {
          event.type = TouchEvent.TOUCH_DOWN;
          pressedButtons.add(event.button);
      mouseX = event.x;
      mouseY = event.y;
      deltaX = (int)(Mouse.getEventDX() * Display.getPixelScaleFactor());
      deltaY = (int)(Mouse.getEventDY() * Display.getPixelScaleFactor());

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

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();
    evt.setTime(Mouse.getEventNanoseconds());
    listener.onMouseMotionEvent(evt);
        Mouse.getEventButtonState(), x, y);
    evt.setTime(Mouse.getEventNanoseconds());
    listener.onMouseButtonEvent(evt);

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Vector2i getPosition() {
  return new Vector2i(Mouse.getX() / this.uiScale, (Display.getHeight() - Mouse.getY()) / this.uiScale);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

/**
 * Send the input listener a special mouse-motion event with zero deltas in
 * order to initialize the listener's cursor position.
 */
private void sendFirstMouseEvent() {
  assert listener != null;
  assert Mouse.isCreated();
  int x = Mouse.getX();
  int y = Mouse.getY();
  int xDelta = 0;
  int yDelta = 0;
  int wheelDelta = 0;
  MouseMotionEvent evt = new MouseMotionEvent(x, y, xDelta, yDelta,
      curWheel, wheelDelta);
  evt.setTime(Mouse.getEventNanoseconds());
  listener.onMouseMotionEvent(evt);
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

@Override
public void handleMouseInput() throws IOException {
  super.handleMouseInput();
  int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
  int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
  int button = Mouse.getEventButton();
  boolean state = Mouse.getEventButtonState();
  int wheel = Mouse.getEventDWheel();
  int type = button >= 0 ? (state ? Listener.MOUSE_DOWN : Listener.MOUSE_UP) : wheel != 0 ? Listener.MOUSE_WHEEL : Listener.MOUSE_MOVED;
  ActivationEvent evt = new ActivationEvent(type, button, state, x, y, wheel);
  for (GuiElement element : this.elements) {
    element.handleMouseInput(evt);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public void handleMouseInput() throws IOException
{
  super.handleMouseInput();
  final int i = Mouse.getEventDWheel();
  if( i != 0 && isShiftKeyDown() )
  {
    final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
    final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    this.mouseWheelEvent( x, y, i / Math.abs( i ) );
  }
  else if( i != 0 && this.getScrollBar() != null )
  {
    this.getScrollBar().wheel( i );
  }
}

代码示例来源:origin: com.ardor3d/ardor3d-lwjgl

if (!Mouse.next()) {
  return endOfData();
if (Mouse.getButtonCount() > 0) {
  final boolean down = Mouse.isButtonDown(0);
  processButtonForClick(MouseButton.LEFT, down);
  buttons.put(MouseButton.LEFT, down ? ButtonState.DOWN : ButtonState.UP);
if (Mouse.getButtonCount() > 1) {
  final boolean down = Mouse.isButtonDown(1);
  processButtonForClick(MouseButton.RIGHT, down);
  buttons.put(MouseButton.RIGHT, down ? ButtonState.DOWN : ButtonState.UP);
if (Mouse.getButtonCount() > 2) {
  final boolean down = Mouse.isButtonDown(2);
  processButtonForClick(MouseButton.MIDDLE, down);
  buttons.put(MouseButton.MIDDLE, down ? ButtonState.DOWN : ButtonState.UP);
final MouseState nextState = new MouseState(Mouse.getEventX(), Mouse.getEventY(), Mouse.getEventDX(), Mouse
    .getEventDY(), Mouse.getEventDWheel(), buttons, null);

代码示例来源:origin: thraaawn/CompactMachines

@Override
public void handleMouseInput() throws IOException {
  super.handleMouseInput();
  if(activeTab == 1) {
    int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth;
    int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
    if (this.guiWhiteList != null) {
      this.guiWhiteList.handleMouseInput(mouseX, mouseY);
    }
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@Override
public Queue<MouseAction> getInputQueue() {
  Queue<MouseAction> result = Queues.newArrayDeque();
  while (Mouse.next()) {
    if (Mouse.getEventButton() != -1) {
      ButtonState state = (Mouse.getEventButtonState()) ? ButtonState.DOWN : ButtonState.UP;
      result.add(new MouseAction(InputType.MOUSE_BUTTON.getInput(Mouse.getEventButton()), state, getPosition()));
    }
    if (Mouse.getEventDWheel() != 0) {
      int id = (Mouse.getEventDWheel() > 0) ? 1 : -1;
      result.add(new MouseAction(InputType.MOUSE_WHEEL.getInput(id), id * Mouse.getEventDWheel() / 120, getPosition()));
    }
  }
  return result;
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

@Override
  public void handleMouseInput() throws IOException {
    int x = Mouse.getEventX() * width / mc.displayWidth;
    int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
    mouseX = x - guiLeft;
    mouseY = y - guiTop;
    mouseWheel = Mouse.getDWheel();
    super.handleMouseInput();
  }
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

@Override
protected boolean onGuiCloseRequested() {
  getContainer().addSlots();
  int x = Mouse.getX();
  int y = Mouse.getY();
  Minecraft.getMinecraft().displayGuiScreen(parent);
  Mouse.setCursorPosition(x, y);
  return false;
}

代码示例来源:origin: TehNut/HWYLA

public MouseEvent(IWidget widget) {
  this.srcwidget = widget;
  this.timestamp = System.nanoTime();
  this.mc = Minecraft.getMinecraft();
  this.x = (double) Mouse.getEventX() * (double) this.srcwidget.getSize().getX() / (double) this.mc.displayWidth;
  this.y = (double) this.srcwidget.getSize().getY() - (double) Mouse.getEventY() * (double) this.srcwidget.getSize().getY() / (double) this.mc.displayHeight - 1.0;
  //this.x = Mouse.getEventX();
  //this.y = Mouse.getEventY();
  //System.out.printf("%s %s\n", this.x, this.y);
  //this.z = Mouse.getEventDWheel();
  this.z = Mouse.getDWheel();
  for (int i = 0; i < buttonCount; i++)
    buttonState[i] = Mouse.isButtonDown(i);
  this.trgwidget = this.srcwidget.getWidgetAtCoordinates(this.x, this.y);
}

代码示例来源:origin: RS485/LogisticsPipes

public void preRender() {
  if (isOverlaySlotActive) {
    // Save Mouse Pos
    oldX = Mouse.getX();
    oldY = Mouse.getY();
    // Set Pos 0,0
    try {
      fX.set(null, 0);
      fY.set(null, 0);
      hasBeenSaved = true;
    } catch (Exception e) {
      if (LPConstants.DEBUG) {
        e.printStackTrace();
      }
    }
    while (Mouse.next()) {
      if (Mouse.getEventButton() == 0 && Mouse.getEventButtonState()) {
        clicked = true;
      }
    }
  }
}

代码示例来源:origin: SleepyTrousers/EnderCore

private void processMouseEvents(int mX, int mY) {
 if (Mouse.isButtonDown(0)) {
  processMouseBown(mX, mY);
 } else {
  while (!mc.gameSettings.touchscreen && Mouse.next()) {
   int mouseWheelDelta = Mouse.getEventDWheel();
   if (mouseWheelDelta != 0) {
    if (mouseWheelDelta > 0) {
     mouseWheelDelta = -1;
    } else if (mouseWheelDelta < 0) {
     mouseWheelDelta = 1;
    }
    amountScrolled += mouseWheelDelta * slotHeight / 2;
   }
  }
  initialClickY = -1.0F;
 }
}

代码示例来源:origin: Direwolf20-MC/BuildingGadgets

@Override
public void handleMouseInput() throws IOException {
  super.handleMouseInput();
  //System.out.println(Mouse.getEventDWheel());
  zoom = initZoom + Mouse.getEventDWheel() / 2;
  if (zoom < -200) zoom = -200;
  if (zoom > 1000) zoom = 1000;
  //System.out.println(zoom);
}

代码示例来源:origin: Vazkii/Botania

@Override
public void handleMouseInput() throws IOException {
  super.handleMouseInput();
  if(Mouse.getEventButton() == 0)
    swiped = false;
  int w = Mouse.getEventDWheel();
  if(w < 0)
    nextPage();
  else if(w > 0)
    prevPage();
}

代码示例来源:origin: mezz/JustEnoughItems

public boolean handleMouseEvent(GuiScreen guiScreen, int mouseX, int mouseY) {
  boolean cancelEvent = false;
  final int eventButton = Mouse.getEventButton();
  if (eventButton > -1) {
    if (Mouse.getEventButtonState()) {
      if (!clickHandled.contains(eventButton)) {
        cancelEvent = handleMouseClick(guiScreen, eventButton, mouseX, mouseY);
        if (cancelEvent) {
          clickHandled.add(eventButton);
        }
      }
    } else if (clickHandled.contains(eventButton)) {
      clickHandled.remove(eventButton);
      cancelEvent = true;
    }
  } else if (Mouse.getEventDWheel() != 0) {
    cancelEvent = handleMouseScroll(Mouse.getEventDWheel(), mouseX, mouseY);
  }
  return cancelEvent;
}

代码示例来源:origin: Mine-and-blade-admin/Battlegear2

@Override
public void draw(int x, int y, int[] pixels, int rgb, boolean shift) {
  if(Mouse.getEventButton() == 0 &&(!Mouse.getEventButtonState()) && last_x > -1000 && last_y > -1000){
    if(shift){
      if(last_y > y)
        y = last_y - Math.abs(last_x - x);
      else
        y = last_y + Math.abs(last_x - x);
    }
    drawShape(Math.min(last_x, x),
        Math.min(last_y, y),
        Math.max(last_x, x),
        Math.max(last_y, y),
        pixels,
        rgb);
  }
}

代码示例来源:origin: org.ode4j/demo

/**
 * reads a mouse in buffered mode
 */
private void readBufferedMouse() {
  // iterate all events, use the last button down
  while(Mouse.next()) {
    if (Mouse.getEventButton() != -1) {
      if (Mouse.getEventButtonState()) {
    }
      //lastButton = Mouse.getEventButton();
    }
  }  
  updateState();
}

相关文章