CPTextInputSprite
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 some of the built-in sprites:
- CPCanvasSprite
- CPImageSprite
- CPStaticImageSprite
- CPLabelSprite
- CPOffScreenSprite
- CPKeyboardSprite
- CPParticleSprite
- CPVideoSprite
- CPTextInputSprite
UI Framework
Although CosPlay does not define an opinionated UI framework, several sprites and supporting classes are often used for constructing UI element on the screen. These include:
- CPLayoutSprite
- CPDynamicSprite
- CPLabelSprite
- CPSpacerSprite
- CPListBoxSprite
- CPTitlePanelSprite
- CPTextInputSprite
- CPSystemFont
You can can also look at the following UI-related examples:
- org.cosplay.examples.listbox.CPListBoxExample
- org.cosplay.examples.dialog.CPDialogExample
- org.cosplay.examples.layout.CPLayoutExample
- org.cosplay.examples.textinput.CPTextInputExample
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, marked as ready and its result set to
None
. Default value is CPKeyboardKey.KEY_ESC. Note that neither cancel or submit keys can contain any of the internally used keys: CPKeyboardKey.KEY_LEFT, CPKeyboardKey.KEY_RIGHT, CPKeyboardKey.KEY_BACKSPACE or CPKeyboardKey.KEY_DEL. - collidable
-
Whether or not this sprite has a collision shape. Default is
false
. - id
-
Optional ID of this sprite.
- initTxt
-
Optional initial text to show at the initial state. Default value is an empty string.
- keyFilter
-
Optional filter on keyboard events. Only if this filter returns
true
for a given keyboard event its key will be used as an input. Note that this filter is not applied to built-in keyboard keys such as cursor movements, escape, backspace, as well as cancel and submit keys. This filter can be used, for example, to ensure that only digits can be entered. - 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 for the inactive state (when sprite does not have keyboard focus). Skin function takes a character, its position in the input string and whether or not it is at the current cursor position (i.e. cursor is over the character). The function must return CPPixel instance.
- onSkin
-
The skinning function for the active state (when sprite has keyboard focus). Skin function takes a character, its position in the input string and whether or not it is at the current cursor position (i.e. cursor is over the character). The function must return CPPixel instance.
- prev
-
Optional scene object ID to switch keyboard focus to after the user pressed one of the cancel keys. Default value is
None
. - shaders
-
Optional sequence of shaders for this sprite. Default value is an empty sequence.
- 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. Note that neither cancel or submit keys can contain any of the internally used keys: CPKeyboardKey.KEY_LEFT, CPKeyboardKey.KEY_RIGHT, CPKeyboardKey.KEY_BACKSPACE or CPKeyboardKey.KEY_DEL. - 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. Default value is zero.
- y
-
Y-coordinate of the top-left corner. Default value is zero.
- z
-
Z-index at which to render this sprite. Default value is zero.
Attributes
- See also
-
CPSceneObjectContext.getCanvas to get current canvas you can draw on.
CPCanvas various API to draw on the canvas.
- Example
-
See CPTextInputExample class for the example of using labels and text input.
- Source
- CPTextInputSprite.scala
- Graph
-
- Supertypes
-
class CPDynamicSpriteclass CPSceneObjecttrait CPLifecycleclass CPGameObjectclass Objecttrait Matchableclass AnyShow all
Members list
Value members
Concrete methods
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.
Attributes
- Source
- CPTextInputSprite.scala
Gets current text of this input sprite. Note that a non-empty result does not mean that overall result is ready (i.e. submit key was pressed). This method simply returns whatever is currently entered in the text input.
Gets current text of this input sprite. Note that a non-empty result does not mean that overall result is ready (i.e. submit key was pressed). This method simply returns whatever is currently entered in the text input.
Attributes
- Source
- CPTextInputSprite.scala
Gets current dimension (width and height) of this object.
Gets current initial text for this sprite.
Gets optional ID of the 'next' scene object which will receive the keyboard focus after one of submit keys is pressed.
Gets optional ID of the 'next' scene object which will receive the keyboard focus after one of submit keys is pressed.
Attributes
- Source
- CPTextInputSprite.scala
Gets optional ID of the 'previous' scene object which will receive the keyboard focus after one of the cancel keys is pressed.
Gets optional ID of the 'previous' scene object which will receive the keyboard focus after one of the cancel keys is pressed.
Attributes
- Source
- CPTextInputSprite.scala
Gets the tuple of the last key pressed and input result. Input result will be None
if result is not yet ready or got cancelled. Last key pressed is None
when no keys were pressed yet on this sprite. Call method isReady on each frame to check whether the input result is actually ready.
Gets the tuple of the last key pressed and input result. Input result will be None
if result is not yet ready or got cancelled. Last key pressed is None
when no keys were pressed yet on this sprite. Call method isReady on each frame to check whether the input result is actually ready.
Note that if result was ready the internal ready flag will be reset to false
after this call so that the next call to isReady will return false
.
Attributes
- See also
- Source
- CPTextInputSprite.scala
Whether or not the result is either submitted or cancelled, i.e. ready. Note that the internal ready flag is set to false
again after the getResult call (if the result was ready).
Whether or not the result is either submitted or cancelled, i.e. ready. Note that the internal ready flag is set to false
again after the getResult call (if the result was ready).
Attributes
- See also
- Source
- CPTextInputSprite.scala
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 and monitor callbacks. Note that unlike update and monitor 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. The order in which scene objects are called is undefined.
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 and monitor callbacks. Note that unlike update and monitor 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. The order in which scene objects are called is undefined.
Note that generally this callback should not modify scene object state (which should be done in either update or monitor callbacks.
Default implementation is no-op.
Attributes
- Definition Classes
- Source
- CPTextInputSprite.scala
Sets optional ID of the 'next' scene object which will receive the keyboard focus after one of the submit keys is pressed.
Sets optional ID of the 'next' scene object which will receive the keyboard focus after one of the submit keys is pressed.
Value parameters
- next
-
ID of the 'next' scene object or
None
to remove it.
Attributes
- Source
- CPTextInputSprite.scala
Sets optional ID of the 'next' scene object which will receive the keyboard focus after one of the cancel keys is pressed.
Sets optional ID of the 'next' scene object which will receive the keyboard focus after one of the cancel keys is pressed.
Value parameters
- prev
-
ID of the 'previous' scene object or
None
to remove it.
Attributes
- Source
- CPTextInputSprite.scala
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. The order in which scene objects are called is undefined.
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. The order in which scene objects are called is undefined.
Default implementation is no-op. No rendering should be done in this callback.
Attributes
- Definition Classes
- Source
- CPTextInputSprite.scala
Inherited methods
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
x
of typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
-
CPGameObject -> Any
- 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.
Attributes
- Definition Classes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Gets current height of this object.
Gets current height of this object.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Gets unique ID of this game object.
Gets unique ID of this game object.
Attributes
- 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.
Attributes
- 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.
Attributes
- Definition Classes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Gets current lifecycle state.
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.
Attributes
- See also
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Gets current width of this object.
Gets current width of this object.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
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.
Attributes
- Definition Classes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Gets last X-coordinate which is
Gets last X-coordinate which is
getX + getWidth - 1
. Note the value when the width is zero.
Attributes
- Returns
-
Last X-coordinate for this sprite.
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
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.
Attributes
- Definition Classes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Gets last Y-coordinate which is
Gets last Y-coordinate which is
getY + getHeight - 1
. Note the value when the height is zero.
Attributes
- Returns
-
Last Y-coordinate for this sprite.
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
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.
Attributes
- Definition Classes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Shortcut method for hiding this object. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Shortcut method for hiding this object. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Increments current X-coordinate by given value.
Increments current X-coordinate by given value.
Value parameters
- d
-
A value (negative, zero or positive) to increment X-coordinate by.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Increments current Y-coordinate by given value.
Increments current Y-coordinate by given value.
Value parameters
- d
-
A value (negative, zero or positive) to increment Y-coordinate by.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
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.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Called after all scene objects have been updated but before any of them were rendered. It allows, for example, to rearrange UI sprites on the screen after all of them had a chance to update their dimensions but before they are actually rendered on the screen. Essentially, it provides for "post-update, pre-render" notification. The order in which scene objects are called is undefined.
Called after all scene objects have been updated but before any of them were rendered. It allows, for example, to rearrange UI sprites on the screen after all of them had a chance to update their dimensions but before they are actually rendered on the screen. Essentially, it provides for "post-update, pre-render" notification. The order in which scene objects are called is undefined.
Note that in most cases one should not override this callback. It is only meant for the use cases when one needs to be notified when all scene objects to be updated but before any of them are rendered. Default implementation is no-op. No rendering should be done in this callback.
Default implementation is no-op.
Value parameters
- ctx
-
Frame context. This context provides bulk of functionality that a scene object can do in a game, e.g. interact with other scene objects, check collisions, read input events and manage input focus, add or remove scene objects, add new and switch between scenes, etc.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Callback on lifecycle object activation. Default implementation is no-op.
Callback on lifecycle object activation. Default implementation is no-op.
Attributes
- See also
-
CPLifecycle.State.LF_ACTIVE
- Inherited from:
- CPLifecycle
- Source
- CPLifecycle.scala
Callback on lifecycle object deactivation. Default implementation is no-op.
Callback on lifecycle object deactivation. Default implementation is no-op.
Attributes
- See also
-
CPLifecycle.State.LF_INACTIVE
- Inherited from:
- CPLifecycle
- Source
- CPLifecycle.scala
Callback on lifecycle object start. Default implementation is no-op.
Callback on lifecycle object start. Default implementation is no-op.
Attributes
- See also
-
CPLifecycle.State.LF_STARTED
- Inherited from:
- CPLifecycle
- Source
- CPLifecycle.scala
Callback on lifecycle object stop. Default implementation is no-op.
Callback on lifecycle object stop. Default implementation is no-op.
Attributes
- See also
-
CPLifecycle.State.LF_STOPPED
- Inherited from:
- CPLifecycle
- Source
- CPLifecycle.scala
Resets this sprite to its initial XYZ-coordinates.
Resets this sprite to its initial XYZ-coordinates.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Resets this sprite to its initial XY-coordinates.
Resets this sprite to its initial XY-coordinates.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Sets visibility flag. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Sets visibility flag. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Value parameters
- vis
-
true
to make this object visible,false
otherwise.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Sets current X-coordinate. This coordinate will be returned from getX method.
Sets current X-coordinate. This coordinate will be returned from getX method.
Value parameters
- d
-
X-coordinate to set.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Sets both current XY-coordinates.
Sets both current XY-coordinates.
Value parameters
- a
-
X-coordinate to set.
- b
-
Y-coordinate to set.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Sets both current XY-coordinates as wel as z-index.
Sets both current XY-coordinates as wel as z-index.
Value parameters
- a
-
X-coordinate to set.
- b
-
Y-coordinate to set.
- z
-
Z-index to set.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Sets current Y-coordinate. This coordinate will be returned from getY method.
Sets current Y-coordinate. This coordinate will be returned from getY method.
Value parameters
- d
-
Y-coordinate to set.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Sets current z-index. This index will be returned from getZ method.
Sets current z-index. This index will be returned from getZ method.
Value parameters
- z
-
Z-index to set.
Attributes
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Shortcut method for showing this object. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Shortcut method for showing this object. Note that by default all scene objects are visible. Note also that this change happens immediately in the same frame. If you want this to happen in the next frame only you need to use CPSceneObjectContext.runNextFrame.
Attributes
- See also
- Inherited from:
- CPSceneObject
- Source
- CPSceneObject.scala
Inherited fields
Initial X-coordinate of the sprite.
Initial X-coordinate of the sprite.
Attributes
- See also
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Initial Y-coordinate of the sprite.
Initial Y-coordinate of the sprite.
Attributes
- See also
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala
Initial Z-index of the sprite.
Initial Z-index of the sprite.
Attributes
- See also
- Inherited from:
- CPDynamicSprite
- Source
- CPDynamicSprite.scala