CPTextInputSprite

class CPTextInputSprite(id: String, x: Int, y: Int, z: Int, visLen: Int, maxBuf: Int, var initTxt: String, onSkin: (Char, Int, Boolean) => CPPixel, offSkin: (Char, Int, Boolean) => CPPixel, var next: Option[String], cancelKeys: Seq[CPKeyboardKey], submitKeys: Seq[CPKeyboardKey], tags: String*) extends CPSceneObject

Scene object tailor-made for accepting text input.

This sprite acts as a classic input field: user can input text using keyboard and cursor keys. It supports different field and buffer lengths, skinning input (i.e. password field) as well as user-defined set of keys for submission and cancellation. You can also chain multiple text inputs together to create an auto-navigable forms. NOTE: this sprite works only with system font - you can't use FIGLeft fonts with this sprite.

Sprites

CosPlay provides number of built-in sprites. A sprite is a scene objects, visible or off-screen, that is custom designed for a particular use case. Built-in sprites provide concrete implementations for the abstract methods in the base CPSceneObject class. Most non-trivial games will use combination of the built-in sprites and their own ones. Here's the list of the built-in sprites:

Value parameters:
cancelKeys

Optional set of keyboard keys to accept for cancellation action. When one of these keys is pressed the sprite will reset to its initial state. Default value is CPKeyboardKey.KEY_ESC.

id

Optional ID of this sprite.

initTxt

Optional initial text to show at the initial state. Default value is an empty string.

maxBuf

Overall buffer length of this field. It should always be greater then or equal to visible length.

next

Optional scene object ID to switch keyboard focus to after the user pressed one of the submit keys. Default value is None.

offSkin

The skinning function to the inactive state (when sprite does not have keyboard focus).

onSkin

The skinning function to the active state (when sprite has keyboard focus).

submitKeys

Optional set of keyboard keys to accept for submission action. When one of these keys is pressed the sprite will make result available via isReady method and will optionally switch keyboard focus for the next scene object, if any. Default value is CPKeyboardKey.KEY_ENTER.

tags

Optional set of organizational or grouping tags. By default, the empty set is used.

visLen

Visible length of this field.

x

X-coordinate of the top-left corner.

y

Y-coordinate of the top-left corner.

z

Z-index at which to render this sprite.

Example:

See CPTextInputExample class for the example of using labels and text input.

Source:
CPTextInputSprite.scala
class Object
trait Matchable
class Any

Value members

Concrete methods

def clear(initTxt: String): Unit

Clears this sprite resetting it to its initial state.

Clears this sprite resetting it to its initial state.

Value parameters:
initTxt

Optional new initial text to use. Default value is null which will retain the previous initial text.

Source:
CPTextInputSprite.scala

Gets current dimension (width and height) of this object.

Gets current dimension (width and height) of this object.

Source:
CPTextInputSprite.scala
def getInitText: String

Gets current initial text for this sprite.

Gets current initial text for this sprite.

Source:
CPTextInputSprite.scala
def getNext: Option[String]

Gets optional ID of the 'next' scene object which will receive the keyboard focus after this sprite result is ready.

Gets optional ID of the 'next' scene object which will receive the keyboard focus after this sprite result is ready.

Source:
CPTextInputSprite.scala
def getResult: Option[String]

Gets input result, None if result is not yet ready.

Gets input result, None if result is not yet ready.

Source:
CPTextInputSprite.scala
def getX: Int

Gets current X-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Gets current X-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Source:
CPTextInputSprite.scala
def getY: Int

Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Gets current Y-coordinate of this object within dimensions of its scene. Note that returned value is allowed to be outside scene's dimension (e.g. negative value). In such cases, the clipping of the scene rendering will result in showing only portion or none of the object.

Source:
CPTextInputSprite.scala
def getZ: Int

Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.

Gets Z-index or order to use in rendering of this object. A pixel with higher Z-index visually overrides the overlapping pixel in the same XY-coordinate with equal or smaller Z-index.

Source:
CPTextInputSprite.scala
def isReady: Boolean

Whether or not the result is ready.

Whether or not the result is ready.

Source:
CPTextInputSprite.scala
override def render(ctx: CPSceneObjectContext): Unit

Called to render this scene object. Only visible and in camera frame objects will receive this callback. This callback is called on scene object after all scene objects received update callback. Note that unlike update callbacks and shaders that are called for all scene objects on each frame, this callback is only called for scene objects that are visible and, at least partially, in camera frame.

Called to render this scene object. Only visible and in camera frame objects will receive this callback. This callback is called on scene object after all scene objects received update callback. Note that unlike update callbacks and shaders that are called for all scene objects on each frame, this callback is only called for scene objects that are visible and, at least partially, in camera frame.

Definition Classes
Source:
CPTextInputSprite.scala
def setNext(next: Option[String]): Unit

Sets optional ID of the 'next' scene object which will receive the keyboard focus after this sprite result is ready.

Sets optional ID of the 'next' scene object which will receive the keyboard focus after this sprite result is ready.

Value parameters:
next

ID of the 'next' scene object or None to remove it.

Source:
CPTextInputSprite.scala
override def update(ctx: CPSceneObjectContext): Unit

Called to update the internal state of this scene object. This callback is called each frame on every object in the scene and it is called before any render callback. Note that all scene object will receive this callback before first render callback.

Called to update the internal state of this scene object. This callback is called each frame on every object in the scene and it is called before any render callback. Note that all scene object will receive this callback before first render callback.

Definition Classes
Source:
CPTextInputSprite.scala

Inherited methods

override def equals(obj: Any): Boolean
Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala

Gets optional collision shape or hit box for this sprite.

Gets optional collision shape or hit box for this sprite.

Returns:

Optional collision shape, None if this sprite does not support collisions.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
inline def getHeight: Int

Gets current height of this object.

Gets current height of this object.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Inherited from:
CPGameObject
Source:
CPGameObject.scala

Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.

Gets rectangular shape of this sprite. It is basically a combination of its top-left corner XY-coordinate and sprite's dimension.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala

Gets the optional list of shaders attached to this scene object. By default, returns an empty list. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

Gets the optional list of shaders attached to this scene object. By default, returns an empty list. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
final def getState: State

Gets current lifecycle state.

Gets current lifecycle state.

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def getTags: Set[String]

Gets optional set of organizational tags. Note that by default the set of tags is empty.

Gets optional set of organizational tags. Note that by default the set of tags is empty.

See also:
Inherited from:
CPGameObject
Source:
CPGameObject.scala
inline def getWidth: Int

Gets current width of this object.

Gets current width of this object.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def hide(): Unit

Shortcut method for hiding this object. Note that by default all scene objects are visible.

Shortcut method for hiding this object. Note that by default all scene objects are visible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def isVisible: Boolean

Checks the visibility flag.

Checks the visibility flag.

If object is invisible than only update method will be called on each frame. If object is visible and in camera frame - method render will be called as well to render itself. Note that shaders are called regardless of whether the object visible, in camera frame or invisible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def onActivate(): Unit

Callback on lifecycle object activation. Default implementation is no-op.

Callback on lifecycle object activation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_ACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onDeactivate(): Unit

Callback on lifecycle object deactivation. Default implementation is no-op.

Callback on lifecycle object deactivation. Default implementation is no-op.

See also:

CPLifecycle.State.LF_INACTIVE

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStart(): Unit

Callback on lifecycle object start. Default implementation is no-op.

Callback on lifecycle object start. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STARTED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def onStop(): Unit

Callback on lifecycle object stop. Default implementation is no-op.

Callback on lifecycle object stop. Default implementation is no-op.

See also:

CPLifecycle.State.LF_STOPPED

Inherited from:
CPLifecycle
Source:
CPLifecycle.scala
def setVisible(vis: Boolean): Unit

Sets visibility flag. Note that by default all scene objects are visible.

Sets visibility flag. Note that by default all scene objects are visible.

Value parameters:
vis

true to make this object visible, false otherwise.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala
def show(): Unit

Shortcut method for showing this object. Note that by default all scene objects are visible.

Shortcut method for showing this object. Note that by default all scene objects are visible.

See also:
Inherited from:
CPSceneObject
Source:
CPSceneObject.scala