?? main.cpp
字號:
/* * Celestia GTK+ Front-End * Copyright (C) 2005 Pat Suwalski <pat@suwalski.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * $Id: main.cpp,v 1.6 2006/01/01 23:43:51 suwalski Exp $ */#ifdef HAVE_CONFIG_H#include <config.h>#endif /* HAVE_CONFIG_H */#include <iostream>#include <fstream>#include <cstdlib>#include <cctype>#include <cstring>#include <time.h>#ifdef WIN32#include <direct.h>#else#include <unistd.h>#endif /* WIN32 */#include <gtk/gtk.h>#include <gtk/gtkgl.h>#include <celengine/astro.h>#include <celengine/celestia.h>#include <celengine/gl.h>#include <celengine/glext.h>#include <celengine/galaxy.h>#include <celengine/simulation.h>#include <celestia/celestiacore.h>#include <celutil/debug.h>/* Includes for the GNOME front-end */#ifdef GNOME#include <gnome.h>#include <libgnomeui/libgnomeui.h>#include <gconf/gconf-client.h>#endif /* GNOME *//* Includes for the GTK front-end */#include "common.h"#include "glwidget.h"#include "menu-context.h"#include "splash.h"#include "ui.h"/* Includes for the settings interface */#ifdef GNOME#include "settings-gconf.h"#else#include "settings-file.h"#endif /* GNOME */#ifndef DEBUG#define G_DISABLE_ASSERT#endif /* DEBUG */using namespace std;/* Function Definitions */static void createMainMenu(GtkWidget* window, AppData* app);static void initRealize(GtkWidget* widget, AppData* app);/* Command-Line Options */static gchar* configFile = NULL;static gchar* installDir = NULL;static gchar** extrasDir = NULL;static gboolean fullScreen = FALSE;static gboolean noSplash = FALSE;/* Command-Line Options specification */static GOptionEntry optionEntries[] ={ { "conf", 'c', 0, G_OPTION_ARG_FILENAME, &configFile, "Alternate configuration file", "file" }, { "dir", 'd', 0, G_OPTION_ARG_FILENAME, &installDir, "Alternate installation directory", "directory" }, { "extrasdir", 'e', 0, G_OPTION_ARG_FILENAME_ARRAY, &extrasDir, "Additional \"extras\" directory", "directory" }, { "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &fullScreen, "Start full-screen", NULL }, { "nosplash", 's', 0, G_OPTION_ARG_NONE, &noSplash, "Disable splash screen", NULL }, { NULL },};/* Initializes GtkActions and creates main menu */static void createMainMenu(GtkWidget* window, AppData* app){ GtkUIManager *ui_manager; GtkAccelGroup *accel_group; GError *error; app->agMain = gtk_action_group_new ("MenuActions"); app->agRender = gtk_action_group_new("RenderActions"); app->agLabel = gtk_action_group_new("LabelActions"); app->agOrbit = gtk_action_group_new("OrbitActions"); app->agVerbosity = gtk_action_group_new("VerbosityActions"); app->agStarStyle = gtk_action_group_new("StarStyleActions"); app->agAmbient = gtk_action_group_new("AmbientActions"); /* All actions have the AppData structure passed */ gtk_action_group_add_actions(app->agMain, actionsPlain, G_N_ELEMENTS(actionsPlain), app); gtk_action_group_add_toggle_actions(app->agMain, actionsToggle, G_N_ELEMENTS(actionsToggle), app); gtk_action_group_add_radio_actions(app->agVerbosity, actionsVerbosity, G_N_ELEMENTS(actionsVerbosity), 0, G_CALLBACK(actionVerbosity), app); gtk_action_group_add_radio_actions(app->agStarStyle, actionsStarStyle, G_N_ELEMENTS(actionsStarStyle), 0, G_CALLBACK(actionStarStyle), app); gtk_action_group_add_radio_actions(app->agAmbient, actionsAmbientLight, G_N_ELEMENTS(actionsAmbientLight), 0, G_CALLBACK(actionAmbientLight), app); gtk_action_group_add_toggle_actions(app->agRender, actionsRenderFlags, G_N_ELEMENTS(actionsRenderFlags), app); gtk_action_group_add_toggle_actions(app->agLabel, actionsLabelFlags, G_N_ELEMENTS(actionsLabelFlags), app); gtk_action_group_add_toggle_actions(app->agOrbit, actionsOrbitFlags, G_N_ELEMENTS(actionsOrbitFlags), app); ui_manager = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(ui_manager, app->agMain, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agRender, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agLabel, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agOrbit, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agStarStyle, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agAmbient, 0); gtk_ui_manager_insert_action_group(ui_manager, app->agVerbosity, 0); accel_group = gtk_ui_manager_get_accel_group(ui_manager); gtk_window_add_accel_group(GTK_WINDOW (window), accel_group); error = NULL; if (!gtk_ui_manager_add_ui_from_file(ui_manager, "celestiaui.xml", &error)) { g_message("Building menus failed: %s", error->message); g_error_free(error); exit(EXIT_FAILURE); } app->mainMenu = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");}/* Our own watcher. Celestiacore will call notifyChange() to tell us * we need to recheck the check menu items and option buttons. */class GtkWatcher : public CelestiaWatcher{ public: GtkWatcher(CelestiaCore*, AppData*); virtual void notifyChange(CelestiaCore*, int); private: AppData* app;};GtkWatcher::GtkWatcher(CelestiaCore* _appCore, AppData* _app) : CelestiaWatcher(*_appCore), app(_app){}void GtkWatcher::notifyChange(CelestiaCore*, int property){ if (property & CelestiaCore::LabelFlagsChanged) resyncLabelActions(app); else if (property & CelestiaCore::RenderFlagsChanged) { resyncRenderActions(app); resyncOrbitActions(app); resyncStarStyleActions(app); } else if (property & CelestiaCore::VerbosityLevelChanged) resyncVerbosityActions(app); else if (property & CelestiaCore::TimeZoneChanged) resyncTimeZoneAction(app); else if (property & CelestiaCore::AmbientLightChanged) resyncAmbientActions(app); /* else if (property & CelestiaCore::FaintestChanged) DEPRECATED? else if (property & CelestiaCore::HistoryChanged) */ else if (property == CelestiaCore::TextEnterModeChanged) { if (app->core->getTextEnterMode() != 0) { /* Grey-out the menu */ gtk_widget_set_sensitive(app->mainMenu, FALSE); /* Disable any actions that will interfere in typing and autocomplete */ gtk_action_group_set_sensitive(app->agMain, FALSE); gtk_action_group_set_sensitive(app->agRender, FALSE); gtk_action_group_set_sensitive(app->agLabel, FALSE); } else { /* Set the menu normal */ gtk_widget_set_sensitive(app->mainMenu, TRUE); /* Re-enable action groups */ gtk_action_group_set_sensitive(app->agMain, TRUE); gtk_action_group_set_sensitive(app->agRender, TRUE); gtk_action_group_set_sensitive(app->agLabel, TRUE); } } else if (property & CelestiaCore::GalaxyLightGainChanged) resyncGalaxyGainActions(app);}/* END Watcher *//* CALLBACK: Event "realize" on the main GL area. Things that go here are those * that require the glArea to be set up. */static void initRealize(GtkWidget* widget, AppData* app){ if (!app->core->initRenderer()) { cerr << "Failed to initialize renderer.\n"; } /* Read/Apply Settings */ #ifdef GNOME applySettingsGConfMain(app, app->client); #else applySettingsFileMain(app, app->settingsFile); #endif /* GNOME */ /* Synchronize all actions with core settings */ resyncLabelActions(app); resyncRenderActions(app); resyncOrbitActions(app); resyncVerbosityActions(app); resyncAmbientActions(app); resyncStarStyleActions(app); /* If full-screen at startup, make it so. */ if (app->fullScreen) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_action_group_get_action(app->agMain, "FullScreen")), TRUE); /* If URL at startup, make it so. */ if (app->startURL != NULL) app->core->setStartURL(app->startURL); /* Set simulation time */ app->core->start((double)time(NULL) / 86400.0 + (double)astro::Date(1970, 1, 1)); updateTimeZone(app, app->showLocalTime); /* Setting time zone name not very useful, but makes space for "LT" status in * the top-right corner. Set to some default. */ app->core->setTimeZoneName("UTC"); /* Set the cursor to a crosshair */ gdk_window_set_cursor(widget->window, gdk_cursor_new(GDK_CROSSHAIR));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -