TextField

From Gnash Project Wiki

Jump to: navigation, search

Current as-of Aug 6, 2009

Notes:

-- A TextField is an InteractiveObject is a DisplayObject
-- A Glyph is the TextField manifestation of a character. A Glyph is a struct defined in TextRecord.h which contains a float advance and an int index. When rendered advance is the amount of space given to this Glyph, and index is the number that tells the renderer which character to draw.
-- Some properties in TextField have equivalents in TextRecord or Font. A TextRecord even has it's own Font, which is usually set using the TextField Font. When setting a property, be aware of which object's property you are changing.
-- format_text() calls handleChar() which is recursive. It iterates through the characters in _text, applying proper formatting at each stage. WordWrap functionality, for now, is contained in handleChar, and is run each time a character is evaluated.

TODO:

-- Do not re-format text every time a key is pressed!
-- When a key is pressed, we should not change _text, we should change the glyphs in the records.
-- TextField.text and TextField.htmlText should be parsed from the records, and records should only be reset when _text is set

Related Classes

  • TextRecord - This is a vector of Glyph structs. It has it's own _underline property, as well as it's own font. It only contains glyphs that should potentially be written to the screen, therefore html tags, tabs, newlines, backspaces and the like have all been parsed out. All the glyphs in a TextRecord will have the same formatting. The TextRecord.displayRecords() method is where the glyphs in the record (and the underline) are actually drawn.
  • Font - This is an object that contains information about the shape of a character, referenced by an int index. It contains information about the text font, color, bold, italic, size.
  • TextFormat - This actionscript object contains information about a TextField:
Property Function Gnash Equiv.
Align Where the text is anchored. Can be left, center, right, or justify. Should be set using TextFieldAlign enum. TextField._align
BlockIndentIndent applied to all text.TextField._blockIndent
BoldSets the text to bold.TextField._font._bold
BulletDisplays bullets before each new line.TextField._bullet
ColorSets the text color.TextField._font.color
FontSets the font by name. TextField._font._name
IndentSets the space before the first character after a newlineTextField._indent
ItalicSets the text to italic.TextField._font._italiced
KerningSets the text kerning. Kerning inserts space between certain characters to improve readability.
LeadingSets the space between lines.TextField._leading
LeftMarginSets the left margin, or the space between the left side of the TextField and the text.TextField._leftMargin
LetterSpacingSets the space added to the area between characters
RightMarginSets the right margin, or the space between the right side of the TextField and the text.TextField._rightMargin
SizeSets the size of the fontTextField._font._textHeight
TabStopsAsk SharadTextField._tabStops
TargetIndicates where a clicked hyperlink will open. Can be _self, _blank, _parent, or _top.TextField._target
UnderlineSets the text to underlineTextField._textRecords._underline
URLAddress to open if the text is clicked.TextField._url

Property Summary

  • _text - This string property of TextField contains every character represented in the TextField. This includes html tags, tabs, newlines, and occasionally backspaces.
  • _textRecords - This is a vector of all the TextRecords contained in this TextField.
  • _displayRecords - This is a vector of the TextRecords contained in this TextField that we wish to display. It is filled inside display().
  • _scroll - This size_t represents the topmost line that should be displayed. For example, if scroll is 0, we should see the top section of our TextField.
  • _maxScroll - This size_t indicates the maximum value of _scroll. Also, it should be noted that it will always be equal to the number of lines that are not in the display.
  • _glyphcount - This size_t keeps track of how many glyphs we are adding to the records in _textRecords
  • _line_starts - This vector of size_t keeps track of the glyph count at the beginning of each new line
  • m_cursor - This size_t keeps track of the number of glyphs before the cursor. In other words, the location of the cursor
  • _linesindisplay - This size_t is calculated in scrollLines() using _bounds.height(), _font._textHeight(), _font.leading(), and PADDING_TWIPS. It is equal to the number of lines we can display in our Textfield.
  • _restrictedChars - This set of wchar_t contains all the characters that are allowed to be input by a user into the TextField. It is only used if _restrictDefined is true.

Method Summary

  • display() - This method is called on a refresh when the TextField is set_invalidated(). Inside, it decides which TextRecords in _textRecords should be displayed using _scroll and _linesindisplay.
  • show_cursor() - This method is called inside display(), and uses m_cursor and _textRecords to place a gray line at the location in the TextField where the cursor is.
  • format_text() - This method is called when _text needs to be re-evaluated, such as when setTextFormat is called, or when _text is set to a new string.
  • handleChar() - This method iterates over the _text string, parsing if necessary and inserting glyphs into TextRecords in _textRecords.
  • newLine() - This method inserts a newline, pushing the old TextRecord and starting a new one at the correct x/y offset.
  • scrollLines() - This method changes _scroll if necessary, based on m_cursor.
  • cursorRecord() - This method returns the index of the TextRecord in _textRecords that m_cursor is in.
  • parseHTML() - This method starts parsing an html tag in _text after a <. It returns the value of the tag, as well as a map<name, value> of any attributes
  • setRestrict() - This method sets the _restrictedChars vector based on the input string. It also sets _restrictDefined to true.