#include <CeylanTextBuffer.h>
Classes | |
class | TextBufferException |
Exception raised by text buffers. More... | |
Public Types | |
enum | TextLayout { Raw, WordWrapped, Justified } |
Describes the various modes supported for text layout. More... | |
typedef Ceylan::Uint8 | CharAbscissa |
Abscissa index of a character in a buffer. | |
typedef Ceylan::Uint8 | CharOrdinate |
Ordinate index of a character in a buffer. | |
typedef Ceylan::Uint32 | TextIndex |
Index of a text in buffer list. | |
typedef Ceylan::Uint32 | LineIndex |
Index of a preformatted line in a text. | |
typedef std::list< char * > | TextGrid |
Records a preformatted text entry, whose escape sequences (, ) have been translated into a series of basic characters (alphanumerical and spaces) stored in a list of lines, each line being an array of width characters (char *), to fit in character grid. | |
Public Member Functions | |
TextBuffer (CharAbscissa screenWidth, CharOrdinate screenHeight, TextLayout layout=Raw) | |
Creates a new text buffer, whose sliding window (abstracted screen) is of specified size. | |
virtual | ~TextBuffer () throw () |
Virtual destructor. | |
virtual CharAbscissa | getWidth () const |
Returns the width of the abstract screen associated to this buffer. | |
virtual CharOrdinate | getHeight () const |
Returns the height of the abstract screen associated to this buffer. | |
virtual TextLayout | getTextLayout () const |
Returns the text layout being currently used. | |
virtual void | setTextLayout (TextLayout newLayout) |
Sets a new text layout. | |
virtual CharAbscissa | getAlineaWidth () const |
Returns the current alinea width, in characters. | |
virtual void | setAlineaWidth (CharAbscissa newAlineaWidth) |
Sets a new alinea width, in character. | |
virtual void | add (const std::string &text) |
Adds specified text in the buffer. | |
virtual void | blank () |
Blanks this whole buffer. | |
virtual bool | jumpNextText () |
Centers the abstract screen on next text entry, if any. | |
virtual bool | jumpPreviousText () |
Centers the abstract screen on previous text, if any. | |
virtual bool | jumpNextLine () |
Makes the abstract screen go one line down. | |
virtual void | jumpNextLineNoRefresh () |
Makes the abstract screen go one line down, but does not refresh the screen lines. | |
virtual bool | jumpPreviousLine () |
Makes the abstract screen go one line up. | |
virtual const TextGrid & | getScreenLines () const |
Returns the list of lines that should be displayed, should this buffer be rendered. | |
virtual const std::string | toString (Ceylan::VerbosityLevels level=Ceylan::high) const |
Returns an user-friendly description of the state of this object. | |
Static Public Member Functions | |
static const std::string | ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high) |
Returns a user-friendly description of this list of pointers to text displayable instances. | |
static TextOutputFormat | GetOutputFormat () |
Returns the current overall text format to be used by TextDisplayable instances. | |
static void | SetOutputFormat (TextOutputFormat newOutputFormat) |
Sets the current overall text format to be used by TextDisplayable instances. | |
Static Public Attributes | |
static const CharAbscissa | TabSpacing = 4 |
Number of spaces corresponding to one tabulation. | |
Protected Types | |
typedef std::pair< std::string, TextGrid * > | TextEntry |
A text entry is made of a chunk of text and its precomputed lines (if any). | |
typedef std::list< TextEntry > | ListOfTexts |
A list of text entries. | |
Protected Member Functions | |
virtual void | recomputeGrids () |
Recomputes cached grid lines with current settings. | |
void | updateScreenLines () |
Updates screen lines according to current buffer text and line index. | |
TextGrid & | createTextGridFrom (const std::string &text) |
Translates specified text entry into a list of lines of buffer width, according to current screen dimensions and layout. | |
void | deleteTextGrid (TextGrid *grid) |
Deletes a TextGrid. | |
TextGrid & | createRawGridFrom (const std::string &text) |
Translates specified text entry into a list of lines of buffer width, with no special concern for layout: text written letter by letter. | |
TextGrid & | createAdvancedGridFrom (const std::string &text) |
Translates specified text entry into a list of lines of buffer width, with word-wrapped or justified (i.e. | |
LineIndex | getHeightFromCurrentPosition () const |
Tells how many lines spread from the current position to the end of text. | |
LineIndex | getHeightFromEntry (ListOfTexts::const_iterator textIterator) const |
Tells how many lines spread from the beggining of specified text entry to the end of text. | |
char * | getNewLine () |
Creates a new blank line of the appropriate width (length). | |
Protected Attributes | |
ListOfTexts | _textEntries |
Records the text stored by this buffer and its precomputed lines. | |
CharAbscissa | _width |
The width of the character grid. | |
CharOrdinate | _height |
The ordinate of the character grid. | |
TextLayout | _layout |
Records the current text layout being used. | |
CharAbscissa | _alineaWidth |
The width, in characters, of a paragraph alinea. | |
ListOfTexts::const_iterator | _currentText |
The index of the text entry being rendered. | |
TextGrid::const_iterator | _currentLine |
Index of a preformatted line in current rendered text grid. | |
TextGrid | _screenLines |
The current screen, seen as a list of (at most _height) lines. | |
Static Protected Attributes | |
static TextOutputFormat | _OutputFormat = rawText |
The text format to be used currently by TextDisplayable instances. | |
Private Member Functions | |
TextBuffer (const TextBuffer &source) | |
Copy constructor made private to ensure that it will be never called. | |
TextBuffer & | operator= (const TextBuffer &source) |
Assignment operator made private to ensure that it will be never called. |
Computes the corresponding character layout for onscreen rendering, depending on the specified abstract screen dimensions (expressed in characters, not in pixels, as character look-up and rendering are uncoupled here).
The abstract screen is a kind of grid of characters, of user-specified size, that can slide over parts of the stored text.
This helps for example fixed-font text rendering.
Definition at line 60 of file CeylanTextBuffer.h.
typedef std::list<TextEntry> Ceylan::TextBuffer::ListOfTexts [protected] |
typedef std::pair<std::string, TextGrid*> Ceylan::TextBuffer::TextEntry [protected] |
A text entry is made of a chunk of text and its precomputed lines (if any).
Definition at line 448 of file CeylanTextBuffer.h.
typedef std::list<char *> Ceylan::TextBuffer::TextGrid |
Records a preformatted text entry, whose escape sequences (,
) have been translated into a series of basic characters (alphanumerical and spaces) stored in a list of lines, each line being an array of width characters (char *), to fit in character grid.
Definition at line 323 of file CeylanTextBuffer.h.
Describes the various modes supported for text layout.
Raw | Letters displayed on after the other with no regards for words. |
WordWrapped | Words are wrapped (not cut), but text is not justified. |
Justified | Words are wrapped (not cut), and text is justified. |
Definition at line 95 of file CeylanTextBuffer.h.
enum Ceylan::TextDisplayable::TextOutputFormat [inherited] |
Defines what text output formats for TextDisplayable instances are available.
Definition at line 124 of file CeylanTextDisplayable.h.
TextBuffer::TextBuffer | ( | CharAbscissa | screenWidth, | |
CharOrdinate | screenHeight, | |||
TextLayout | layout = Raw | |||
) |
Creates a new text buffer, whose sliding window (abstracted screen) is of specified size.
width | the width of the character grid. | |
height | the width of the character grid. | |
layout | the desired text layout for this buffer. |
StringUtilsException | if the operation failed. |
Definition at line 64 of file CeylanTextBuffer.cc.
References _currentText, and _textEntries.
TextBuffer::~TextBuffer | ( | ) | throw () [virtual] |
Ceylan::TextBuffer::TextBuffer | ( | const TextBuffer & | source | ) | [private] |
Copy constructor made private to ensure that it will be never called.
The compiler should complain whenever this undefined constructor is called, implicitly or not.
void TextBuffer::add | ( | const std::string & | text | ) | [virtual] |
Adds specified text in the buffer.
Updates the internal virtual screen accordingly.
text | the text to add in buffer. |
TextBufferException | if the operation failed. |
Definition at line 150 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _textEntries, createTextGridFrom(), jumpNextLineNoRefresh(), and updateScreenLines().
Referenced by Ceylan::System::Console::addInBuffer().
void TextBuffer::blank | ( | ) | [virtual] |
Blanks this whole buffer.
Removes all text content.
Definition at line 183 of file CeylanTextBuffer.cc.
References _textEntries, and deleteTextGrid().
Referenced by Ceylan::System::Console::blankBuffer(), and ~TextBuffer().
TextBuffer::TextGrid & TextBuffer::createAdvancedGridFrom | ( | const std::string & | text | ) | [protected] |
Translates specified text entry into a list of lines of buffer width, with word-wrapped or justified (i.e.
word-wrapped with adapted spaces) lines, depending on current layout.
Adapted from OSDL: in OSDL/trunk/src/code/video/twoDimensional/OSDLFont.cc, see OSDL::Video::Surface & Font::renderLatin1MultiLineText
Definition at line 670 of file CeylanTextBuffer.cc.
References _alineaWidth, _layout, _width, generalUtils::false, getNewLine(), Justified, Ceylan::splitIntoParagraphs(), Ceylan::splitIntoWords(), and generalUtils::true.
Referenced by createTextGridFrom().
TextBuffer::TextGrid & TextBuffer::createRawGridFrom | ( | const std::string & | text | ) | [protected] |
Translates specified text entry into a list of lines of buffer width, with no special concern for layout: text written letter by letter.
Definition at line 603 of file CeylanTextBuffer.cc.
References _width, getNewLine(), and TabSpacing.
Referenced by createTextGridFrom().
TextBuffer::TextGrid & TextBuffer::createTextGridFrom | ( | const std::string & | text | ) | [protected] |
Translates specified text entry into a list of lines of buffer width, according to current screen dimensions and layout.
Definition at line 570 of file CeylanTextBuffer.cc.
References _layout, createAdvancedGridFrom(), createRawGridFrom(), Justified, Raw, and WordWrapped.
Referenced by add(), and recomputeGrids().
void TextBuffer::deleteTextGrid | ( | TextGrid * | grid | ) | [protected] |
Deletes a TextGrid.
Definition at line 1013 of file CeylanTextBuffer.cc.
Referenced by blank(), and recomputeGrids().
TextBuffer::CharAbscissa TextBuffer::getAlineaWidth | ( | ) | const [virtual] |
Returns the current alinea width, in characters.
Definition at line 132 of file CeylanTextBuffer.cc.
References _alineaWidth.
TextBuffer::CharOrdinate TextBuffer::getHeight | ( | ) | const [virtual] |
Returns the height of the abstract screen associated to this buffer.
Definition at line 98 of file CeylanTextBuffer.cc.
References _height.
TextBuffer::LineIndex TextBuffer::getHeightFromCurrentPosition | ( | ) | const [protected] |
Tells how many lines spread from the current position to the end of text.
Definition at line 944 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, and _textEntries.
Referenced by jumpNextLine(), and jumpNextLineNoRefresh().
TextBuffer::LineIndex TextBuffer::getHeightFromEntry | ( | ListOfTexts::const_iterator | textIterator | ) | const [protected] |
Tells how many lines spread from the beggining of specified text entry to the end of text.
Definition at line 979 of file CeylanTextBuffer.cc.
References _textEntries.
char * TextBuffer::getNewLine | ( | ) | [protected] |
Creates a new blank line of the appropriate width (length).
Definition at line 1000 of file CeylanTextBuffer.cc.
References _width.
Referenced by createAdvancedGridFrom(), and createRawGridFrom().
TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat | ( | ) | [static, inherited] |
Returns the current overall text format to be used by TextDisplayable instances.
Definition at line 63 of file CeylanTextDisplayable.cc.
References Ceylan::TextDisplayable::_OutputFormat.
Referenced by Ceylan::formatStringList(), Ceylan::formatStringMap(), Ceylan::XML::XMLMarkup::toString(), Ceylan::Maths::Linear::Vector3::toString(), Ceylan::Maths::Linear::Vector2::toString(), Ceylan::Maths::Linear::Tripoint::toString(), Ceylan::Module::toString(), Ceylan::Maths::Linear::Matrix3::toString(), Ceylan::Maths::Linear::Matrix2::toString(), Ceylan::Maths::Linear::HomogeneousMatrix3::toString(), and Ceylan::Maths::Linear::Bipoint::toString().
const TextBuffer::TextGrid & TextBuffer::getScreenLines | ( | ) | const [virtual] |
Returns the list of lines that should be displayed, should this buffer be rendered.
Depends on the stored texts and on the location of the abstract screen.
The width of each line is the one of this buffer (char[_width]). The screen list has between [0.._height] lines, missing ones mean they are blank.
Definition at line 405 of file CeylanTextBuffer.cc.
References _screenLines.
Referenced by Ceylan::System::Console::render().
TextBuffer::TextLayout TextBuffer::getTextLayout | ( | ) | const [virtual] |
Returns the text layout being currently used.
Definition at line 107 of file CeylanTextBuffer.cc.
References _layout.
Referenced by Ceylan::System::Console::getTextLayout().
TextBuffer::CharAbscissa TextBuffer::getWidth | ( | ) | const [virtual] |
Returns the width of the abstract screen associated to this buffer.
Definition at line 89 of file CeylanTextBuffer.cc.
References _width.
Referenced by Ceylan::System::Console::render().
bool TextBuffer::jumpNextLine | ( | ) | [virtual] |
Makes the abstract screen go one line down.
Does nothing if there is no text line left (already at bottom).
Definition at line 254 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _height, _textEntries, generalUtils::false, getHeightFromCurrentPosition(), generalUtils::true, and updateScreenLines().
Referenced by Ceylan::System::Console::jumpNextLine().
void TextBuffer::jumpNextLineNoRefresh | ( | ) | [virtual] |
Makes the abstract screen go one line down, but does not refresh the screen lines.
Definition at line 309 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _height, _textEntries, and getHeightFromCurrentPosition().
Referenced by add().
bool TextBuffer::jumpNextText | ( | ) | [virtual] |
Centers the abstract screen on next text entry, if any.
Does nothing if there is no text left.
Definition at line 203 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _textEntries, generalUtils::false, generalUtils::true, and updateScreenLines().
Referenced by Ceylan::System::Console::jumpNextText().
bool TextBuffer::jumpPreviousLine | ( | ) | [virtual] |
Makes the abstract screen go one line up.
Does nothing if there is no text line left (already on top).
Definition at line 339 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _height, _screenLines, _textEntries, generalUtils::false, and generalUtils::true.
Referenced by Ceylan::System::Console::jumpPreviousLine().
bool TextBuffer::jumpPreviousText | ( | ) | [virtual] |
Centers the abstract screen on previous text, if any.
Does nothing if there is no text left.
Definition at line 230 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _textEntries, generalUtils::false, generalUtils::true, and updateScreenLines().
Referenced by Ceylan::System::Console::jumpPreviousText().
TextBuffer& Ceylan::TextBuffer::operator= | ( | const TextBuffer & | source | ) | [private] |
Assignment operator made private to ensure that it will be never called.
The compiler should complain whenever this undefined operator is called, implicitly or not.
void TextBuffer::recomputeGrids | ( | ) | [protected, virtual] |
Recomputes cached grid lines with current settings.
Any previous ones are removed first.
Definition at line 490 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _textEntries, createTextGridFrom(), deleteTextGrid(), and updateScreenLines().
Referenced by setTextLayout().
void TextBuffer::setAlineaWidth | ( | CharAbscissa | newAlineaWidth | ) | [virtual] |
Sets a new alinea width, in character.
newAlineaWidth | the new alinea width, in character. It can be null for no alinea at all. |
Definition at line 141 of file CeylanTextBuffer.cc.
References _alineaWidth.
void TextDisplayable::SetOutputFormat | ( | TextOutputFormat | newOutputFormat | ) | [static, inherited] |
Sets the current overall text format to be used by TextDisplayable instances.
newOutputFormat | the new output format. |
Definition at line 72 of file CeylanTextDisplayable.cc.
References Ceylan::TextDisplayable::_OutputFormat.
Referenced by Ceylan::Log::LogHolder::LogHolder().
void TextBuffer::setTextLayout | ( | TextLayout | newLayout | ) | [virtual] |
Sets a new text layout.
Triggers an update of the preformatted text.
newLayout | the new layout to be used from now on. |
TextBufferException | if the operation failed. |
Definition at line 116 of file CeylanTextBuffer.cc.
References _layout, and recomputeGrids().
Referenced by Ceylan::System::Console::setTextLayout().
const std::string TextDisplayable::ToString | ( | std::list< TextDisplayable * > | displayables, | |
Ceylan::VerbosityLevels | level = Ceylan::high | |||
) | [static, inherited] |
Returns a user-friendly description of this list of pointers to text displayable instances.
displayables | a list of pointers to TextDisplayable instances/ | |
level | the requested verbosity level. |
Definition at line 45 of file CeylanTextDisplayable.cc.
References Ceylan::formatStringList().
const std::string TextBuffer::toString | ( | Ceylan::VerbosityLevels | level = Ceylan::high |
) | const [virtual] |
Returns an user-friendly description of the state of this object.
level | the requested verbosity level. |
Implements Ceylan::TextDisplayable.
Definition at line 414 of file CeylanTextBuffer.cc.
References _height, _layout, _screenLines, _textEntries, _width, Ceylan::formatStringList(), Ceylan::high, Justified, Raw, Ceylan::toNumericalString(), and WordWrapped.
Referenced by Ceylan::System::Console::toString().
void TextBuffer::updateScreenLines | ( | ) | [protected] |
Updates screen lines according to current buffer text and line index.
Recreates from scratch the list of line references.
Definition at line 515 of file CeylanTextBuffer.cc.
References _currentLine, _currentText, _height, _screenLines, _textEntries, generalUtils::false, and generalUtils::true.
Referenced by add(), jumpNextLine(), jumpNextText(), jumpPreviousText(), and recomputeGrids().
CharAbscissa Ceylan::TextBuffer::_alineaWidth [protected] |
The width, in characters, of a paragraph alinea.
Definition at line 521 of file CeylanTextBuffer.h.
Referenced by createAdvancedGridFrom(), getAlineaWidth(), and setAlineaWidth().
TextGrid::const_iterator Ceylan::TextBuffer::_currentLine [protected] |
Index of a preformatted line in current rendered text grid.
Definition at line 538 of file CeylanTextBuffer.h.
Referenced by add(), getHeightFromCurrentPosition(), jumpNextLine(), jumpNextLineNoRefresh(), jumpNextText(), jumpPreviousLine(), jumpPreviousText(), recomputeGrids(), and updateScreenLines().
ListOfTexts::const_iterator Ceylan::TextBuffer::_currentText [protected] |
The index of the text entry being rendered.
Definition at line 534 of file CeylanTextBuffer.h.
Referenced by add(), getHeightFromCurrentPosition(), jumpNextLine(), jumpNextLineNoRefresh(), jumpNextText(), jumpPreviousLine(), jumpPreviousText(), recomputeGrids(), TextBuffer(), and updateScreenLines().
CharOrdinate Ceylan::TextBuffer::_height [protected] |
The ordinate of the character grid.
Definition at line 512 of file CeylanTextBuffer.h.
Referenced by getHeight(), jumpNextLine(), jumpNextLineNoRefresh(), jumpPreviousLine(), toString(), and updateScreenLines().
TextLayout Ceylan::TextBuffer::_layout [protected] |
Records the current text layout being used.
Definition at line 517 of file CeylanTextBuffer.h.
Referenced by createAdvancedGridFrom(), createTextGridFrom(), getTextLayout(), setTextLayout(), and toString().
TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited] |
The text format to be used currently by TextDisplayable instances.
Definition at line 158 of file CeylanTextDisplayable.h.
Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().
TextGrid Ceylan::TextBuffer::_screenLines [protected] |
The current screen, seen as a list of (at most _height) lines.
Definition at line 542 of file CeylanTextBuffer.h.
Referenced by getScreenLines(), jumpPreviousLine(), toString(), and updateScreenLines().
ListOfTexts Ceylan::TextBuffer::_textEntries [protected] |
Records the text stored by this buffer and its precomputed lines.
Definition at line 502 of file CeylanTextBuffer.h.
Referenced by add(), blank(), getHeightFromCurrentPosition(), getHeightFromEntry(), jumpNextLine(), jumpNextLineNoRefresh(), jumpNextText(), jumpPreviousLine(), jumpPreviousText(), recomputeGrids(), TextBuffer(), toString(), and updateScreenLines().
CharAbscissa Ceylan::TextBuffer::_width [protected] |
The width of the character grid.
Definition at line 508 of file CeylanTextBuffer.h.
Referenced by createAdvancedGridFrom(), createRawGridFrom(), getNewLine(), getWidth(), and toString().
const CharAbscissa Ceylan::TextBuffer::TabSpacing = 4 [static] |
Number of spaces corresponding to one tabulation.
Definition at line 361 of file CeylanTextBuffer.h.
Referenced by createRawGridFrom().