?? actions.cpp
字號:
{ setLabelMode(app, Renderer::SpacecraftLabels, gtk_toggle_action_get_active(action));}void actionLabelStars(GtkToggleAction* action, AppData* app){ setLabelMode(app, Renderer::StarLabels, gtk_toggle_action_get_active(action));}/* Script opening helper called by actionOpenScript() */static void openScript(const char* filename, AppData* app){ /* Modified From Win32 HandleOpenScript */ if (filename) { /* If you got here, a path and file has been specified. * filename contains full path to specified file. */ ContentType type = DetermineFileType(filename); if (type == Content_CelestiaScript) { app->core->runScript(filename); } else if (type == Content_CelestiaLegacyScript) { ifstream scriptfile(filename); if (!scriptfile.good()) { GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error opening script file."); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); } else { CommandParser parser(scriptfile); CommandSequence* script = parser.parse(); if (script == NULL) { const vector<string>* errors = parser.getErrors(); const char* errorMsg = ""; if (errors->size() > 0) errorMsg = (*errors)[0].c_str(); GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", errorMsg); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); } else { /* Cancel any running script */ app->core->cancelScript(); app->core->runScript(script); } } } else { GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Bad File Type. Use *.(cel|celx|clx)."); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); } }}/* Image capturing helper called by actionCaptureImage() */static void captureImage(const char* filename, AppData* app){ /* Get the dimensions of the current viewport */ int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); bool success = false; ContentType type = DetermineFileType(filename); if (type == Content_Unknown) { GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Unable to determine image file type from name, please use a name ending in '.jpg' or '.png'."); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); return; } else if (type == Content_JPEG) { success = CaptureGLBufferToJPEG(filename, viewport[0], viewport[1], viewport[2], viewport[3]); } else if (type == Content_PNG) { success = CaptureGLBufferToPNG(filename, viewport[0], viewport[1], viewport[2], viewport[3]); } else { GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Currently screen capturing to only JPEG or PNG files is supported."); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); return; } if (!success) { GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error writing captured image."); gtk_dialog_run(GTK_DIALOG(errBox)); gtk_widget_destroy(errBox); }}/* Runs a dialog that displays text; should be replaced at some point with a more elegant solution. */static void textInfoDialog(const char *txt, const char *title, AppData* app){ /* I would use a gnome_message_box dialog for this, except they don't seem * to notice that the texts are so big that they create huge windows, and * would work better with a scrolled window. Deon */ GtkWidget* dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(app->mainWindow), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolled_window, TRUE, TRUE, 0); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_show(scrolled_window); GtkWidget *text = gtk_label_new(txt); gtk_widget_modify_font(text, pango_font_description_from_string("mono")); gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), GTK_WIDGET(text)); gtk_widget_show(text); gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 400); /* Absolute Size, urghhh */ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog);}/* Calculates and sets the render-flag int */static void setRenderFlag(AppData* a, int flag, gboolean state){ int rf = (a->renderer->getRenderFlags() & ~flag) | (state ? flag : 0); a->renderer->setRenderFlags(rf); #ifdef GNOME /* Update GConf */ gcSetRenderFlag(flag, state, a->client); #endif /* GNOME */}/* Calculates and sets the orbit-mask int */static void setOrbitMask(AppData* a, int mask, gboolean state){ int om = (a->renderer->getOrbitMask() & ~mask) | (state ? mask : 0); a->renderer->setOrbitMask(om); #ifdef GNOME /* Update GConf */ gcSetOrbitMask(mask, state, a->client); #endif /* GNOME */}/* Calculates and sets the label-mode int */static void setLabelMode(AppData* a, int mode, gboolean state){ int lm = (a->renderer->getLabelMode() & ~mode) | (state ? mode : 0); a->renderer->setLabelMode(lm); #ifdef GNOME /* Update GConf */ gcSetLabelMode(mode, state, a->client); #endif /* GNOME */}/* Synchronizes the Label Actions with the state of the core */void resyncLabelActions(AppData* app){ GtkAction* action; const char* actionName; /* Simply for readability */ int f = app->renderer->getLabelMode(); for (int i = Renderer::StarLabels; i <= Renderer::I18nConstellationLabels; i *= 2) { switch (i) { case Renderer::StarLabels: actionName = "LabelStars"; break; case Renderer::PlanetLabels: actionName = "LabelPlanets"; break; case Renderer::MoonLabels: actionName = "LabelMoons"; break; case Renderer::ConstellationLabels: actionName = "LabelConstellations"; break; case Renderer::GalaxyLabels: actionName = "LabelGalaxies"; break; case Renderer::AsteroidLabels: actionName = "LabelAsteroids"; break; case Renderer::SpacecraftLabels: actionName = "LabelSpacecraft"; break; case Renderer::LocationLabels: actionName = "LabelLocations"; break; case Renderer::CometLabels: actionName = "LabelComets"; break; case Renderer::NebulaLabels: actionName = "LabelNebulae"; break; case Renderer::OpenClusterLabels: actionName = "LabelOpenClusters"; break; case Renderer::I18nConstellationLabels: /* Not used yet */ default: actionName = NULL; } if (actionName != NULL) { /* Get the action */ action = gtk_action_group_get_action(app->agLabel, actionName); /* The current i anded with the labelMode gives state of flag */ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & f)); } }}/* Synchronizes the Render Actions with the state of the core */void resyncRenderActions(AppData* app){ GtkAction* action; const char* actionName; /* Simply for readability */ int rf = app->renderer->getRenderFlags(); /* Unlike the other interfaces, which go through each menu item and set * the corresponding renderFlag, we go the other way and set the menu * based on the renderFlag. Last one is ShowOpenClusters. */ for (int i = Renderer::ShowStars; i <= Renderer::ShowOpenClusters; i *= 2) { switch (i) { case Renderer::ShowStars: actionName = "RenderStars"; break; case Renderer::ShowPlanets: actionName = "RenderPlanets"; break; case Renderer::ShowGalaxies: actionName = "RenderGalaxies"; break; case Renderer::ShowDiagrams: actionName = "RenderConstellations"; break; case Renderer::ShowCloudMaps: actionName = "RenderClouds"; break; case Renderer::ShowOrbits: actionName = "RenderOrbits"; break; case Renderer::ShowCelestialSphere: actionName = "RenderCelestialGrid"; break; case Renderer::ShowNightMaps: actionName = "RenderNightLights"; break; case Renderer::ShowAtmospheres: actionName = "RenderAtmospheres"; break; case Renderer::ShowSmoothLines: actionName = "RenderAA"; break; case Renderer::ShowEclipseShadows: actionName = "RenderEclipseShadows"; break; case Renderer::ShowStarsAsPoints: actionName = NULL; break; /* Deprecated */ case Renderer::ShowRingShadows: actionName = "RenderRingShadows"; break; case Renderer::ShowBoundaries: actionName = "RenderConstellationBoundaries"; break; case Renderer::ShowAutoMag: actionName = "RenderAutoMagnitude"; break; case Renderer::ShowCometTails: actionName = "RenderCometTails"; break; case Renderer::ShowMarkers: actionName = "RenderMarkers"; break; case Renderer::ShowPartialTrajectories: actionName = NULL; break; /* Not useful yet */ case Renderer::ShowNebulae: actionName = "RenderNebulae"; break; case Renderer::ShowOpenClusters: actionName = "RenderOpenClusters"; break; default: actionName = NULL; } if (actionName != NULL) { /* Get the action */ action = gtk_action_group_get_action(app->agRender, actionName); /* The current i anded with the renderFlags gives state of flag */ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & rf)); } }}/* Synchronizes the Orbit Actions with the state of the core */void resyncOrbitActions(AppData* app){ GtkAction* action; const char* actionName; /* Simply for readability */ int om = app->renderer->getOrbitMask(); for (int i = Body::Planet; i <= Body::Spacecraft; i *= 2) { switch (i) { case Body::Planet: actionName = "OrbitPlanets"; break; case Body::Moon: actionName = "OrbitMoons"; break; case Body::Asteroid: actionName = "OrbitAsteroids"; break; case Body::Comet: actionName = "OrbitComets"; break; case Body::Spacecraft: actionName = "OrbitSpacecraft"; break; default: actionName = NULL; } if (actionName != NULL) { /* Get the action */ action = gtk_action_group_get_action(app->agOrbit, actionName); /* The current i anded with the orbitMask gives state of flag */ gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & om)); } }}/* Synchronizes the Verbosity Actions with the state of the core */void resyncVerbosityActions(AppData* app){ GtkAction* action; const char* actionName; switch (app->core->getHudDetail()) { case 0: actionName = "HudNone"; break; case 1: actionName = "HudTerse"; break; case 2: actionName = "HudVerbose"; break; default: return; } /* Get the action, set the widget */ action = gtk_action_group_get_action(app->agVerbosity, actionName); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);}/* Synchronizes the TimeZone Action with the state of the core */void resyncTimeZoneAction(AppData* app){ /* Get the action, set the widget */ GtkAction* action = gtk_action_group_get_action(app->agMain, "TimeLocal"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), app->showLocalTime);}/* Synchronizes the Ambient Light Actions with the state of the core */void resyncAmbientActions(AppData* app){ GtkAction* action; float ambient = app->renderer->getAmbientLightLevel(); /* Try to be smart about being close to the value of a float */ if (ambient > amLevels[0] && ambient < (amLevels[1] / 2.0)) action = gtk_action_group_get_action(app->agAmbient, "AmbientNone"); else if (ambient < amLevels[1] + ((amLevels[2] - amLevels[1]) / 2.0)) action = gtk_action_group_get_action(app->agAmbient, "AmbientLow"); else action = gtk_action_group_get_action(app->agAmbient, "AmbientMedium"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); #ifdef GNOME /* The action callback only occurs when one of the None/Low/Medium barriers * is surpassed, so an update is forced. */ gconf_client_set_float(app->client, "/apps/celestia/ambientLight", ambient, NULL); #endif}/* Synchronizes the Verbosity Actions with the state of the core */void resyncStarStyleActions(AppData* app){ GtkAction* action; const char* actionName; switch (app->renderer->getStarStyle()) { case Renderer::FuzzyPointStars: actionName = "StarsFuzzy"; break; case Renderer::PointStars: actionName = "StarsPoints"; break; case Renderer::ScaledDiscStars: actionName = "StarsDiscs"; break; default: return; } /* Get the action, set the widget */ action = gtk_action_group_get_action(app->agStarStyle, actionName); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);}/* Placeholder for when galaxy brightness is added as an action */void resyncGalaxyGainActions(AppData* app){ float gain = Galaxy::getLightGain(); #ifdef GNOME gconf_client_set_float(app->client, "/apps/celestia/galaxyLightGain", gain, NULL); #endif}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -