ManaPlus
|
#include <textbox.h>
Public Member Functions | |
TextBox (const Widget2 *const widget) | |
~TextBox () | |
void | setTextWrapped (const std::string &text, const int minDimension) |
int | getMinWidth () const |
void | keyPressed (KeyEvent &event) |
void | draw (Graphics *const graphics) |
void | safeDraw (Graphics *const graphics) |
void | setForegroundColor (const Color &color) |
void | setForegroundColorAll (const Color &color1, const Color &color2) |
void | setText (const std::string &text) |
std::string | getText () const |
const std::string & | getTextRow (const int row) const |
void | setTextRow (const int row, const std::string &text) |
unsigned int | getNumberOfRows () const |
unsigned int | getCaretPosition () const |
void | setCaretPosition (unsigned int position) |
unsigned int | getCaretRow () const |
void | setCaretRow (const int row) |
unsigned int | getCaretColumn () const |
void | setCaretColumn (const int column) |
void | setCaretRowColumn (const int row, const int column) |
void | scrollToCaret () |
bool | isEditable () const |
void | setEditable (const bool editable) |
void | addRow (const std::string &row) |
bool | isOpaque () const |
void | setOpaque (const Opaque opaque) |
void | fontChanged () |
void | mousePressed (MouseEvent &event) |
void | mouseDragged (MouseEvent &event) |
Public Member Functions inherited from Widget | |
Widget (const Widget2 *const widget) | |
~Widget () | |
virtual void | drawFrame (Graphics *graphics) |
virtual void | safeDrawFrame (Graphics *graphics) |
void | setFrameSize (const unsigned int frameSize) |
unsigned int | getFrameSize () const |
virtual void | logic () |
Widget * | getParent () const |
void | setWidth (const int width) |
int | getWidth () const |
void | setHeight (const int height) |
int | getHeight () const |
void | setSize (const int width, const int height) |
void | setX (const int x) |
int | getX () const |
void | setY (const int y) |
int | getY () const |
void | setPosition (const int x, const int y) |
void | setDimension (const Rect &dimension) |
const Rect & | getDimension () const |
void | setFocusable (const bool focusable) |
bool | isFocusable () const |
virtual bool | isFocused () const |
void | setEnabled (const bool enabled) |
bool | isEnabled () const |
void | setVisible (Visible visible) |
bool | isVisible () const |
void | setBaseColor (const Color &color) |
const Color & | getBaseColor () const |
void | setForegroundColor (const Color &color) |
const Color & | getForegroundColor () const |
void | setBackgroundColor (const Color &color) |
const Color & | getBackgroundColor () const |
virtual void | requestFocus () |
virtual void | requestMoveToTop () |
virtual void | requestMoveToBottom () |
virtual void | setFocusHandler (FocusHandler *const focusHandler) |
FocusHandler * | getFocusHandler () |
void | addActionListener (ActionListener *const actionListener) |
void | removeActionListener (ActionListener *const actionListener) |
void | addDeathListener (WidgetDeathListener *const deathListener) |
void | removeDeathListener (WidgetDeathListener *const deathListener) |
void | addMouseListener (MouseListener *const mouseListener) |
void | removeMouseListener (MouseListener *const mouseListener) |
void | addKeyListener (KeyListener *const keyListener) |
void | removeKeyListener (KeyListener *const keyListener) |
void | addFocusListener (FocusListener *const focusListener) |
void | removeFocusListener (FocusListener *const focusListener) |
void | addWidgetListener (WidgetListener *const widgetListener) |
void | removeWidgetListener (WidgetListener *const widgetListener) |
void | setActionEventId (const std::string &actionEventId) |
const std::string & | getActionEventId () const |
virtual void | getAbsolutePosition (int &x, int &y) const |
virtual void | setParent (Widget *parent) |
Font * | getFont () const |
void | setFont (Font *const font) |
bool | isTabInEnabled () const |
void | setTabInEnabled (const bool enabled) |
bool | isTabOutEnabled () const |
void | setTabOutEnabled (const bool enabled) |
void | requestModalFocus () |
virtual void | requestModalMouseInputFocus () |
virtual void | releaseModalFocus () |
virtual void | releaseModalMouseInputFocus () |
virtual bool | isModalFocused () const |
virtual bool | isModalMouseInputFocused () const |
virtual Widget * | getWidgetAt (int x, int y) |
const std::list< MouseListener * > & | getMouseListeners () const A_CONST |
const std::list< KeyListener * > & | getKeyListeners () const A_CONST |
const std::list< FocusListener * > & | getFocusListeners () const A_CONST |
virtual Rect | getChildrenArea () |
virtual FocusHandler * | getInternalFocusHandler () |
void | setInternalFocusHandler (FocusHandler *const internalFocusHandler) |
virtual void | moveToTop (Widget *widget) |
virtual void | moveToBottom (Widget *widget) |
virtual void | focusNext () |
virtual void | focusPrevious () |
virtual void | showWidgetPart (Widget *const widget, const Rect &area) |
void | setId (const std::string &id) |
const std::string & | getId () const |
virtual void | showPart (const Rect &rectangle) |
bool | isAllowLogic () const |
void | setMouseConsume (const bool b) |
bool | isMouseConsume () const |
void | setRedraw (const bool b) |
virtual bool | isSelectable () const |
void | setSelectable (const bool selectable) |
void | windowResized () |
virtual void | postInit () |
Public Member Functions inherited from Widget2 | |
virtual | ~Widget2 () |
const Color & | getThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE |
const Color & | getThemeCharColor (const signed char c, bool &valid) const A_INLINE |
virtual void | setWidget2 (const Widget2 *const widget) |
void | setPalette (int palette) |
void | checkPalette () |
void | setForegroundColor2 (const Color &color) |
Widget * | getWindow () const |
virtual void | setWindow (Widget *const window) |
Public Member Functions inherited from MouseListener | |
virtual | ~MouseListener () |
virtual void | mouseEntered (MouseEvent &event) |
virtual void | mouseExited (MouseEvent &event) |
virtual void | mouseReleased (MouseEvent &event) |
virtual void | mouseClicked (MouseEvent &event) |
virtual void | mouseWheelMovedUp (MouseEvent &event) |
virtual void | mouseWheelMovedDown (MouseEvent &event) |
virtual void | mouseMoved (MouseEvent &event) |
Public Member Functions inherited from KeyListener | |
virtual | ~KeyListener () |
virtual void | keyReleased (KeyEvent &event) |
Private Member Functions | |
void | drawCaret (Graphics *const graphics, const int x, const int y) const |
void | adjustSize () |
Private Attributes | |
std::vector< std::string > | mTextRows |
int | mCaretColumn |
int | mCaretRow |
int | mMinWidth |
bool | mEditable |
Opaque | mOpaque |
A text box, meant to be used inside a scroll area. Same as the Guichan text box except this one doesn't have a background or border, instead completely relying on the scroll area.
|
explicit |
Constructor.
Definition at line 79 of file textbox.cpp.
References Widget::addKeyListener(), Widget::addMouseListener(), adjustSize(), Widget2::getThemeColor(), Widget::mAllowLogic, Widget::mForegroundColor, Opaque_false, Widget::setFocusable(), Widget::setFrameSize(), setOpaque(), and setText().
TextBox::~TextBox | ( | ) |
void TextBox::addRow | ( | const std::string & | row | ) |
Adds a row of text to the end of the text.
row | The row to add. |
Definition at line 596 of file textbox.cpp.
References adjustSize(), and mTextRows.
|
private |
Adjusts the text box's size to fit the text.
Definition at line 635 of file textbox.cpp.
References CAST_S32, Widget::getFont(), Font::getHeight(), Font::getWidth(), mTextRows, Widget::setHeight(), and Widget::setWidth().
Referenced by addRow(), fontChanged(), keyPressed(), setText(), setTextRow(), and TextBox().
|
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 widget's dimension.
graphics | aA graphics object to draw with. |
Implements Widget.
Definition at line 446 of file textbox.cpp.
References BLOCK_END, BLOCK_START, CAST_S32, CAST_SIZE, drawCaret(), Font::drawString(), Graphics::fillRectangle(), Widget::getFont(), Font::getHeight(), Widget::getHeight(), Widget::getWidth(), Font::getWidth(), isEditable(), Widget::isFocused(), Widget::mBackgroundColor, mCaretColumn, mCaretRow, Widget::mForegroundColor, Widget2::mForegroundColor2, mOpaque, mTextRows, Opaque_true, and Graphics::setColor().
Referenced by safeDraw().
|
private |
Draws the caret. Overloaded this method if you want to change the style of the caret.
graphics | a Graphics object to draw with. |
x | the x position. |
y | the y position. |
Definition at line 627 of file textbox.cpp.
References Graphics::drawLine(), Widget::getFont(), Widget::getHeight(), Widget::mForegroundColor, Graphics::setColor(), x, and y.
Referenced by draw().
|
inlinevirtual |
Called when the font has changed. If the change is global, this function will only be called if the widget doesn't have a font already set.
Reimplemented from Widget.
Definition at line 276 of file textbox.h.
References adjustSize().
unsigned int TextBox::getCaretColumn | ( | ) | const |
Gets the column where the caret is currently located.
unsigned int TextBox::getCaretPosition | ( | ) | const |
Gets the caret position in the text.
Definition at line 556 of file textbox.cpp.
References CAST_S32, mCaretColumn, mCaretRow, mTextRows, and EmoteDB::size().
|
inline |
Gets the row number where the caret is currently located.
Definition at line 187 of file textbox.h.
References mCaretRow.
|
inline |
Get the minimum text width for the text box.
Definition at line 108 of file textbox.h.
References mMinWidth.
Referenced by OkDialog::OkDialog(), ConfirmDialog::postInit(), ItemPopup::setItem(), and SkillPopup::show().
|
inline |
Gets the number of rows in the text.
Definition at line 162 of file textbox.h.
References CAST_S32, and mTextRows.
Referenced by ConfirmDialog::postInit(), ItemPopup::setItem(), and SkillPopup::show().
std::string TextBox::getText | ( | ) | const |
Gets the text of the text box.
Definition at line 495 of file textbox.cpp.
|
inline |
Gets a certain row from the text.
row | The number of the row to get from the text. |
Definition at line 145 of file textbox.h.
References mTextRows.
|
inline |
|
inline |
Checks if the text box is opaque. An opaque text box will draw it's background and it's text. A non opaque text box only draw it's text making it transparent.
Definition at line 262 of file textbox.h.
References mOpaque, and Opaque_true.
|
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.
event | Discribes the event. |
Reimplemented from KeyListener.
Definition at line 258 of file textbox.cpp.
References adjustSize(), CAST_S32, CAST_S8, Widget::getChildrenArea(), Widget::getFont(), Font::getHeight(), Widget::getParent(), Key::getValue(), InputAction::GUI_BACKSPACE, InputAction::GUI_DELETE, InputAction::GUI_DOWN, InputAction::GUI_END, InputAction::GUI_HOME, InputAction::GUI_LEFT, InputAction::GUI_PAGE_DOWN, InputAction::GUI_PAGE_UP, InputAction::GUI_RIGHT, InputAction::GUI_SELECT2, InputAction::GUI_TAB, InputAction::GUI_UP, Rect::height, Key::isCharacter(), mCaretColumn, mCaretRow, mEditable, mTextRows, PRAGMA45(), scrollToCaret(), setCaretRow(), and EmoteDB::size().
|
virtual |
Called when the mouse has moved and the mouse has previously been pressed on the widget.
event | Describes the event. |
Reimplemented from MouseListener.
Definition at line 622 of file textbox.cpp.
|
virtual |
Called when a mouse button has been pressed on the widget area.
NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.
event | Describes the event. |
Reimplemented from MouseListener.
Definition at line 602 of file textbox.cpp.
References CAST_S32, MouseEvent::getButton(), Widget::getFont(), Font::getHeight(), Font::getStringIndexAt(), MouseEvent::getX(), MouseButton::LEFT, mCaretColumn, mCaretRow, and mTextRows.
|
virtual |
void TextBox::scrollToCaret | ( | ) |
Scrolls the text to the caret if the text box is in a scroll area.
Definition at line 584 of file textbox.cpp.
References Widget::getFont(), Font::getHeight(), Font::getWidth(), Rect::height, mCaretColumn, mCaretRow, mTextRows, Widget::showPart(), Rect::width, Rect::x, and Rect::y.
Referenced by keyPressed().
void TextBox::setCaretColumn | ( | const int | column | ) |
Sets the column where the caret should be currently located.
The | column where the caret should be currently located. |
Definition at line 566 of file textbox.cpp.
References CAST_S32, mCaretColumn, mCaretRow, mTextRows, and EmoteDB::size().
Referenced by setCaretRow(), setCaretRowColumn(), and setTextRow().
void TextBox::setCaretPosition | ( | unsigned int | position | ) |
Sets the position of the caret in the text.
position | the positon of the caret. |
Definition at line 521 of file textbox.cpp.
References CAST_S32, mCaretColumn, mCaretRow, mTextRows, and EmoteDB::size().
void TextBox::setCaretRow | ( | const int | row | ) |
Sets the row where the caret should be currently located.
The | row where the caret should be currently located. |
Definition at line 542 of file textbox.cpp.
References CAST_S32, mCaretColumn, mCaretRow, mTextRows, and setCaretColumn().
Referenced by keyPressed(), and setCaretRowColumn().
void TextBox::setCaretRowColumn | ( | const int | row, |
const int | column | ||
) |
Sets the row and the column where the caret should be curretly located.
row | The row where the caret should be currently located. |
column | The column where the caret should be currently located. |
Definition at line 578 of file textbox.cpp.
References setCaretColumn(), and setCaretRow().
void TextBox::setEditable | ( | const bool | editable | ) |
Sets the text box to be editable or not.
editable | True if the text box should be editable, false otherwise. |
Definition at line 650 of file textbox.cpp.
References mEditable, and Widget::mSelectable.
Referenced by ConfirmDialog::ConfirmDialog(), ItemPopup::ItemPopup(), OkDialog::OkDialog(), TextBoxPopup::postInit(), and SkillPopup::SkillPopup().
void TextBox::setForegroundColor | ( | const Color & | color | ) |
Definition at line 482 of file textbox.cpp.
References Widget::mForegroundColor, and Widget2::mForegroundColor2.
Definition at line 488 of file textbox.cpp.
References Widget::mForegroundColor, and Widget2::mForegroundColor2.
Referenced by ItemPopup::ItemPopup(), TextBoxPopup::postInit(), and SkillPopup::SkillPopup().
|
inline |
Sets the text box to be opaque or not. An opaque text box will draw it's background and it's text. A non opaque text box only draw it's text making it transparent.
opaque | True if the text box should be opaque, false otherwise. |
Definition at line 273 of file textbox.h.
References mOpaque.
Referenced by ConfirmDialog::ConfirmDialog(), OkDialog::OkDialog(), TextBoxPopup::postInit(), and TextBox().
void TextBox::setText | ( | const std::string & | text | ) |
Sets the text of the text box.
text | The text of the text box. |
Definition at line 227 of file textbox.cpp.
References adjustSize(), CAST_S32, mCaretColumn, mCaretRow, and mTextRows.
Referenced by setTextWrapped(), and TextBox().
void TextBox::setTextRow | ( | const int | row, |
const std::string & | text | ||
) |
Sets the text of a certain row of the text.
row | The number of the row to set in the text. |
text | The text to set in the given row number. |
Definition at line 511 of file textbox.cpp.
References adjustSize(), mCaretColumn, mCaretRow, mTextRows, and setCaretColumn().
void TextBox::setTextWrapped | ( | const std::string & | text, |
const int | minDimension | ||
) |
Sets the text after wrapping it to the current width of the widget.
Definition at line 109 of file textbox.cpp.
References Widget::getFont(), Widget::getParent(), Font::getWidth(), Widget::logic(), mMinWidth, and setText().
Referenced by ConfirmDialog::ConfirmDialog(), OkDialog::OkDialog(), ItemPopup::setItem(), TextBoxPopup::show(), and SkillPopup::show().
|
private |
Holds the current column of the caret.
Definition at line 309 of file textbox.h.
Referenced by draw(), getCaretPosition(), keyPressed(), mousePressed(), scrollToCaret(), setCaretColumn(), setCaretPosition(), setCaretRow(), setText(), and setTextRow().
|
private |
Holds the current row of the caret.
Definition at line 314 of file textbox.h.
Referenced by draw(), getCaretPosition(), getCaretRow(), keyPressed(), mousePressed(), scrollToCaret(), setCaretColumn(), setCaretPosition(), setCaretRow(), setText(), and setTextRow().
|
private |
True if the text box is editable, false otherwise.
Definition at line 321 of file textbox.h.
Referenced by isEditable(), keyPressed(), and setEditable().
|
private |
Definition at line 316 of file textbox.h.
Referenced by getMinWidth(), and setTextWrapped().
|
private |
True if the text box is editable, false otherwise.
Definition at line 326 of file textbox.h.
Referenced by draw(), isOpaque(), and setOpaque().
|
private |
Holds all the rows of the text.
Definition at line 304 of file textbox.h.
Referenced by addRow(), adjustSize(), draw(), getCaretPosition(), getNumberOfRows(), getText(), getTextRow(), keyPressed(), mousePressed(), scrollToCaret(), setCaretColumn(), setCaretPosition(), setCaretRow(), setText(), and setTextRow().