Exemple #1
0
void TextLayout::_RenderRaw(float maxWidth) const
{
	TextureFontFace *font = Gui::Screen::GetFont();
	float py = 0;
	init_clip_test();

	glPushMatrix();

	const float spaceWidth = font->GetGlyph(' ').advx;

	std::list<word_t>::const_iterator wpos = this->words.begin();
	// build lines of text
	while (wpos != this->words.end()) {
		float len = 0;
		int num = 0;

		std::list<word_t>::const_iterator i = wpos;
		len += (*i).advx;
		num++;
		bool overflow = false;
		bool explicit_newline = false;
		if ((*i).word != 0) {
			++i;
			for (; i != this->words.end(); ++i) {
				if ((*i).word == 0) {
					// newline
					explicit_newline = true;
					num++;
					break;
				}
				if (len + spaceWidth + (*i).advx > maxWidth) { overflow = true; break; }
				len += (*i).advx + spaceWidth;
				num++;
			}
		}

		float _spaceWidth;
		if ((m_justify) && (num>1) && overflow) {
			float spaceleft = maxWidth - len;
			_spaceWidth = spaceWidth + (spaceleft/(float)(num-1));
		} else {
			_spaceWidth = spaceWidth;
		}

		if (line_clip_test(py, py+font->GetHeight()*2.0)) {
			float px = 0;
			for (int i=0; i<num; i++) {
				if ((*wpos).word) font->RenderMarkup((*wpos).word, floor(px), py);
				px += (*wpos).advx + _spaceWidth;
				wpos++;
			}
		} else {
			for (int i=0; i<num; i++) wpos++;
		}
		py += floor(font->GetHeight() * (explicit_newline ? PARAGRAPH_SPACING : 1.0f));

	}
	glPopMatrix();
}
Exemple #2
0
void TextLayout::_RenderRaw(float maxWidth, const Color &color) const
{
	float py = 0;
	init_clip_test();

	glPushMatrix();

	const float spaceWidth = m_font->GetGlyph(' ').advx;

	Color c = color;

	std::list<word_t>::const_iterator wpos = this->words.begin();
	// build lines of text
	while (wpos != this->words.end()) {
		float len = 0;
		int num = 0;

		std::list<word_t>::const_iterator i = wpos;
		len += (*i).advx;
		num++;
		bool overflow = false;
		bool explicit_newline = false;
		if ((*i).word != 0) {
			++i;
			for (; i != this->words.end(); ++i) {
				if ((*i).word == 0) {
					// newline
					explicit_newline = true;
					num++;
					break;
				}
				if (len + spaceWidth + (*i).advx > maxWidth) { overflow = true; break; }
				len += (*i).advx + spaceWidth;
				num++;
			}
		}

		float _spaceWidth;
		if ((m_justify) && (num>1) && overflow) {
			float spaceleft = maxWidth - len;
			_spaceWidth = spaceWidth + (spaceleft/float(num-1));
		} else {
			_spaceWidth = spaceWidth;
		}

		if (line_clip_test(py, py+m_font->GetHeight()*2.0)) {
			float px = 0;
			for (int j=0; j<num; j++) {
				if ((*wpos).word) {
					if (m_colourMarkup == ColourMarkupUse)
						c = m_font->RenderMarkup((*wpos).word, round(px), round(py), c);
					else
						m_font->RenderString((*wpos).word, round(px), round(py), c);
				}
				px += (*wpos).advx + _spaceWidth;
				wpos++;
			}
		} else {
			for (int j=0; j<num; j++) wpos++;
		}
		py += m_font->GetHeight() * (explicit_newline ? PARAGRAPH_SPACING : 1.0f);
	}
	glPopMatrix();
}