Spinning Topp Logo BlackTopp Studios
inc
textlayer.cpp
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _uitextlayer_cpp
42 #define _uitextlayer_cpp
43 
44 #include "UI/textlayer.h"
45 #include "UI/textline.h"
46 #include "UI/textcursor.h"
47 #include "UI/texttoken.h"
48 #include "UI/defaultmarkupparser.h"
49 #include "UI/widget.h"
50 #include "UI/screen.h"
51 
52 #include "UI/uimanager.h"
53 #include "unicode.h"
54 #include "stringtool.h"
55 #include "MathTools/mathtools.h"
56 
57 namespace Mezzanine
58 {
59  namespace UI
60  {
61  TextLayer::TextLayer(QuadRenderable* ParentRenderable) :
62  RenderLayer(ParentRenderable),
63  ManualCharScaling(1.0,1.0),
64 
65  MUParser(NULL),
66  Cursor(NULL),
67  TextTokens(NULL),
68 
69  HighlightStart(-1),
70  HighlightEnd(-1),
71  MaxLineWidth(this->Parent->GetActualSize().X),
72  AutoCharScaling(0.0),
73 
74  AutoCharScalingMode(TextLayer::SM_NoAutoScaling),
75  HorizontalOrder(UI::TO_Left_To_Right), // Default to english
76  VerticalAlign(UI::LA_TopLeft)
77  {
78  // Set our colour defaults
82  this->ActiveHLColour.AlphaChannel = 0.5;
83  this->InactiveHLColour.AlphaChannel = 0.5;
84  this->TextTokens = new TokenString();
85 
86  // Create our one free line for text
87  this->CreateTextLine();
88 
89  // Set the default parser
90  this->MUParser = Parent->GetScreen()->GetMarkupParser("Default");
91 
92  // This constructor does not set a font. A font will need to be set prior to setting any text.
93  }
94 
95  TextLayer::TextLayer(const String& FontName, QuadRenderable* ParentRenderable) :
96  RenderLayer(ParentRenderable),
97  ManualCharScaling(1.0,1.0),
98 
99  MUParser(NULL),
100  Cursor(NULL),
101  TextTokens(NULL),
102 
103  HighlightStart(-1),
104  HighlightEnd(-1),
105  MaxLineWidth(this->Parent->GetActualSize().X),
106  AutoCharScaling(0.0),
107 
108  AutoCharScalingMode(TextLayer::SM_NoAutoScaling),
109  HorizontalOrder(UI::TO_Left_To_Right), // Default to english
110  VerticalAlign(UI::LA_TopLeft)
111  {
112  // Set our colour defaults
116  this->ActiveHLColour.AlphaChannel = 0.5;
117  this->InactiveHLColour.AlphaChannel = 0.5;
118  this->TextTokens = new TokenString();
119 
120  // Set our font
121  this->DefaultCharTraits.CharFont = this->Parent->GetScreen()->GetFont(FontName,this->PriAtlas);
122 
123  // Create our one free line for text
124  this->CreateTextLine();
125 
126  // Set the default parser
127  this->MUParser = Parent->GetScreen()->GetMarkupParser("Default");
128  }
129 
130  TextLayer::TextLayer(const Real& LineHeight, QuadRenderable* ParentRenderable) :
131  RenderLayer(ParentRenderable),
132  ManualCharScaling(1.0,1.0),
133 
134  MUParser(NULL),
135  Cursor(NULL),
136  TextTokens(NULL),
137 
138  HighlightStart(-1),
139  HighlightEnd(-1),
140  MaxLineWidth(this->Parent->GetActualSize().X),
141  AutoCharScaling(LineHeight),
142 
143  AutoCharScalingMode(TextLayer::SM_ScreenRelative),
144  HorizontalOrder(UI::TO_Left_To_Right), // Default to english
145  VerticalAlign(UI::LA_TopLeft)
146  {
147  // Set our colour defaults
151  this->ActiveHLColour.AlphaChannel = 0.5;
152  this->InactiveHLColour.AlphaChannel = 0.5;
153  this->TextTokens = new TokenString();
154 
155  // Set our font
156  UIManager::FontResult Result = UIManager::GetSingletonPtr()->SuggestGlyphIndex(static_cast<UInt32>(this->AutoCharScaling * Parent->GetActualSize().Y),PriAtlas);
157  this->DefaultCharTraits.CharFont = this->Parent->GetScreen()->GetFont(Result.first,PriAtlas);
158  //this->SetTextScale(Vector2(Result.second,Result.second));
159 
160  // Create our one free line for text
161  this->CreateTextLine();
162 
163  // Set the default parser
164  this->MUParser = Parent->GetScreen()->GetMarkupParser("Default");
165  }
166 
168  {
169  this->ClearAllTextLines();
170  this->DestroyAllCharacters();
171  this->DestroyAllTextLines();
172  }
173 
175  {
176  // Update our text
177  Real MaxWidth = this->Parent->GetActualSize().X * this->Scale.X;
178  if( Force || MaxWidth != this->MaxLineWidth ) {
179  // In general the only time this will be forced is on a resizing of the parent
180  // quad renderable. So we must repopulate for the change of space.
181  this->MaxLineWidth = MaxWidth;
182  this->PopulateTextLines( this->MaxLineWidth );
183  }
184 
185  // Get the Texel Offsets
186  Real TexelOffsetX = this->Parent->GetScreen()->GetTexelOffsetX();
187  Real TexelOffsetY = this->Parent->GetScreen()->GetTexelOffsetY();
188 
189  // Get the parent rect and apply the scaling
190  Rect ActDims = this->GetAreaRect();
191  Vector2 LayerCenter = ActDims.GetRectCenter();
192 
193  // Setup the text specific data we'll use
194  Vector2 TopLeft, TopRight, BottomLeft, BottomRight;
195  Vector2 PrevHLTopRight, PrevHLBottomRight;
196  Vector2 WhitePixelCoords;
197  Real CursorX = ActDims.Position.X, CursorY = ActDims.Position.Y;
198  ColourValue HighlightColour = this->InactiveHLColour;
199  Character* CurrChar = NULL;
200  TextLine* CurrLine = NULL;
201 
202  // Check if we need the active highlight colour
203  if( this->Parent->IsWidget() && (static_cast<Widget*>(this->Parent))->HasFocus() ) {
204  HighlightColour = this->ActiveHLColour;
205  }
206 
207  for( TextLineIterator LineIt = this->TextLines.begin() ; LineIt != this->TextLines.end() ; ++LineIt )
208  {
209  CurrLine = (*LineIt);
210  CursorY = ActDims.Position.Y + CurrLine->GetPositionOffset();
211 
212  PrevHLTopRight.SetValues(-1,-1);
213  PrevHLBottomRight.SetValues(-1,-1);
214 
215  // If we have ran out of room, halt rendering
216  if( CursorY >= ActDims.Position.Y + ActDims.Size.Y )
217  break;
218 
219  // Update the X cursor starting position
220  CursorX = ActDims.Position.X + CurrLine->GetCursorStartPosition();
221 
222  for( TextLine::CharacterIterator CharIt = CurrLine->BeginCharacter() ; CharIt != CurrLine->EndCharacter() ; ++CharIt )
223  {
224  CurrChar = (*CharIt);
225  if( !CurrChar->IsRenderable() )
226  continue;
227 
228  String CharAtlas = CurrChar->GetAtlasName();
229  Real VertOffset = CurrChar->GetVerticalOffset();
230  Vector2 CharSize = CurrChar->GetCharacterSize();
231  ColourValue CharColour = CurrChar->GetCharacterColour();
232  CursorX = ActDims.Position.X + CurrChar->GetLengthOffset();
233 
234  TopLeft.SetValues( MathTools::Floor( CursorX - TexelOffsetX ),
235  MathTools::Floor( (CursorY + TexelOffsetY + VertOffset) - CharSize.Y ) );
236  BottomRight.SetValues( MathTools::Floor( (CursorX - TexelOffsetX) + CharSize.X ),
237  MathTools::Floor( CursorY + TexelOffsetY + VertOffset ) );
238  TopRight.SetValues( BottomRight.X, TopLeft.Y );
239  BottomLeft.SetValues( TopLeft.X, BottomRight.Y );
240 
241  this->RotationTransform(TopLeft,TopRight,BottomLeft,BottomRight,LayerCenter);
242 
243  if( CurrChar->GetHighlighted() ) {
244  WhitePixelCoords = CurrChar->GetAtlasWhitePixel();
245 
246  // When higlighting we have to account for kerning, so use the previous characters right edge for this characters left edge.
247  // This comes with a minor caveat though. If we have a gap in the highlighting it'll draw highlights over the gap. However
248  // with the way the system is set up at the time of this writing, highlights can't have gaps in text layers. So this shouldn't
249  // ever be an issue. If the system changes however...then this will need to be updated to be more intelligent.
250  if( PrevHLTopRight.X > -1 && PrevHLTopRight.Y > -1 && PrevHLBottomRight.X > -1 && PrevHLBottomRight.Y > -1 ) {
251  // Triangle A
252  PushVertex(PrevHLBottomRight.X, PrevHLBottomRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Bottom 3
253  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Top 1
254  PushVertex(PrevHLTopRight.X, PrevHLTopRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Top 0
255 
256  // Triangle B
257  PushVertex(PrevHLBottomRight.X, PrevHLBottomRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Bottom 3
258  PushVertex(BottomRight.X, BottomRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Bottom 2
259  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Top 1
260  }else{
261  // Triangle A
262  PushVertex(BottomLeft.X, BottomLeft.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Bottom 3
263  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Top 1
264  PushVertex(TopLeft.X, TopLeft.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Top 0
265 
266  // Triangle B
267  PushVertex(BottomLeft.X, BottomLeft.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Left/Bottom 3
268  PushVertex(BottomRight.X, BottomRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Bottom 2
269  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, HighlightColour, CharAtlas); // Right/Top 1
270  }
271 
272  PrevHLTopRight = TopRight;
273  PrevHLBottomRight = BottomRight;
274  }
275 
276  // Triangle A
277  PushVertex(BottomLeft.X, BottomLeft.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_BottomLeft), CharColour, CharAtlas); // Left/Bottom 3
278  PushVertex(TopRight.X, TopRight.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_TopRight), CharColour, CharAtlas); // Right/Top 1
279  PushVertex(TopLeft.X, TopLeft.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_TopLeft), CharColour, CharAtlas); // Left/Top 0
280 
281  // Triangle B
282  PushVertex(BottomLeft.X, BottomLeft.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_BottomLeft), CharColour, CharAtlas); // Left/Bottom 3
283  PushVertex(BottomRight.X, BottomRight.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_BottomRight), CharColour, CharAtlas); // Right/Bottom 2
284  PushVertex(TopRight.X, TopRight.Y, CurrChar->GetRelativeAtlasCoords(UI::QC_TopRight), CharColour, CharAtlas); // Right/Top 1
285  }//for each character
286  }//for each text line
287 
288  // Last thing to do is rendering the text cursor
289  if( this->GetCursorEnabled() ) {
290  if( this->Cursor->GetVisible() ) {
291  Rect CursorRect = Cursor->GetCursorRect();
292  ColourValue CursorColour = Cursor->GetColour();
293  WhitePixelCoords = Parent->GetScreen()->GetWhitePixel(PriAtlas);
294 
295  BottomLeft = ActDims.Position + CursorRect.Position;
296  TopRight.SetValues( BottomLeft.X + CursorRect.Size.X , BottomLeft.Y - CursorRect.Size.Y );
297  TopLeft.SetValues( BottomLeft.X , TopRight.Y );
298  BottomRight.SetValues( TopRight.X , BottomLeft.Y );
299 
300  // Triangle A
301  PushVertex(BottomLeft.X, BottomLeft.Y, WhitePixelCoords, CursorColour, PriAtlas); // Left/Bottom 3
302  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, CursorColour, PriAtlas); // Right/Top 1
303  PushVertex(TopLeft.X, TopLeft.Y, WhitePixelCoords, CursorColour, PriAtlas); // Left/Top 0
304 
305  // Triangle B
306  PushVertex(BottomLeft.X, BottomLeft.Y, WhitePixelCoords, CursorColour, PriAtlas); // Left/Bottom 3
307  PushVertex(BottomRight.X, BottomRight.Y, WhitePixelCoords, CursorColour, PriAtlas); // Right/Bottom 2
308  PushVertex(TopRight.X, TopRight.Y, WhitePixelCoords, CursorColour, PriAtlas); // Right/Top 1
309  }
310  }
311  }
312 
314  {
315  // Get the actual starting position on the Y axis
316  Real CursorY = 0;
317  Real TotalHeight = this->GetTotalHeight();
318  Rect ActDims = this->GetAreaRect();
319  if( TotalHeight < ActDims.Size.Y )
320  {
321  switch(VerticalAlign)
322  {
323  case UI::LA_TopLeft: /* do nothing, we're at the top */ break;
324  case UI::LA_BottomRight: CursorY = ActDims.Size.Y - TotalHeight; break;
325  case UI::LA_Center: CursorY = (ActDims.Size.Y * 0.5) - (TotalHeight * 0.5); break;
326  }
327  }
328  // Set all the actual offsets
329  for( TextLineIterator TLIt = TextLines.begin() ; TLIt != TextLines.end() ; ++TLIt )
330  {
331  CursorY += (*TLIt)->GetLineHeight();
332  (*TLIt)->SetPositionOffset(CursorY);
333  }
334  }
335 
336  ///////////////////////////////////////////////////////////////////////////////
337  // Parser Methods
338 
340  {
341  if( Parser != NULL ) {
342  this->MUParser = Parser;
343  return true;
344  }else{
345  return false;
346  }
347  }
348 
350  {
351  MarkupParser* Parser = Parent->GetScreen()->GetMarkupParser(ParserName);
352  return this->SetMarkupParser(Parser);
353  }
354 
356  {
357  return this->MUParser;
358  }
359 
360  ///////////////////////////////////////////////////////////////////////////////
361  // Utility
362 
364  {
365  Real Ret = 0;
366  for( ConstTextLineIterator TextIt = this->TextLines.begin() ; TextIt != this->TextLines.end() ; ++TextIt )
367  {
368  Ret += (*TextIt)->GetLineHeight();
369  }
370  return Ret;
371  }
372 
374  {
375  return this->MaxLineWidth;
376  }
377 
379  {
380  switch( this->AutoCharScalingMode )
381  {
382  case TextLayer::SM_ScreenRelative: return ( this->Parent->GetScreen()->GetActualSize().Y * this->AutoCharScaling ); break;
383  case TextLayer::SM_ParentRelative: return ( this->Parent->GetActualSize().Y * this->AutoCharScaling ); break;
384  case TextLayer::SM_LayerRelative: return ( this->GetAreaRect().Size.Y * this->AutoCharScaling ); break;
386  default: return 0; break;
387  }
388  }
389 
390  ///////////////////////////////////////////////////////////////////////////////
391  // Offset - Index Conversion Methods
392 
394  {
395  // Get the parent rect and apply the scaling
396  Rect LayerDims = this->GetAreaRect();
397  if( !LayerDims.IsInside(LayerDims.Position + Offset) || 0 == this->GetNumTextLines() )
398  return CharIndexPair(false,0);
399 
400  return this->GetIndexAtOffsetImpl(Offset);
401  }
402 
404  {
405  return this->GetOffsetAtIndexImpl(Index);
406  }
407 
408  ///////////////////////////////////////////////////////////////////////////////
409  // Text Methods
410 
411  void TextLayer::SetText(const String& Text)
412  {
413  if( this->DefaultCharTraits.CharFont == NULL ) {
414  StringStream ExceptionStream;
415  ExceptionStream << "Attempting to set text on a TextLayer without a default font set. Layer owned by renderable \"" << Parent->GetName() << "\".";
417  }
418 
419  /// @todo Character generation and storage is a good candidate for pool allocation.
420  this->DestroyAllCharacters();
421 
422  if( this->TextTokens != NULL ) {
423  delete this->TextTokens;
424  this->TextTokens = NULL;
425  }
426 
427  this->TextTokens = this->MUParser->Lex(Text);
428  this->Characters = this->MUParser->ParseTextTokens(this->TextTokens,this->DefaultCharTraits,this);
429  this->PopulateTextLines( this->MaxLineWidth );
430 
431  this->_MarkDirty();
432  }
433 
435  {
436  return this->TextTokens->GetRawString();
437  }
438 
440  {
441  if( this->DefaultCharTraits.CharColour != Colour ) {
442  this->DefaultCharTraits.CharColour = Colour;
443  this->_MarkDirty();
444  }
445  }
446 
448  {
449  return this->DefaultCharTraits.CharColour;
450  }
451 
453  {
454  if( this->ManualCharScaling != Scale ) {
455  this->ManualCharScaling = Scale;
456  this->PopulateTextLines( this->MaxLineWidth );
457  this->_MarkDirty();
458  }
459  }
460 
462  {
463  return this->ManualCharScaling;
464  }
465 
467  {
468  if( this->AutoCharScalingMode != Mode || this->AutoCharScaling != Scalar ) {
469  this->AutoCharScalingMode = Mode;
470  this->AutoCharScaling = Scalar;
471  this->PopulateTextLines( this->MaxLineWidth );
472  this->_MarkDirty();
473  }
474  }
475 
477  {
478  return this->AutoCharScalingMode;
479  }
480 
482  {
483  return this->AutoCharScaling;
484  }
485 
486  ///////////////////////////////////////////////////////////////////////////////
487  // Font Methods
488 
490  {
491  if(NewFont != this->DefaultCharTraits.CharFont && NewFont) {
492  this->DefaultCharTraits.CharFont = NewFont;
493  this->_MarkDirty();
494  }else{
495  /// @todo Throw an error?
496  }
497  }
498 
499  void TextLayer::SetDefaultFont(const String& FontName)
500  {
501  FontData* NewData = Parent->GetScreen()->GetFont(FontName,PriAtlas);
502  this->SetDefaultFont(NewData);
503  }
504 
505  void TextLayer::SetDefaultFont(const String& FontName, const String& Atlas)
506  {
507  FontData* NewData = Parent->GetScreen()->GetFont(FontName,Atlas);
508  this->SetDefaultFont(NewData);
509  }
510 
512  {
513  return this->DefaultCharTraits.CharFont;
514  }
515 
516  ///////////////////////////////////////////////////////////////////////////////
517  // Highlight Methods
518 
520  {
521  if( this->ActiveHLColour != Colour ) {
522  this->ActiveHLColour = Colour;
523  this->_MarkDirty();
524  }
525  }
526 
528  {
529  return this->ActiveHLColour;
530  }
531 
533  {
534  if( this->InactiveHLColour != Colour ) {
535  this->InactiveHLColour = Colour;
536  this->_MarkDirty();
537  }
538  }
539 
541  {
542  return this->InactiveHLColour;
543  }
544 
546  {
547  this->HighlightStart = 0;
548  this->HighlightEnd = this->Characters.size() - 1;
550  }
551 
552  void TextLayer::Highlight(const Integer Index)
553  {
554  this->ClearHighlights();
555  if( static_cast<Whole>(Index) < this->Characters.size() ) {
556  CharacterIterator ToHighlight = this->GetCharacterIteratorAtIndex(Index);
557  (*ToHighlight)->SetHighlighted(true);
558 
559  this->HighlightStart = Index;
560  this->HighlightEnd = Index;
561  }
562  }
563 
564  void TextLayer::Highlight(const Integer StartIndex, const Integer EndIndex)
565  {
566  this->ClearHighlights();
567  CharacterIterator StartIterator = this->GetCharacterIteratorAtIndex(StartIndex);
568  CharacterIterator EndIterator = ( static_cast<Whole>(EndIndex + 1) >= this->Characters.size() ? this->Characters.end() : this->GetCharacterIteratorAtIndex(EndIndex + 1) );
569 
570  while( StartIterator != EndIterator )
571  {
572  (*StartIterator)->SetHighlighted(true);
573  ++StartIterator;
574  }
575 
576  this->HighlightStart = StartIndex;
577  this->HighlightEnd = EndIndex;
578  }
579 
581  {
582  return this->HighlightStart;
583  }
584 
586  {
587  return this->HighlightEnd;
588  }
589 
591  {
592  if( this->HighlightStart == -1 && this->HighlightEnd == -1 )
593  return;
594 
595  CharacterIterator StartIterator = this->GetCharacterIteratorAtIndex(this->HighlightStart);
596  CharacterIterator EndIterator = ( static_cast<Whole>(this->HighlightEnd + 1) >= this->Characters.size() ? this->Characters.end() : this->GetCharacterIteratorAtIndex(this->HighlightEnd + 1) );
597 
598  while( StartIterator != EndIterator )
599  {
600  (*StartIterator)->SetHighlighted(false);
601  ++StartIterator;
602  }
603 
604  this->HighlightStart = -1;
605  this->HighlightEnd = -1;
606  }
607 
608  ///////////////////////////////////////////////////////////////////////////////
609  // Ordering Methods
610 
612  {
613  if( this->HorizontalOrder == Order )
614  return;
615 
616  this->DestroyAllTextLines();
617  this->CreateTextLine();
618  this->PopulateTextLines( this->MaxLineWidth );
619 
620  this->HorizontalOrder = Order;
621  this->_MarkDirty();
622  }
623 
625  {
626  return this->HorizontalOrder;
627  }
628 
629  ///////////////////////////////////////////////////////////////////////////////
630  // Cursor Methods
631 
633  {
634  if( Enable == this->GetCursorEnabled() )
635  return;
636 
637  if(Enable) {
638  TextLine* Line = this->TextLines.at(0);
639  this->Cursor = new TextCursor(this);
641  }else{
642  delete this->Cursor;
643  this->Cursor = NULL;
644  }
645 
646  this->_MarkDirty();
647  }
648 
650  {
651  return ( this->Cursor != NULL );
652  }
653 
655  {
656  return this->Cursor;
657  }
658 
659  ///////////////////////////////////////////////////////////////////////////////
660  // TextLine Methods
661 
663  {
664  TextLine* NewLine = NULL;
665  UI::LinearAlignment Align = ( this->TextLines.empty() ? UI::LA_TopLeft : this->TextLines.back()->GetAlignment() );
666  if( this->HorizontalOrder == UI::TO_Left_To_Right ) {
667  NewLine = new LeftToRightTextLine(this);
668  }else{
669  NewLine = new RightToLeftTextLine(this);
670  }
671 
672  NewLine->SetAlignment(Align);
673  this->TextLines.push_back(NewLine);
674  return NewLine;
675  }
676 
678  {
679  TextLineIterator LineIt = TextLines.begin();
680  // Check if we're too far to the top to get anything
681  if( Offset < (*LineIt)->GetPositionOffset() - (*LineIt)->GetLineHeight() )
682  return NULL;
683 
684  while( LineIt != this->TextLines.end() && Offset < (*LineIt)->GetPositionOffset() )
685  {
686  ++LineIt;
687  }
688 
689  // Check if we're too low to get anything
690  if( LineIt == (--this->TextLines.end()) && Offset > (*LineIt)->GetPositionOffset() )
691  return NULL;
692 
693  return (*LineIt);
694  }
695 
697  {
698  return this->TextLines.size();
699  }
700 
701  void TextLayer::PopulateTextLines(const Real MaxWidth)
702  {
703  this->ClearAllTextLines();
704  this->PopulateTextLinesImpl(MaxWidth);
705  this->RecalculateOffsets();
706  this->_MarkDirty();
707  }
708 
710  {
711  for( TextLineIterator TLIt = this->TextLines.begin() ; TLIt != this->TextLines.end() ; ++TLIt )
712  { (*TLIt)->RemoveAllCharacters(); }
713 
714  this->_MarkDirty();
715  }
716 
718  {
719  for( TextLineIterator TLIt = this->TextLines.begin() ; TLIt != this->TextLines.end() ; ++TLIt )
720  { delete (*TLIt); }
721 
722  this->TextLines.clear();
723  this->_MarkDirty();
724  }
725 
727  {
728  for( TextLineIterator TLIt = this->TextLines.begin() ; TLIt != this->TextLines.end() ; ++TLIt )
729  { (*TLIt)->SetAlignment(Align); }
730  }
731 
733  {
734  if( this->VerticalAlign == Align )
735  return;
736 
737  this->VerticalAlign = Align;
738  this->RecalculateOffsets();
739  this->_MarkDirty();
740  }
741 
743  {
744  return this->VerticalAlign;
745  }
746 
748  { return this->TextLines.begin(); }
749 
751  { return this->TextLines.end(); }
752 
754  { return this->TextLines.begin(); }
755 
757  { return this->TextLines.end(); }
758 
759  ///////////////////////////////////////////////////////////////////////////////
760  // Character Methods
761 
763  {
764  return *(this->GetCharacterIteratorAtIndex(Index));
765  }
766 
768  {
769  // Get the parent rect and apply the scaling
770  Rect ActDims = this->GetAreaRect();
771  if( !ActDims.IsInside(ActDims.Position + Offset) || this->TextLines.empty() )
772  return NULL;
773 
774  // Get our line
775  ConstTextLineIterator LineIt = this->TextLines.begin();
776  while( LineIt != this->TextLines.end() && Offset.Y > (*LineIt)->GetPositionOffset() )
777  {
778  /// @todo The way this logic works, in the event of a slight bit of clipping at the bottom of the quad space that
779  /// isn't enough for the next line, this logic will assume that space is a part of the last line. Is that a problem?
780  ++LineIt;
781  }
782 
783  // Quickly check to see if we're to the side of any lines.
784  if( Offset.X < (*LineIt)->GetLeftMostCursorPosition() ||
785  Offset.X > (*LineIt)->GetRightMostCursorPosition() )
786  {
787  return NULL;
788  }
789 
790  // Get the character in that line
791  CharacterIterator CharIt = (*LineIt)->BeginCharacter();
792  while( CharIt != (*LineIt)->EndCharacter() && Offset.X > (*CharIt)->GetLengthOffset() + (*CharIt)->GetCharacterSize().X )
793  {
794  /// @todo In the event that letter spacing for the font is big ( >0 ), and the point provided rests on a gap in the spacing,
795  /// this algorithm will grab the character to the right as the hovered character. Is that a problem?
796  ++CharIt;
797  }
798 
799  if( CharIt == (*LineIt)->EndCharacter() ) return NULL;
800  else return (*CharIt);
801  }
802 
804  {
805  if( 0 > Index || static_cast<Whole>(Index) >= this->Characters.size() ) {
806  return --(this->Characters.end());
807  }else{
808  UInt32 Count = Index;
809  CharacterIterator CharIt = this->Characters.begin();
810  while( 0 != Count )
811  {
812  ++CharIt;
813  --Count;
814  }
815  return CharIt;
816  }
817  }
818 
820  {
821  if( 0 > Index || static_cast<Whole>(Index) >= this->Characters.size() ) {
822  return --(this->Characters.end());
823  }else{
824  UInt32 Count = Index;
825  ConstCharacterIterator CharIt = this->Characters.begin();
826  while( 0 != Count )
827  {
828  ++CharIt;
829  --Count;
830  }
831  return CharIt;
832  }
833  }
834 
836  {
837  return this->Characters.size();
838  }
839 
841  {
842  Integer OldSize = this->Characters.size();
843  // Do our work
844  this->TextTokens->InsertCharacter( Index < 0 ? this->TextTokens->GetNumCharacters() : Index ,GlyphID);
845  // Regenerate the text
846  String RawText = this->GetText();
847  this->SetText(RawText);
848  return ( this->Characters.size() - OldSize );
849  }
850 
851  Integer TextLayer::InsertCharactersAtIndex(const Integer Index, const Char8* Characters, const UInt32 BufSize)
852  {
853  Integer OldSize = this->Characters.size();
854  // Do our work
855  this->TextTokens->InsertCharacters( Index < 0 ? this->TextTokens->GetNumCharacters() : Index ,Characters,BufSize);
856  // Regenerate the text
857  String RawText = this->GetText();
858  this->SetText(RawText);
859  return ( this->Characters.size() - OldSize );
860  }
861 
862  Integer TextLayer::InsertCharactersAtIndex(const Integer Index, const UInt32* Characters, const UInt32 BufSize)
863  {
864  Integer OldSize = this->Characters.size();
865  // Do our work
866  this->TextTokens->InsertCharacters( Index < 0 ? this->TextTokens->GetNumCharacters() : Index ,Characters,BufSize);
867  // Regenerate the text
868  String RawText = this->GetText();
869  this->SetText(RawText);
870  return ( this->Characters.size() - OldSize );
871  }
872 
874  {
875  Integer OldSize = this->Characters.size();
876  // Do our work
877  this->TextTokens->RemoveCharacter( Index < 0 ? this->TextTokens->GetNumCharacters() : Index );
878  // Regenerate the text
879  String RawText = this->GetText();
880  this->SetText(RawText);
881  return ( OldSize - this->Characters.size() );
882  }
883 
885  {
886  Integer OldSize = this->Characters.size();
887  // Do our work
888  this->TextTokens->RemoveCharacters( Index < 0 ? this->TextTokens->GetNumCharacters() : Index ,Length);
889  // Regenerate the text
890  String RawText = this->GetText();
891  this->SetText(RawText);
892  return ( OldSize - this->Characters.size() );
893  }
894 
896  {
897  return this->RemoveCharactersAtIndex(First,(Last - First) + 1);
898  }
899 
901  {
902  Integer OldSize = this->Characters.size();
903  // Remove from the TextLines and tokens first
904  this->ClearAllTextLines();
905  this->TextTokens->DestroyAllTokens();
906  // Now clean up the characters
907  for( CharacterIterator CharIt = this->Characters.begin() ; CharIt != this->Characters.end() ; ++CharIt )
908  { delete (*CharIt); }
909  this->Characters.clear();
910 
911  this->HighlightStart = -1;
912  this->HighlightEnd = -1;
913 
914  this->_MarkDirty();
915  return OldSize;
916  }
917 
919  { return this->Characters.begin(); }
920 
922  { return this->Characters.end(); }
923 
925  { return this->Characters.begin(); }
926 
928  { return this->Characters.end(); }
929 
930  ///////////////////////////////////////////////////////////////////////////////
931  // Serialization
932 
933  void TextLayer::ProtoSerialize(XML::Node& ParentNode) const
934  {
935  XML::Node SelfRoot = ParentNode.AppendChild( this->GetDerivedSerializableName() );
936 
937  this->ProtoSerializeProperties(SelfRoot);
938  this->ProtoSerializeCursor(SelfRoot);
939  this->ProtoSerializeText(SelfRoot);
940  }
941 
943  {
945  XML::Node PropertiesNode = SelfRoot.AppendChild( TextLayer::GetSerializableName() + "Properties" );
946 
947  if( PropertiesNode.AppendAttribute("Version").SetValue("1") &&
948  PropertiesNode.AppendAttribute("HighlightStart").SetValue(this->HighlightStart) &&
949  PropertiesNode.AppendAttribute("HighlightEnd").SetValue(this->HighlightEnd) &&
950  PropertiesNode.AppendAttribute("MaxLineWidth").SetValue(this->MaxLineWidth) &&
951  PropertiesNode.AppendAttribute("AutoCharScaling").SetValue(this->AutoCharScaling) &&
952  PropertiesNode.AppendAttribute("AutoCharScalingMode").SetValue(this->AutoCharScalingMode) &&
953  PropertiesNode.AppendAttribute("HorizontalOrder").SetValue(this->HorizontalOrder) &&
954  PropertiesNode.AppendAttribute("VerticalAlign").SetValue(this->VerticalAlign) &&
955  PropertiesNode.AppendAttribute("ParserName").SetValue( ( this->MUParser ? this->MUParser->GetName() : "" ) ) &&
956  PropertiesNode.AppendAttribute("RawText").SetValue(this->GetText()) )
957  {
958  XML::Node DefaultCharTraitsNode = PropertiesNode.AppendChild("DefaultCharTraits");
959  this->DefaultCharTraits.ProtoSerialize( DefaultCharTraitsNode );
960  XML::Node ActiveHLColourNode = PropertiesNode.AppendChild("ActiveHLColour");
961  this->ActiveHLColour.ProtoSerialize( ActiveHLColourNode );
962  XML::Node InactiveHLColourNode = PropertiesNode.AppendChild("InactiveHLColour");
963  this->InactiveHLColour.ProtoSerialize( InactiveHLColourNode );
964  XML::Node CharScalingNode = PropertiesNode.AppendChild("ManualCharScaling");
965  this->ManualCharScaling.ProtoSerialize( CharScalingNode );
966 
967  return;
968  }else{
969  SerializeError("Create XML Attribute Values",TextLayer::GetSerializableName() + "Properties",true);
970  }
971  }
972 
974  {
975  if( this->Cursor ) {
976  XML::Node CursorNode = SelfRoot.AppendChild("Cursor");
977  this->Cursor->ProtoSerialize( CursorNode );
978  }
979  }
980 
982  {
983  XML::Node TextNode = SelfRoot.AppendChild( TextLayer::GetSerializableName() + "Text" );
984 
985  if( TextNode.AppendAttribute("Version").SetValue(1) &&
986  TextNode.AppendAttribute("Text").SetValue( this->GetText() ) ) {
987  return;
988  }else{
989  SerializeError("Create XML Attribute Values",TextLayer::GetSerializableName() + "Text",true);
990  }
991  }
992 
994  {
995  this->ProtoDeSerializeProperties(SelfRoot);
996  this->ProtoDeSerializeCursor(SelfRoot);
997  this->ProtoDeSerializeText(SelfRoot);
998 
999  // Set Highlights
1000  if( this->HighlightStart > -1 && this->HighlightEnd > -1 ) {
1001  Integer StartCopy = this->HighlightStart;
1002  Integer EndCopy = this->HighlightEnd;
1003  this->Highlight(StartCopy,EndCopy);
1004  }
1005  }
1006 
1008  {
1009  this->ClearAllTextLines();
1010  this->DestroyAllCharacters();
1011  this->DestroyAllTextLines();
1012 
1014  XML::Attribute CurrAttrib;
1015  XML::Node PropertiesNode = SelfRoot.GetChild( TextLayer::GetSerializableName() + "Properties" );
1016 
1017  if( !PropertiesNode.Empty() ) {
1018  if( PropertiesNode.GetAttribute("Version").AsInt() == 1 ) {
1019  CurrAttrib = PropertiesNode.GetAttribute("HighlightStart");
1020  if( !CurrAttrib.Empty() )
1021  this->HighlightStart = CurrAttrib.AsInt();
1022 
1023  CurrAttrib = PropertiesNode.GetAttribute("HighlightEnd");
1024  if( !CurrAttrib.Empty() )
1025  this->HighlightEnd = CurrAttrib.AsInt();
1026 
1027  CurrAttrib = PropertiesNode.GetAttribute("MaxLineWidth");
1028  if( !CurrAttrib.Empty() )
1029  this->MaxLineWidth = CurrAttrib.AsReal();
1030 
1031  CurrAttrib = PropertiesNode.GetAttribute("AutoCharScaling");
1032  if( !CurrAttrib.Empty() )
1033  this->AutoCharScaling = CurrAttrib.AsReal();
1034 
1035  CurrAttrib = PropertiesNode.GetAttribute("AutoCharScalingMode");
1036  if( !CurrAttrib.Empty() )
1037  this->AutoCharScalingMode = static_cast<TextLayer::ScalingMode>( CurrAttrib.AsWhole() );
1038 
1039  CurrAttrib = PropertiesNode.GetAttribute("HorizontalOrder");
1040  if( !CurrAttrib.Empty() )
1041  this->HorizontalOrder = static_cast<UI::TextOrdering>( CurrAttrib.AsWhole() );
1042 
1043  CurrAttrib = PropertiesNode.GetAttribute("VerticalAlign");
1044  if( !CurrAttrib.Empty() )
1045  this->VerticalAlign = static_cast<UI::LinearAlignment>( CurrAttrib.AsWhole() );
1046 
1047  XML::Node DefaultCharTraitsNode = PropertiesNode.GetChild("DefaultCharTraits").GetFirstChild();
1048  if( !DefaultCharTraitsNode.Empty() )
1049  this->DefaultCharTraits.ProtoDeSerialize(DefaultCharTraitsNode);
1050 
1051  XML::Node ActiveHLColourNode = PropertiesNode.GetChild("ActiveHLColour").GetFirstChild();
1052  if( !ActiveHLColourNode.Empty() )
1053  this->ActiveHLColour.ProtoDeSerialize(ActiveHLColourNode);
1054 
1055  XML::Node InactiveHLColourNode = PropertiesNode.GetChild("InactiveHLColour").GetFirstChild();
1056  if( !InactiveHLColourNode.Empty() )
1057  this->InactiveHLColour.ProtoDeSerialize(InactiveHLColourNode);
1058 
1059  XML::Node CharScalingNode = PropertiesNode.GetChild("ManualCharScaling").GetFirstChild();
1060  if( !CharScalingNode.Empty() )
1061  this->ManualCharScaling.ProtoDeSerialize(CharScalingNode);
1062  }else{
1063  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (TextLayer::GetSerializableName() + "Properties") + ": Not Version 1.");
1064  }
1065  }else{
1066  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,TextLayer::GetSerializableName() + "Properties" + " was not found in the provided XML node, which was expected.");
1067  }
1068  }
1069 
1071  {
1072  XML::Node CursorNode = SelfRoot.GetChild("Cursor");
1073  if( !CursorNode.Empty() ) {
1074  if( this->GetCursorEnabled() == false ) {
1075  this->SetCursorEnabled(true);
1076  }
1077  this->Cursor->ProtoDeSerialize( CursorNode.GetFirstChild() );
1078  }
1079  }
1080 
1082  {
1083  XML::Attribute CurrAttrib;
1084  XML::Node TextNode = SelfRoot.GetChild( TextLayer::GetSerializableName() + "Text" );
1085 
1086  if( !TextNode.Empty() ) {
1087  if( TextNode.GetAttribute("Version").AsInt() == 1 ) {
1088  CurrAttrib = TextNode.GetAttribute("Text");
1089  if( !CurrAttrib.Empty() )
1090  this->SetText( CurrAttrib.AsString() );
1091  }else{
1092  MEZZ_EXCEPTION(ExceptionBase::INVALID_VERSION_EXCEPTION,"Incompatible XML Version for " + (TextLayer::GetSerializableName() + "Text") + ": Not Version 1.");
1093  }
1094  }else{
1095  MEZZ_EXCEPTION(ExceptionBase::II_IDENTITY_NOT_FOUND_EXCEPTION,TextLayer::GetSerializableName() + "Text" + " was not found in the provided XML node, which was expected.");
1096  }
1097  }
1098 
1100  { return TextLayer::GetSerializableName(); }
1101 
1103  { return "TextLayer"; }
1104  }//UI
1105 }//Mezzanine
1106 
1107 #endif
UI::LinearAlignment VerticalAlign
The alignment TextLines will have.
Definition: textlayer.h:146
This contains simple tools for indexing with UTF8 characters swiftly.
virtual Integer InsertCharacterAtIndex(const Integer Index, const UInt32 GlyphID)
Creates a character from a Glyph ID and inserts it into the layer at the specified index...
Definition: textlayer.cpp:840
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Characters/New Lines originate from the left, and advance to the right.
std::pair< Boole, Vector2 > CharOffsetPair
An std::pair type used as a return for index-offset conversions.
Definition: textlayer.h:88
virtual CharacterContainer ParseTextTokens(TokenString *Tokens, const CharacterTraits &InitialTraits, TextLayer *CallingLayer) const
Processes a collection of text tokens into a list of renderable characters.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
This class represents a collection of Glyphs in a common visual style.
Definition: font.h:55
virtual CharIndexPair GetIndexAtOffsetImpl(const Vector2 &Position)=0
Gets the index of the character at the specified offset position.
const String & GetName() const
Gets the name of this renderable.
Definition: renderable.cpp:77
void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
virtual TextLineIterator BeginTextLine()
Gets an iterator to the first TextLine.
Definition: textlayer.cpp:747
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Definition: textlayer.cpp:942
A light-weight handle for manipulating attributes in DOM tree.
Definition: attribute.h:74
virtual void SetTextLineVerticalAlignment(const UI::LinearAlignment Align)
Sets the alignment used to determine the start position of the textlines in this layer.
Definition: textlayer.cpp:732
virtual UInt32 RemoveCharacters(const UInt32 Index, const UInt32 Length)
Removes rendered characters from this string.
Definition: texttoken.cpp:550
virtual const ColourValue & GetTextColour() const
Gets the default colour of the tect being rendered by this layer.
Definition: textlayer.cpp:447
This is a helper class that facilitates operations with collections of tokens generated from Markup P...
Definition: texttoken.h:282
virtual TextLineIterator EndTextLine()
Gets an iterator to one passed the last TextLine.
Definition: textlayer.cpp:750
Real GetPositionOffset() const
Gets the offset on the Y axis from the parent layer.
Definition: textline.cpp:225
virtual CharacterIterator GetCharacterIteratorAtIndex(const Integer Index)
Gets an iterator to the character at the specified index.
Definition: textlayer.cpp:803
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
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...
void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
CharacterIterator BeginCharacter()
Gets an iterator to the first Character.
Definition: textline.cpp:318
static ColourValue Blue()
Creates a ColourValue representing the colour Blue.
virtual void RotationTransform(Vector2 &Point, const Vector2 &RotationCenter)
Applies rotation to a point in 2D space.
Definition: renderlayer.cpp:64
virtual Real GetTotalHeight() const
Gets the combined height of all the text lines in this layer.
Definition: textlayer.cpp:363
virtual UI::LinearAlignment GetTextLineVerticalAlignment() const
Gets the current set alignment for positioning textlines in this layer.
Definition: textlayer.cpp:742
virtual Rect GetAreaRect() const
Gets a rect containing the actual position and size of this layer.
Vector2 Size
Vector2 representing the width and height of the rect.
Definition: rect.h:71
CharacterContainer Characters
Container with all this layers Characters.
Definition: textlayer.h:104
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: textcursor.cpp:237
CharacterIterator EndCharacter()
Gets an iterator to one passed the last Character.
Definition: textline.cpp:321
CharacterIterator BeginCharacter()
Gets an iterator to the first Character.
Definition: textlayer.cpp:918
virtual void SetAutoTextScale(const TextLayer::ScalingMode Mode, const Real Scalar)
Sets the mode and scaler of auto-scaling applied to the text generated by this textlayer.
Definition: textlayer.cpp:466
Thrown when the requested identity could not be found.
Definition: exception.h:94
Node GetFirstChild() const
Get the first child Node of this Node.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
The provided scaler will be treated as relative to this layers Y size after layer scaling...
Definition: textlayer.h:96
MarkupParser * MUParser
The parser to use when converting raw strings to renderable characters.
Definition: textlayer.h:119
QuadRenderable * Parent
A pointer to the parent of this RenderLayer.
Definition: renderlayer.h:67
virtual UInt32 InsertCharacter(const UInt32 Index, UInt32 UChar)
Inserts a single UTF-32 size character into this string.
Definition: texttoken.cpp:502
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
String PriAtlas
This contains the name of the atlas that will be used as default when one isn't specified.
Boole IsRenderable() const
Gets if this character contains valid data for rendering.
Definition: character.cpp:285
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Vector2 GetRelativeAtlasCoords(const UI::QuadCorner Corner) const
Gets the relative atlas coordinates of a quad corner.
Definition: character.cpp:226
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
Definition: exception.h:112
static ColourValue White()
Creates a ColourValue representing the colour White.
virtual TokenString * Lex(const String &Source) const
Converts a string into a series of tokens that can be parsed more readily.
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
virtual void SetInactiveHighlightBackgroundColour(const ColourValue &Colour)
Sets the colour of the highlight when the quad is not focused.
Definition: textlayer.cpp:532
Real GetLengthOffset() const
Gets the length offset of this Character from it's parent TextLine.
Definition: character.cpp:317
virtual ~TextLayer()
Class destructor.
Definition: textlayer.cpp:167
virtual Boole SetMarkupParser(MarkupParser *Parser)
Sets the MarkupParser to be used by this TextLayer.
Definition: textlayer.cpp:339
FontData * GetFont(const String &FontName, const String &Atlas) const
Gets the specified FontData from an Atlas.
Definition: screen.cpp:889
Screen * GetScreen() const
Gets the parent screen of this renderable.
Definition: renderable.cpp:80
This class represents a box shaped area on the screen.
Definition: rect.h:55
Vector2 GetCharacterSize() const
Gets the rendered size of this character.
Definition: character.cpp:341
TextOrdering
This enum describes the direction of advancing characters or lines along the X axis.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
Definition: colourvalue.h:64
Real MaxLineWidth
The maximum width of textlines generated by this layer in pixels.
Definition: textlayer.h:134
virtual void _MarkDirty()
Marks this renderable as well as all parent objects as dirty.
bool Empty() const
Is this storing anything at all?
TextLineContainer::iterator TextLineIterator
Iterator type for TextLine instances stored by this class.
Definition: textlayer.h:82
Integer HighlightStart
The index of the character at the start of the highlight sequence.
Definition: textlayer.h:128
Real GetVerticalOffset() const
Gets the vertical adjustment for this character.
Definition: character.cpp:176
ColourValue ActiveHLColour
The colour of the highlight when this layer belongs to a focused widget.
Definition: textlayer.h:110
virtual void ProtoSerializeCursor(XML::Node &SelfRoot) const
Convert the TextCursor of this class to an XML::Node ready for seriailization.
Definition: textlayer.cpp:973
virtual const ColourValue & GetActiveHighlightBackgroundColour() const
Gets the colour of the highlight when the quad is being focused.
Definition: textlayer.cpp:527
This represents a single line of text to be rendered by a TextLayer.
Definition: textline.h:59
Integer HighlightEnd
The index of the character at the end of the highlight sequence.
Definition: textlayer.h:131
TextLayer(QuadRenderable *ParentRenderable)
No-Font constructor.
Definition: textlayer.cpp:61
Real AutoCharScaling
The auto-scaling height the text is to be in relative units.
Definition: textlayer.h:137
virtual void PopulateTextLines(const Real MaxWidth)
Populates text lines in this layer with parsed characters.
Definition: textlayer.cpp:701
FontData * CharFont
The font this Character belongs to.
std::stringstream StringStream
A Datatype used for streaming operations with strings.
Definition: datatypes.h:176
virtual Character * GetCharacterAtOffset(const Vector2 &Offset) const
Gets a Character by offset position.
Definition: textlayer.cpp:767
virtual void RedrawImpl(Boole Force)
Provides the class specific implementation for regenerating vertices for this renderable.
Definition: textlayer.cpp:174
virtual void DestroyAllTextLines()
Destroys all TextLines in this layer.
Definition: textlayer.cpp:717
virtual void SetCursorEnabled(Boole Enable)
Enables (or disables) the cursor for use in this layer.
Definition: textlayer.cpp:632
This is a TextLine specialization class for text read from the right to the left. ...
Definition: textline.h:323
std::pair< Boole, Integer > CharIndexPair
An std::pair type used as a return for index-offset conversions.
Definition: textlayer.h:86
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
LinearAlignment
Used by various UI classes to determine the alignment of their child objects, such as text in text li...
char Char8
A datatype to represent one character.
Definition: datatypes.h:169
Whole GetNumCharacters() const
Gets the number of renderable characters that exist in this string.
Definition: texttoken.cpp:442
There is no auto-scaling applied to text in this layer. Any scaling has to be done explicitly...
Definition: textlayer.h:93
Vector2 Scale
The scaling applied to this RenderLayer.
Definition: renderlayer.h:64
virtual Real GetAutoTextScalar() const
Gets the relative scalar being used to automatically scale text generated by this layer...
Definition: textlayer.cpp:481
This is a TextLine specialization class for text read from the left to the right. ...
Definition: textline.h:275
virtual Rect GetCursorRect() const
Gets a rect representing this cursors dimentions.
Definition: textcursor.cpp:107
bool SetValue(const Char8 *rhs)
Set the value of this.
void SetAlignment(const UI::LinearAlignment Align)
Sets the current alignment for the text in this line of text.
Definition: textline.cpp:70
virtual Integer RemoveCharacterAtIndex(const Integer Index)
Removes a character from the layer at the specified index.
Definition: textlayer.cpp:873
virtual TextLine * GetTextLineAtOffset(const Real &Offset)
Gets the TextLine at the specified offset position.
Definition: textlayer.cpp:677
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
ScalingMode
An enum used to describe how the text generated by this layer will be automatically scaled...
Definition: textlayer.h:91
static UIManager * GetSingletonPtr()
Fetches a pointer to the singleton.
Definition: singleton.h:97
Vector2 GetAtlasWhitePixel() const
Gets the coordinates to the white pixel on the atlas this character belongs to.
Definition: character.cpp:214
The provided scaler will be treated as relative to the Screen Y size.
Definition: textlayer.h:94
Vector2 GetWhitePixel(const String &Atlas) const
Gets the position of the white pixel from an Atlas.
Definition: screen.cpp:883
Real Y
Coordinate on the Y vector.
Definition: vector2.h:69
virtual Integer GetHighlightEnd() const
Gets the index of this last character that is highlighted in this layer.
Definition: textlayer.cpp:585
virtual void RecalculateOffsets()
Recalculates the offset for every text line in this layer.
Definition: textlayer.cpp:313
virtual CharIndexPair GetIndexAtOffset(const Vector2 &Offset)
Gets the index of the character at the specified offset position.
Definition: textlayer.cpp:393
static ColourValue Gray()
Creates a ColourValue representing the colour Gray.
virtual void PopulateTextLinesImpl(const Real MaxWidth)=0
Clears and then places characters belonging to this layer in the appropriate text lines...
virtual TextLine * CreateTextLine()
Creates a new TextLine.
Definition: textlayer.cpp:662
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
This class creates and encapsultes a character that can be used in text renders.
Definition: character.h:59
Real X
Coordinate on the X vector.
Definition: vector2.h:67
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual FontData * GetDefaultFont()
Gets the default font in use by this layer.
Definition: textlayer.cpp:511
This is used to represent a point on a 2 dimentional area, such as a screen.
Definition: vector2.h:63
virtual UInt32 RemoveCharacter(const UInt32 Index)
Removes a single rendered character from this string.
Definition: texttoken.cpp:544
bool Empty() const
Is this storing anything at all?
Real AlphaChannel
Value from 0.0 to 1.0 representing the transparency of the colours. 1.0 is opaque and 0...
Definition: colourvalue.h:79
This is the base class for all widgets.
Definition: widget.h:126
CharacterTraits DefaultCharTraits
Default set of traits all characters generated inside this layer are to have.
Definition: textlayer.h:107
Boole GetHighlighted() const
Gets if this character is being highlighted.
Definition: character.cpp:257
virtual Real GetMaxLineWidth() const
Gets the maximum width of text lines in this layer.
Definition: textlayer.cpp:373
virtual Vector2 GetActualSize() const
Gets the pixel size of this widget.
virtual Real GetDesiredLineHeight() const
Gets the height in pixels this layer is configured to render it's text.
Definition: textlayer.cpp:378
virtual void Highlight()
Highlights all characters in this layer.
Definition: textlayer.cpp:545
virtual Boole GetCursorEnabled() const
Gets whether or not the Text Cursor is enabled.
Definition: textlayer.cpp:649
virtual MarkupParser * GetMarkupParser() const
Gets the MarkupParser being used by this TextLayer.
Definition: textlayer.cpp:355
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
virtual const ColourValue & GetInactiveHighlightBackgroundColour() const
Gets the colour of the highlight when the quad is being focused.
Definition: textlayer.cpp:540
virtual CharOffsetPair GetOffsetAtIndexImpl(const Integer Index)=0
Gets the position of the character at the specified index.
CharacterIterator EndCharacter()
Gets an iterator to one passed the last Character.
Definition: textlayer.cpp:921
Class for encapsulating the functionality of the text cursor/carat navigation in text layers...
Definition: textcursor.h:59
virtual Integer GetHighlightStart() const
Gets the index of the first character that is highlighted in this layer.
Definition: textlayer.cpp:580
virtual Boole GetVisible() const
Gets the visibility of this cursor.
Definition: textcursor.cpp:70
virtual void SetOffsetPosition(const Vector2 &Offset)
Sets the offset position of this cursor to the nearest appropriate point.
Definition: textcursor.cpp:96
Real GetTexelOffsetX() const
Gets the X axis Texel Offset for the current rendersystem.
Definition: screen.cpp:898
virtual void ProtoDeSerializeText(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the Text of this object with it.
Definition: textlayer.cpp:1081
String GetAtlasName() const
Gets the name of the atlas this character is using for rendering.
Definition: character.cpp:207
virtual void SetManualTextScale(const Vector2 &Scale)
Sets the scaling to be applied to the text being rendered.
Definition: textlayer.cpp:452
virtual CharOffsetPair GetOffsetAtIndex(const Integer Index)
Gets the offset position of the character at the provided index.
Definition: textlayer.cpp:403
void SetValues(const Real &x, const Real &y)
Sets the X and Y values of this vector2.
Definition: vector2.cpp:105
virtual Integer InsertCharactersAtIndex(const Integer Index, const Char8 *Characters, const UInt32 BufSize)
Creates a series of characters from a UTF-8 encoded string to be inserted into this layer...
Definition: textlayer.cpp:851
static String GetSerializableName()
Get the name of the the XML tag the Renderable class will leave behind as its instances are serialize...
Definition: textlayer.cpp:1102
const ColourValue & GetCharacterColour() const
Gets the fill colour of this character.
Definition: character.cpp:243
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Renderable.
Definition: textlayer.cpp:1099
virtual String GetText() const
Gets the text displayed within this layer.
Definition: textlayer.cpp:434
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: textlayer.cpp:993
Thrown when the available information should have worked but failed for unknown reasons.
Definition: exception.h:113
CharacterContainer::iterator CharacterIterator
Iterator type for Character instances stored by this class.
Definition: textline.h:65
virtual void ClearHighlights()
Clears all the highlights in this layer.
Definition: textlayer.cpp:590
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
Definition: textlayer.cpp:1007
virtual Integer DestroyAllCharacters()
Destroy's all characters in this TextLayer.
Definition: textlayer.cpp:900
virtual TextLayer::ScalingMode GetAutoTextScalingMode() const
Gets the automatic scaling mode being used by this textlayer.
Definition: textlayer.cpp:476
virtual Whole GetNumCharacters() const
Gets the number of characters being rendered by this TextLayer.
Definition: textlayer.cpp:835
virtual void SetTextOrder(const UI::TextOrdering Order)
Sets the ordering for characters in this layer.
Definition: textlayer.cpp:611
virtual const Vector2 & GetManualTextScale() const
Gets the scaling currently being applied to the rendered text.
Definition: textlayer.cpp:461
ColourValue CharColour
The colour to render this Character as.
virtual void SetActiveHighlightBackgroundColour(const ColourValue &Colour)
Sets the colour of the highlight when the quad is being focused.
Definition: textlayer.cpp:519
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
std::pair< String, Real > FontResult
An std::pair type for returning the result of a font suggestion.
Definition: uimanager.h:140
virtual void SetTextLineHorizontalAlignment(const UI::LinearAlignment Align)
Sets the horizontal alignment of every textline in this layer.
Definition: textlayer.cpp:726
CharacterContainer::const_iterator ConstCharacterIterator
Const Iterator type for Character instances stored by this class.
Definition: textlayer.h:72
virtual void SetTextColour(const ColourValue &Colour)
Sets the default colour of the text being rendered by this layer.
Definition: textlayer.cpp:439
virtual UI::TextOrdering GetTextOrder() const
Gets the currently set direction of advancement for characters on the horizontal axis created by this...
Definition: textlayer.cpp:624
virtual String GetName() const =0
Gets the name of this parser implementation.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Definition: vector2.cpp:314
virtual Character * GetCharacterAtIndex(const Integer Index) const
Gets a Character by index.
Definition: textlayer.cpp:762
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
Definition: textcursor.cpp:254
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
virtual UInt32 InsertCharacters(const UInt32 Index, const Char8 *Characters, const UInt32 Size)
Inserts multiple characters into this string.
Definition: texttoken.cpp:516
Vector2 ManualCharScaling
The scaling to apply to all characters in this layer.
Definition: textlayer.h:116
Boole IsWidget() const
Gets whether or not this renderable is a Widget.
Definition: renderable.cpp:83
TextLineContainer TextLines
Container with all this layers TextLines.
Definition: textlayer.h:101
virtual Integer RemoveCharacterRange(const Integer First, const Integer Last)
Removes a range of characters from the text in this layer.
Definition: textlayer.cpp:895
virtual void DestroyAllTokens()
Destroys all tokens currently in this string.
Definition: texttoken.cpp:490
This is a base class for the parsing of markup texts contained in text layers.
Definition: markupparser.h:126
virtual TextCursor * GetCursor() const
Gets the TextCursor in use by this layer.
Definition: textlayer.cpp:654
Boole IsInside(const Vector2 &Point) const
Checks to see if a point in 2D space is inside this rect.
Definition: rect.h:207
This represents a nestable quad for an object in a GUI layout.
ScalingMode AutoCharScalingMode
The auto-scaling mode that is to be used on text generated by this textlayer.
Definition: textlayer.h:140
Vector2 Position
Vector2 representing the top-left position of the rect.
Definition: rect.h:69
virtual void SetDefaultFont(FontData *NewFont)
Sets the default font to be used with this layer.
Definition: textlayer.cpp:489
virtual void SetText(const String &Text)
Sets the text displayed within this layer.
Definition: textlayer.cpp:411
UI::TextOrdering HorizontalOrder
The order text will have in TextLines.
Definition: textlayer.h:143
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
The provided scaler will be treated as relative to the parent widget Y size.
Definition: textlayer.h:95
TextLineContainer::const_iterator ConstTextLineIterator
Const Iterator type for TextLine instances stored by this class.
Definition: textlayer.h:84
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
TextCursor * Cursor
The cursor to be used for insert and manipulation operations.
Definition: textlayer.h:122
TokenString * TextTokens
The actual text parsed into tokens used for generating characters.
Definition: textlayer.h:125
virtual void ProtoDeSerializeCursor(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the TextCursor of this object with it...
Definition: textlayer.cpp:1070
virtual const ColourValue & GetColour() const
Gets the colour that the Text Cursor will be rendered as.
Definition: textcursor.cpp:157
virtual Whole GetNumTextLines() const
Gets the number of TextLines this layer contains.
Definition: textlayer.cpp:696
virtual void ProtoSerializeText(XML::Node &SelfRoot) const
Convert the Text of this class to an XML::Node ready for serialization.
Definition: textlayer.cpp:981
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual Integer RemoveCharactersAtIndex(const Integer Index, const UInt32 Length)
Removes a length of characters from this layer at the specified index.
Definition: textlayer.cpp:884
virtual void ClearAllTextLines()
Removes all characters from all TextLines belonging to this layer.
Definition: textlayer.cpp:709
virtual String GetRawString() const
Gets a string containing all the raw characters of the tokens in this string.
Definition: texttoken.cpp:432
This is a base class for render layers that render text.
Definition: textlayer.h:64
Real GetTexelOffsetY() const
Gets the Y axis Texel Offset for the current rendersystem.
Definition: screen.cpp:901
void ProtoDeSerialize(const XML::Node &OneNode)
Take the data stored in an XML and overwrite this instance of this object with it.
Definition: vector2.cpp:335
UI::MarkupParser * GetMarkupParser(const String &ParserName) const
Gets a MarkupParser by it's registered name.
Definition: screen.cpp:910
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual void PushVertex(const Real &X, const Real &Y, const Vector2 &UV, const ColourValue &Colour, const String &Atlas)
Collects all the relevant information for a single vertex and pushes it to a vector.
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
Definition: textlayer.cpp:933
Vector2 GetRectCenter() const
Gets the coordinates to the center of this rect.
Definition: rect.h:186
ColourValue InactiveHLColour
The colour of the highlight when this layer belongs to a widget not being focused.
Definition: textlayer.h:113
This is the base class for the types of layers that can be added to a renderable. ...
Definition: renderlayer.h:58
CharacterContainer::iterator CharacterIterator
Iterator type for Character instances stored by this class.
Definition: textlayer.h:70
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.