overview wiki api reference download
 All Classes Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
gameplay::TextBox Class Reference

#include <TextBox.h>

Inheritance diagram for gameplay::TextBox:
gameplay::Label gameplay::Control gameplay::Ref gameplay::AnimationTarget gameplay::ScriptTarget

List of all members.

Public Types

enum  InputMode { TEXT = 0x01, PASSWORD = 0x02 }

Public Member Functions

const char * getTypeName () const
unsigned int getCaretLocation () const
void setCaretLocation (unsigned int index)
int getLastKeypress ()
void setPasswordChar (char character)
char getPasswordChar () const
void setInputMode (InputMode inputMode)
InputMode getInputMode () const
virtual void addListener (Control::Listener *listener, int eventFlags)

Static Public Member Functions

static TextBoxcreate (const char *id, Theme::Style *style=NULL)

Protected Member Functions

 TextBox ()
 ~TextBox ()
void initialize (const char *typeName, Theme::Style *style, Properties *properties)
bool touchEvent (Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
bool keyEvent (Keyboard::KeyEvent evt, int key)
void controlEvent (Control::Listener::EventType evt)
void updateState (State state)
unsigned int drawImages (Form *form, const Rectangle &clip)
unsigned int drawText (Form *form, const Rectangle &clip)
std::string getDisplayedText () const

Static Protected Member Functions

static Controlcreate (Theme::Style *style, Properties *properties=NULL)
static InputMode getInputMode (const char *inputMode)

Protected Attributes

unsigned int _caretLocation
Vector2 _prevCaretLocation
int _lastKeypress
unsigned int _fontSize
char _passwordChar
InputMode _inputMode
bool _ctrlPressed
bool _shiftPressed = false

Detailed Description

Defines a text control.

Listeners can listen for a TEXT_CHANGED event, and then query the text box for the last keypress it received. On mobile device you can tap or click within the text box to bring up the virtual keyboard.

See also:

Member Enumeration Documentation

Input modes. Default is Text.


Text: Text is displayed directly.


Password: Text is replaced by _passwordChar, which is '*' by default.

Constructor & Destructor Documentation

gameplay::TextBox::TextBox ( ) [protected]


gameplay::TextBox::~TextBox ( ) [protected]


Member Function Documentation

virtual void gameplay::TextBox::addListener ( Control::Listener listener,
int  eventFlags 
) [virtual]

Add a listener to be notified of specific events affecting this control. Event types can be OR'ed together. E.g. To listen to touch-press and touch-release events, pass Control::Listener::TOUCH | Control::Listener::RELEASE as the second parameter.

listenerThe listener to add.
eventFlagsThe events to listen for.

Reimplemented from gameplay::Label.

See also:

Reimplemented from gameplay::Control.

static TextBox* gameplay::TextBox::create ( const char *  id,
Theme::Style style = NULL 
) [static]

Creates a new TextBox.

idThe textbox ID.
styleThe textbox style (optional).
The new textbox.

Reimplemented from gameplay::Label.

static Control* gameplay::TextBox::create ( Theme::Style style,
Properties properties = NULL 
) [static, protected]

Create a text box with a given style and properties.

styleThe style to apply to this text box.
propertiesA properties object containing a definition of the text box (optional).
The new text box.

Reimplemented from gameplay::Label.

unsigned int gameplay::TextBox::drawImages ( Form form,
const Rectangle clip 
) [protected, virtual]
See also:

Reimplemented from gameplay::Control.

unsigned int gameplay::TextBox::drawText ( Form form,
const Rectangle clip 
) [protected, virtual]
See also:

Reimplemented from gameplay::Label.

unsigned int gameplay::TextBox::getCaretLocation ( ) const

Returns the current location of the caret with the text of this TextBox.

The current caret location.
std::string gameplay::TextBox::getDisplayedText ( ) const [protected]

Get the text which should be displayed, depending on _inputMode.

The text to be displayed.

Get the input mode.

The input mode.
static InputMode gameplay::TextBox::getInputMode ( const char *  inputMode) [static, protected]

Gets an InputMode by string.

inputModeThe string representation of the InputMode type.
The InputMode enum value corresponding to the given string.

Get the last key pressed within this text box.

The last key pressed within this text box.

Get the character displayed in password mode.

The character displayed in password mode.
const char* gameplay::TextBox::getTypeName ( ) const [virtual]

Extends ScriptTarget::getTypeName() to return the type name of this class.

Child controls should override this function to return the correct type name.

The type name of this class: "TextBox"
See also:

Reimplemented from gameplay::Label.

void gameplay::TextBox::initialize ( const char *  typeName,
Theme::Style style,
Properties properties 
) [protected, virtual]
See also:

Reimplemented from gameplay::Label.

bool gameplay::TextBox::keyEvent ( Keyboard::KeyEvent  evt,
int  key 
) [protected, virtual]

Keyboard callback on key events.

evtThe key event that occurred.
keyIf evt is KEY_PRESS or KEY_RELEASE then key is the key code from Keyboard::Key. If evt is KEY_CHAR then key is the unicode value of the character.
See also:

Reimplemented from gameplay::Control.

void gameplay::TextBox::setCaretLocation ( unsigned int  index)

Sets the location of the caret within this text box.

indexThe new location of the caret within the text of this TextBox.

Set the input mode.

inputModeInput mode to set.
void gameplay::TextBox::setPasswordChar ( char  character)

Set the character displayed in password mode.

characterCharacter to display in password mode.
bool gameplay::TextBox::touchEvent ( Touch::TouchEvent  evt,
int  x,
int  y,
unsigned int  contactIndex 
) [protected, virtual]

Touch callback on touch events. Controls return true if they consume the touch event.

evtThe touch event that occurred.
xThe x position of the touch in pixels. Left edge is zero.
yThe y position of the touch in pixels. Top edge is zero.
contactIndexThe order of occurrence for multiple touch contacts starting at zero.
Whether the touch event was consumed by the control.
See also:

Reimplemented from gameplay::Control.

void gameplay::TextBox::updateState ( State  state) [protected, virtual]
See also:

Reimplemented from gameplay::Label.

Member Data Documentation

The Theme::Image for the TextBox's caret.

unsigned int gameplay::TextBox::_caretLocation [protected]

The current location of the TextBox's caret.

Indicate if the CTRL key is currently pressed.

unsigned int gameplay::TextBox::_fontSize [protected]

The font size to be used in the TextBox.

The mode used to display the typed text.

The last character that was entered into the TextBox.

The character displayed in password mode.

The previous position of the TextBox's caret.

bool gameplay::TextBox::_shiftPressed = false [protected]

Indicate if the SHIFT key is currently pressed.

 All Classes Functions Variables Typedefs Enumerations Enumerator