All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lessvoid.nifty.slick2d.input.events.MouseEventPressed Maven / Gradle / Ivy

There is a newer version: 1.4.3
Show newest version
package de.lessvoid.nifty.slick2d.input.events;

import de.lessvoid.nifty.NiftyInputConsumer;
import de.lessvoid.nifty.slick2d.input.InputState;
import org.newdawn.slick.InputListener;

import javax.annotation.Nonnull;

/**
 * This mouse event is used to store the event generated in case a mouse button is pressed down.
 *
 * @author Martin Karing <[email protected]>
 */
public final class MouseEventPressed extends AbstractMouseEventButton {
  /**
   * Create a new mouse button pressed event.
   *
   * @param x           the x coordinate of the event location
   * @param y           the y coordinate of the event location
   * @param mouseButton the mouse button that was used
   */
  public MouseEventPressed(final int x, final int y, final int mouseButton) {
    super(x, y, mouseButton);
  }

  /**
   * Send the event to a Nifty input event consumer.
   */
  @Override
  public boolean sendToNifty(@Nonnull final NiftyInputConsumer consumer) {
    return consumer.processMouseEvent(getX(), getY(), 0, getButton(), true);
  }

  /**
   * Send the event to a slick input event consumer.
   */
  @Override
  public boolean sendToSlick(@Nonnull final InputListener listener) {
    if(!listener.isAcceptingInput()) return false;
    
    listener.mousePressed(getButton(), getX(), getY());
    return true;
  }

  /**
   * Tell the state to consume the next click event in case the click happened upon the GUI.
   */
  @Override
  public void updateState(@Nonnull final InputState state, final boolean handledByGUI) {
    state.setConsumeNextClick(handledByGUI);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy