|  | overview |  | wiki |  | api reference |  | download

- Main Page
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:

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 TextBox * | create (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 Control * | create (Theme::Style *style, Properties *properties=NULL)
static InputMode | getInputMode (const char *inputMode)

## Protected Attributes

unsigned int | _caretLocation
Vector2 | _prevCaretLocation
int | _lastKeypress
unsigned int | _fontSize
Theme::ThemeImage * | _caretImage
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:
  http://gameplay3d.github.io/GamePlay/docs/file-formats.html#wiki-UI_Forms

## Member Enumeration Documentation

enum gameplay::TextBox::InputMode

Input modes. Default is Text.

Enumerator:

  TEXT | Text: Text is displayed directly.
  PASSWORD | Password: Text is replaced by _passwordChar, which is '*' by default.

## Constructor & Destructor Documentation

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

Constructor.

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

Destructor.

## 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.

Parameters:

  listener | The listener to add.
  eventFlags | The events to listen for.

Reimplemented from gameplay::Label.

void gameplay::TextBox::controlEvent | ( | Control::Listener::EventType | evt | ) | `[protected, virtual]`

See also:
  Control::controlEvent

Reimplemented from gameplay::Control.

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

Creates a new TextBox.

Parameters:

  id | The textbox ID.
  style | The textbox style (optional).

Returns:
  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.

Parameters:

  style | The style to apply to this text box.
  properties | A properties object containing a definition of the text box (optional).

Returns:
  The new text box.

Reimplemented from gameplay::Label.

unsigned int gameplay::TextBox::drawImages | ( | Form * | form,
|  | const Rectangle & | clip
| ) |  | `[protected, virtual]`

See also:
  Control::drawImages

Reimplemented from gameplay::Control.

unsigned int gameplay::TextBox::drawText | ( | Form * | form,
|  | const Rectangle & | clip
| ) |  | `[protected, virtual]`

See also:
  Control::drawText

Reimplemented from gameplay::Label.

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

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

Returns:
  The current caret location.

std::string gameplay::TextBox::getDisplayedText | ( |  | ) | const`[protected]`

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

Returns:
  The text to be displayed.

InputMode gameplay::TextBox::getInputMode | ( |  | ) | const

Get the input mode.

Returns:
  The input mode.

static InputMode gameplay::TextBox::getInputMode | ( | const char * | inputMode | ) | `[static, protected]`

Gets an InputMode by string.

Parameters:

  inputMode | The string representation of the InputMode type.

Returns:
  The InputMode enum value corresponding to the given string.

int gameplay::TextBox::getLastKeypress | ( |  | ) |

Get the last key pressed within this text box.

Returns:
  The last key pressed within this text box.

char gameplay::TextBox::getPasswordChar | ( |  | ) | const

Get the character displayed in password mode.

Returns:
  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.

Returns:
  The type name of this class: "TextBox"

See also:
  ScriptTarget::getTypeName()

Reimplemented from gameplay::Label.

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

See also:
  Control::initialize

Reimplemented from gameplay::Label.

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

Keyboard callback on key events.

Parameters:

  evt | The key event that occurred.
  key | If 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:
  Keyboard::KeyEvent
  Keyboard::Key

Reimplemented from gameplay::Control.

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

Sets the location of the caret within this text box.

Parameters:

  index | The new location of the caret within the text of this TextBox.

void gameplay::TextBox::setInputMode | ( | InputMode | inputMode | ) |

Set the input mode.

Parameters:

  inputMode | Input mode to set.

void gameplay::TextBox::setPasswordChar | ( | char | character | ) |

Set the character displayed in password mode.

Parameters:

  character | Character 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.

Parameters:

  evt | The touch event that occurred.
  x | The x position of the touch in pixels. Left edge is zero.
  y | The y position of the touch in pixels. Top edge is zero.
  contactIndex | The order of occurrence for multiple touch contacts starting at zero.

Returns:
  Whether the touch event was consumed by the control.

See also:
  Touch::TouchEvent

Reimplemented from gameplay::Control.

void gameplay::TextBox::updateState | ( | State | state | ) | `[protected, virtual]`

See also:
  Control::updateState

Reimplemented from gameplay::Label.

## Member Data Documentation

Theme::ThemeImage* gameplay::TextBox::_caretImage `[protected]`

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

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

The current location of the TextBox's caret.

bool gameplay::TextBox::_ctrlPressed `[protected]`

Indicate if the CTRL key is currently pressed.

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

The font size to be used in the TextBox.

InputMode gameplay::TextBox::_inputMode `[protected]`

The mode used to display the typed text.

int gameplay::TextBox::_lastKeypress `[protected]`

The last character that was entered into the TextBox.

char gameplay::TextBox::_passwordChar `[protected]`

The character displayed in password mode.

Vector2 gameplay::TextBox::_prevCaretLocation `[protected]`

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