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

de.lessvoid.nifty.slick2d.input.SlickSlickInputSystem Maven / Gradle / Ivy

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

import de.lessvoid.nifty.slick2d.input.events.InputEvent;
import org.newdawn.slick.InputListener;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * This is the input system that forwards all events to a slick listener. Also this input system is so slick, writing
 * slick once is not even enough.
 *
 * @author Martin Karing <[email protected]>
 */
public final class SlickSlickInputSystem extends AbstractSlickInputSystem implements ForwardingInputSystem {
  /**
   * The input listener that will receive any events the NiftyGUI does not use.
   */
  @Nullable
  private final InputListener listener;

  /**
   * Create the input system and set the listener that will receive any unused input events.
   *
   * @param targetListener the listener
   * @throws IllegalArgumentException in case the targetListener parameter is {@code null}
   */
  public SlickSlickInputSystem(@Nullable final InputListener targetListener) {
    if (targetListener == null) {
      throw new IllegalArgumentException("The target listener must not be NULL.");
    }
    listener = targetListener;
  }

  /**
   * Forward the input event to the slick listener.
   */
  @Override
  protected void handleInputEvent(@Nonnull final InputEvent event) {
    event.sendToSlick(listener);
  }

  @Override
  public void requestExclusiveMouse() {
    enableForwardingMode(ForwardingMode.mouse);
  }

  @Override
  public void requestExclusiveKeyboard() {
    enableForwardingMode(ForwardingMode.keyboard);
  }

  @Override
  public void requestExclusiveInput() {
    enableForwardingMode(ForwardingMode.all);
  }

  @Override
  public void releaseExclusiveMouse() {
    disableForwardingMode(ForwardingMode.mouse);
  }

  @Override
  public void releaseExclusiveKeyboard() {
    disableForwardingMode(ForwardingMode.keyboard);
  }

  @Override
  public void releaseExclusiveInput() {
    disableForwardingMode(ForwardingMode.all);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy