main.cpp

来自「celestia源代码」· C++ 代码 · 共 519 行 · 第 1/2 页

CPP
519
字号
}/* MAIN */int main(int argc, char* argv[]){	/* Initialize the structure that holds the application's vitals. */	AppData* app = g_new0(AppData, 1);	/* Not ready to render yet. */	app->bReady = FALSE;	/* Initialize variables in the AppData structure. */	app->lastX = 0;	app->lastY = 0;	app->showLocalTime = FALSE;	app->fullScreen = FALSE;	app->startURL = NULL;	/* Watcher enables sending signals from inside of core */	GtkWatcher* gtkWatcher;	/* Command line option parsing */	GError *error = NULL;	GOptionContext* context = g_option_context_new("");	g_option_context_add_main_entries(context, optionEntries, NULL);	g_option_context_add_group(context, gtk_get_option_group(TRUE));	g_option_context_parse(context, &argc, &argv, &error);	if (error != NULL)	{		g_print("Error in command line options. Use --help for full list.\n");		exit(1);	}		/* At this point, the argument count should be 1 or 2, with the lastX	 * potentially being a cel:// URL. */		/* If there's an argument left, assume it's a URL. This happens here	 * because it's after the saved prefs are applied. The appCore gets	 * initialized elsewhere. */	if (argc > 1)		app->startURL = argv[argc - 1];		if (installDir == NULL)		installDir = (gchar*)CONFIG_DATA_DIR;	if (chdir(installDir) == -1)		cerr << "Cannot chdir to '" << installDir << "', probably due to improper installation.\n";	#ifdef GNOME	/* GNOME Initialization */	GnomeProgram *program;	program = gnome_program_init("Celestia", VERSION, LIBGNOMEUI_MODULE,	                             argc, argv, GNOME_PARAM_NONE);	#else	/* GTK-Only Initialization */	gtk_init(&argc, &argv);	#endif	/* Turn on the splash screen */	SplashData* ss = splashStart(app, !noSplash);	splashSetText(ss, "Initializing...");	SetDebugVerbosity(0);	/* Force number displays into C locale. */	setlocale(LC_NUMERIC, "C");	setlocale(LC_ALL, "");	#ifndef WIN32	bindtextdomain(PACKAGE, LOCALEDIR);	bind_textdomain_codeset(PACKAGE, "UTF-8");	textdomain(PACKAGE);	#endif /* WIN32 */	app->core = new CelestiaCore();	if (app->core == NULL)	{		cerr << "Failed to initialize Celestia core.\n";		return 1;	}	app->renderer = app->core->getRenderer();	g_assert(app->renderer);		/* Parse simulation arguments */	string cf;	if (configFile != NULL)		cf = string(configFile);		string* altConfig = (configFile != NULL) ? &cf : NULL;	vector<string> configDirs;	if (extrasDir != NULL)	{		/* Add each extrasDir to the vector */		int i = 0;		while (extrasDir[i] != NULL)		{			configDirs.push_back(extrasDir[i]);			i++;		}	}	/* Initialize the simulation */		if (!app->core->initSimulation(altConfig, &configDirs, ss->notifier))		return 1;		app->simulation = app->core->getSimulation();	g_assert(app->simulation);		#ifdef GNOME	/* Create the main window (GNOME) */	app->mainWindow = gnome_app_new("Celestia", "Celestia");	#else	/* Create the main window (GTK) */	app->mainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);	gtk_window_set_title(GTK_WINDOW(app->mainWindow), "Celestia");	#endif /* GNOME */	/* Set pointer to AppData structure. This is for when a function is in a	 * *real* bind to get at this structure. */	g_object_set_data(G_OBJECT(app->mainWindow), "CelestiaData", app);		GtkWidget* mainBox = GTK_WIDGET(gtk_vbox_new(FALSE, 0));	gtk_container_set_border_width(GTK_CONTAINER(mainBox), 0);	g_signal_connect(GTK_OBJECT(app->mainWindow), "destroy",	                 G_CALLBACK(actionQuit), app);	/* Initialize the OpenGL widget */	gtk_gl_init (&argc, &argv);	/* Configure OpenGL. Try double-buffered visual. */	GdkGLConfig* glconfig = gdk_gl_config_new_by_mode(static_cast<GdkGLConfigMode>	                                                  (GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE));	if (glconfig == NULL)	{		g_print("*** Cannot find the double-buffered visual.\n");		g_print("*** Trying single-buffered visual.\n");		/* Try single-buffered visual */		glconfig = gdk_gl_config_new_by_mode(static_cast<GdkGLConfigMode>		                                     (GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH));		if (glconfig == NULL)		{			g_print ("*** No appropriate OpenGL-capable visual found.\n");			exit(1);		}	}	/* Initialize settings system */	#ifdef GNOME	initSettingsGConf(app);	#else	initSettingsFile(app);	#endif /* GNOME */		/* Create area to be used for OpenGL display */	app->glArea = gtk_drawing_area_new();		/* Set OpenGL-capability to the widget. */	gtk_widget_set_gl_capability(app->glArea,	                             glconfig,	                             NULL,	                             TRUE,	                             GDK_GL_RGBA_TYPE);		gtk_widget_set_events(GTK_WIDGET(app->glArea),	                      GDK_EXPOSURE_MASK |	                      GDK_KEY_PRESS_MASK |	                      GDK_KEY_RELEASE_MASK |	                      GDK_BUTTON_PRESS_MASK |	                      GDK_BUTTON_RELEASE_MASK |	                      GDK_POINTER_MOTION_MASK);	/* Load settings the can be applied before the simulation is initialized */	#ifdef GNOME	applySettingsGConfPre(app, app->client);	#else	applySettingsFilePre(app, app->settingsFile);	#endif /* GNOME */	/* Full-Screen option from the command line (overrides above). */	if (fullScreen)		app->fullScreen = TRUE;	/* Initialize handlers to all events in the glArea */	initGLCallbacks(app);	/* Handler than completes initialization when the glArea is realized */	g_signal_connect(GTK_OBJECT(app->glArea), "realize",	                 G_CALLBACK(initRealize), app);	/* Create the main menu bar */	createMainMenu(app->mainWindow, app);		/* Initialize the context menu */	initContext(app);	/* Set context menu callback for the core */	app->core->setContextMenuCallback(menuContext);		#ifdef GNOME	/* Set window contents (GNOME) */	gnome_app_set_contents((GnomeApp *)app->mainWindow, GTK_WIDGET(mainBox));	#else	/* Set window contents (GTK) */	gtk_container_add(GTK_CONTAINER(app->mainWindow), GTK_WIDGET(mainBox));	#endif /* GNOME */	gtk_box_pack_start(GTK_BOX(mainBox), app->mainMenu, FALSE, TRUE, 0);	gtk_box_pack_start(GTK_BOX(mainBox), app->glArea, TRUE, TRUE, 0);	gtk_window_set_default_icon_from_file("celestia-logo.png", NULL);	/* Set focus to glArea widget */	GTK_WIDGET_SET_FLAGS(app->glArea, GTK_CAN_FOCUS);	gtk_widget_grab_focus(GTK_WIDGET(app->glArea));	/* Initialize the Watcher */	gtkWatcher = new GtkWatcher(app->core, app);	/* Unload the splash screen */	splashEnd(ss);	gtk_widget_show_all(app->mainWindow);	/* HACK: Now that window is drawn, set minimum window size */	gtk_widget_set_size_request(app->glArea, 320, 240);	#ifdef GNOME	initSettingsGConfNotifiers(app);	#endif /* GNOME */		/* Set the ready flag */	app->bReady = TRUE;		/* Call Main GTK Loop */	gtk_main();    	g_free(app);	return 0;}#ifdef WIN32int APIENTRY WinMain(HINSTANCE hInstance,                     HINSTANCE hPrevInstance,                     LPSTR lpCmdLine,                     int nCmdShow){	return main(__argc, __argv);}#endif /* WIN32 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?