int GUIText::Render(void)
{
	if (!isConditionTrue())
		return 0;

	void* fontResource = NULL;
	string displayValue;

	if (mFont)
		fontResource = mFont->GetResource();

	mLastValue = parseText();
	displayValue = mLastValue;

	if (charSkip)
		displayValue.erase(0, charSkip);

	mVarChanged = 0;

	int x = mRenderX, y = mRenderY;
	int width = gr_measureEx(displayValue.c_str(), fontResource);

	if (mPlacement != TOP_LEFT && mPlacement != BOTTOM_LEFT)
	{
		if (mPlacement == CENTER || mPlacement == CENTER_X_ONLY)
			x -= (width / 2);
		else
			x -= width;
	}
	if (mPlacement != TOP_LEFT && mPlacement != TOP_RIGHT)
	{
		if (mPlacement == CENTER)
			y -= (mFontHeight / 2);
		else if (mPlacement == BOTTOM_LEFT || mPlacement == BOTTOM_RIGHT)
			y -= mFontHeight;
	}

	if (hasHighlightColor && isHighlighted)
		gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, mHighlightColor.alpha);
	else
		gr_color(mColor.red, mColor.green, mColor.blue, mColor.alpha);

	if (maxWidth)
		gr_textExW(x, y, displayValue.c_str(), fontResource, maxWidth + x);
	else
		gr_textEx(x, y, displayValue.c_str(), fontResource);
	return 0;
}
Exemplo n.º 2
0
int GUIConsole::RenderConsole(void)
{
    void* fontResource = NULL;
    if (mFont)  fontResource = mFont->GetResource();

    // We fill the background
    gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255);
    gr_fill(mConsoleX, mConsoleY, mConsoleW, mConsoleH);

    gr_color(mScrollColor.red, mScrollColor.green, mScrollColor.blue, mScrollColor.alpha);
    gr_fill(mConsoleX + (mConsoleW * 9 / 10), mConsoleY, (mConsoleW / 10), mConsoleH);

    // Render the lines
    gr_color(mForegroundColor.red, mForegroundColor.green, mForegroundColor.blue, mForegroundColor.alpha);

    // Don't try to continue to render without data
    mLastCount = gConsole.size();
    if (mLastCount == 0)        return (mSlideout ? RenderSlideout() : 0);

    // Find the start point
    int start;
    int curLine = mCurrentLine;    // Thread-safing (Another thread updates this value)
    if (curLine == -1)
    {
        start = mLastCount - mMaxRows;
    }
    else
    {
        if (curLine > (int) mLastCount)   curLine = (int) mLastCount;
        if ((int) mMaxRows > curLine)     curLine = (int) mMaxRows;
        start = curLine - mMaxRows;
    }

    unsigned int line;
    for (line = 0; line < mMaxRows; line++)
    {
        if ((start + (int) line) >= 0 && (start + (int) line) < (int) mLastCount)
        {
            gr_textExW(mConsoleX, mStartY + (line * mFontHeight), gConsole[start + line].c_str(), fontResource, mConsoleW + mConsoleX);
        }
    }
    return (mSlideout ? RenderSlideout() : 0);
}