本文整理汇总了C++中TextLine::GetWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ TextLine::GetWidth方法的具体用法?C++ TextLine::GetWidth怎么用?C++ TextLine::GetWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextLine
的用法示例。
在下文中一共展示了TextLine::GetWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetLineHeight
CBSurface *CBFontTT::RenderTextToTexture(const WideString &text, int width, TTextAlign align, int maxHeight, int &textOffset) {
TextLineList lines;
WrapText(text, width, maxHeight, lines);
TextLineList::iterator it;
int textHeight = lines.size() * (m_MaxCharHeight + m_Ascender);
SDL_Surface *surface = SDL_CreateRGBSurface(0, width, textHeight, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
SDL_LockSurface(surface);
int posY = (int)GetLineHeight() - (int)m_Descender;
for (it = lines.begin(); it != lines.end(); ++it) {
TextLine *line = (*it);
int posX = 0;
switch (align) {
case TAL_CENTER:
posX += (width - line->GetWidth()) / 2;
break;
case TAL_RIGHT:
posX += width - line->GetWidth();
break;
}
textOffset = 0;
for (size_t i = 0; i < line->GetText().length(); i++) {
wchar_t ch = line->GetText()[i];
GlyphInfo *glyph = m_GlyphCache->GetGlyph(ch);
if (!glyph) continue;
textOffset = std::max(textOffset, glyph->GetBearingY());
}
int origPosX = posX;
wchar_t prevChar = L'\0';
for (size_t i = 0; i < line->GetText().length(); i++) {
wchar_t ch = line->GetText()[i];
GlyphInfo *glyph = m_GlyphCache->GetGlyph(ch);
if (!glyph) continue;
float kerning = 0;
if (prevChar != L'\0') kerning = GetKerning(prevChar, ch);
posX += (int)kerning;
if (glyph->GetBearingY() > 0) {
int i = 10;
}
SDL_Rect rect;
rect.x = posX + glyph->GetBearingX();
rect.y = posY - glyph->GetBearingY() + textOffset;
rect.w = glyph->GetImage()->w;
rect.h = glyph->GetImage()->h;
BlitSurface(glyph->GetImage(), surface, &rect);
prevChar = ch;
posX += (int)(glyph->GetAdvanceX());
posY += (int)(glyph->GetAdvanceY());
}
if (m_IsUnderline) {
for (int i = origPosX; i < origPosX + line->GetWidth(); i++) {
Uint8 *buf = (Uint8 *)surface->pixels + (int)(m_UnderlinePos + m_Ascender) * surface->pitch;
Uint32 *buf32 = (Uint32 *)buf;
buf32[i] = SDL_MapRGBA(surface->format, 255, 255, 255, 255);
}
}
SDL_UnlockSurface(surface);
delete line;
line = NULL;
posY += GetLineHeight();
}
CBSurfaceSDL *wmeSurface = new CBSurfaceSDL(Game);
if (SUCCEEDED(wmeSurface->CreateFromSDLSurface(surface))) {
SDL_FreeSurface(surface);
return wmeSurface;
} else {
SDL_FreeSurface(surface);
delete wmeSurface;
return NULL;
}
}