Example #1
0
void LabelImpl::drawShadow(CL_GraphicContext &p_gc, const CL_Pointf &p_pos)
{
	CL_Pointf position;
	position.x = p_pos.x + m_shadowOffset.x;
	position.y = p_pos.y + m_shadowOffset.y;
	m_clFont->draw_text(p_gc, position.x, position.y, m_text, m_shadowColor);
}
Example #2
0
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
}
Example #3
0
void CL_StatusBar_Impl::on_render(CL_GraphicContext &gc, const CL_Rect &update_rect)
{
	CL_Rect rect(CL_Point(0,0), statusbar->get_geometry().get_size());
	part_component.render_box(gc, rect, update_rect);
	CL_Rect content = part_component.get_content_box(rect);

	CL_Rect rect_status_text = content;

	if (show_size_grip)
	{
		int preferred_width = part_size_grip.get_preferred_width();
		CL_Rect rect_sizegrip(content.right - preferred_width, content.top, content.right, content.bottom);
		part_size_grip.render_box(gc, rect_sizegrip, update_rect);
		rect_status_text.right = rect_sizegrip.left;
	}

	if (!statusbar_parts.empty())
		rect_status_text.right = statusbar_parts[0].position.left;

	part_status_text.render_box(gc, rect_status_text, update_rect);
	CL_Rect status_text_content = part_status_text.get_content_box(rect_status_text);

	font.draw_text(gc, status_text_content.left + 4, content.bottom - 6, status_text, text_color);

	for (unsigned int index = 0; index < statusbar_parts.size(); index++)
	{
		CL_StatusBar_Part &statusbar_part = statusbar_parts[index];
		part_status_part.render_box(gc, statusbar_part.position, update_rect);
		CL_Rect part_content = part_status_part.get_content_box(statusbar_part.position);
		int icon_width = 0;
		if (!statusbar_part.icon.is_null())
		{
			statusbar_part.icon.draw(gc, (float)part_content.left + 4, (float)part_content.bottom - 6 - statusbar_part.icon.get_height());
			icon_width = statusbar_part.icon.get_width() + 4;
		}
		if (!statusbar_part.text.empty())
		{
			font.draw_text(gc, part_content.left + 4 + icon_width, part_content.bottom - 6, statusbar_part.text, text_color);
		}
	}
}
Example #4
0
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);
}
Example #5
0
void ExampleText::update_text(CL_GraphicContext &gc, CL_FrameBuffer &fb_text, CL_Font &font, std::vector<CL_SpanLayout> &layout)
{
	gc.set_frame_buffer(fb_text);

	CL_Draw::fill(gc, 0.0f, 0.0f, (float)text_window_size, (float)text_window_size, CL_Colorf(0.0f, 0.0f, 0.0f, 1.0f));

	CL_String text(cl_format("Frames per second = %1", last_fps));
	font.draw_text(gc, 20, 20, text, CL_Colorf::white);

	for (unsigned int line_count = 0; line_count < layout.size(); line_count++)
	{
		layout[line_count].draw_layout(gc);
	}

	gc.reset_frame_buffer();
}
Example #6
0
//Zeichnen eines Menüeintrages, z.B.: Lebensanzeige (nicht für Baufelder)
void Menu::drawMenuItem(std::string outputString, int itemLength, CL_Texture texture, CL_Font font,
		int textOffsetY, int xPosition)
{
	CL_Rectf textureRectangle;
	CL_Quadf textureQuad;

	//Definieren eines Rechtecks für Position und Größe der Textur des Menüeintrages
	textureRectangle = CL_Rectf(
		(float)xPosition,
		viewPort.get_height() - menuHeight + ((menuHeight - itemLength) / 2.0f),
		CL_Sizex<float>((float)itemLength, (float)itemLength));
	textureQuad = CL_Quadf(textureRectangle);
	CL_Draw::texture(world->get_gc(), texture, textureRectangle);
	
	//Text zum Menüeintrag schreiben
	font.draw_text(world->get_gc(), textureRectangle.right + 5.0f,
		(float)(viewPort.get_height() - menuHeight + textOffsetY),
		outputString, CL_Colorf::white);
}
Example #7
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	quit = false;

	try
	{

		CL_OpenGLWindowDescription desc;

		desc.set_title("ClanLib AnimCursor Test");
		desc.set_size(CL_Size(800, 600), true);
		CL_DisplayWindow window(desc);

		// Connect the Window close event
		CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);

		// Connect a keyboard handler to on_key_up()
		CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

		// Get the graphic context
		CL_GraphicContext gc = window.get_gc();

		CL_Font font = CL_Font(gc, "Tahoma", 20);

		CL_PixelBuffer pacman("pacman.png");

		CL_SpriteDescription description;
		CL_Size size(22, 22);

		for (int frame_cnt=0; frame_cnt < 6; frame_cnt++)
		{
			CL_PixelBuffer frame(size.width, size.height, cl_rgba8);
			pacman.convert(frame, size, CL_Rect((frame_cnt * 28) + 4, 4, size));
			description.add_frame(frame);
			description.set_frame_delay(frame_cnt, 0.1);
		}

		CL_Point hotspot(0,0);
		CL_Cursor cursor(window, description, hotspot);
		window.set_cursor(cursor);

		// Run until someone presses escape
		while (!quit)
		{
			gc.clear(CL_Colorf(0.0f,0.0f,0.5f));

			font.draw_text(gc, 32, 32, "Observe the animated cursor");

			// Flip the display, showing on the screen what we have drawed
			// since last call to flip()
			window.flip(1);

			// This call processes user input and other events
			CL_KeepAlive::process();
		}
	}
	catch(CL_Exception& exception)
	{
		// Create a console window for text-output if not available
		CL_ConsoleWindow console("Console", 80, 200);

		CL_Console::write_line("Exception caught:");
		CL_Console::write_line(exception.message);

		// Display the stack trace (if available)
		std::vector<CL_String> stacktrace = exception.get_stack_trace();
		int size = stacktrace.size();
		if (size > 0)
		{
			CL_Console::write_line("Stack Trace:");
			for (int cnt=0; cnt < size; cnt++)
			{
				CL_Console::write_line(stacktrace[cnt]);
			}
		}

		console.display_close_message();

		return -1;
	}
	return 0;
}
Example #8
0
//Zeichnet das Menü
void Menu::draw()
{
	CL_Font fontSmall;
	CL_Font fontBig;
	CL_Rect rectangle;
	std::stringstream sstream;
	std::string outputString;
	CL_Quadf textureQuad;
	CL_Rectf textureRectangle;
	CL_GraphicContext graphicContext;
	int space = 30;
	CL_Size textSize;
	int xPosition;

	//Ist die Menübreite gesetzt, wird der Anfang in x-Richtung
	//berechnet, damit das Menü zentriert ist
	if(menuWidth == -1)
		xPosition = 0;
	else
		xPosition = (viewPort.get_width() - menuWidth) / 2;

	graphicContext = world->get_gc();

	//Schriften setzen
	fontSmall = CL_Font(graphicContext, "Comic Sans MS", 10);
	fontBig = CL_Font(graphicContext, "Comic Sans MS", 20);

	//Die unterschiedlichen Turmtypen durchgehen
	for(unsigned int i = 0; i < towerTypes.size(); i++)
	{
		//Ein Rechteck für den Rahmen eines Baufeldes definieren
		rectangle = CL_Rect(
			i*menuHeight + xPosition,
			viewPort.get_height() - menuHeight,
			(i+1)*menuHeight + xPosition,
			viewPort.get_height()-1);
		//Den Rahmen des Baufeldes zeichnen
		CL_Draw::box(graphicContext, rectangle, CL_Colorf::white);
		
		//Ein Rechteck für die Anzeige der Turmtextur innerhalb des Baufeldes definieren
		textureRectangle = CL_Rectf(
			i * menuHeight + ((menuHeight - menuTowerLength) / 2.0f) + xPosition,
			viewPort.get_height() - menuHeight + 5.0f,
			CL_Sizex<float>((float)menuTowerLength, (float)menuTowerLength));
		textureQuad = CL_Quadf(textureRectangle);
		//Turmtextur zeichnen
		CL_Draw::texture(graphicContext, towerTypes[i]->texture, textureRectangle);
		
		//Nummer (=Shortcut auf Tastatur) des Baufeldes in der linken oberen Ecke zeichnen
		sstream << (i+1);
		sstream >> outputString;
		sstream.clear();
		fontSmall.draw_text(graphicContext, rectangle.left + 5, rectangle.top + 10,
			outputString,CL_Colorf::white);

		//Kosten des Turmes unterhalb der Textur und zentriert im Baufeld ausgeben
		sstream << towerTypes[i]->price;
		sstream >> outputString;
		sstream.clear();
		textSize = fontSmall.get_text_size(graphicContext, outputString);
		fontSmall.draw_text(graphicContext, ((menuHeight - textSize.width) / 2) + i * menuHeight + xPosition,
			viewPort.get_height() - textSize.height/2, outputString, CL_Colorf::white);
	}
	
	//x-Position weitersetzen für nächsten Menüeintrag
	xPosition += towerTypes.size()*menuHeight + space;

	//Geldanzeige
	sstream << world->getMoney();
	sstream >> outputString;
	sstream.clear();
	textSize = fontBig.get_text_size(world->get_gc(), outputString);

	Menu::drawMenuItem(outputString, menuCoinsLength, coinsTexture, fontBig, menuHeight/2, xPosition);

	xPosition += menuCoinsLength + textSize.width + space;

	//Zeitanzeige
	sstream << world->getCountdown();
	sstream >> outputString;
	sstream.clear();
	outputString = "Next Wave:\n" + outputString;
	textSize = fontBig.get_text_size(graphicContext, outputString);

	Menu::drawMenuItem(outputString, menuTimeLength, clockTexture, fontBig, menuHeight/2 - 10, xPosition);

	xPosition += menuTimeLength + textSize.width + space;

	//Lebensanzeige
	sstream << world->getLifes();
	sstream >> outputString;
	sstream.clear();
	
	Menu::drawMenuItem(outputString, menuLifeLength, heartTexture, fontBig, menuHeight/2, xPosition);

	//Beim ersten Aufruf wird die Menübreite errechnet
	if(menuWidth == -1)
	{
		textSize = fontBig.get_text_size(graphicContext, outputString);
		menuWidth = xPosition + menuLifeLength + textSize.width;
	}
}
void FramerateCounter::show_fps(CL_GraphicContext &gc, CL_Font &fps_font)
{
	CL_String fps = cl_format("%1 fps", get_framerate());
	fps_font.draw_text(gc, gc.get_width() - 100, 30, fps);
}
Example #10
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	// Setup the window
	CL_DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("3D GUI Example");
	win_desc.set_size(CL_Size( 700, 700 ), false);
	window = CL_DisplayWindow(win_desc);

	// Connect the slots that we require
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);
	CL_Slot slot_input_down = (window.get_ic().get_keyboard()).sig_key_down().connect(this, &App::on_input_down);

	CL_GraphicContext gc = window.get_gc();

	CL_Font font = CL_Font(gc, "tahoma", 16);

	// Initialise the GUI system
	GUI gui(this);

	// NOTE: The GUI component positions are still in 2D world, therefore
	// be careful not to overlap windows, else unpredicted results may occur!

	window1 = new Window1(gui, CL_Rect(0,0, CL_Size(256, 256)));

	slider_1_xrotation = new Slider(gui, CL_Rect(0, 512, CL_Size(200, 17)));
	slider_1_xrotation->object_matrix.translate_self(0.0f, 0.8f, 3.0f);
	slider_1_xrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));

	slider_1_yrotation = new Slider(gui, CL_Rect(256*1, 512, CL_Size(200, 17)));
	slider_1_yrotation->object_matrix.translate_self(0.0f, 0.7f, 3.0f);
	slider_1_yrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));

	slider_1_zrotation = new Slider(gui, CL_Rect(256*2, 512, CL_Size(200, 17)));
	slider_1_zrotation->object_matrix.translate_self(0.0f, 0.6f, 3.0f);
	slider_1_zrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));

	slider_1_xtranslation = new Slider(gui, CL_Rect(256*3, 512, CL_Size(200, 17)));
	slider_1_xtranslation->object_matrix.translate_self(0.0f, 0.5f, 3.0f);
	slider_1_xtranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));
	slider_1_xtranslation->component->set_position(500);

	slider_1_ytranslation = new Slider(gui, CL_Rect(256*4, 512, CL_Size(200, 17)));
	slider_1_ytranslation->object_matrix.translate_self(0.0f, 0.4f, 3.0f);
	slider_1_ytranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));
	slider_1_ytranslation->component->set_position(500);

	slider_1_ztranslation = new Slider(gui, CL_Rect(256*5, 512, CL_Size(200, 17)));
	slider_1_ztranslation->object_matrix.translate_self(0.0f, 0.3f, 3.0f);
	slider_1_ztranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f));
	slider_1_ztranslation->component->set_position(500);

	while(!quit)
	{
		calculate_matrix();

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left));

		// Draw the gradient
		CL_Draw::gradient_fill(gc, CL_Rect(0, 0, gc.get_width(), gc.get_height()/2), CL_Gradient(CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f), CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f)));
		CL_Draw::gradient_fill(gc, CL_Rect(0, gc.get_height()/2, gc.get_width(), gc.get_height()), CL_Gradient(CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f), CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f)));

		font.draw_text(gc, 8, 20, "GUI3D");

		int xoffset = 160;
		int yoffset = 70;
		const int ygap = 35;
		font.draw_text(gc, xoffset, yoffset, "X Rotation");
		yoffset += ygap;
		font.draw_text(gc, xoffset, yoffset, "Y Rotation");
		yoffset += ygap;
		font.draw_text(gc, xoffset, yoffset, "Z Rotation");
		yoffset += ygap;
		font.draw_text(gc, xoffset, yoffset, "X Translation");
		yoffset += ygap;
		font.draw_text(gc, xoffset, yoffset, "Y Translation");
		yoffset += ygap;
		font.draw_text(gc, xoffset, yoffset, "Z Translation");
		yoffset += ygap;

		if (!gui.run())
			break;

		gc.set_map_mode(cl_user_projection);
		gc.set_projection(projection_matrix);
		gc.set_modelview(modelview_matrix);

		control_window();

		gui.draw();

		window.flip(1);

		CL_KeepAlive::process();
	}

	return 0;
}