Package jexer.backend
Class LogicalScreen
- java.lang.Object
-
- jexer.backend.LogicalScreen
-
- All Implemented Interfaces:
Screen
- Direct Known Subclasses:
ECMA48Terminal,HeadlessBackend,MultiScreen,SwingTerminal
public class LogicalScreen extends java.lang.Object implements Screen
A logical screen composed of a 2D array of Cells.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancursorVisibleIf true, the cursor is visible and should be placed onscreen at (cursorX, cursorY) during a call to flushPhysical().protected intcursorXCursor X position if visible.protected intcursorYCursor Y position if visible.protected intheightHeight of the visible window.protected Cell[][]logicalThe logical screen being rendered to.protected Cell[][]physicalThe physical screen last sent out on flush().protected booleanreallyClearedSet if the user explicitly wants to redraw everything starting with a ECMATerminal.clearAll().protected intwidthWidth of the visible window.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLogicalScreen()Public constructor.protectedLogicalScreen(int width, int height)Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblendRectangle(int x, int y, int width, int height, int color, int alpha)Alpha-blend a rectangle with a specified color and alpha onto this screen.voidblendScreen(Screen otherScreen, int x, int y, int width, int height, int alpha, boolean filterHatch)Alpha-blend a rectangular portion of another screen onto this one.voidclear()Clear the logical screen.voidclearPhysical()Clear the physical screen.voidcopyScreen(Screen other)Copy all of screen's data to this screen.voidcopyScreen(Screen other, int x, int y, int width, int height)Copy a rectangular portion of another screen to this one.voidcopySelection(Clipboard clipboard, int x0, int y0, int x1, int y1, boolean rectangle)Copy the screen selection area to the clipboard.voiddrawBox(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background)Draw a box with a border and empty background.voiddrawBox(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background, BorderStyle borderStyle, boolean shadow)Draw a box with a border and empty background.voiddrawBoxShadow(int left, int top, int right, int bottom)Draw a box shadow.voidflushPhysical()Default implementation does nothing.CellAttributesgetAttrXY(int x, int y)Get the attributes at one location.BackendgetBackend()Get the backend that instantiated this screen.CellgetCharXY(int x, int y)Get the cell at one location in absolute coordinates.CellgetCharXY(int x, int y, boolean clip)Get the cell at one location, in either absolute or clipped coordinates.intgetClipBottom()Get bottom drawing clipping boundary.intgetClipLeft()Get left drawing clipping boundary.intgetClipRight()Get right drawing clipping boundary.intgetClipTop()Get top drawing clipping boundary.intgetCursorX()Get the cursor X position.intgetCursorY()Get the cursor Y position.intgetHeight()Get the height.intgetOffsetX()Get drawing offset for x.intgetOffsetY()Get drawing offset for y.intgetTextHeight()Get the height of a character cell in pixels.intgetTextWidth()Get the width of a character cell in pixels.intgetWidth()Get the width.voidhideCursor()Hide the cursor.voidhLineXY(int x, int y, int n, int ch, CellAttributes attr)Draw a horizontal line from (x, y) to (x + n, y).voidhLineXY(int x, int y, int n, Cell ch)Draw a horizontal line from (x, y) to (x + n, y).voidinvertCell(int x, int y)Invert the cell color at a position, including both halves of a double-width cell.voidinvertCell(int x, int y, boolean onlyThisCell)Invert the cell color at a position.booleanisCursorVisible()Get the cursor visibility.booleanisDirty()Get dirty flag.voidputAll(int ch, CellAttributes attr)Fill the entire screen with one character with attributes.voidputAttrXY(int x, int y, CellAttributes attr)Set the attributes at one location.voidputAttrXY(int x, int y, CellAttributes attr, boolean clip)Set the attributes at one location.voidputCharXY(int x, int y, int ch)Render one character without changing the underlying attributes.voidputCharXY(int x, int y, int ch, CellAttributes attr)Render one character with attributes.voidputCharXY(int x, int y, Cell ch)Render one character with attributes.voidputCursor(boolean visible, int x, int y)Put the cursor at (x,y).voidputFullwidthCharXY(int x, int y, int ch)Render one fullwidth character with attributes.voidputFullwidthCharXY(int x, int y, int ch, CellAttributes attr)Render one fullwidth character with attributes.voidputFullwidthCharXY(int x, int y, Cell cell)Render one fullwidth cell.voidputStringXY(int x, int y, java.lang.String str)Render a string without changing the underlying attribute.voidputStringXY(int x, int y, java.lang.String str, CellAttributes attr)Render a string.voidreset()Reset screen to not-bold, white-on-black.voidresetClipping()Flush the offset and clip variables.voidresizeToScreen()Resize the physical screen to match the logical screen dimensions.voidsetBackend(Backend backend)Set the backend to associated with this screen.voidsetClipBottom(int clipBottom)Set bottom drawing clipping boundary.voidsetClipLeft(int clipLeft)Set left drawing clipping boundary.voidsetClipRight(int clipRight)Set right drawing clipping boundary.voidsetClipTop(int clipTop)Set top drawing clipping boundary.voidsetDimensions(int width, int height)Change the width and height.voidsetHeight(int height)Change the height.voidsetOffsetX(int offsetX)Set drawing offset for x.voidsetOffsetY(int offsetY)Set drawing offset for y.voidsetSelection(int x0, int y0, int x1, int y1, boolean rectangle)Set a selection area on the screen.voidsetTitle(java.lang.String title)Set the window title.voidsetWidth(int width)Change the width.Screensnapshot()Obtain a snapshot copy of the screen.Screensnapshot(int x, int y, int width, int height)Obtain a snapshot copy of a rectangular portion of the screen.ScreensnapshotPhysical(int x, int y, int width, int height)Obtain a snapshot copy of a rectangular portion of the screen of the PHYSICAL screen - what was LAST emitted.voidunsetImageRow(int y)Unset every image cell on one row of the physical screen, forcing images on that row to be redrawn.voidvLineXY(int x, int y, int n, int ch, CellAttributes attr)Draw a vertical line from (x, y) to (x, y + n).voidvLineXY(int x, int y, int n, Cell ch)Draw a vertical line from (x, y) to (x, y + n).
-
-
-
Field Detail
-
width
protected int width
Width of the visible window.
-
height
protected int height
Height of the visible window.
-
physical
protected Cell[][] physical
The physical screen last sent out on flush().
-
logical
protected Cell[][] logical
The logical screen being rendered to.
-
reallyCleared
protected boolean reallyCleared
Set if the user explicitly wants to redraw everything starting with a ECMATerminal.clearAll().
-
cursorVisible
protected boolean cursorVisible
If true, the cursor is visible and should be placed onscreen at (cursorX, cursorY) during a call to flushPhysical().
-
cursorX
protected int cursorX
Cursor X position if visible.
-
cursorY
protected int cursorY
Cursor Y position if visible.
-
-
Constructor Detail
-
LogicalScreen
protected LogicalScreen()
Public constructor. Sets everything to not-bold, white-on-black.
-
LogicalScreen
protected LogicalScreen(int width, int height)Public constructor. Sets everything to not-bold, white-on-black.- Parameters:
width- width in cellsheight- height in cells
-
-
Method Detail
-
getTextWidth
public int getTextWidth()
Get the width of a character cell in pixels.- Specified by:
getTextWidthin interfaceScreen- Returns:
- the width in pixels of a character cell
-
getTextHeight
public int getTextHeight()
Get the height of a character cell in pixels.- Specified by:
getTextHeightin interfaceScreen- Returns:
- the height in pixels of a character cell
-
setOffsetX
public final void setOffsetX(int offsetX)
Set drawing offset for x.- Specified by:
setOffsetXin interfaceScreen- Parameters:
offsetX- new drawing offset
-
getOffsetX
public int getOffsetX()
Get drawing offset for x.- Specified by:
getOffsetXin interfaceScreen- Returns:
- the drawing offset
-
setOffsetY
public final void setOffsetY(int offsetY)
Set drawing offset for y.- Specified by:
setOffsetYin interfaceScreen- Parameters:
offsetY- new drawing offset
-
getOffsetY
public int getOffsetY()
Get drawing offset for y.- Specified by:
getOffsetYin interfaceScreen- Returns:
- the drawing offset
-
getClipRight
public final int getClipRight()
Get right drawing clipping boundary.- Specified by:
getClipRightin interfaceScreen- Returns:
- drawing boundary
-
setClipRight
public final void setClipRight(int clipRight)
Set right drawing clipping boundary.- Specified by:
setClipRightin interfaceScreen- Parameters:
clipRight- new boundary
-
getClipBottom
public final int getClipBottom()
Get bottom drawing clipping boundary.- Specified by:
getClipBottomin interfaceScreen- Returns:
- drawing boundary
-
setClipBottom
public final void setClipBottom(int clipBottom)
Set bottom drawing clipping boundary.- Specified by:
setClipBottomin interfaceScreen- Parameters:
clipBottom- new boundary
-
getClipLeft
public final int getClipLeft()
Get left drawing clipping boundary.- Specified by:
getClipLeftin interfaceScreen- Returns:
- drawing boundary
-
setClipLeft
public final void setClipLeft(int clipLeft)
Set left drawing clipping boundary.- Specified by:
setClipLeftin interfaceScreen- Parameters:
clipLeft- new boundary
-
getClipTop
public final int getClipTop()
Get top drawing clipping boundary.- Specified by:
getClipTopin interfaceScreen- Returns:
- drawing boundary
-
setClipTop
public final void setClipTop(int clipTop)
Set top drawing clipping boundary.- Specified by:
setClipTopin interfaceScreen- Parameters:
clipTop- new boundary
-
isDirty
public final boolean isDirty()
Get dirty flag.
-
getAttrXY
public final CellAttributes getAttrXY(int x, int y)
Get the attributes at one location.
-
getCharXY
public Cell getCharXY(int x, int y)
Get the cell at one location in absolute coordinates.
-
getCharXY
public Cell getCharXY(int x, int y, boolean clip)
Get the cell at one location, in either absolute or clipped coordinates.
-
putAttrXY
public final void putAttrXY(int x, int y, CellAttributes attr)Set the attributes at one location.
-
putAttrXY
public final void putAttrXY(int x, int y, CellAttributes attr, boolean clip)Set the attributes at one location.
-
putAll
public final void putAll(int ch, CellAttributes attr)Fill the entire screen with one character with attributes.
-
putCharXY
public final void putCharXY(int x, int y, Cell ch)Render one character with attributes.
-
putCharXY
public final void putCharXY(int x, int y, int ch, CellAttributes attr)Render one character with attributes.
-
putCharXY
public final void putCharXY(int x, int y, int ch)Render one character without changing the underlying attributes.
-
putStringXY
public final void putStringXY(int x, int y, java.lang.String str, CellAttributes attr)Render a string. Does not wrap if the string exceeds the line.- Specified by:
putStringXYin interfaceScreen- Parameters:
x- column coordinate. 0 is the left-most column.y- row coordinate. 0 is the top-most row.str- string to drawattr- attributes to use (bold, foreColor, backColor)
-
putStringXY
public final void putStringXY(int x, int y, java.lang.String str)Render a string without changing the underlying attribute. Does not wrap if the string exceeds the line.- Specified by:
putStringXYin interfaceScreen- Parameters:
x- column coordinate. 0 is the left-most column.y- row coordinate. 0 is the top-most row.str- string to draw
-
vLineXY
public final void vLineXY(int x, int y, int n, int ch, CellAttributes attr)Draw a vertical line from (x, y) to (x, y + n).
-
vLineXY
public void vLineXY(int x, int y, int n, Cell ch)Draw a vertical line from (x, y) to (x, y + n).
-
hLineXY
public final void hLineXY(int x, int y, int n, int ch, CellAttributes attr)Draw a horizontal line from (x, y) to (x + n, y).
-
hLineXY
public void hLineXY(int x, int y, int n, Cell ch)Draw a horizontal line from (x, y) to (x + n, y).
-
setWidth
public void setWidth(int width)
Change the width. Everything on-screen will be destroyed and must be redrawn.
-
setHeight
public void setHeight(int height)
Change the height. Everything on-screen will be destroyed and must be redrawn.
-
setDimensions
public void setDimensions(int width, int height)Change the width and height. Everything on-screen will be destroyed and must be redrawn.- Specified by:
setDimensionsin interfaceScreen- Parameters:
width- new screen widthheight- new screen height
-
resizeToScreen
public void resizeToScreen()
Resize the physical screen to match the logical screen dimensions.
-
getHeight
public final int getHeight()
Get the height.
-
getWidth
public final int getWidth()
Get the width.
-
reset
public final void reset()
Reset screen to not-bold, white-on-black. Also flushes the offset and clip variables.
-
resetClipping
public final void resetClipping()
Flush the offset and clip variables.- Specified by:
resetClippingin interfaceScreen
-
drawBox
public final void drawBox(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background)Draw a box with a border and empty background.- Specified by:
drawBoxin interfaceScreen- Parameters:
left- left column of box. 0 is the left-most column.top- top row of the box. 0 is the top-most row.right- right column of boxbottom- bottom row of the boxborder- attributes to use for the borderbackground- attributes to use for the background
-
drawBox
public void drawBox(int left, int top, int right, int bottom, CellAttributes border, CellAttributes background, BorderStyle borderStyle, boolean shadow)Draw a box with a border and empty background.- Specified by:
drawBoxin interfaceScreen- Parameters:
left- left column of box. 0 is the left-most column.top- top row of the box. 0 is the top-most row.right- right column of boxbottom- bottom row of the boxborder- attributes to use for the borderbackground- attributes to use for the backgroundborderStyle- style of bordershadow- if true, draw a "shadow" on the box
-
drawBoxShadow
public final void drawBoxShadow(int left, int top, int right, int bottom)Draw a box shadow.- Specified by:
drawBoxShadowin interfaceScreen- Parameters:
left- left column of box. 0 is the left-most column.top- top row of the box. 0 is the top-most row.right- right column of boxbottom- bottom row of the box
-
flushPhysical
public void flushPhysical()
Default implementation does nothing.- Specified by:
flushPhysicalin interfaceScreen
-
putCursor
public void putCursor(boolean visible, int x, int y)Put the cursor at (x,y).
-
hideCursor
public final void hideCursor()
Hide the cursor.- Specified by:
hideCursorin interfaceScreen
-
isCursorVisible
public boolean isCursorVisible()
Get the cursor visibility.- Specified by:
isCursorVisiblein interfaceScreen- Returns:
- true if the cursor is visible
-
getCursorX
public int getCursorX()
Get the cursor X position.- Specified by:
getCursorXin interfaceScreen- Returns:
- the cursor x column position
-
getCursorY
public int getCursorY()
Get the cursor Y position.- Specified by:
getCursorYin interfaceScreen- Returns:
- the cursor y row position
-
setTitle
public void setTitle(java.lang.String title)
Set the window title. Default implementation does nothing.
-
clearPhysical
public void clearPhysical()
Clear the physical screen.- Specified by:
clearPhysicalin interfaceScreen
-
unsetImageRow
public final void unsetImageRow(int y)
Unset every image cell on one row of the physical screen, forcing images on that row to be redrawn.- Specified by:
unsetImageRowin interfaceScreen- Parameters:
y- row coordinate. 0 is the top-most row.
-
putFullwidthCharXY
public final void putFullwidthCharXY(int x, int y, Cell cell)Render one fullwidth cell.- Parameters:
x- column coordinate. 0 is the left-most column.y- row coordinate. 0 is the top-most row.cell- the cell to draw
-
putFullwidthCharXY
public final void putFullwidthCharXY(int x, int y, int ch, CellAttributes attr)Render one fullwidth character with attributes.- Parameters:
x- column coordinate. 0 is the left-most column.y- row coordinate. 0 is the top-most row.ch- character to drawattr- attributes to use (bold, foreColor, backColor)
-
putFullwidthCharXY
public final void putFullwidthCharXY(int x, int y, int ch)Render one fullwidth character with attributes.- Parameters:
x- column coordinate. 0 is the left-most column.y- row coordinate. 0 is the top-most row.ch- character to draw
-
invertCell
public void invertCell(int x, int y)Invert the cell color at a position, including both halves of a double-width cell.- Specified by:
invertCellin interfaceScreen- Parameters:
x- column positiony- row position
-
invertCell
public void invertCell(int x, int y, boolean onlyThisCell)Invert the cell color at a position.- Specified by:
invertCellin interfaceScreen- Parameters:
x- column positiony- row positiononlyThisCell- if true, only invert this cell, otherwise invert both halves of a double-width cell if necessary
-
setSelection
public void setSelection(int x0, int y0, int x1, int y1, boolean rectangle)Set a selection area on the screen.- Specified by:
setSelectionin interfaceScreen- Parameters:
x0- the starting X position of the selectiony0- the starting Y position of the selectionx1- the ending X position of the selectiony1- the ending Y position of the selectionrectangle- if true, this is a rectangle select
-
copySelection
public void copySelection(Clipboard clipboard, int x0, int y0, int x1, int y1, boolean rectangle)
Copy the screen selection area to the clipboard.- Specified by:
copySelectionin interfaceScreen- Parameters:
clipboard- the clipboard to usex0- the starting X position of the selectiony0- the starting Y position of the selectionx1- the ending X position of the selectiony1- the ending Y position of the selectionrectangle- if true, this is a rectangle select
-
snapshot
public Screen snapshot()
Obtain a snapshot copy of the screen.
-
snapshot
public Screen snapshot(int x, int y, int width, int height)
Obtain a snapshot copy of a rectangular portion of the screen.- Specified by:
snapshotin interfaceScreen- Parameters:
x- left column of rectangle. 0 is the left-most column.y- top row of the rectangle. 0 is the top-most row.width- number of columns to copyheight- number of rows to copy- Returns:
- a copy of the screen's data from this rectangle. Any cells outside the actual screen dimensions will be blank.
-
snapshotPhysical
public Screen snapshotPhysical(int x, int y, int width, int height)
Obtain a snapshot copy of a rectangular portion of the screen of the PHYSICAL screen - what was LAST emitted.- Specified by:
snapshotPhysicalin interfaceScreen- Parameters:
x- left column of rectangle. 0 is the left-most column.y- top row of the rectangle. 0 is the top-most row.width- number of columns to copyheight- number of rows to copy- Returns:
- a copy of the screen's data from this rectangle. Any cells outside the actual screen dimensions will be blank.
-
copyScreen
public void copyScreen(Screen other)
Copy all of screen's data to this screen.- Specified by:
copyScreenin interfaceScreen- Parameters:
other- the other screen
-
copyScreen
public void copyScreen(Screen other, int x, int y, int width, int height)
Copy a rectangular portion of another screen to this one. Any cells outside this screen's dimensions will be ignored.- Specified by:
copyScreenin interfaceScreen- Parameters:
other- the other screenx- left column of rectangle. 0 is the left-most column.y- top row of the rectangle. 0 is the top-most row.width- number of columns to copyheight- number of rows to copy
-
setBackend
public final void setBackend(Backend backend)
Set the backend to associated with this screen.- Parameters:
backend- the backend
-
getBackend
public final Backend getBackend()
Get the backend that instantiated this screen.- Specified by:
getBackendin interfaceScreen- Returns:
- the backend
-
blendRectangle
public void blendRectangle(int x, int y, int width, int height, int color, int alpha)Alpha-blend a rectangle with a specified color and alpha onto this screen. Any cells outside this screen's dimensions will be ignored.- Specified by:
blendRectanglein interfaceScreen- Parameters:
x- left column of rectangle. 0 is the left-most column.y- top row of the rectangle. 0 is the top-most row.width- number of columns to copyheight- number of rows to copycolor- the RGB color to blendalpha- the alpha transparency level (0 - 255) to use for cells from the other screen
-
blendScreen
public void blendScreen(Screen otherScreen, int x, int y, int width, int height, int alpha, boolean filterHatch)
Alpha-blend a rectangular portion of another screen onto this one. Any cells outside this screen's dimensions will be ignored.- Specified by:
blendScreenin interfaceScreen- Parameters:
otherScreen- the other screenx- left column of rectangle. 0 is the left-most column.y- top row of the rectangle. 0 is the top-most row.width- number of columns to copyheight- number of rows to copyalpha- the alpha transparency level (0 - 255) to use for cells from the other screenfilterHatch- if true, prevent hatch-like characters from showing through
-
-