예제 #1
0
파일: editor.c 프로젝트: jquick/pioneers
int main(int argc, char *argv[])
{
	gchar *filename;
	gboolean default_used;
	GtkWidget *notebook;
	GtkActionGroup *action_group;
	GtkUIManager *ui_manager;
	GtkWidget *vbox;
	GtkWidget *menubar;
	GtkAccelGroup *accel_group;
	GError *error = NULL;
	gchar *icon_file;
	GOptionContext *context;

	default_game = g_build_filename(get_pioneers_dir(), "default.game",
					NULL);

	/* Gtk+ handles the locale, we must bind the translations */
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	bind_textdomain_codeset(PACKAGE, "UTF-8");

GtkOSXApplication *theApp = g_object_new(GTK_TYPE_OSX_APPLICATION, NULL);

	context =
	    /* Long description in the command line: --help */
	    g_option_context_new(_("- Editor for games of Pioneers"));
	g_option_context_add_main_entries(context, commandline_entries,
					  GETTEXT_PACKAGE);
	g_option_context_add_group(context, gtk_get_option_group(TRUE));
	g_option_context_parse(context, &argc, &argv, &error);
	if (error != NULL) {
		g_print("%s\n", error->message);
		g_error_free(error);
		return 1;
	}
	if (show_version) {
		g_print(_("Pioneers version:"));
		g_print(" ");
		g_print(FULL_VERSION);
		g_print("\n");
		return 0;
	}

	if (filenames != NULL)
		filename = g_strdup(filenames[0]);
	else
		filename = NULL;

	toplevel = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(G_OBJECT(toplevel), "delete_event",
			 G_CALLBACK(exit_cb), NULL);

	action_group = gtk_action_group_new("MenuActions");
	gtk_action_group_set_translation_domain(action_group, PACKAGE);
	gtk_action_group_add_actions(action_group, entries,
				     G_N_ELEMENTS(entries), toplevel);

	ui_manager = gtk_ui_manager_new();
	gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);

	accel_group = gtk_ui_manager_get_accel_group(ui_manager);
	gtk_window_add_accel_group(GTK_WINDOW(toplevel), accel_group);

	error = NULL;
	if (!gtk_ui_manager_add_ui_from_string(ui_manager, ui_description,
					       -1, &error)) {
		g_message(_("Building menus failed: %s"), error->message);
		g_error_free(error);
		return 1;
	}

	config_init("pioneers-editor");

	icon_file =
	    g_build_filename(g_get_user_runtime_dir(), "pixmaps", MAINICON_FILE, NULL);
	if (g_file_test(icon_file, G_FILE_TEST_EXISTS)) {
		gtk_window_set_default_icon_from_file(icon_file, NULL);
	} else {
		/* Missing pixmap, main icon file */
		g_warning("Pixmap not found: %s", icon_file);
	}
	g_free(icon_file);

	themes_init();
	colors_init();

	notebook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);

	gtk_notebook_append_page(GTK_NOTEBOOK(notebook), build_map(),
				 /* Tab page name */
				 gtk_label_new(_("Map")));

	gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
				 build_settings(GTK_WINDOW(toplevel)),
				 /* Tab page name */
				 gtk_label_new(_("Settings")));

	terrain_menu = build_terrain_menu();
	roll_menu = build_roll_menu();
	port_menu = build_port_menu();

	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(toplevel), vbox);

	menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
	gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);

	if (filename == NULL) {
		filename =
		    config_get_string("editor/last-game", &default_used);
		if (default_used
		    || !g_file_test(filename, G_FILE_TEST_EXISTS)) {
			g_free(filename);
			filename = NULL;
		}
	}

	load_game(filename, FALSE);
	g_free(filename);
	if (params == NULL)
		return 1;

	gtk_widget_show_all(toplevel);

	gtk_accel_map_load(g_getenv("ACCEL_MAP"));
	gtk_widget_hide (menubar);
	gtk_osxapplication_set_menu_bar(theApp, GTK_MENU_SHELL(menubar));
	gtk_osxapplication_ready(theApp);

	gtk_main();

	config_finish();
	guimap_delete(gmap);
	g_free(default_game);

	g_option_context_free(context);
	return 0;
}
예제 #2
0
/** \ingroup settings
 *  Saves the current settings (as specified by allegro_gl_set()) to
 *  the current config file, in the section [OpenGL].
 *
 *  \sa allegro_gl_load_settings()
 */
