Class SquidMouse
java.lang.Object
com.badlogic.gdx.InputAdapter
com.github.yellowstonegames.press.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 screen-space x,y to grid-based x,y .
This class is meant to be used as a wrapper to your own mouse InputProcessor; it simply converts the coordinates from screen-space x,y to grid-based x,y .
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected floatprotected floatprotected floatprotected floatprotected intprotected intprotected com.badlogic.gdx.InputProcessor -
Constructor Summary
ConstructorsConstructorDescriptionSquidMouse(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 TypeMethodDescriptionfloatfloatfloatfloatintintcom.badlogic.gdx.InputProcessorGets the InputProcessor this object uses to handle mouse input.booleanmouseMoved(int screenX, int screenY) booleanonGrid(int gridX, int gridY) Returns true if the provided screen coordinate is on the grid, ignoring the current offset.voidreinitialize(float cellWidth, float cellHeight) voidreinitialize(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY) booleanscrolled(float amountX, float amountY) voidsetCellHeight(float cellHeight) voidsetCellWidth(float cellWidth) voidsetGridHeight(float gridHeight) voidsetGridWidth(float gridWidth) voidsetOffsetX(int offsetX) voidsetOffsetY(int offsetY) voidsetProcessor(com.badlogic.gdx.InputProcessor processor) Sets the InputProcessor this object uses to handle mouse input.booleantouchDown(int screenX, int screenY, int pointer, int button) booleantouchDragged(int screenX, int screenY, int pointer) booleantouchUp(int screenX, int screenY, int pointer, int button) inttranslateX(int screenX) Translates the given screen pixel coordinate to the underlying grid coordinate, taking into account the related offset.inttranslateY(int screenY) Translates the given screen pixel coordinate to the underlying grid coordinate, taking into account the related offset.Methods inherited from class com.badlogic.gdx.InputAdapter
keyDown, keyTyped, keyUp, touchCancelled
-
Field Details
-
cellWidth
protected float cellWidth -
cellHeight
protected float cellHeight -
gridWidth
protected float gridWidth -
gridHeight
protected float gridHeight -
offsetX
protected int offsetX -
offsetY
protected int offsetY -
processor
protected com.badlogic.gdx.InputProcessor processor
-
-
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 pixelscellHeight- the height of one cell in screen coordinates, usually pixelsprocessor- 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 pixelscellHeight- the height of one cell in screen coordinates, usually pixelsgridWidth- in number of cells horizontally on the gridgridHeight- in number of cells vertically on the gridoffsetX- the horizontal offset in screen coordinates, usually pixelsoffsetY- the vertical offset in screen coordinates, usually pixelsprocessor- an InputProcessor that implements some of touchUp(), touchDown(), touchDragged(), mouseMoved(), or scrolled().
-
-
Method Details
-
getCellWidth
public float getCellWidth() -
getCellHeight
public float getCellHeight() -
getOffsetX
public int getOffsetX() -
getOffsetY
public int getOffsetY() -
getGridWidth
public float getGridWidth() -
getGridHeight
public float getGridHeight() -
setCellWidth
public void setCellWidth(float cellWidth) -
setCellHeight
public void setCellHeight(float cellHeight) -
setOffsetX
public void setOffsetX(int offsetX) -
setOffsetY
public void setOffsetY(int offsetY) -
setGridWidth
public void setGridWidth(float gridWidth) -
setGridHeight
public void setGridHeight(float gridHeight) -
reinitialize
public void reinitialize(float cellWidth, float cellHeight) -
reinitialize
public void reinitialize(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY) -
getProcessor
public com.badlogic.gdx.InputProcessor getProcessor()Gets the InputProcessor this object uses to handle mouse input.- Returns:
- the wrapped InputProcessor.
-
setProcessor
public void setProcessor(com.badlogic.gdx.InputProcessor processor) Sets the InputProcessor this object uses to handle mouse input.- Parameters:
processor- an InputProcessor that implements some of touchUp(), touchDown(), touchDragged(), mouseMoved(), or scrolled().
-
translateX
public int translateX(int screenX) Translates the given screen pixel coordinate to the underlying grid coordinate, taking into account the related offset.- Parameters:
screenX- a screen x position, usually in pixels- Returns:
- a grid x position
-
translateY
public int translateY(int screenY) Translates the given screen pixel coordinate to the underlying grid coordinate, taking into account the related offset.- Parameters:
screenY- a screen y position, usually in pixels- Returns:
- a grid y position
-
onGrid
public boolean onGrid(int gridX, int gridY) Returns true if the provided screen coordinate is on the grid, ignoring the current offset.- Parameters:
gridX- x-coordinate measured in grid cells, not pixelsgridY- y-coordinate measured in grid cells, not pixels- Returns:
- true if the given gridX and gridY are on the grid, or false if they are outside it
-
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) - Specified by:
touchDownin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDownin classcom.badlogic.gdx.InputAdapter
-
touchUp
public boolean touchUp(int screenX, int screenY, int pointer, int button) - Specified by:
touchUpin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchUpin classcom.badlogic.gdx.InputAdapter
-
touchDragged
public boolean touchDragged(int screenX, int screenY, int pointer) - Specified by:
touchDraggedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
touchDraggedin classcom.badlogic.gdx.InputAdapter
-
mouseMoved
public boolean mouseMoved(int screenX, int screenY) - Specified by:
mouseMovedin interfacecom.badlogic.gdx.InputProcessor- Overrides:
mouseMovedin classcom.badlogic.gdx.InputAdapter
-
scrolled
public boolean scrolled(float amountX, float amountY) - Specified by:
scrolledin interfacecom.badlogic.gdx.InputProcessor- Overrides:
scrolledin classcom.badlogic.gdx.InputAdapter
-