Пример #1
0
D3DXVECTOR2 Font::MeasureString(std::string text, bool _cache)
{
	bool isCached;
	CachedText* t = getCachedText(text, TEXT_ALIGNMENT::ALIGN_Left, 100, isCached);
	auto size = t->GetSize();
	if (_cache)
	{
		if (!isCached)
			cache.push_back(t);
	}
	else
	{
		t->Dispose();
		delete t;
	}
	return size;
}
Пример #2
0
static void drawTextNormal(int x, int y, int size, int align, SDL_Color c, char *text)
{
	SDL_Surface *surface;
	SDL_Texture *t;
	int w, h;
	long hash;
	
	if (size >= MAX_FONTS)
	{
		printf("ERROR: %d exceeds max font size index of %d\n", size, MAX_FONTS);
		exit(1);
	}
	
	if (!font[size])
	{
		loadFont(size);
	}

	hash = hashcode(text, size);

	t = getCachedText(hash);

	if (!t)
	{
		surface = TTF_RenderText_Blended(font[size], text, c);
		t = SDL_CreateTextureFromSurface(app.renderer, surface);
		SDL_FreeSurface(surface);
		
		cacheText(hash, t);
	}

	SDL_QueryTexture(t, NULL, NULL, &w, &h);

	if (align == TA_CENTER)
	{
		x -= (w / 2);
	}
	else if (align == TA_RIGHT)
	{
		x -= w;
	}
	
	SDL_SetTextureColorMod(t, c.r, c.g, c.b);

	blit(t, x, y, 0);
}
Пример #3
0
void Font::Print(std::string text, TEXT_ALIGNMENT alignment, float width, bool _cache)
{
	bool isCached;
	texture->ApplyTexture();
	CachedText* t = getCachedText(text, alignment, width, isCached);
	t->Render();
	if (_cache)
	{
		if (!isCached)
			cache.push_back(t);
	}
	else
	{
		t->Dispose();
		delete t;
	}
}