void CUIDraw::InternalGetTextDim(IFFont *pFont,
													float *fWidth,
													float *fHeight,
													float fMaxWidth,
													float fSizeX,
													float fSizeY,
													const char *strText)
{
	if(NULL == pFont)
	{
		return;
	}

	const bool bWrapText = fMaxWidth > 0.0f;
	if (bWrapText)
		fMaxWidth = m_pRenderer->ScaleCoordX(fMaxWidth);

	//	fSizeX = m_pRenderer->ScaleCoordX(fSizeX);
	//	fSizeY = m_pRenderer->ScaleCoordY(fSizeY);

	// Note: First ScaleCoordY is not a mistake
	if (fSizeX<=0.0f) fSizeX=15.0f;
	if (fSizeY<=0.0f) fSizeY=15.0f;

	fSizeX = m_pRenderer->ScaleCoordY(fSizeX);
	fSizeY = m_pRenderer->ScaleCoordY(fSizeY);

	STextDrawContext ctx;
	ctx.SetSizeIn800x600(false);
	ctx.SetSize(Vec2(fSizeX, fSizeY));

	string wrappedStr;
	if (bWrapText)
	{
		pFont->WrapText(wrappedStr, fMaxWidth, strText, ctx);
		strText = wrappedStr.c_str();
	}

	Vec2 dim = pFont->GetTextSize(strText, true, ctx);

	float fScaleBack=1.0f/m_pRenderer->ScaleCoordY(1.0f);
	if (fWidth)
		*fWidth=dim.x*fScaleBack;
	if (fHeight)
		*fHeight=dim.y*fScaleBack;
}
Exemple #2
0
int CryWatchFunc(const char *message)
{
	// Fran: we need these guards for the testing framework to work
	if(gEnv && gEnv->pRenderer && g_pGameCVars && g_pGameCVars->watch_enabled)
	{
		float color[4] = {1,1,1,1};
		IFFont *pFont = gEnv->pCryFont->GetFont("default");
		float xscale = g_pGameCVars->watch_text_render_size*g_pGameCVars->watch_text_render_fxscale;
		STextDrawContext ctx;
		ctx.SetSize(Vec2(xscale, xscale));
		float width = pFont->GetTextSize(message, true, ctx).x;

		if(width>s_max_width_this_col)
			s_max_width_this_col = width;

		float yPos = GetWatchTextYPos(); // also updates s_watchTextXPos
		gEnv->pRenderer->Draw2dLabel(g_pGameCVars->watch_text_render_start_pos_x+s_watchTextXPos, yPos, g_pGameCVars->watch_text_render_size, color, false, "%s", message);
		return 1;
	}

	return 0;
}
void CUIDraw::InternalDrawText(IFFont *pFont,
																float fX,
																float fY,
																float fMaxWidth,
																float fSizeX,
																float fSizeY,
																const char *strText,
																float fAlpha,
																float fRed,
																float fGreen,
																float fBlue,
																EUIDRAWHORIZONTAL	eUIDrawHorizontalDocking,
																EUIDRAWVERTICAL		eUIDrawVerticalDocking,
																EUIDRAWHORIZONTAL	eUIDrawHorizontal,
																EUIDRAWVERTICAL		eUIDrawVertical
																)
{
	if(NULL == pFont)
	{
		return;
	}

	const bool bWrapText = fMaxWidth > 0.0f;
	if (bWrapText)
		fMaxWidth = m_pRenderer->ScaleCoordX(fMaxWidth);

	//	fSizeX = m_pRenderer->ScaleCoordX(fSizeX);
	//	fSizeY = m_pRenderer->ScaleCoordY(fSizeY);

	// Note: First ScaleCoordY is not a mistake
	if (fSizeX<=0.0f) fSizeX=15.0f;
	if (fSizeY<=0.0f) fSizeY=15.0f;

	fSizeX = m_pRenderer->ScaleCoordY(fSizeX);
	fSizeY = m_pRenderer->ScaleCoordY(fSizeY);

	STextDrawContext ctx;
	ctx.SetSizeIn800x600(false);
	ctx.SetSize(Vec2(fSizeX,fSizeY));
	ctx.SetColor(ColorF(fRed,fGreen,fBlue,fAlpha));

	// Note: First ScaleCoordY is not a mistake

	float fTextX = m_pRenderer->ScaleCoordY(fX);
	float fTextY = m_pRenderer->ScaleCoordY(fY);

	if(UIDRAWHORIZONTAL_CENTER == eUIDrawHorizontalDocking)
	{
		fTextX += m_pRenderer->GetWidth() * 0.5f;
	}
	else if(UIDRAWHORIZONTAL_RIGHT == eUIDrawHorizontalDocking)
	{
		fTextX += m_pRenderer->GetWidth();
	}

	if(UIDRAWVERTICAL_CENTER == eUIDrawVerticalDocking)
	{
		fTextY += m_pRenderer->GetHeight() * 0.5f;
	}
	else if(UIDRAWVERTICAL_BOTTOM == eUIDrawVerticalDocking)
	{
		fTextY += m_pRenderer->GetHeight();
	}

	string wrappedStr;
	if (bWrapText)
	{
		pFont->WrapText(wrappedStr, fMaxWidth, strText, ctx);
		strText = wrappedStr.c_str();
	}

	Vec2 vDim = pFont->GetTextSize(strText, true, ctx);
	int flags = 0;

	if(UIDRAWHORIZONTAL_CENTER == eUIDrawHorizontal)
	{
		fTextX -= vDim.x * 0.5f;
		flags |= eDrawText_Center;
	}
	else if(UIDRAWHORIZONTAL_RIGHT == eUIDrawHorizontal)
	{
		fTextX -= vDim.x;
		flags |= eDrawText_Right;
	}

	if(UIDRAWVERTICAL_CENTER == eUIDrawVertical)
	{
		fTextY -= vDim.y * 0.5f;
		flags |= eDrawText_CenterV;
	}
	else if(UIDRAWVERTICAL_BOTTOM == eUIDrawVertical)
	{
		fTextY -= vDim.y;
		flags |= eDrawText_Bottom;
	}

	ctx.SetFlags(flags);

	pFont->DrawString(fTextX, fTextY, strText, true, ctx);
}
Exemple #4
0
void CPersistantDebug::UpdateTags(float frameTime, SObj& obj, bool doFirstPass)
{
    if (!doFirstPass)
    {
        // Every update calls itself recursively first to calculate the widths of each column
        // for multicolumn mode. Not the prettiest thing, but it's the best idea I've got so far!
        UpdateTags(frameTime, obj, true);
        frameTime = 0.f;

        for (int i=0; i<obj.columns.size(); ++i)
            obj.columns[i].height = 0.f;
    }

    IFFont *pFont = gEnv->pCryFont->GetFont("default");
    assert(pFont);
    STextDrawContext ctx;
    ctx.SetSizeIn800x600(false);
    ctx.SetProportional(true);

    for (TListTag::iterator iterList = obj.tags.begin(); iterList != obj.tags.end(); ++iterList)
    {
        if (iterList->vScreenPos.IsZero())
            continue;

        float tagMaxDist = iterList->params.viewDistance;
        float fontSize = iterList->params.size * m_pETFontSizeMultiplier->GetFVal();

        // Calculate size of text on screen (so we can place it properly)
        ctx.SetSize(Vec2(12*fontSize, 12*fontSize));
        Vec2 textBoxSize = pFont->GetTextSize(iterList->params.text.c_str(), true, ctx);

        if (doFirstPass)
        {
            int pos(iterList->params.column - 1);
            obj.columns[pos].width = max(obj.columns[pos].width, textBoxSize.x + 15.f);
        }
        else
        {
            // Determine position
            SColumn &column = obj.columns[iterList->params.column - 1];
            Vec3 screenPos(iterList->vScreenPos);
            screenPos.x = screenPos.x*0.01f*gEnv->pRenderer->GetWidth();
            screenPos.y = screenPos.y*0.01f*gEnv->pRenderer->GetHeight() - textBoxSize.y - column.height;
            column.height += textBoxSize.y;

            // Adjust X value for multi-columns
            if (obj.columns.size() > 1)
            {
                int centerLine = obj.columns.size() / 2;
                if (iterList->params.column <= centerLine)
                    for (int i=iterList->params.column-1; i<centerLine; ++i)
                        screenPos.x -= obj.columns[i].width;
                else
                    for (int i=centerLine; i<iterList->params.column-1; ++i)
                        screenPos.x += obj.columns[i].width;

                if (obj.columns.size() % 2 != 0)
                    screenPos.x -= textBoxSize.x*0.5f;
            }
            else
            {
                screenPos.x -= textBoxSize.x*0.5f;
            }

            // Determine color
            ColorF clr = iterList->params.color;
            if (1==m_pETColorOverrideEnable->GetIVal())
            {
                clr.r = max(0.f, min(1.f, m_pETColorOverrideR->GetFVal()));
                clr.g = max(0.f, min(1.f, m_pETColorOverrideG->GetFVal()));
                clr.b = max(0.f, min(1.f, m_pETColorOverrideB->GetFVal()));
            }
            clr.a *= iterList->params.fadeTime / iterList->totalFadeTime; // Apply fade out time to alpha

            float clrAry[4] = {clr.r, clr.g, clr.b, clr.a};
            gEnv->pRenderer->Draw2dLabel( screenPos.x, screenPos.y, fontSize, clrAry, true, "%s", iterList->params.text.c_str() );
        }
    }
}