Exemplo n.º 1
0
void RenderManagerGP2X::drawText(const std::string& text, Vector2 position, unsigned int flags)
{
	int FontSize = (flags & TF_SMALL_FONT ? FONT_WIDTH_SMALL : FONT_WIDTH_NORMAL);
	int length = 0;
	std::string string = text;
	int index = getNextFontIndex(string);
	while (index != -1)
	{
		if (flags & TF_OBFUSCATE)
			index = FONT_INDEX_ASTERISK;
		
		length += FontSize;
		SDL_Rect charPosition;
		charPosition.x = lround(position.x) + length - FontSize;
		charPosition.y = lround(position.y);
		
		if (flags & TF_SMALL_FONT)
			if (flags & TF_HIGHLIGHT)
				SDL_BlitSurface( mHighlightSmallFont[index], 0, mScreen, &charPosition );
			else
				SDL_BlitSurface( mSmallFont[index], 0, mScreen, &charPosition );
		else
			if (flags & TF_HIGHLIGHT)
				SDL_BlitSurface( mHighlightFont[index], 0, mScreen, &charPosition );
			else
				SDL_BlitSurface( mFont[index], 0, mScreen, &charPosition );
		
		index = getNextFontIndex(string);
	}
}
void RenderManagerGL2D::drawText(const std::string& text, Vector2 position, unsigned int flags)
{
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	glDisable(GL_BLEND);
	
	glColor4f(1.0, 1.0, 1.0, 1.0);
	int FontSize = (flags & TF_SMALL_FONT ? FONT_WIDTH_SMALL : FONT_WIDTH_NORMAL);
	std::string string = text;
	int index = getNextFontIndex(string);
	
	float x = position.x - (FontSize / 2);
	float y = position.y + (FontSize / 2);
	while (index != -1)
	{
		if (flags & TF_OBFUSCATE)
			index = FONT_INDEX_ASTERISK;
		
		x += FontSize;
		if (flags & TF_SMALL_FONT)
			if (flags & TF_HIGHLIGHT)
				drawQuad(x, y, mHighlightSmallFont[index]);
			else
				drawQuad(x, y, mSmallFont[index]);
		else
			if (flags & TF_HIGHLIGHT)
				drawQuad(x, y, mHighlightFont[index]);
			else
				drawQuad(x, y, mFont[index]);
		
		index = getNextFontIndex(string);
	}
}
Exemplo n.º 3
0
void RenderManagerGL2D::drawText(const std::string& text, Vector2 position, unsigned int flags)
{
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	glDisable(GL_BLEND);

	glColor4f(1.0, 1.0, 1.0, 1.0);
	int FontSize = (flags & TF_SMALL_FONT ? FONT_WIDTH_SMALL : FONT_WIDTH_NORMAL);

	float x = position.x - (FontSize / 2);
	float y = position.y + (FontSize / 2);

	for (auto iter = text.cbegin(); iter != text.cend(); )

	{
		int index = getNextFontIndex(iter);

		if (flags & TF_OBFUSCATE)
			index = FONT_INDEX_ASTERISK;

		x += FontSize;
		if (flags & TF_SMALL_FONT)
		{
			if (flags & TF_HIGHLIGHT)
			{
				int charWidth = mHighlightFont[index].w;
				int charHeight = mHighlightFont[index].h;
				mHighlightFont[index].w = FONT_WIDTH_SMALL;
				mHighlightFont[index].h = FONT_WIDTH_SMALL;
				drawQuad(x, y, mHighlightFont[index]);
				mHighlightFont[index].w = charWidth;
				mHighlightFont[index].h = charHeight;
			}
			else
			{
				int charWidth = mFont[index].w;
				int charHeight = mFont[index].h;
				mFont[index].w = FONT_WIDTH_SMALL;
				mFont[index].h = FONT_WIDTH_SMALL;
				drawQuad(x, y, mFont[index]);
				mFont[index].w = charWidth;
				mFont[index].h = charHeight;
			}
		}
		else
		{
			if (flags & TF_HIGHLIGHT)
				drawQuad(x, y, mHighlightFont[index]);
			else
				drawQuad(x, y, mFont[index]);
		}
	}
}
Exemplo n.º 4
0
void RenderManagerSDL::drawTextImpl(const std::string& text, Vector2 position, unsigned int flags)
{
    int FontSize = (flags & TF_SMALL_FONT ? FONT_WIDTH_SMALL : FONT_WIDTH_NORMAL);
    int length = 0;

    for (auto iter = text.cbegin(); iter != text.cend(); )
    {
        int index = getNextFontIndex(iter);

        if (flags & TF_OBFUSCATE)
            index = FONT_INDEX_ASTERISK;

        SDL_Rect charRect;
        charRect.x = lround(position.x) + length;
        charRect.y = lround(position.y);

        if (flags & TF_SMALL_FONT)
        {
            charRect.w = FONT_WIDTH_SMALL;
            charRect.h = FONT_WIDTH_SMALL;
            if (flags & TF_HIGHLIGHT)
            {
                SDL_RenderCopy(mRenderer, mHighlightFont[index], NULL, &charRect);
            }
            else
            {
                SDL_RenderCopy(mRenderer,mFont[index], NULL, &charRect);
            }
        }
        else
        {
            if (flags & TF_HIGHLIGHT)
            {
                SDL_QueryTexture(mHighlightFont[index], NULL, NULL, &charRect.w, &charRect.h);
                SDL_RenderCopy(mRenderer, mHighlightFont[index], NULL, &charRect);
            }
            else
            {
                SDL_QueryTexture(mHighlightFont[index], NULL, NULL, &charRect.w, &charRect.h);
                SDL_RenderCopy(mRenderer,mFont[index], NULL, &charRect);
            }
        }

        length += FontSize;
    }
}