Class SquidMouse

java.lang.Object
com.badlogic.gdx.InputAdapter
squidpony.squidgrid.gui.gdx.SquidMouse
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor

public class SquidMouse
extends com.badlogic.gdx.InputAdapter
This mouse processor allows for easy conversion to a grid based system. This class covers all aspects of mouse movement and clicking, passing those off to a given InputProcessor after converting to cell-based grid coordinates instead of pixel-based screen coordinates. It also passes off scroll events to the InputProcessor without additional changes. This class is meant to be used as a wrapper to your own mouse InputProcessor, it simply converts the coordinates from UI Component x,y to Grid based x,y
Author:
Eben Howard - http://squidpony.com - howard@squidpony.com, Tommy Ettinger
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected float cellHeight  
    protected float cellWidth  
    protected float gridHeight  
    protected float gridWidth  
    protected int offsetX  
    protected int offsetY  
    protected com.badlogic.gdx.InputProcessor processor  
  • Constructor Summary

    Constructors 
    Constructor Description
    SquidMouse​(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, com.badlogic.gdx.InputProcessor processor)
    Sets the size of the cell so that all mouse input can be evaluated as relative to the grid.
    SquidMouse​(float cellWidth, float cellHeight, com.badlogic.gdx.InputProcessor processor)
    Sets the size of the cell so that all mouse input can be evaluated as relative to the grid.
  • Method Summary

    Modifier and Type Method Description
    float getCellHeight()  
    float getCellWidth()  
    float getGridHeight()  
    float getGridWidth()  
    int getOffsetX()  
    int getOffsetY()  
    com.badlogic.gdx.InputProcessor getProcessor()
    Gets the InputProcessor this object uses to handle mouse input.
    boolean mouseMoved​(int screenX, int screenY)  
    boolean onGrid​(int screenX, int screenY)  
    void reinitialize​(float cellWidth, float cellHeight)  
    void reinitialize​(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY)  
    boolean scrolled​(int amount)  
    void setCellHeight​(float cellHeight)  
    void setCellWidth​(float cellWidth)  
    void setGridHeight​(float gridHeight)  
    void setGridWidth​(float gridWidth)  
    void setOffsetX​(int offsetX)  
    void setOffsetY​(int offsetY)  
    void setProcessor​(com.badlogic.gdx.InputProcessor processor)
    Sets the InputProcessor this object uses to handle mouse input.
    boolean touchDown​(int screenX, int screenY, int pointer, int button)  
    boolean touchDragged​(int screenX, int screenY, int pointer)  
    boolean touchUp​(int screenX, int screenY, int pointer, int button)  
    protected int translateX​(int screenX)  
    protected int translateY​(int screenY)  

    Methods inherited from class com.badlogic.gdx.InputAdapter

    keyDown, keyTyped, keyUp

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • SquidMouse

      public SquidMouse​(float cellWidth, float cellHeight, com.badlogic.gdx.InputProcessor processor)
      Sets the size of the cell so that all mouse input can be evaluated as relative to the grid. All input is passed to the provided InputProcessor once it has had its coordinates translated to grid coordinates. Offsets are initialized to 0 here, and the grid is assumed to take up the full game window.
      Parameters:
      cellWidth - the width of one cell in screen coordinates, usually pixels
      cellHeight - the height of one cell in screen coordinates, usually pixels
      processor - an InputProcessor that implements some of touchUp(), touchDown(), touchDragged(), mouseMoved(), or scrolled().
    • SquidMouse

      public SquidMouse​(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY, com.badlogic.gdx.InputProcessor processor)
      Sets the size of the cell so that all mouse input can be evaluated as relative to the grid. Offsets can be specified for x and y if the grid is displayed at a position other than the full screen. Specify the width and height in grid cells of the area to receive input, as well as the offsets from the bottom and left edges also measured in screen coordinates, which are often pixels but may be stretched or shrunk. All input is passed to the provided InputProcessor once it's had its coordinates translated to grid coordinates. If the input is not within the bounds of the grid as determined by gridWidth, gridHeight, offsetX, and offsetY, the input will be clamped.
      Parameters:
      cellWidth - the width of one cell in screen coordinates, usually pixels
      cellHeight - the height of one cell in screen coordinates, usually pixels
      gridWidth - in number of cells horizontally on the grid
      gridHeight - in number of cells vertically on the grid
      offsetX - the horizontal offset in screen coordinates, usually pixels
      offsetY - the vertical offset in screen coordinates, usually pixels
      processor - an InputProcessor that implements some of touchUp(), touchDown(), touchDragged(), mouseMoved(), or scrolled().
  • Method Details