示例#1
0
bool App::update()
{
	game_time.update();

	options->set_viewport(canvas.get_size());
	options->set_background_color(clan::Colorf(0.6f, 0.6f, 0.2f, 1.0f));
	options->update();

	int num_balls = options->num_balls;
	if (num_balls > max_balls)
		num_balls = max_balls;

	if (options->is_moveballs_set)
		move_balls(game_time.get_time_elapsed(), num_balls);

	canvas.set_map_mode(options->current_mapmode);

	const float grid_xpos = 10.0f;
	const float grid_ypos = 10.0f;

	if (options->current_mapmode == clan::map_user_projection)
	{
		float grid_width = (float)image_grid.get_width();
		float grid_height = (float)image_grid.get_height();
		clan::Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f));
		set_user_projection(canvas, area_size, options.get());
	}

	// Draw the grid
	image_grid.draw(canvas, grid_xpos, grid_ypos);

	for (int cnt=0; cnt<num_balls; cnt++)
	{
		image_ball.draw(canvas, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos);
	}

	canvas.set_transform(clan::Mat4f::identity());
	canvas.set_projection(clan::Mat4f::identity());
	canvas.set_map_mode(clan::map_2d_upper_left);

	canvas.set_viewport(canvas.get_size());

	window.flip(1);

	return !quit;
}
示例#2
0
文件: app.cpp 项目: finalJ2/ClanLib
// The start of the Application
int App::start(const std::vector<std::string> &args)
{
	clan::DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("MapMode Example");
	win_desc.set_size(clan::Size( 800, 480 ), false);

	clan::DisplayWindow window(win_desc);
    clan::SlotContainer cc;
	cc.connect(window.sig_window_close(), clan::bind_member(this, &App::on_window_close));
	cc.connect(window.get_ic().get_keyboard().sig_key_up(), clan::bind_member(this, &App::on_input_up));

	std::string theme;
	if (clan::FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (clan::FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw clan::Exception("No themes found");

	clan::GUIWindowManagerTexture wm(window);
	clan::GUIManager gui(wm, theme);
	
	clan::Canvas canvas(window);

	// Deleted automatically by the GUI
	Options *options = new Options(gui, clan::Rect(0, 0, canvas.get_size()));

	clan::Image image_grid(canvas, "../Blend/Resources/grid.png");
	clan::Image image_ball(canvas, "../Blend/Resources/ball.png");
	float grid_width = (float) image_grid.get_width();
	float grid_height = (float) image_grid.get_height();

	grid_space = (float) (image_grid.get_width() - image_ball.get_width());

	setup_balls();

	options->request_repaint();

	clan::GameTime game_time;

	while (!quit)
	{
		game_time.update();

		wm.process();
		wm.draw_windows(canvas);

		int num_balls = options->num_balls;
		if (num_balls > max_balls)
			num_balls = max_balls;

		if (options->is_moveballs_set)
			move_balls(game_time.get_time_elapsed(), num_balls);

		canvas.set_map_mode(options->current_mapmode);

		const float grid_xpos = 10.0f;
		const float grid_ypos = 10.0f;

		if (options->current_mapmode == clan::map_user_projection)
		{
			clan::Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f));
			set_user_projection(canvas, area_size, options);
		}

		// Draw the grid
		image_grid.draw(canvas, grid_xpos, grid_ypos);

		for (int cnt=0; cnt<num_balls; cnt++)
		{
			image_ball.draw(canvas, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos);
		}

		canvas.set_modelview(clan::Mat4f::identity());
		canvas.set_projection(clan::Mat4f::identity());
		canvas.set_map_mode(clan::map_2d_upper_left);
		canvas.get_gc().set_viewport(canvas.get_size());

		window.flip(1);

		clan::KeepAlive::process();
	}
	return 0;
}
示例#3
0
// The start of the Application
int App::start(const std::vector<CL_String> &args)
{
	CL_DisplayWindowDescription win_desc;
	win_desc.set_allow_resize(true);
	win_desc.set_title("MapMode Example");
	win_desc.set_size(CL_Size( 800, 480 ), false);

	CL_DisplayWindow window(win_desc);
	CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close);
	CL_Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &App::on_input_up);

	CL_String theme;
	if (CL_FileHelp::file_exists("../../../Resources/GUIThemeAero/theme.css"))
		theme = "../../../Resources/GUIThemeAero";
	else if (CL_FileHelp::file_exists("../../../Resources/GUIThemeBasic/theme.css"))
		theme = "../../../Resources/GUIThemeBasic";
	else
		throw CL_Exception("No themes found");

	CL_GUIWindowManagerTexture wm(window);
	CL_GUIManager gui(wm, theme);
	
	CL_GraphicContext gc = window.get_gc();

	// Deleted automatically by the GUI
	Options *options = new Options(gui, CL_Rect(0, 0, gc.get_size()));

	CL_Image image_grid(gc, "../Blend/Resources/grid.png");
	CL_Image image_ball(gc, "../Blend/Resources/ball.png");
	float grid_width = (float) image_grid.get_width();
	float grid_height = (float) image_grid.get_height();

	grid_space = (float) (image_grid.get_width() - image_ball.get_width());

	setup_balls();

	options->request_repaint();

	unsigned int time_last = CL_System::get_time();

	while (!quit)
	{
		unsigned int time_now = CL_System::get_time();
		float time_diff = (float) (time_now - time_last);
		time_last = time_now;

		wm.process();
		wm.draw_windows(gc);

		int num_balls = options->num_balls;
		if (num_balls > max_balls)
			num_balls = max_balls;

		if (options->is_moveballs_set)
			move_balls(time_diff, num_balls);

		gc.set_map_mode(options->current_mapmode);

		const float grid_xpos = 10.0f;
		const float grid_ypos = 10.0f;

		if (options->current_mapmode == cl_user_projection)
		{
			CL_Sizef area_size(grid_width + (grid_xpos * 2.0f), grid_height + (grid_ypos * 2.0f));
			set_user_projection(gc, area_size, options);
		}

		// Draw the grid
		image_grid.draw(gc, grid_xpos, grid_ypos);

		gc.flush_batcher();	// <--- Fix me, this should not be required for cl_user_projection

		for (int cnt=0; cnt<num_balls; cnt++)
		{
			image_ball.draw(gc, grid_xpos + balls[cnt].xpos, grid_ypos + balls[cnt].ypos);
		}

		gc.set_modelview(CL_Mat4f::identity());
		gc.set_projection(CL_Mat4f::identity());

		gc.set_map_mode(cl_map_2d_upper_left);

		window.flip(1);

		CL_KeepAlive::process();
	}
	return 0;
}