41 #ifndef _uitextline_cpp
42 #define _uitextline_cpp
44 #include "UI/textline.h"
45 #include "UI/textlayer.h"
46 #include "UI/quadrenderable.h"
88 if( Offset < (*CharIt)->GetLengthOffset() ) {
95 while( CharIt != this->
Characters.end() && Offset > (*CharIt)->GetRightEdgeLengthOffset() )
101 if( CharIt == (--this->
Characters.end()) && Offset > (*CharIt)->GetRightEdgeLengthOffset() ) {
109 Real CharXPos = (*CharIt)->GetLengthOffset();
110 Real CharXSize = (*CharIt)->GetCharacterSize().X;
112 Ret.first = (*CharIt);
113 Ret.second.X = ( CharXPos + (CharXSize * 0.5) < Offset ? CharXPos + CharXSize : CharXPos );
124 if( Offset < (*CharIt)->GetLengthOffset() )
128 while( CharIt != this->
Characters.end() && Offset > (*CharIt)->GetRightEdgeLengthOffset() )
138 Real CharXPos = (*CharIt)->GetLengthOffset();
139 Real CharXSize = (*CharIt)->GetCharacterSize().X;
140 return ( Offset < CharXPos + (CharXSize * 0.5) ? RetIndex : ++RetIndex );
149 if( Index < 0 || static_cast<Whole>(Index) > this->
Characters.size() ) {
151 return (*Last)->GetLengthOffset() + (*Last)->GetCharacterSize().X;
156 while( CharIt != this->
Characters.end() && IndexCount < Index )
162 return (*CharIt)->GetLengthOffset();
174 case UI::LA_TopLeft:
return 0;
break;
175 case UI::LA_BottomRight:
return MaxWidth -
CurrLength;
break;
176 case UI::LA_Center:
return (MaxWidth * 0.5) - (CurrLength * 0.5);
break;
186 case UI::LA_TopLeft:
return CurrLength;
break;
187 case UI::LA_BottomRight:
return MaxWidth;
break;
188 case UI::LA_Center:
return (MaxWidth * 0.5) + (
CurrLength * 0.5);
break;
197 if( Position < (*CharIt)->GetLengthOffset() )
200 while( CharIt != this->
Characters.end() && Position < (*CharIt)->GetLengthOffset() )
202 if( (*CharIt)->IsNewLine() )
209 Real CharXPos = (*CharIt)->GetLengthOffset();
210 Real CharXSize = (*CharIt)->GetCharacterSize().X;
213 if( CharIt == (--(this->
Characters.end())) && Position > CharXPos + CharXSize )
216 return ( Position < CharXPos + (CharXSize * 0.5) ? CharXPos : CharXPos + CharXSize );
243 if( AddedLength <= MaxWidth ) {
274 while( CharIt != this->
Characters.end() && Count < Index )
286 if( Offset < (*CharIt)->GetLengthOffset() )
289 while( CharIt != this->
Characters.end() && Offset < (*CharIt)->GetLengthOffset() )
291 if( (*CharIt)->IsNewLine() )
298 if( CharIt == (--(this->
Characters.end())) && Offset > (*CharIt)->GetLengthOffset() + (*CharIt)->GetCharacterSize().X )
353 CursorPosition += (*CharIt)->GetCharacterAdvance( Previous != NULL ? Previous->
GetCharGlyph() : NULL );
354 Previous = (*CharIt);
386 Real Tallest = 0, SequenceLength = 0;
393 Tallest = std::max(Tallest,(*CharIt)->GetLineHeight());
394 Previous = (*CharIt);
398 if( AddedLength <= MaxWidth )
400 this->CurrLength = AddedLength;
422 for( ; CharIt != Last ; ++CharIt )
426 if( AddedLength <= MaxWidth ) {
432 Previous = (*CharIt);
480 { this->
Alignment = UI::LA_BottomRight; }
498 (*CharIt)->SetLengthOffset(CursorPosition);
499 Previous = (*CharIt);
531 Real Tallest = 0, SequenceLength = 0;
544 Tallest = std::max(Tallest,(*CharIt)->GetLineHeight());
545 Previous = (*CharIt);
549 if( AddedLength <= MaxWidth )
551 this->CurrLength = AddedLength;
579 for( ; CharIt != FirstCopy ; --CharIt )
583 if( AddedLength <= MaxWidth ) {
589 Previous = (*CharIt);
613 if( *Current != this->
Characters.front() )
return --Copy;
CharacterIterator GetFirstCharacter()
Gets the first character in this TextLine.
virtual void AppendToBack(Character *ToAppend)=0
Adds a character such that it becomes the last in the sequence.
TextLayer * Parent
The parent layer this text line belongs to.
CharacterIterator GetLastCharacter()
Gets the last character in this TextLine.
Real GetPositionOffset() const
Gets the offset on the Y axis from the parent layer.
bool Boole
Generally acts a single bit, true or false.
virtual Real GetCursorStartPosition() const =0
Gets the offset position of the cursor based on the text order of the layer this text line belongs to...
CharacterIterator BeginCharacter()
Gets an iterator to the first Character.
CharacterIterator AppendFittingCharacters(CharacterIterator First, CharacterIterator Last, const Real MaxWidth)
Adds as many Characters in a range as will fit to this TextLine.
LeftToRightTextLine(TextLayer *ParentLayer)
Class constructor.
CharacterIterator EndCharacter()
Gets an iterator to one passed the last Character.
Character * GetCharacterAtOffset(const Real &Offset)
Gets the character in this textline at the specified offset.
virtual ~TextLine()
Class destructor.
UInt32 GetNumCharacters() const
Gets the number of characters in this TextLine.
UI::LinearAlignment GetAlignment() const
Gets the current alignment for the text in this line of text.
Real PositionOffset
The offset in pixels from the parent layer on the Y axis.
CharacterIterator GetNextCharacter(CharacterIterator Current)
Gets an iterator to the next Character.
int Integer
A datatype used to represent any integer close to.
Real GetOffsetAtIndex(const Integer &Index) const
Gets the Offset position of the character at the specified index.
Real GetCursorStartPosition() const
Gets the offset position of the cursor based on the text order of the layer this text line belongs to...
virtual void _MarkDirty()
Marks this renderable as well as all parent objects as dirty.
CharacterIterator AppendFittingCharacters(CharacterIterator First, CharacterIterator Last, const Real MaxWidth)
Adds as many Characters in a range as will fit to this TextLine.
Real CurrLength
The current length of this TextLine.
This represents a single line of text to be rendered by a TextLayer.
OffsetResultPair GetCharacterAndCursorPositionAtOffset(const Real &Offset) const
Gets the character at the provided offset as well as the nearest valid position the cursor can take...
void RemoveAllCharacters()
Removes all characters from this TextLine.
CharacterIterator AppendFittingCharacters(CharacterContainer &ToAdd, const Real MaxWidth)
Adds as many Characters in a range as will fit to this TextLine.
Boole AppendCharacter(Character *ToAdd, const Real MaxWidth)
Adds a Character to the end of this TextLine.
virtual ~LeftToRightTextLine()
Class destructor.
CharacterIterator GetNextCharacter(CharacterIterator Current)
Gets an iterator to the next Character.
CharacterIterator GetLastCharacter()
Gets the last character in this TextLine.
float Real
A Datatype used to represent a real floating point number.
LinearAlignment
Used by various UI classes to determine the alignment of their child objects, such as text in text li...
std::list< Character * > CharacterContainer
Basic container type for Character storage by this class.
void SetAlignment(const UI::LinearAlignment Align)
Sets the current alignment for the text in this line of text.
Real GetRightMostCursorPosition() const
Gets the offset position of the right-most part of this TextLine.
void AppendToBack(Character *ToAppend)
Adds a character such that it becomes the last in the sequence.
Real GetCharacterAdvance(Glyph *Prev) const
Gets the amount of pixels to advance the cursor after placing this character.
void RecalculateOffsets()
Recalculates the offset for every character in this line.
std::pair< Character *, Vector2 > OffsetResultPair
An std::pair storing a Character and it's offset position (relative to the parent layer)...
Boole AppendCharacters(CharacterIterator First, CharacterIterator Last, const Real MaxWidth)
Adds a series of Characters to the end of this TextLine.
Integer GetIndexAtOffset(const Real &Offset) const
Gets the index of the character at the provided offset.
This class creates and encapsultes a character that can be used in text renders.
uint32_t UInt32
An 32-bit unsigned integer.
This is used to represent a point on a 2 dimentional area, such as a screen.
void RecalculateOffsets()
Recalculates the offset for every character in this line.
Character * GetSecondFromLastCharacter() const
Gets the character before the last character.
Real GetLineHeight() const
Gets the size of this TextLine on the Y axis.
virtual Real GetMaxLineWidth() const
Gets the maximum width of text lines in this layer.
Real TallestHeight
The size of the largest glyph on the Y axis.
Real GetClosestCursorPosition(const Real &Offset)
Gets the closest valid cursor position to the offset provided.
UI::LinearAlignment Alignment
The alignment of the text on the X axis in this line.
void RemoveLastCharacter()
Removes the character at the end of this TextLine.
std::pair< CharacterIterator, CharacterIterator > CharacterIteratorPair
An std::pair storing two CharacterIterators, usually for expressing a range.
void RemoveFirstCharacter()
Removes the character at the start of this TextLine.
Character * GetSecondFromLastCharacter() const
Gets the character before the last character.
Real GetCurrentLength() const
Calculates the current length of this text line.
CharacterContainer::iterator CharacterIterator
Iterator type for Character instances stored by this class.
CharacterContainer::reverse_iterator ReverseCharacterIterator
Reverse Iterator type for Character instances stored by this class.
Boole AppendCharacters(CharacterIterator First, CharacterIterator Last, const Real MaxWidth)
Adds a series of Characters to the end of this TextLine.
Real GetCursorStartPosition() const
Gets the offset position of the cursor based on the text order of the layer this text line belongs to...
Real GetLineHeight() const
Gets the height a line needs to be to support rendering this character.
void SetLengthOffset(const Real &Offset)
Sets the offset from the position of the parent TextLine.
Glyph * GetCharGlyph() const
Gets the glyph being rendered by this character.
The bulk of the engine components go in this namspace.
Boole AppendCharacters(CharacterContainer &ToAdd, const Real MaxWidth)
Adds a series of Characters to the end of this TextLine.
Real GetLeftMostCursorPosition() const
Gets the offset position of the left-most part of this TextLine.
void SetPositionOffset(const Real &Offset)
Sets the offset on the Y axis from the parent layer.
void RemoveFirstCharacter()
Removes the character at the start of this TextLine.
Character * GetCharacterAtIndex(const UInt32 &Index)
Gets the character in this textline at the specified index.
virtual void RecalculateOffsets()=0
Recalculates the offset for every character in this line.
virtual ~RightToLeftTextLine()
Class destructor.
CharacterContainer::const_iterator ConstCharacterIterator
Const Iterator type for Character instances stored by this class.
TextLine(TextLayer *ParentLayer)
Class constructor.
void AppendToBack(Character *ToAppend)
Adds a character such that it becomes the last in the sequence.
This is a base class for render layers that render text.
RightToLeftTextLine(TextLayer *ParentLayer)
Class constructor.
virtual CharacterIterator GetLastCharacter()=0
Gets the last character in this TextLine.
CharacterContainer Characters
Vector containing all the characters belonging to this TextLine.
CharacterIterator GetFirstCharacter()
Gets the first character in this TextLine.
void RemoveLastCharacter()
Removes the character at the end of this TextLine.