Package de.tum.cit.ase.editor.drawing
Class Canvas
java.lang.Object
de.tum.cit.ase.editor.drawing.Canvas
Represents a canvas that allows drawing and manipulation of a virtual grid.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncom.badlogic.gdx.math.GridPoint2
calculateGridPoint
(float x, float y, boolean clampToGrid) Converts screen Coordinates to the Position relative to the gridcom.badlogic.gdx.math.GridPoint2
calculateGridPoint
(com.badlogic.gdx.math.Vector2 position, boolean clampToGrid) Converts screen Coordinates to the Position relative to the gridprotected void
changeGrid
(TileTypes[][] tileTypes) Changes the grid of the canvas to the given TileTypes array.com.badlogic.gdx.math.GridPoint2
convertWorldPositionToGrid
(com.badlogic.gdx.math.Vector2 position, boolean clampToGrid) Converts WORLD Coordinates to the Position relative to the gridvoid
createNewGrid
(int width, int height) Creates a new grid with the specified width and height.void
createNewGrid
(TileTypes[][] grid) Creates a new grid with the given TileTypes array.void
draw
(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer) Draws the canvas using the specified ShapeRenderer.void
Ends a new grid epoch by either popping the top grid from pastVGrids stack if it is the same as the current virtual grid, or clearing the futureVGrids list.com.badlogic.gdx.math.Vector2
Returns the starting point of the grid.float
com.badlogic.gdx.math.GridPoint2
getMouseGridPosition
(boolean alwaysGrid) Retrieves the grid position of the mouse.float
com.badlogic.gdx.math.Vector2
Retrieves the unprotected mouse position on the canvas.float
getWidth()
void
redo()
Redoes the most recent action on the canvas.void
setGridTile
(int x, int y, TileTypes tileType) void
Starts a new grid epoch by pushing the current virtual grid onto the pastVGrids stack.void
undo()
Undoes the most recent action on the canvas.void
update
(float dt) Updates the canvas.
-
Field Details
-
virtualGrid
-
-
Constructor Details
-
Canvas
Represents a canvas for an editor.
-
-
Method Details
-
update
public void update(float dt) Updates the canvas.- Parameters:
dt
- the time difference between the current frame and the previous frame
-
changeGrid
Changes the grid of the canvas to the given TileTypes array. Manual version ofstartNewGridEpoch()
The current virtual grid is pushed onto the pastVGrids stack, and the futureVGrids list is cleared.- Parameters:
tileTypes
- the new TileTypes array representing the grid- See Also:
-
undo
public void undo()Undoes the most recent action on the canvas. If there are actions in the pastVGrids stack, the method will: 1. Push a clone of the current virtualGrid onto the futureVGrids stack. 2. Assign the top grid in the pastVGrids stack as the new virtualGrid. 3. Set the saved flag in the editorCanvas to false. -
redo
public void redo()Redoes the most recent action on the canvas. If there are actions in the futureVGrids list, the method will: 1. Push a clone of the current virtualGrid onto the pastVGrids stack. 2. Assign the top grid in the futureVGrids list as the new virtualGrid. 3. Set the saved flag in the editorCanvas to false. -
createNewGrid
public void createNewGrid(int width, int height) Creates a new grid with the specified width and height.- Parameters:
width
- the width of the gridheight
- the height of the grid
-
createNewGrid
Creates a new grid with the given TileTypes array.- Parameters:
grid
- the TileTypes array representing the new grid
-
draw
public void draw(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer) Draws the canvas using the specified ShapeRenderer. This method renders the grid and the selected tool on the canvas.- Parameters:
shapeRenderer
- the ShapeRenderer used to draw the canvas
-
calculateGridPoint
public com.badlogic.gdx.math.GridPoint2 calculateGridPoint(float x, float y, boolean clampToGrid) Converts screen Coordinates to the Position relative to the grid- Parameters:
clampToGrid
- if true value will be clamped to grid else value can be null- Returns:
- Grid Point
-
calculateGridPoint
public com.badlogic.gdx.math.GridPoint2 calculateGridPoint(com.badlogic.gdx.math.Vector2 position, boolean clampToGrid) Converts screen Coordinates to the Position relative to the grid- Parameters:
clampToGrid
- if true value will be clamped to grid else value can be null- Returns:
- Grid Point
-
convertWorldPositionToGrid
public com.badlogic.gdx.math.GridPoint2 convertWorldPositionToGrid(com.badlogic.gdx.math.Vector2 position, boolean clampToGrid) Converts WORLD Coordinates to the Position relative to the grid- Parameters:
clampToGrid
- if true value will be clamped to grid else value can be null- Returns:
- Grid Point
-
getMouseGridPosition
public com.badlogic.gdx.math.GridPoint2 getMouseGridPosition(boolean alwaysGrid) Retrieves the grid position of the mouse.- Parameters:
alwaysGrid
- specifies whether the mouse position should always be restricted to the grid- Returns:
- the grid position of the mouse as a GridPoint2 object, or null if the mouse position is outside the grid
-
getUnprotectedMousePosition
public com.badlogic.gdx.math.Vector2 getUnprotectedMousePosition()Retrieves the unprotected mouse position on the canvas. This method returns the mouse position on the canvas without any restrictions or clamping to the grid.- Returns:
- the mouse position as a
Vector2
object on the canvas
-
getGridStartPoint
public com.badlogic.gdx.math.Vector2 getGridStartPoint()Returns the starting point of the grid.- Returns:
- the starting point of the grid as a Vector2 object
-
startNewGridEpoch
public void startNewGridEpoch()Starts a new grid epoch by pushing the current virtual grid onto the pastVGrids stack. Automatic version When operation is finished callendNewGridEpoch()
Alternative:changeGrid(TileTypes[][])
- See Also:
-
endNewGridEpoch
public void endNewGridEpoch()Ends a new grid epoch by either popping the top grid from pastVGrids stack if it is the same as the current virtual grid, or clearing the futureVGrids list.- See Also:
-
getHeight
public float getHeight() -
getWidth
public float getWidth() -
setGridTile
-
getTileSize
public float getTileSize()
-