Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //! Same using a wchar_t* instead of a stringw to go faster and avoid memory waste
- void CGUIFont::draw(const wchar_t *text, u32 textSize, const core::rect<s32>& position,
- video::SColor color,
- bool hcenter, bool vcenter, const core::rect<s32>* clip
- )
- {
- if (!Driver)
- return;
- core::dimension2d<s32> textDimension; // NOTE: don't make this u32 or the >> later on can fail when the dimension widht is < position width
- core::position2d<s32> offset = position.UpperLeftCorner;
- if (hcenter || vcenter || clip)
- textDimension = getDimension(text);
- if (hcenter)
- offset.X += (position.getWidth() - textDimension.Width) >> 1;
- if (vcenter)
- offset.Y += (position.getHeight() - textDimension.Height) >> 1;
- if (clip)
- {
- core::rect<s32> clippedRect(offset, textDimension);
- clippedRect.clipAgainst(*clip);
- if (!clippedRect.isValid())
- return;
- }
- core::array<u32> indices(textSize);
- core::array<core::position2di> offsets(textSize);
- for(u32 i = 0;i < textSize; ++i)
- {
- wchar_t c = text[i];
- bool lineBreak=false;
- if ( c == L'\r') // Mac or Windows breaks
- {
- lineBreak = true;
- if ( text[i + 1] == L'\n') // Windows breaks
- c = text[++i];
- }
- else if ( c == L'\n') // Unix breaks
- {
- lineBreak = true;
- }
- if (lineBreak)
- {
- offset.Y += MaxHeight;
- offset.X = position.UpperLeftCorner.X;
- if ( hcenter )
- {
- offset.X += (position.getWidth() - textDimension.Width) >> 1;
- }
- continue;
- }
- SFontArea& area = Areas[getAreaFromCharacter(c)];
- offset.X += area.underhang;
- if ( Invisible.findFirst ( c ) < 0 )
- {
- indices.push_back(area.spriteno);
- offsets.push_back(offset);
- }
- offset.X += area.width + area.overhang + GlobalKerningWidth;
- }
- SpriteBank->draw2DSpriteBatch(indices, offsets, clip, color);
- }
Advertisement
Add Comment
Please, Sign In to add comment