java.lang.Object
com.googlecode.lanterna.TerminalPosition
- All Implemented Interfaces:
Comparable<TerminalPosition>
A 2-d position in 'terminal space'. Please note that the coordinates are 0-indexed, meaning 0x0 is the top left
corner of the terminal. This object is immutable so you cannot change it after it has been created. Instead, you
can easily create modified 'clones' by using the 'with' methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
static final TerminalPosition
Constant for the 1x1 position (one offset in both directions from top-left)private final int
static final TerminalPosition
Constant for the top-left corner (0x0) -
Constructor Summary
ConstructorsConstructorDescriptionTerminalPosition
(int column, int row) Creates a new TerminalPosition object, which represents a location on the screen. -
Method Summary
Modifier and TypeMethodDescriptionabs()
int
divide
(TerminalPosition denominator) boolean
equals
(int columnIndex, int rowIndex) boolean
int
Returns the index of the column this position is representing, zero indexed (the first column has index 0).int
getRow()
Returns the index of the row this position is representing, zero indexed (the first row has index 0)int
hashCode()
max
(TerminalPosition position) min
(TerminalPosition position) minus
(TerminalPosition position) multiply
(TerminalPosition position) plus
(TerminalPosition position) toString()
with
(TerminalPosition position) Returns itself if it is equal to the supplied position, otherwise the supplied position.withColumn
(int column) Creates a new TerminalPosition object representing a position with the same row index as this but with a supplied column index.withRelative
(int deltaColumn, int deltaRow) Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by the two parameters.withRelative
(TerminalPosition translate) Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by another TerminalPosition.withRelativeColumn
(int delta) Creates a new TerminalPosition object representing a position on the same row, but with a column offset by a supplied value.withRelativeRow
(int delta) Creates a new TerminalPosition object representing a position on the same column, but with a row offset by a supplied value.withRow
(int row) Creates a new TerminalPosition object representing a position with the same column index as this but with a supplied row index.
-
Field Details
-
TOP_LEFT_CORNER
Constant for the top-left corner (0x0) -
OFFSET_1x1
Constant for the 1x1 position (one offset in both directions from top-left) -
row
private final int row -
column
private final int column
-
-
Constructor Details
-
TerminalPosition
public TerminalPosition(int column, int row) Creates a new TerminalPosition object, which represents a location on the screen. There is no check to verify that the position you specified is within the size of the current terminal and you can specify negative positions as well.- Parameters:
column
- Column of the location, or the "x" coordinate, zero indexed (the first column is 0)row
- Row of the location, or the "y" coordinate, zero indexed (the first row is 0)
-
-
Method Details
-
getColumn
public int getColumn()Returns the index of the column this position is representing, zero indexed (the first column has index 0).- Returns:
- Index of the column this position has
-
getRow
public int getRow()Returns the index of the row this position is representing, zero indexed (the first row has index 0)- Returns:
- Index of the row this position has
-
withRow
Creates a new TerminalPosition object representing a position with the same column index as this but with a supplied row index.- Parameters:
row
- Index of the row for the new position- Returns:
- A TerminalPosition object with the same column as this but with a specified row index
-
withColumn
Creates a new TerminalPosition object representing a position with the same row index as this but with a supplied column index.- Parameters:
column
- Index of the column for the new position- Returns:
- A TerminalPosition object with the same row as this but with a specified column index
-
withRelativeColumn
Creates a new TerminalPosition object representing a position on the same row, but with a column offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal position delta number of columns to the right and for negative numbers the same to the left.- Parameters:
delta
- Column offset- Returns:
- New terminal position based off this one but with an applied offset
-
withRelativeRow
Creates a new TerminalPosition object representing a position on the same column, but with a row offset by a supplied value. Calling this method with delta 0 will return this, calling it with a positive delta will return a terminal position delta number of rows to the down and for negative numbers the same up.- Parameters:
delta
- Row offset- Returns:
- New terminal position based off this one but with an applied offset
-
withRelative
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by another TerminalPosition. Same as callingwithRelativeRow(translate.getRow()).withRelativeColumn(translate.getColumn())
- Parameters:
translate
- How many columns and rows to translate- Returns:
- New TerminalPosition that is the result of the original with added translation
-
withRelative
Creates a new TerminalPosition object that is 'translated' by an amount of rows and columns specified by the two parameters. Same as callingwithRelativeRow(deltaRow).withRelativeColumn(deltaColumn)
- Parameters:
deltaColumn
- How many columns to move from the current position in the new TerminalPositiondeltaRow
- How many rows to move from the current position in the new TerminalPosition- Returns:
- New TerminalPosition that is the result of the original position with added translation
-
with
Returns itself if it is equal to the supplied position, otherwise the supplied position. You can use this if you have a position field which is frequently recalculated but often resolves to the same; it will keep the same object in memory instead of swapping it out every cycle.- Parameters:
position
- Position you want to return- Returns:
- Itself if this position equals the position passed in, otherwise the position passed in
-
plus
-
minus
-
multiply
-
divide
-
abs
-
min
-
max
-
compareTo
- Specified by:
compareTo
in interfaceComparable<TerminalPosition>
-
toString
-
hashCode
public int hashCode() -
equals
public boolean equals(int columnIndex, int rowIndex) -
equals
-