本文整理汇总了C++中LPD3DXFONT::GetSpriteRect方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXFONT::GetSpriteRect方法的具体用法?C++ LPD3DXFONT::GetSpriteRect怎么用?C++ LPD3DXFONT::GetSpriteRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXFONT
的用法示例。
在下文中一共展示了LPD3DXFONT::GetSpriteRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateRect
void C_Renderer::CalculateRect(IResource* font, RectangleI* pt, const wchar_t* str, unsigned int start, unsigned int end, unsigned int style, float scale)
{
if(font==0) return;
#ifdef USE_BITMAPFONT
Sprite* Font = CAST_RES(Sprite*, font);
FontResource* rc = (FontResource*)font;
#else
LPD3DXFONT Font = CAST_RES(LPD3DXFONT, font);
#endif
if(Font==0) return;
#ifdef USE_BITMAPFONT
#else
D3DXMatrixScaling(&mat, scale, scale, 1.0f);
m_sprite->GetTransform(&m2);
m_sprite->SetTransform(&(mat * m2));
pt->left = (LONG)(pt->left/scale);
pt->top = (LONG)(pt->top/scale);
pt->right = (LONG)(pt->right/scale);
pt->bottom = (LONG)(pt->bottom/scale);
#endif
#ifdef USE_BITMAPFONT
float sw = 0.0f;
RectangleI* rct = 0;
RectangleF rect;
rect.left = (float)pt->left;
rect.top = (float)pt->top;
rect.right = (float)pt->right;
rect.bottom = (float)pt->bottom;
unsigned int txtsize = wcslen(str);
float fsize = (float)rc->GetSize();
if(start>=txtsize || end>txtsize) return;
float fwidth = 0.0f;
float fheight = 0.0f;
for(unsigned int i=start; i< start + end; i++)
{
rct = Font->GetSpriteRect((unsigned int)str[i]);
if(rct!=0)
{
float scale2 = fsize / (rct->bottom - rct->top);
fwidth += ((rct->right - rct->left - BFONTSPACEW) * scale2) * scale;
fheight = ((rct->bottom - rct->top) * scale2) * scale;
}
}
if(style&FONT_STYLE_MULTILINE)
{
rect.left -= BFONTSPACE;
rect.right -= BFONTSPACE;
}
else
{
rect.left -= BFONTSPACE;
rect.right = rect.left + fwidth - BFONTSPACE;
rect.bottom = rect.top + fheight;
pt->left = (int)(rect.left/scale);
pt->top = (int)(rect.top/scale);
pt->right = (int)(rect.right/scale);
pt->bottom = (int)(rect.bottom/scale);
}
#else
Font->DrawTextW(m_sprite, str + start, end, (LPRECT)pt, style | DT_CALCRECT, D3DXCOLOR(0,0,0,1));
m_sprite->SetTransform(&m2);
#endif
}
示例2: DrawText
void C_Renderer::DrawText(IResource* font, const wchar_t* text, int dx, int dy, int dr, int db, unsigned int color, unsigned int style, float scale, int Drawonly)
{
if(font==0) return;
#ifdef USE_BITMAPFONT
Sprite* Font = CAST_RES(Sprite*, font);
FontResource* rc = (FontResource*)font;
#else
LPD3DXFONT Font = CAST_RES(LPD3DXFONT, font);
#endif
if(Font==0) return;
#ifdef USE_BITMAPFONT
#else
D3DXMatrixScaling(&mat, scale, scale, 1.0f);
m_sprite->GetTransform(&m2);
m_sprite->SetTransform(&(mat * m2));
rect.left = (LONG)(dx/scale);
rect.top = (LONG)(dy/scale);
rect.right = (LONG)(dr/scale);
rect.bottom = (LONG)(db/scale);
#endif
#ifdef USE_BITMAPFONT
float sw = 0.0f;
RectangleI* rct = 0;
RectangleF rect;
rect.left = (float)dx;
rect.top = (float)dy;
rect.right = (float)dr;
rect.bottom = (float)db;
unsigned int txtsize = wcslen(text);
float fsize = (float)rc->GetSize();
float fwidth = 0.0f;
float fheight = 0.0f;
for(unsigned int i=0; i<txtsize; i++)
{
rct = Font->GetSpriteRect((unsigned int)text[i]);
if(rct!=0)
{
float scale2 = fsize / (rct->bottom - rct->top);
fwidth += ((rct->right - rct->left - BFONTSPACEW) * scale2) * scale;
fheight = ((rct->bottom - rct->top) * scale2) * scale;
}
}
if(style&FONT_STYLE_MULTILINE)
{
rect.left -= BFONTSPACE;
rect.right -= BFONTSPACE;
}
else
{
if(style&FONT_STYLE_CENTERALIGN)
{
float hfwidth = fwidth / 2.0f;
float hwidth = (rect.right - rect.left) / 2.0f;
rect.left = (rect.left + hwidth) - hfwidth - BFONTSPACEW;
rect.right = rect.left + fwidth - BFONTSPACEW;
}
else if(style&FONT_STYLE_RIGHTALIGN)
{
rect.left = rect.right - fwidth - BFONTSPACE;
rect.right = rect.left + fwidth - BFONTSPACE;
}
else
{
rect.left -= BFONTSPACE;
rect.right = rect.left + fwidth - BFONTSPACE;
}
if(style&FONT_STYLE_VCENTERALIGN)
{
float hfheight = fheight / 2.0f;
float hheight = (rect.bottom - rect.top) / 2.0f;
rect.top = (rect.top + hheight) - hfheight;
rect.bottom = rect.top + fheight;
}
else if(style&FONT_STYLE_BOTTOMALIGN)
{
rect.top = rect.bottom - fheight;
rect.right = rect.top + fheight;
}
else
{
rect.bottom = rect.top + fheight;
}
}
float ty = 0.0f;
float tx = 0;
//.........这里部分代码省略.........