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();
}
Пример #2
0
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);
	}
}