コード例 #1
0
ファイル: Label.cpp プロジェクト: genail/gear
void LabelImpl::draw(CL_GraphicContext &p_gc)
{
	G_ASSERT(m_parent->isLoaded());

	float ax, ay;
	const CL_Size s = m_parent->size(p_gc);

	calculateAttachPoint(s.width, s.height, ax, ay);

	CL_Pointf position;
	position.x = m_pos.x - ax;
	position.y = m_pos.y - ay - m_fontMetrics.get_descent();

	if (m_shadowVisible) {
		drawShadow(p_gc, position);
	}

	m_clFont->draw_text(p_gc, position.x, position.y, m_text, m_color);

#if !defined(NDEBUG) && defined(DRAW_LABEL_BOUNDS)
	// draw label frame debug code
	CL_Pen newPen;
	newPen.set_line_width(1.0f);

	const CL_Pen oldPen = p_gc.get_pen();
	p_gc.set_pen(newPen);

	const float y2 = y + m_fontMetrics.get_descent();
	CL_Draw::box(p_gc, x, y2 - s.height, x + s.width, y2, CL_Colorf::red);

	p_gc.set_pen(oldPen);
#endif // !NDEBUG && DRAW_LABEL_BOUNDS
}
コード例 #2
0
ファイル: font.cpp プロジェクト: PaulFSherwood/cplusplus
CL_Size CL_Font::get_text_size(CL_GraphicContext &gc, const CL_StringRef &text)
{
	CL_Size total_size;

	if (!impl.is_null())
	{
		CL_FontMetrics fm = get_font_metrics(gc);
		int line_spacing = fm.get_external_leading();
		std::vector<CL_String> lines = CL_StringHelp::split_text(text, "\n", false);
		for (std::vector<CL_String>::size_type i=0; i<lines.size(); i++)
		{
			CL_Size line_size = get_provider()->get_text_size(gc, lines[i]);

			if ((line_size.width == 0) && (line_size.height == 0) && (lines.size() > 1)) // blank line
				line_size.height = fm.get_descent() + fm.get_ascent(); 

			if ((i+1) != lines.size())	// Do not add the line spacing on the last line
				line_size.height += line_spacing;

			if (total_size.width < line_size.width)	// Find the widest line
				total_size.width = line_size.width;

			total_size.height += line_size.height;
		}
	}
	
	return total_size;
}
コード例 #3
0
CL_GUIThemePart::VerticalTextPosition CL_GUIThemePart::get_vertical_text_align(CL_GraphicContext &gc, CL_Font &font, const CL_Rect &content_rect)
{
	// See diagram in: Documentation\Overview\fonts.html (Font Metrics)

	CL_FontMetrics metrics = font.get_font_metrics();
	float align_height = metrics.get_ascent() - metrics.get_internal_leading();
	float content_height = content_rect.get_height();
	float baseline = (content_height + align_height) / 2.0f;

	VerticalTextPosition result;
	result.baseline = baseline + content_rect.top;
	result.top = result.baseline - metrics.get_ascent();
	result.bottom = result.baseline + metrics.get_descent();
	return result;
}