Package de.tum.cit.ase.editor.tools
Class EditorTool
java.lang.Object
de.tum.cit.ase.editor.input.ToolInputAdapter
de.tum.cit.ase.editor.tools.EditorTool
- All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
,com.badlogic.gdx.utils.Pool.Poolable
,ShortcutAdapter
,Tool
public abstract sealed class EditorTool
extends ToolInputAdapter
implements Tool, com.badlogic.gdx.utils.Pool.Poolable
permits Bucket, Eraser, Pen, Square
The base class for all editor tools.
-
Field Summary
Modifier and TypeFieldDescriptionprotected com.badlogic.gdx.math.Bresenham2
protected Canvas
protected com.badlogic.gdx.math.GridPoint2
protected com.badlogic.gdx.math.GridPoint2
Fields inherited from interface de.tum.cit.ase.editor.input.ShortcutAdapter
pressedKeys
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer) Draws using the provided ShapeRenderer.TileTypes[][]
getGrid()
getInstance
(Canvas canvas) Retrieves an instance of the Tool class with the provided Canvas.protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.GridPoint2>
getLine
(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 end) Returns an array of GridPoint2 objects representing a line between the given start and end points.protected void
getStraightLineCoordinates
(com.badlogic.gdx.math.GridPoint2 startGrid, com.badlogic.gdx.math.Vector2 start, com.badlogic.gdx.math.Vector2 end) Sets the start and end coordinates of a straight line based on the given start grid point.protected boolean
Determines if the current tool is set to draw a straight line.protected abstract void
markTile
(com.badlogic.gdx.math.GridPoint2 gridPoint) Marks a tile on the grid based on the given grid point.com.badlogic.gdx.math.Vector2
projectGridPointToWorld
(com.badlogic.gdx.math.GridPoint2 gridPoint2) Projects a grid point to world coordinates.com.badlogic.gdx.math.Vector2
projectGridPointToWorld
(com.badlogic.gdx.math.GridPoint2 gridPoint2, boolean edge) Projects a grid point to world coordinates.void
reset()
Resets the state of the tool.boolean
touchDown
(int screenX, int screenY, int pointer, int button) Handles the touch down event in the editor.boolean
touchDragged
(int screenX, int screenY, int pointer) Handles the touch dragged event in the editor.boolean
touchUp
(int screenX, int screenY, int pointer, int button) void
validate()
Validates the current state of the tool.Methods inherited from class de.tum.cit.ase.editor.input.ToolInputAdapter
keyDown, keyTyped, keyUp, mouseMoved, scrolled, touchCancelled
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.tum.cit.ase.editor.input.ShortcutAdapter
addKey, isShortcut, isShortcut, isShortcut, removeKey
-
Field Details
-
bresenham2
protected com.badlogic.gdx.math.Bresenham2 bresenham2 -
canvas
-
lastPosition
protected com.badlogic.gdx.math.GridPoint2 lastPosition -
lastGridPosition
protected com.badlogic.gdx.math.GridPoint2 lastGridPosition
-
-
Constructor Details
-
EditorTool
public EditorTool()
-
-
Method Details
-
draw
public void draw(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer) Description copied from interface:Tool
Draws using the provided ShapeRenderer. -
isStraightLine
protected boolean isStraightLine()Determines if the current tool is set to draw a straight line.- Returns:
true
if the tool is set to draw a straight line,false
otherwise
-
getStraightLineCoordinates
protected void getStraightLineCoordinates(com.badlogic.gdx.math.GridPoint2 startGrid, com.badlogic.gdx.math.Vector2 start, com.badlogic.gdx.math.Vector2 end) Sets the start and end coordinates of a straight line based on the given start grid point.- Parameters:
startGrid
- the starting grid pointstart
- the starting point of the lineend
- the ending point of the line
-
getGrid
-
getInstance
Description copied from interface:Tool
Retrieves an instance of the Tool class with the provided Canvas.- Specified by:
getInstance
in interfaceTool
- Parameters:
canvas
- The Canvas object to associate with the Tool instance.- Returns:
- The Tool instance with the provided Canvas.
-
getLine
protected com.badlogic.gdx.utils.Array<com.badlogic.gdx.math.GridPoint2> getLine(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 end) Returns an array of GridPoint2 objects representing a line between the given start and end points.- Parameters:
start
- the starting point of the lineend
- the ending point of the line- Returns:
- an array of GridPoint2 objects representing the line
-
projectGridPointToWorld
public com.badlogic.gdx.math.Vector2 projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2) Projects a grid point to world coordinates.- Parameters:
gridPoint2
- the grid point to project- Returns:
- the projected world coordinates as a Vector2
-
projectGridPointToWorld
public com.badlogic.gdx.math.Vector2 projectGridPointToWorld(com.badlogic.gdx.math.GridPoint2 gridPoint2, boolean edge) Projects a grid point to world coordinates.- Parameters:
gridPoint2
- the grid point to projectedge
- indicates whether to project the edge or center of the grid point- Returns:
- the projected world coordinates as a Vector2
-
validate
public void validate()Description copied from interface:Tool
Validates the current state of the tool. This method is called internally to ensure the tool is in a valid state. It performs necessary validations and updates to the tool's internal state. -
touchDown
public boolean touchDown(int screenX, int screenY, int pointer, int button) Handles the touch down event in the editor.- Specified by:
touchDown
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDown
in classToolInputAdapter
- Parameters:
screenX
- The x coordinate of the touch positionscreenY
- The y coordinate of the touch positionpointer
- The pointer for the eventbutton
- The button that was pressed- Returns:
true
if the touch event is handled,false
otherwise
-
markTile
protected abstract void markTile(com.badlogic.gdx.math.GridPoint2 gridPoint) throws InvalidGridCellException Marks a tile on the grid based on the given grid point.- Parameters:
gridPoint
- the grid point representing the tile to be marked- Throws:
InvalidGridCellException
- if the grid point is invalid
-
touchUp
public boolean touchUp(int screenX, int screenY, int pointer, int button) - Specified by:
touchUp
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchUp
in classToolInputAdapter
-
touchDragged
public boolean touchDragged(int screenX, int screenY, int pointer) Handles the touch dragged event in the editor.- Specified by:
touchDragged
in interfacecom.badlogic.gdx.InputProcessor
- Overrides:
touchDragged
in classToolInputAdapter
- Parameters:
screenX
- The x coordinate of the touch positionscreenY
- The y coordinate of the touch positionpointer
- The pointer for the event- Returns:
true
if the touch event is handled,false
otherwise
-
reset
public void reset()Resets the state of the tool.This method is responsible for resetting the tool to its initial state by setting the
canvas
field tonull
, and clearing thelastPosition
andlastGridPosition
fields.- Specified by:
reset
in interfacecom.badlogic.gdx.utils.Pool.Poolable
-