コード例 #1
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;
}
コード例 #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
int CL_GlyphCache::get_character_index(CL_FontEngine *font_engine, CL_GraphicContext &gc, const CL_String &text, const CL_Point &point)
{
	int dest_x = 0;
	int dest_y = 0;

	int character_counter = 0;

	CL_FontMetrics fm = get_font_metrics();
	int font_height = fm.get_height();
	int font_ascent = fm.get_ascent();
	int font_external_leading = 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++)
	{
		int xpos = dest_x;
		int ypos = dest_y;

		CL_String &textline = lines[i];
		CL_String::size_type string_length = textline.length();

		// Scan the string

		CL_UTF8_Reader reader(textline);
		while(!reader.is_end())
		{
			unsigned int glyph = reader.get_char();
			CL_String::size_type glyph_pos = reader.get_position();
			reader.next();

			CL_Font_TextureGlyph *gptr = get_glyph(font_engine, gc, glyph);
			if (gptr == NULL) continue;

			CL_Rect position(xpos, ypos - font_ascent, CL_Size(gptr->increment.x, gptr->increment.y + font_height + font_external_leading));
			if (position.contains(point))
			{
				return glyph_pos + character_counter;
			}
		
			xpos += gptr->increment.x;
			ypos += gptr->increment.y;
		}

		dest_y += font_height + font_external_leading;

		character_counter += string_length + 1;		// (Including the '\n')

	}
	return -1;	// Not found
}
コード例 #4
0
ファイル: info.cpp プロジェクト: PaulFSherwood/cplusplus
void Info::draw(CL_GraphicContext &gc)
{
	CL_String text_to_draw = name;

	CL_Rect draw_rect = get_geometry();

	int draw_xpos = 0;
	int draw_ypos = 0;

	//CL_Draw::fill(gc, CL_Rect(draw_xpos, draw_ypos, CL_Size(get_width(), get_height())), CL_Colorf(CL_Colorf::red));

	CL_Font font = gui->get_font();

	CL_FontMetrics metrics = font.get_font_metrics(gc);
	draw_ypos += (int) metrics.get_ascent();

	CL_Colorf color;

	int time_diff = CL_System::get_time() - activated_time;
	float color_value = 1.0f - ( ( (float) time_diff ) / 1000.0f);
	if ( (color_value <= 1.0f) && (color_value > 0.0f) )
	{
		color = CL_Colorf(color_value, color_value/2.0f, color_value/2.0f, color_value);
		font.draw_text(gc, draw_xpos, draw_ypos, "#", color);
		color = CL_Colorf(color_value, color_value/2.0f, color_value/2.0f, 1.0f);
		text_to_draw = name + comment;

		set_constant_repaint(true);
	}
	else
	{
		color = CL_Colorf(0, 0, 0, 1.0f);
		set_constant_repaint(false);
	}

	//font.draw_text(gc, draw_xpos + 16, draw_ypos, text_to_draw, CL_Colorf::white);
	font.draw_text(gc, draw_xpos + 16-1, draw_ypos-1, text_to_draw, color);
}