Guest User

Untitled

a guest
Aug 2nd, 2011
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. //! Same using a wchar_t* instead of a stringw to go faster and avoid memory waste
  2. void CGUIFont::draw(const wchar_t *text, u32 textSize, const core::rect<s32>& position,
  3.                     video::SColor color,
  4.                     bool hcenter, bool vcenter, const core::rect<s32>* clip
  5.                 )
  6. {
  7.     if (!Driver)
  8.         return;
  9.  
  10.     core::dimension2d<s32> textDimension;   // NOTE: don't make this u32 or the >> later on can fail when the dimension widht is < position width
  11.     core::position2d<s32> offset = position.UpperLeftCorner;
  12.  
  13.     if (hcenter || vcenter || clip)
  14.         textDimension = getDimension(text);
  15.  
  16.     if (hcenter)
  17.         offset.X += (position.getWidth() - textDimension.Width) >> 1;
  18.  
  19.     if (vcenter)
  20.         offset.Y += (position.getHeight() - textDimension.Height) >> 1;
  21.  
  22.     if (clip)
  23.     {
  24.         core::rect<s32> clippedRect(offset, textDimension);
  25.         clippedRect.clipAgainst(*clip);
  26.         if (!clippedRect.isValid())
  27.             return;
  28.     }
  29.  
  30.     core::array<u32> indices(textSize);
  31.     core::array<core::position2di> offsets(textSize);
  32.  
  33.     for(u32 i = 0;i < textSize; ++i)
  34.     {
  35.         wchar_t c = text[i];
  36.  
  37.         bool lineBreak=false;
  38.         if ( c == L'\r') // Mac or Windows breaks
  39.         {
  40.             lineBreak = true;
  41.             if ( text[i + 1] == L'\n') // Windows breaks
  42.                 c = text[++i];
  43.         }
  44.         else if ( c == L'\n') // Unix breaks
  45.         {
  46.             lineBreak = true;
  47.         }
  48.  
  49.         if (lineBreak)
  50.         {
  51.             offset.Y += MaxHeight;
  52.             offset.X = position.UpperLeftCorner.X;
  53.  
  54.             if ( hcenter )
  55.             {
  56.                 offset.X += (position.getWidth() - textDimension.Width) >> 1;
  57.             }
  58.             continue;
  59.         }
  60.  
  61.         SFontArea& area = Areas[getAreaFromCharacter(c)];
  62.  
  63.         offset.X += area.underhang;
  64.         if ( Invisible.findFirst ( c ) < 0 )
  65.         {
  66.             indices.push_back(area.spriteno);
  67.             offsets.push_back(offset);
  68.         }
  69.  
  70.         offset.X += area.width + area.overhang + GlobalKerningWidth;
  71.     }
  72.  
  73.     SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment