当前位置: 首页>>代码示例>>C++>>正文


C++ CFont::GetData方法代码示例

本文整理汇总了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);
}
开发者ID:Kajune,项目名称:Javelin,代码行数:38,代码来源:Text.cpp

示例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();
}
开发者ID:Kajune,项目名称:Javelin,代码行数:68,代码来源:Text.cpp


注:本文中的CFont::GetData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。