Package squidpony.squidgrid.gui.gdx
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)
-
Field Details
-
Constructor Details
-
SquidMouse
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
-
getCellHeight
-
getOffsetX
-
getOffsetY
-
getGridWidth
-
getGridHeight
-
setCellWidth
-
setCellHeight
-
setOffsetX
-
setOffsetY
-
setGridWidth
-
setGridHeight
-
reinitialize
-
reinitialize
public void reinitialize(float cellWidth, float cellHeight, float gridWidth, float gridHeight, int offsetX, int offsetY) -
getProcessor
Gets the InputProcessor this object uses to handle mouse input.- Returns:
- the wrapped InputProcessor.
-
setProcessor
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
-
translateY
-
onGrid
-
touchDown
- Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDown
in classcom.badlogic.gdx.InputAdapter
-
touchUp
- Specified by:
touchUp
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchUp
in classcom.badlogic.gdx.InputAdapter
-
touchDragged
- Specified by:
touchDragged
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDragged
in classcom.badlogic.gdx.InputAdapter
-
mouseMoved
- Specified by:
mouseMoved
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
mouseMoved
in classcom.badlogic.gdx.InputAdapter
-
scrolled
- Specified by:
scrolled
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
scrolled
in classcom.badlogic.gdx.InputAdapter
-