void allegro_gl_save_settings() {

	char *section = "OpenGL";
	int save = allegro_gl_get(AGL_REQUIRE) | allegro_gl_get(AGL_SUGGEST);
	
	if (save & AGL_ALLEGRO_FORMAT)
		set_config_int(section, "allegro_format",
			allegro_gl_get(AGL_ALLEGRO_FORMAT));
	if (save & AGL_RED_DEPTH)
		set_config_int(section, "red_depth",
			allegro_gl_get(AGL_RED_DEPTH));
	if (save & AGL_GREEN_DEPTH)
		set_config_int(section, "green_depth",
			allegro_gl_get(AGL_GREEN_DEPTH));
	if (save & AGL_BLUE_DEPTH)
		set_config_int(section, "blue_depth",
			allegro_gl_get(AGL_BLUE_DEPTH));
	if (save & AGL_ALPHA_DEPTH)
		set_config_int(section, "alpha_depth",
			allegro_gl_get(AGL_ALPHA_DEPTH));
	if (save & AGL_COLOR_DEPTH)
		set_config_int(section, "color_depth",
			allegro_gl_get(AGL_COLOR_DEPTH));
	if (save & AGL_ACC_RED_DEPTH)
		set_config_int(section, "accum_red_depth",
			allegro_gl_get(AGL_ACC_RED_DEPTH));
	if (save & AGL_ACC_GREEN_DEPTH)
		set_config_int(section, "accum_green_depth",
			allegro_gl_get(AGL_ACC_GREEN_DEPTH));
	if (save & AGL_ACC_BLUE_DEPTH)
		set_config_int(section, "accum_blue_depth",
			allegro_gl_get(AGL_ACC_BLUE_DEPTH));
	if (save & AGL_ACC_ALPHA_DEPTH)
		set_config_int(section, "accum_alpha_depth",
			allegro_gl_get(AGL_ACC_ALPHA_DEPTH));
	if (save & AGL_DOUBLEBUFFER)
		set_config_int(section, "double_buffer",
			allegro_gl_get(AGL_DOUBLEBUFFER));
	if (save & AGL_STEREO)
		set_config_int(section, "stereo_display",
			allegro_gl_get(AGL_STEREO));
	if (save & AGL_AUX_BUFFERS)
		set_config_int(section, "aux_buffers",
			allegro_gl_get(AGL_AUX_BUFFERS));
	if (save & AGL_Z_DEPTH)
		set_config_int(section, "z_depth",
			allegro_gl_get(AGL_Z_DEPTH));
	if (save & AGL_STENCIL_DEPTH)
		set_config_int(section, "stencil_depth",
			allegro_gl_get(AGL_STENCIL_DEPTH));
	if (save & AGL_WINDOW_X)
		set_config_int(section, "window_x",
			allegro_gl_get(AGL_WINDOW_X));
	if (save & AGL_WINDOW_Y)
		set_config_int(section, "window_y",
			allegro_gl_get(AGL_WINDOW_Y));
	if (save & AGL_FULLSCREEN)
		set_config_int(section, "fullscreen",
			allegro_gl_get(AGL_FULLSCREEN));
	if (save & AGL_WINDOWED)
		set_config_int(section, "windowed",
			allegro_gl_get(AGL_WINDOWED));
	if (save & AGL_VIDEO_MEMORY_POLICY)
		set_config_int(section, "video_memory_policy",
			allegro_gl_get(AGL_VIDEO_MEMORY_POLICY));
	if (save & AGL_SAMPLE_BUFFERS)
		set_config_int(section, "sample_buffers",
		               allegro_gl_get(AGL_SAMPLE_BUFFERS));
	if (save & AGL_SAMPLES)
		set_config_int(section, "samples",
		               allegro_gl_get(AGL_SAMPLES));
	if (save & AGL_FLOAT_COLOR)
		set_config_int(section, "float_color",
		               allegro_gl_get(AGL_FLOAT_COLOR));
	if (save & AGL_FLOAT_Z)
		set_config_int(section, "float_depth",
		               allegro_gl_get(AGL_FLOAT_Z));

	if (save & AGL_REQUIRE)
		build_settings(allegro_gl_get(AGL_REQUIRE), section, "require");
	if (save & AGL_SUGGEST)
		build_settings(allegro_gl_get(AGL_SUGGEST), section, "suggest");
}