AsciiPanelView

class AsciiPanelView : View

An implementation of terminal view for old-school games. Initially ported from JPanel AsciiPanel https://github.com/trystan/AsciiPanel to Android View

Author
Alexander Roman

Types

ColoredChar

class ColoredChar

Object for chars to print on the panel

OnCharClickedListener

interface OnCharClickedListener

Interface to be called on panel character click

Constructors

<init>

AsciiPanelView(context: Context)

Default View constructors by context

AsciiPanelView(context: Context, attrs: AttributeSet)

Default View constructors by context and attributes

AsciiPanelView(context: Context, attrs: AttributeSet, defStyleAttr: Int)

Default View constructors by context, attributes and default style

Properties

bgColor

var bgColor: Int

color of char background to be drawn if not specified

charColor

var charColor: Int

color of chars to be drawn if not specified

chars

lateinit var chars: Array<Array<ColoredChar>>

matrix of ColoredChar to be drawn on the panel

cursorX

var cursorX: Int

position X of cursor to draw next char at

cursorY

var cursorY: Int

position Y of cursor to draw next char at

fontFamily

var fontFamily: String

font file name to use for drawing chars

onCharClickedListener

var onCharClickedListener: OnCharClickedListener?

interface of OnCharClickedListener to be called on panel char click

panelHeight

var panelHeight: Int

height of panel in chars

panelWidth

var panelWidth: Int

width of panel in chars

Functions

clear

fun clear(): AsciiPanelView

Clear the entire screen to whatever the default background color is.

fun clear(character: Char): AsciiPanelView

Clear the entire screen with the specified character and whatever the default foreground and background colors are.

fun clear(character: Char, charColor: Int, bgColor: Int): AsciiPanelView

Clear the entire screen with the specified character and whatever the specified foreground and background colors are.

clearRect

fun clearRect(character: Char, x: Int, y: Int, width: Int, height: Int): AsciiPanelView

Clear the section of the screen with the specified character and whatever the default foreground and background colors are. The cursor position will not be modified.

fun clearRect(character: Char, x: Int, y: Int, width: Int, height: Int, charColor: Int, bgColor: Int): AsciiPanelView

Clear the section of the screen with the specified character and whatever the specified foreground and background colors are.

onDraw

fun onDraw(canvas: Canvas): Unit

onSizeChanged

fun onSizeChanged(xNew: Int, yNew: Int, xOld: Int, yOld: Int): Unit

onTouchEvent

fun onTouchEvent(event: MotionEvent): Boolean

setCursorPosX

fun setCursorPosX(cursorX: Int): AsciiPanelView

Sets the distance from the left new text will be written to.

setCursorPosY

fun setCursorPosY(cursorY: Int): AsciiPanelView

Sets the distance from the top new text will be written to.

setCursorPosition

fun setCursorPosition(x: Int, y: Int): AsciiPanelView

Sets the x and y position of where new text will be written to. The origin (0,0) is the upper left corner.

writeCenter

fun writeCenter(string: String, y: Int): AsciiPanelView

Write a string to the center of the panel at the specified y position. This updates the cursor's position.

fun writeCenter(string: String, y: Int, charColor: Int): AsciiPanelView

Write a string to the center of the panel at the specified y position with the specified foreground color. This updates the cursor's position but not the default foreground color.

fun writeCenter(string: String, y: Int, charColor: Int?, bgColor: Int?): AsciiPanelView

Write a string to the center of the panel at the specified y position with the specified foreground and background colors. This updates the cursor's position but not the default foreground or background colors.

writeChar

fun writeChar(character: Char): AsciiPanelView

Write a character to the cursor's position. This updates the cursor's position.

fun writeChar(character: Char, charColor: Int): AsciiPanelView

Write a character to the cursor's position with the specified foreground color. This updates the cursor's position but not the default foreground color.

fun writeChar(character: Char, x: Int, y: Int, charColor: Int): AsciiPanelView

Write a character to the specified position with the specified foreground color. This updates the cursor's position but not the default foreground color.

fun writeChar(character: Char, x: Int, y: Int, charColor: Int?, bgColor: Int?): AsciiPanelView

Write a character to the specified position with the specified foreground and background colors. This updates the cursor's position but not the default foreground or background colors.

writeCharWithColor

fun writeCharWithColor(character: Char, charColor: Int, bgColor: Int): AsciiPanelView

Write a character to the cursor's position with the specified foreground and background colors. This updates the cursor's position but not the default foreground or background colors.

writeCharWithPos

fun writeCharWithPos(character: Char, x: Int, y: Int): AsciiPanelView

Write a character to the specified position. This updates the cursor's position.

writeString

fun writeString(string: String): AsciiPanelView

Write a string to the cursor's position. This updates the cursor's position.

fun writeString(string: String, charColor: Int): AsciiPanelView

Write a string to the cursor's position with the specified foreground color. This updates the cursor's position but not the default foreground color.

fun writeString(string: String, x: Int, y: Int, charColor: Int): AsciiPanelView

Write a string to the specified position with the specified foreground color. This updates the cursor's position but not the default foreground color.

fun writeString(string: String, x: Int, y: Int, charColor: Int?, bgColor: Int?): AsciiPanelView

Write a string to the specified position with the specified foreground and background colors. This updates the cursor's position but not the default foreground or background colors.

writeStringWithColor

fun writeStringWithColor(string: String, charColor: Int, bgColor: Int): AsciiPanelView

Write a string to the cursor's position with the specified foreground and background colors. This updates the cursor's position but not the default foreground or background colors.

writeStringWithPos

fun writeStringWithPos(string: String, x: Int, y: Int): AsciiPanelView

Write a string to the specified position. This updates the cursor's position.

Companion Object Properties

DEFAULT_BG_COLOR

const val DEFAULT_BG_COLOR: Int

Default char background color = Color.WHITE

DEFAULT_CHAR_COLOR

const val DEFAULT_CHAR_COLOR: Int

Default char color = Color.BLACK

DEFAULT_FONT

const val DEFAULT_FONT: String

Default font

DEFAULT_PANEL_HEIGHT

const val DEFAULT_PANEL_HEIGHT: Int

Default panel height in chars = 27

DEFAULT_PANEL_WIDTH

const val DEFAULT_PANEL_WIDTH: Int

Default panel width in chars = 64