Exemple #1
0
bool App::update()
{
	game_time.update();
	
	canvas_center.clear(clan::Colorf(0.0f,0.0f,0.0f, 1.0f));
	rock.draw(canvas_center, 0.0f, 0.0f);

	// Move tux
	for (int cnt=0; cnt<num_tuxballs; cnt++)
	{
		tuxballs[cnt].move(tuxballs, game_time.get_time_elapsed() * 1000.0f);
	}

	// Draw tux
	for (int cnt=0; cnt<num_tuxballs; cnt++)
	{
		tuxballs[cnt].draw(canvas_center);
	}

	std::string fps = clan::string_format("%1 fps", clan::StringHelp::float_to_text(game_time.get_updates_per_second(), 1));
	font.draw_text(canvas_center, 150-2, 150-2, fps, clan::Colorf(0.0f, 0.0f, 0.0f, 1.0f));
	font.draw_text(canvas_center, 150, 150, fps, clan::Colorf(1.0f, 1.0f, 1.0f, 1.0f));

	window_center.flip(0);

	return !quit;
}
Exemple #2
0
void Alpha::draw_section(clan::Canvas &canvas, clan::Font &font, int yoffset, const clan::Colorf &background, const clan::Colorf &vertex_colour, const clan::Colorf &image_colour)
{
	// Draw the background without blending to set the specified RGBA

	canvas.set_blend_state(blend_disabled);

	const int outer_area_size = 32;
	const int outer_xoffset = 8;
	canvas.fill_rect( outer_xoffset, yoffset, outer_xoffset + outer_area_size, yoffset + outer_area_size, background);

	canvas.set_blend_state(blend_enabled);

	// Create the image
	clan::Image image = create_block(canvas, image_colour);

	// Draw the image
	image.set_color(vertex_colour);
	image.draw(canvas, outer_xoffset + (outer_area_size - image.get_width())/2, yoffset + (outer_area_size - image.get_height())/2);

	// Get the composited pixel buffer
	clan::Rect rect(outer_xoffset + outer_area_size / 2, (yoffset + outer_area_size / 2), clan::Size(64,64));
	clan::PixelBuffer pbuff = canvas.get_pixeldata(rect, clan::tf_rgba8);
	pbuff.lock(canvas, clan::access_read_only);

	clan::ImageProviderFactory::save(pbuff, "test.png");

 	clan::Colorf output = pbuff.get_pixel(0,0);
	pbuff.unlock();
 
	// Create the information string
	std::string info(clan::string_format("Initial Destination Colour: RGBA = %1, %2, %3, %4", background.r , background.g, background.b, background.a));
	int xpos = outer_xoffset + outer_area_size + 8;
	int ypos = yoffset - 4;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Vertex Colour: RGBA = %1, %2, %3, %4", vertex_colour.r , vertex_colour.g, vertex_colour.b, vertex_colour.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Image Colour: RGBA = %1, %2, %3, %4", image_colour.r , image_colour.g, image_colour.b, image_colour.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Destination Colour: RGBA = %1, %2, %3, %4", output.r , output.g, output.b, output.a));
	ypos += 16;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

}
Exemple #3
0
void TextFade::draw_text(clan::Canvas &canvas, clan::Font &font, int ypos, const char *text)
{
	// For this example, to keep things simple, we only handle ASCII characters

	int gc_width = canvas.get_width();

	clan::Size text_size = clan::Size(font.measure_text(canvas, text).bbox_size);

	int xpos = (gc_width - text_size.width) / 2;

	while(*text)
	{
		char let = *(text++);
		char buffer[2];
		buffer[0] = let;
		buffer[1] = 0;

		int position_off_centre = (gc_width/2) - xpos;
		if (position_off_centre < 0)
			position_off_centre = -position_off_centre;

		float alpha = 1.0f - ( (float) position_off_centre * 2.0f / gc_width );
		if (alpha > 0.0f)
			font.draw_text(canvas, xpos, ypos,  buffer, clan::Colorf(0.4f, 0.4f, 1.0f, alpha));
		xpos += font.get_metrics(canvas, let).bbox_size.width;
	}

}
Exemple #4
0
bool App::update()
{
	game_time.update();

	canvas.clear(clan::Colorf(0.0f,0.0f,0.0f, 0.0f));
	rock.set_color(clan::Colorf(1.0f, 1.0f, 1.0f, 0.8f));
	rock.draw(canvas, 0.0f, 0.0f);

	// Rotate tux
	rotation += game_time.get_time_elapsed() * 100.0f;
	clan::Angle angle;
	angle.set_degrees(rotation);
	tux.set_angle(angle);

	// Caculate tux position
	clan::Pointf circle_center(  (float) (canvas.get_width()/2), (float) (canvas.get_height()/2) );
	const float radius = 210.0f;
	int tux_circle = 12;
	tux_position.x = -(radius - tux_radius - tux_circle)  * cos( angle.to_radians() / 2.0f );
	tux_position.y = (radius - tux_radius - tux_circle) * sin( angle.to_radians()/ 2.0f );
	tux_position += circle_center;
	tux_position.x -= tux.get_width()/2;
	tux_position.y -= tux.get_height()/2;

	// Give tux circle blue outer outline, because it looks nice
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Make see through border
	canvas.set_blend_state(blend_state_off);
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+tux_circle-2, clan::Colorf(0.0f, 0.0f, 0.0f, 0.0f));
	canvas.reset_blend_state();

	// Give tux circle blue outline, to mask the alpha channel
	canvas.fill_circle(tux_position.x + tux_radius, tux_position.y + tux_radius, tux_radius+2, clan::Colorf(0.0f, 0.0f, 1.0f, 1.0f));

	// Draw tux
	tux.draw(canvas, tux_position.x, tux_position.y);

	// Draw text
	font_large.draw_text(canvas, 10-2, 50-2, "ClanLib Layered Window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_large.draw_text(canvas, 10, 50, "ClanLib Layered Window", clan::Colorf::green);
	font_small.draw_text(canvas, 60-2, 80-2, "Click mouse on the penguin to exit", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 60, 80, "Click mouse on the penguin to exit", clan::Colorf::green);
	font_small.draw_text(canvas, 110-2, 110-2, "Drag rock to move window", clan::Colorf(0.1f, 0.1f, 0.1f, 1.0f));
	font_small.draw_text(canvas, 110, 110, "Drag rock to move window", clan::Colorf::green);

	window.flip(1);

	return !quit;
}
Exemple #5
0
void Alpha::draw_section(clan::Canvas &canvas, clan::Font &font, int yoffset, const clan::Colorf &background, const clan::Colorf &vertex_colour, const clan::Colorf &image_colour)
{
	// Draw the background without blending to set the specified RGBA

	canvas.set_blend_state(blend_disabled);

	const int outer_area_size = 32;
	const int outer_xoffset = 8;
	canvas.fill_rect( outer_xoffset, yoffset, outer_xoffset + outer_area_size, yoffset + outer_area_size, background);

	canvas.set_blend_state(blend_enabled);

	// Create the image
	clan::Image image = create_block(canvas, image_colour);

	// Draw the image
	image.set_color(vertex_colour);
	image.draw(canvas, outer_xoffset + (outer_area_size - image.get_width())/2, yoffset + (outer_area_size - image.get_height())/2);

	clan::Colorf output;
	// Get the composited pixel buffer
	clan::Rectf rect(outer_xoffset + outer_area_size / 2, (yoffset + outer_area_size / 2), clan::Sizef(64,64));
	if (rect.is_inside(canvas.get_size()))
	{
		clan::PixelBuffer pbuff = canvas.get_pixeldata(rect, clan::tf_rgba8);
		pbuff.lock(canvas, clan::access_read_only);

		//clan::ImageProviderFactory::save(pbuff, "test.png");

		clan::Colorf output = pbuff.get_pixel(0, 0);
		pbuff.unlock();
	}
 
	// Create the information string
	std::string info(clan::string_format("Background = %1, %2, %3, %4", get_text(background.r), get_text(background.g), get_text(background.b), get_text(background.a)));
	int xpos = outer_xoffset + outer_area_size + 8;
	int ypos = yoffset + 12;
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Vertex = %1, %2, %3, %4", get_text(vertex_colour.r), get_text(vertex_colour.g), get_text(vertex_colour.b), get_text(vertex_colour.a)));
	font.draw_text(canvas, xpos + 250, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Image = %1, %2, %3, %4", get_text(image_colour.r), get_text(image_colour.g), get_text(image_colour.b), get_text(image_colour.a)));
	font.draw_text(canvas, xpos + 500, ypos, info, clan::Colorf::black);

	ypos += 20;
	clan::Colorf source(vertex_colour * image_colour);
	clan::Colorf calculated;
	calculated.r = source.a * source.r + (1.0f - source.a) * background.r;
	calculated.g = source.a * source.g + (1.0f - source.a) * background.g;
	calculated.b = source.a * source.b + (1.0f - source.a) * background.b;
	calculated.a = source.a + (1.0f - source.a) * background.a;

	info = std::string(clan::string_format("Source = %1, %2, %3, %4", get_text(source.r), get_text(source.g), get_text(source.b), get_text(source.a)));
	font.draw_text(canvas, xpos, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Calculated = %1, %2, %3, %4", get_text(calculated.r), get_text(calculated.g), get_text(calculated.b), get_text(calculated.a)));
	font.draw_text(canvas, xpos +  250, ypos, info, clan::Colorf::black);

	info = std::string(clan::string_format("Actual = %1, %2, %3, %4", get_text(output.r), get_text(output.g), get_text(output.b), get_text(output.a)));
	font.draw_text(canvas, xpos + 500, ypos, info, clan::Colorf::black);
}