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


C++ Font::Draw方法代码示例

本文整理汇总了C++中Font::Draw方法的典型用法代码示例。如果您正苦于以下问题:C++ Font::Draw方法的具体用法?C++ Font::Draw怎么用?C++ Font::Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Font的用法示例。


在下文中一共展示了Font::Draw方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Draw

void GameScreen::Draw()
{
    if (isFinishing)
    {
        return;
    }

    if (!caseIsReady)
    {
        string loadingString = "Loading";
        string loadStage = Case::GetInstance()->GetLoadStage();

        if (loadStage.length() > 0)
        {
            loadingString += " " + loadStage;
        }

        Font *pFont = CommonCaseResources::GetInstance()->GetFontManager()->GetFontFromId("MouseOverFont");
        int stringWidth = pFont->GetWidth(loadingString);

        for (int i = 0; i < numLoadingDots; i++)
        {
            loadingString += ".";
        }

        pFont->Draw(loadingString, (Vector2(gScreenWidth, gScreenHeight) * 0.5) - (Vector2(stringWidth, pFont->GetLineHeight()) * 0.5));

        return;
    }
    else if (Case::GetInstance()->IsLoading())
    {
        return;
    }
    else if (caseNeedsReset)
    {
        return;
    }

    Case::GetInstance()->Draw();
}
开发者ID:mbasaglia,项目名称:my-little-investigations,代码行数:40,代码来源:GameScreen.cpp

示例2: DrawText

void DrawHelpersBackend::DrawText(Font &cFont, const String &sText, const Color4 &cColor, const Vector2 &vPosition, uint32 nFlags, const Vector2 &vScale, const Vector2 &vBias)
{
	// Is there any text to draw?
	if (sText.GetLength()) {

		// [TODO] Rethink the font transform into clip space

		// [TODO] Check previous font size usage - this looks to big?!
		const uint32 nFontHeightInPixels = cFont.GetSize();
//		const uint32 nFontHeightInPixels = cFont.GetHeightInPixels();	// Should be this?!

		// Get the viewport (the real display size)
		const PLMath::Rectangle &cViewport = m_pRenderer->GetViewport();

		// Get the virtual screen size
		float fWidth  = 1.0f;
		float fHeight = 1.0f;
		float fClipSpaceFontWidth = 0.0f;
		float fClipSpaceFontHeight = 0.0f;
		if (Is2DMode()) {
			// [TODO] X/Y offset if virtual screen doesn't start at 0/0?
			fWidth  = m_fVirtualScreen[2] - m_fVirtualScreen[0];
			fHeight = m_fVirtualScreen[3] - m_fVirtualScreen[1];

			// [HACK] 'Font size in pixel' => 'normalized window size' => NOT working!
			if (fWidth == 1.0f)
				fClipSpaceFontWidth = static_cast<float>(nFontHeightInPixels)/1024.0f;
			else
				fClipSpaceFontWidth = static_cast<float>(nFontHeightInPixels)/fWidth;
			if (fHeight == 1.0f)
				fClipSpaceFontHeight = static_cast<float>(nFontHeightInPixels)/768.0f;
			else
				fClipSpaceFontHeight = static_cast<float>(nFontHeightInPixels)/fHeight;
			fClipSpaceFontWidth *= 1.75f;
			fClipSpaceFontHeight *= 1.75f;

		} else {
			// [TODO] X/Y offset if renderer viewport doesn't start at 0/0?
			// Just use the renderer viewport
			fWidth  = cViewport.GetWidth();
			fHeight = cViewport.GetHeight();
			fClipSpaceFontWidth  = static_cast<float>(nFontHeightInPixels)/fWidth;
			fClipSpaceFontHeight = static_cast<float>(nFontHeightInPixels)/fHeight;
			fClipSpaceFontWidth *= 1.75f;
			fClipSpaceFontHeight *= 1.75f;
		}

		// Position
		float fX = vPosition.x;
		float fY = vPosition.y;

		// From this space
			/* 2D draw helper space
					 (0, 0)
						|---
						|
						|	(Width, Height)
			*/
		// Into this space:
			/* Clip space
						| (1, 1)
						|
					 ---|---
						|
			   (-1, -1) |
			*/

		// Get normalized 2D draw helper space position
		fX /= fWidth;
		fY /= fHeight;

		// Normalized 2D draw helper space position into clip space
		fX =   fX*2.0f - 1.0f;
		fY = -(fY*2.0f - 1.0f);

		// Feed the transform matrix with the calculated clip space position
		Matrix4x4 mTransform;
		mTransform.SetTranslationMatrix(fX, fY - fClipSpaceFontHeight, 0.0f);

		// Calculate the bias
		Vector2 vFontBias = vBias;
		if (nFlags & Font::CenterText)
			vFontBias.x -= cFont.GetTextWidth(sText)/2;

		// Draw the text
		cFont.Draw(sText, cColor, mTransform, Vector2(fClipSpaceFontWidth/nFontHeightInPixels, fClipSpaceFontHeight/nFontHeightInPixels)*vScale, vFontBias);
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:88,代码来源:DrawHelpersBackend.cpp


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