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

de.lessvoid.nifty.slick2d.input.events.MouseEventDragged 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 org.newdawn.slick.InputListener;

import javax.annotation.Nonnull;

/**
 * This mouse event is used to store the event generated in case the mouse cursor is moved with one button pressed.
 *
 * @author Martin Karing <[email protected]>
 */
public final class MouseEventDragged extends AbstractMouseEventButton {
  /**
   * The X coordinate where the movement stopped.
   */
  private final int targetX;

  /**
   * The Y coordinate where the movement stopped.
   */
  private final int targetY;

  /**
   * Create a mouse dragged event.
   *
   * @param mouseButton the mouse button that was used
   * @param startX      the X coordinate of the location where the movement started
   * @param startY      the Y coordinate of the location where the movement started
   * @param endX        the X coordinate of the location where the movement stopped
   * @param endY        the Y coordinate of the location where the movement stopped
   */
  public MouseEventDragged(final int mouseButton, final int startX, final int startY, final int endX, final int endY) {
    super(startX, startY, mouseButton);
    targetX = endX;
    targetY = endY;
  }

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

  /**
   * Send the event to the Slick input listener.
   */
  @Override
  public boolean sendToSlick(@Nonnull final InputListener listener) {
    if(!listener.isAcceptingInput()) return false;
    
    listener.mouseDragged(getX(), getY(), targetX, targetY);
    return true;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy