本文整理汇总了C++中CFont::GetData方法的典型用法代码示例。如果您正苦于以下问题:C++ CFont::GetData方法的具体用法?C++ CFont::GetData怎么用?C++ CFont::GetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFont
的用法示例。
在下文中一共展示了CFont::GetData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWidthAndHeight
void Text::GetWidthAndHeight(const std::string& str, const CFont& font,
std::vector<float>& str_width, std::vector<float>& str_height,
float& whole_width, float& whole_height) {
std::wstring wstr(str_to_wstr(str));
str_width.resize(1);
str_height.resize(1);
UINT line = 0;
UINT width, height;
Application::GetScreenSize(width, height);
width *= font.GetQuality();
height *= font.GetQuality();
whole_width = whole_height = 0.0f;
for (const auto& it : wstr) {
if (it == '\n') {
whole_width = max(whole_width, str_width.at(line));
whole_height += str_height.at(line);
str_height.emplace_back(0.0f);
str_width.emplace_back(0.0f);
line++;
continue;
}
try {
auto& ch = font.GetData(it);
str_height.at(line) = max(str_height.at(line), ch.gm.gmptGlyphOrigin.y * 2.0f / (float)height);
str_width.at(line) += ch.gm.gmCellIncX * 2.0f / (float)width;
}
catch (...) {
continue;
}
}
whole_width = max(whole_width, str_width.at(line));
whole_height += str_height.at(line);
}
示例2: DrawString
void Text::DrawString(float x, float y, float z, const std::string& str,
const CFont& font, const CPipeline& pipeline, const COLOR& color, float alignX, float alignY) {
std::wstring wstr(str_to_wstr(str));
pipeline.BeginStorePipeline();
pipeline.SetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
pipeline.SetInputLayout(nullptr);
pipeline.SetVertexShader(&m_vs);
pipeline.SetGeometryShader(nullptr);
pipeline.SetPixelShader(&m_ps);
pipeline.SetPixelShaderSamplerState(0, &m_sampler);
pipeline.SetVertexShaderConstantBuffer(0, &m_pos);
m_color.UpdateBufferValue(color, Application::GetImmediateContext());
pipeline.SetPixelShaderConstantBuffer(1, &m_color);
std::vector<float> str_height;
std::vector<float> str_width;
float whole_width, whole_height;
GetWidthAndHeight(str, font, str_width, str_height, whole_width, whole_height);
UINT line = 0;
UINT width, height;
Application::GetScreenSize(width, height);
float lastPosX = 0.0f;
float lastPosY = str_height.at(0);
for (const auto& it : wstr) {
if (it == '\n') {
lastPosX = 0.0f;
line++;
lastPosY += str_height.at(line);
continue;
}
float sizeX;
float sizeY;
try {
const CFont::char_t& ch = font.GetData(it);
pipeline.SetPixelShaderResource(0, &ch.tex);
static int index = 0;
sizeX = (float)ch.gm.gmBlackBoxX / (float)width;
sizeY = (float)ch.gm.gmBlackBoxY / (float)height;
XMFLOAT4X4 mat;
XMStoreFloat4x4(&mat, XMMatrixTranspose(
XMMatrixScaling(sizeX, sizeY, 1.0f)
* XMMatrixTranslation(
x + lastPosX + sizeX + (float)ch.gm.gmptGlyphOrigin.x / (float)width
- alignX * str_width.at(line),
-(y + lastPosY + sizeY - (float)ch.gm.gmptGlyphOrigin.y * 2.0f / (float)height
- alignY * whole_height),
z)
));
m_pos.UpdateBufferValue(mat, Application::GetImmediateContext());
lastPosX += (float)ch.gm.gmCellIncX * 2.0f / (float)width;
} catch (...) {
continue;
}
pipeline.Draw(6);
}
pipeline.RestorePipeline();
}