gcn::TextField Class Reference

#include <textfield.hpp>

Inheritance diagram for gcn::TextField:

gcn::Widget gcn::MouseListener gcn::KeyListener List of all members.

Detailed Description

A text field in which you can write or display a line of text.

Definition at line 72 of file textfield.hpp.

Public Member Functions

 TextField ()
 Default constructor.
 TextField (const std::string &text)
 Constructor.
virtual void setText (const std::string &text)
 Sets the text.
virtual const std::string & getText () const
 Gets the text.
virtual void drawCaret (Graphics *graphics, int x)
 Draws the caret (the little marker in the text that shows where the letters you type will appear).
virtual void adjustSize ()
 Adjusts the size of the TextField to fit the font size.
virtual void adjustHeight ()
 Adjusts the height of the text field to fit the font size.
virtual void setCaretPosition (unsigned int position)
 Sets the caret position.
virtual unsigned int getCaretPosition () const
 Gets the caret position.
virtual void fontChanged ()
 Called when the font has changed.
virtual void draw (Graphics *graphics)
 Draws the Widget.
virtual void drawBorder (Graphics *graphics)
 Draws the Widget border.
virtual void mousePress (int x, int y, int button)
 Called when a mouse button is pressed when the mouse is in the Widget area or if the Widget has focus.
virtual void keyPress (const Key &key)
 Called if a key is pressed when the widget has keyboard focus.

Protected Member Functions

void fixScroll ()
 Scrolls the text horizontally so that the caret shows if needed.

Protected Attributes

std::string mText
unsigned int mCaretPosition
int mXScroll


Constructor & Destructor Documentation

gcn::TextField::TextField ( const std::string &  text  ) 

Constructor.

Initializes the textfield with a given string.

Parameters:
text the initial text.

Definition at line 83 of file textfield.cpp.

References gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), adjustSize(), mCaretPosition, mText, mXScroll, gcn::Widget::setBorderSize(), and gcn::Widget::setFocusable().


Member Function Documentation

void gcn::TextField::adjustHeight (  )  [virtual]

Adjusts the height of the text field to fit the font size.

The height of the TextField is initialized with this function by the constructors.

Definition at line 218 of file textfield.cpp.

References gcn::Widget::getFont(), gcn::Widget::getHeight(), and gcn::Widget::setHeight().

Referenced by adjustSize(), and TextField().

void gcn::TextField::adjustSize (  )  [virtual]

Adjusts the size of the TextField to fit the font size.

The constructor taking a string uses this function to initialize the size of the TextField.

Definition at line 210 of file textfield.cpp.

References adjustHeight(), fixScroll(), gcn::Widget::getFont(), gcn::Widget::getWidth(), mText, and gcn::Widget::setWidth().

Referenced by TextField().

void gcn::TextField::draw ( Graphics graphics  )  [virtual]

Draws the Widget.

It is called by the parent widget when it is time for the Widget to draw itself. The graphics object is set up so that all drawing is relative to the Widget, i.e coordinate (0,0) is the top-left corner of the Widget. It is not possible to draw outside of a Widgets dimension.

Parameters:
graphics a Graphics object to draw with.

Implements gcn::Widget.

Definition at line 108 of file textfield.cpp.

References drawCaret(), gcn::Graphics::drawText(), gcn::Graphics::fillRectangle(), gcn::Widget::getBackgroundColor(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), gcn::Widget::isFocused(), mCaretPosition, mText, mXScroll, gcn::Graphics::setColor(), and gcn::Graphics::setFont().

void gcn::TextField::drawBorder ( Graphics graphics  )  [virtual]

Draws the Widget border.

A border is drawn around a Widget. The width and height of the border is therefore the Widgets height+2*bordersize. Think of a painting that has a certain size, the border surrounds the painting.

Parameters:
graphics a Graphics object to draw with.

Reimplemented from gcn::Widget.

Definition at line 124 of file textfield.cpp.

References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Widget::getBaseColor(), gcn::Widget::getBorderSize(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), and gcn::Graphics::setColor().

void gcn::TextField::drawCaret ( Graphics graphics,
int  x 
) [virtual]

Draws the caret (the little marker in the text that shows where the letters you type will appear).

Easily overloaded if you want to change the style of the caret.

Parameters:
graphics the Graphics object to draw with.
x the caret's x-position.

Definition at line 148 of file textfield.cpp.

References gcn::Graphics::drawLine(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), and gcn::Graphics::setColor().

Referenced by draw().

void gcn::TextField::fontChanged (  )  [virtual]

Called when the font has changed.

If the change is global, this function will only be called if the Widget don't have a font already set.

Reimplemented from gcn::Widget.

Definition at line 269 of file textfield.cpp.

References fixScroll().

unsigned int gcn::TextField::getCaretPosition (  )  const [virtual]

Gets the caret position.

Returns:
the caret position.

Definition at line 259 of file textfield.cpp.

References mCaretPosition.

const std::string & gcn::TextField::getText (  )  const [virtual]

Gets the text.

Returns:
the text of the TextField.

Definition at line 264 of file textfield.cpp.

References mText.

void gcn::TextField::keyPress ( const Key key  )  [virtual]

Called if a key is pressed when the widget has keyboard focus.

If a key is held down the widget will generate multiple key presses.

Parameters:
key the key pressed.

Reimplemented from gcn::KeyListener.

Definition at line 163 of file textfield.cpp.

References fixScroll(), gcn::Widget::generateAction(), gcn::Key::getValue(), gcn::Key::isCharacter(), mCaretPosition, and mText.

void gcn::TextField::mousePress ( int  x,
int  y,
int  button 
) [virtual]

Called when a mouse button is pressed when the mouse is in the Widget area or if the Widget has focus.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters:
x the x coordinate of the mouse relative to the Widget itself.
y the y coordinate of the mouse relative to the Widget itself.
button the button pressed.

Reimplemented from gcn::MouseListener.

Definition at line 154 of file textfield.cpp.

References fixScroll(), gcn::Widget::getFont(), gcn::Font::getStringIndexAt(), gcn::Widget::hasMouse(), mCaretPosition, mText, and mXScroll.

void gcn::TextField::setCaretPosition ( unsigned int  position  )  [virtual]

Sets the caret position.

Parameters:
position the caret position.

Definition at line 245 of file textfield.cpp.

References fixScroll(), mCaretPosition, and mText.

void gcn::TextField::setText ( const std::string &  text  )  [virtual]

Sets the text.

Parameters:
text the new text in the TextField.

Definition at line 98 of file textfield.cpp.

References mCaretPosition, and mText.


The documentation for this class was generated from the following files:
Generated on Sat Jul 29 19:38:49 2006 for Guichan by  doxygen 1.4.7