Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

actions.cpp

Go to the documentation of this file.
00001 /*
00002  *  Celestia GTK+ Front-End
00003  *  Copyright (C) 2005 Pat Suwalski <pat@suwalski.net>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  $Id: actions.cpp,v 1.10 2006/01/09 19:02:54 suwalski Exp $
00011  */
00012 
00013 #ifdef HAVE_CONFIG_H
00014 #include <config.h>
00015 #endif /* HAVE_CONFIG_H */
00016 
00017 #include <cstring>
00018 #include <fstream>
00019 #include <gtk/gtk.h>
00020 
00021 #ifdef GNOME
00022 #include <gconf/gconf-client.h>
00023 #endif /* GNOME */
00024 
00025 #include <celengine/body.h>
00026 #include <celengine/gl.h>
00027 #include <celengine/glext.h>
00028 #include <celengine/simulation.h>
00029 #include <celengine/cmdparser.h>
00030 #include <celengine/render.h>
00031 #include <celestia/celestiacore.h>
00032 #include <celestia/imagecapture.h>
00033 #include <celestia/url.h>
00034 #include <celutil/filetype.h>
00035 
00036 #include "actions.h"
00037 #include "common.h"
00038 #include "dialog-eclipse.h"
00039 #include "dialog-goto.h"
00040 #include "dialog-options.h"
00041 #include "dialog-solar.h"
00042 #include "dialog-star.h"
00043 #include "dialog-time.h"
00044 #include "dialog-tour.h"
00045 
00046 #ifdef GNOME
00047 #include "settings-gconf.h"
00048 #else
00049 #include "settings-file.h"
00050 #endif /* GNOME */
00051 
00052 
00053 /* Declarations: Action Helpers */
00054 static void openScript(const char* filename, AppData* app);
00055 static void captureImage(const char* filename, AppData* app);
00056 static void textInfoDialog(const char *txt, const char *title, AppData* app);
00057 static void setRenderFlag(AppData* a, int flag, gboolean state);
00058 static void setOrbitMask(AppData* a, int mask, gboolean state);
00059 static void setLabelMode(AppData* a, int mode, gboolean state);
00060 
00061 
00062 /* File -> Copy URL */
00063 void actionCopyURL(GtkAction*, AppData* app)
00064 {
00065         GtkClipboard* cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
00066         Url url(app->core);
00067         gtk_clipboard_set_text(cb, url.getAsString().c_str(), -1);
00068 }
00069 
00070 
00071 /* File -> Open URL */
00072 void actionOpenURL(GtkAction*, AppData* app)
00073 {
00074         GtkWidget* dialog = gtk_dialog_new_with_buttons("Enter cel:// URL",
00075                                                         GTK_WINDOW(app->mainWindow),
00076                                                         GTK_DIALOG_MODAL,
00077                                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
00078                                                         GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
00079                                                         NULL);
00080 
00081         /* Create a new entry box with default text, all selected */
00082         GtkWidget* entry = gtk_entry_new();
00083         gtk_entry_set_width_chars(GTK_ENTRY(entry), 80);
00084         gtk_entry_set_text(GTK_ENTRY(entry), "cel://");
00085         gtk_editable_select_region(GTK_EDITABLE(entry), 0, -1);
00086 
00087         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), entry, TRUE, TRUE, CELSPACING);
00088         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
00089         gtk_widget_show_all(dialog);
00090 
00091         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
00092                 app->core->goToUrl(gtk_entry_get_text(GTK_ENTRY(entry)));
00093 
00094         gtk_widget_destroy(dialog);
00095 }
00096 
00097 
00098 /* File -> Open Script... */
00099 void actionOpenScript(GtkAction*, AppData* app)
00100 {
00101         GtkWidget* fs = gtk_file_chooser_dialog_new("Open Script.",
00102                                                     GTK_WINDOW(app->mainWindow),
00103                                                     GTK_FILE_CHOOSER_ACTION_OPEN,
00104                                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00105                                                     GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
00106                                                     NULL);
00107 
00108         #if GTK_CHECK_VERSION(2, 7, 0)
00109         gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(fs), TRUE);
00110         #endif /* GTK_CHECK_VERSION */
00111 
00112         gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
00113         gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs), g_get_home_dir());
00114 
00115         GtkFileFilter* filter = gtk_file_filter_new();
00116         gtk_file_filter_set_name(filter, "Celestia Scripts");
00117         
00118         gtk_file_filter_add_pattern(filter, "*.cel");
00119 
00120         #ifdef CELX
00121         gtk_file_filter_add_pattern(filter, "*.celx");
00122         gtk_file_filter_add_pattern(filter, "*.clx");
00123         #endif /* CELX */
00124         
00125         gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter);
00126         
00127         if (gtk_dialog_run(GTK_DIALOG(fs)) == GTK_RESPONSE_ACCEPT)
00128         {
00129                 char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
00130                 openScript(filename, app);
00131                 g_free(filename);
00132         }
00133 
00134         gtk_widget_destroy(fs); 
00135 }
00136 
00137 
00138 /* File -> Capture Image... */
00139 void actionCaptureImage(GtkAction*, AppData* app)
00140 {
00141         GtkWidget* fs = gtk_file_chooser_dialog_new("Save Image to File",
00142                                                     GTK_WINDOW(app->mainWindow),
00143                                                     GTK_FILE_CHOOSER_ACTION_SAVE,
00144                                                     GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00145                                                     GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
00146                                                     NULL);
00147 
00148         GtkFileFilter* filter = gtk_file_filter_new();
00149         gtk_file_filter_set_name(filter, "PNG and JPEG Images");
00150         gtk_file_filter_add_pattern(filter, "*.jpeg");
00151         gtk_file_filter_add_pattern(filter, "*.jpg");
00152         gtk_file_filter_add_pattern(filter, "*.png");
00153         gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fs), filter);
00154 
00155         #if GTK_CHECK_VERSION(2, 7, 0)
00156         gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(fs), TRUE);
00157         #endif /* GTK_CHECK_VERSION */
00158         
00159         gtk_dialog_set_default_response(GTK_DIALOG(fs), GTK_RESPONSE_ACCEPT);
00160         gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fs), g_get_home_dir());
00161 
00162         if (gtk_dialog_run(GTK_DIALOG(fs)) == GTK_RESPONSE_ACCEPT)
00163         {
00164                 char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
00165                 captureImage(filename, app);
00166                 g_free(filename);
00167         }
00168 
00169         gtk_widget_destroy(fs);
00170 }
00171 
00172 
00173 void actionQuit(GtkAction*, AppData* app)
00174 {
00175         #ifdef GNOME
00176         saveSettingsGConf(app);
00177         #else
00178         saveSettingsFile(app);
00179         #endif /* GNOME */
00180 
00181         gtk_main_quit();
00182 }
00183 
00184 
00185 void actionSelectSol(GtkAction*, AppData* app)
00186 {
00187         app->core->charEntered('H');
00188 }
00189 
00190 
00191 void actionTourGuide(GtkAction*, AppData* app)
00192 {
00193         dialogTourGuide(app);
00194 }
00195 
00196 
00197 void actionSearchObject(GtkAction*, AppData* app)
00198 {
00199         GtkWidget* dialog = gtk_dialog_new_with_buttons("Select Object",
00200                                                         GTK_WINDOW(app->mainWindow),
00201                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
00202                                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
00203                                                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00204                                                         NULL);
00205 
00206         GtkWidget* box = gtk_hbox_new(FALSE, CELSPACING);
00207         gtk_container_set_border_width(GTK_CONTAINER(box), CELSPACING);
00208         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), box, TRUE, TRUE, 0);
00209 
00210         GtkWidget* label = gtk_label_new("Object name");
00211         gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
00212 
00213         GtkWidget* entry = gtk_entry_new();
00214         gtk_box_pack_start(GTK_BOX(box), entry, TRUE, TRUE, 0);
00215 
00216         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
00217         gtk_widget_show_all(GTK_WIDGET(dialog));
00218 
00219         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
00220         {
00221                 const gchar* name = gtk_entry_get_text(GTK_ENTRY(entry));
00222                 if (name != NULL)
00223                 {
00224                         Selection sel = app->simulation->findObject(name);
00225                         if (!sel.empty())
00226                                 app->simulation->setSelection(sel);
00227                 }
00228         }
00229 
00230         gtk_widget_destroy(GTK_WIDGET(dialog));
00231 }
00232 
00233 
00234 void actionGotoObject(GtkAction*, AppData* app)
00235 {
00236         dialogGotoObject(app);
00237 }
00238 
00239 
00240 void actionCenterSelection(GtkAction*, AppData* app)
00241 {
00242         app->core->charEntered('c');
00243 }
00244 
00245 
00246 void actionGotoSelection(GtkAction*, AppData* app)
00247 {
00248         app->core->charEntered('G');
00249 }
00250 
00251 
00252 void actionFollowSelection(GtkAction*, AppData* app)
00253 {
00254         app->core->charEntered('F');
00255 }
00256 
00257 
00258 void actionSyncSelection(GtkAction*, AppData* app)
00259 {
00260         app->core->charEntered('Y');
00261 }
00262 
00263 
00264 void actionTrackSelection(GtkAction*, AppData* app)
00265 {
00266         app->core->charEntered('T');
00267 }
00268 
00269 
00270 void actionSystemBrowser(GtkAction*, AppData* app)
00271 {
00272         dialogSolarBrowser(app);
00273 }
00274 
00275 
00276 void actionStarBrowser(GtkAction*, AppData* app)
00277 {
00278         dialogStarBrowser(app);
00279 }
00280 
00281 
00282 void actionEclipseFinder(GtkAction*, AppData* app)
00283 {
00284         dialogEclipseFinder(app);
00285 }
00286 
00287 
00288 void actionTimeFaster(GtkAction*, AppData* app)
00289 {
00290         app->core->charEntered('L');
00291 }
00292 
00293 
00294 void actionTimeSlower(GtkAction*, AppData* app)
00295 {
00296         app->core->charEntered('K');
00297 }
00298 
00299 
00300 void actionTimeFreeze(GtkAction*, AppData* app)
00301 {
00302         app->core->charEntered(' ');
00303 }
00304 
00305 
00306 void actionTimeReal(GtkAction*, AppData* app)
00307 {
00308         app->core->charEntered('\\');
00309 }
00310 
00311 
00312 void actionTimeReverse(GtkAction*, AppData* app)
00313 {
00314         app->core->charEntered('J');
00315 }
00316 
00317 
00318 void actionTimeSet(GtkAction*, AppData* app)
00319 {
00320         dialogSetTime(app);
00321 }
00322 
00323 
00324 void actionTimeLocal(GtkAction* action, AppData* app)
00325 {
00326         app->showLocalTime = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
00327         updateTimeZone(app, app->showLocalTime);
00328 
00329         #ifdef GNOME
00330         gconf_client_set_bool(app->client, "/apps/celestia/showLocalTime", app->showLocalTime, NULL);
00331         #endif /* GNOME */
00332 }
00333 
00334 
00335 void actionViewerSize(GtkAction*, AppData* app)
00336 {
00337         GtkWidget* dialog;
00338         int newX, currentX, currentY, winX, winY, screenX, i = 1, position = -1;
00339         char res[32];
00340         
00341         screenX = gdk_screen_get_width(gdk_screen_get_default());
00342         currentX = app->glArea->allocation.width;
00343         currentY = app->glArea->allocation.height;
00344 
00345         dialog = gtk_dialog_new_with_buttons("Set Viewer Size...",
00346                                              GTK_WINDOW(app->mainWindow),
00347                                              GTK_DIALOG_DESTROY_WITH_PARENT,
00348                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
00349                                              GTK_STOCK_OK, GTK_RESPONSE_OK,
00350                                              NULL);
00351 
00352         GtkWidget* vbox = gtk_vbox_new(FALSE, CELSPACING); 
00353         gtk_container_set_border_width(GTK_CONTAINER(vbox), CELSPACING);
00354 
00355         GtkWidget* label = gtk_label_new("Dimensions for Main Window:");
00356         gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
00357 
00358         GtkWidget* menubox = gtk_combo_box_new_text();
00359         gtk_box_pack_start(GTK_BOX(vbox), menubox, FALSE, FALSE, 0);
00360 
00361         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, TRUE, TRUE, 0);
00362 
00363         while (resolutions[i] != -1)
00364         {
00365                 if (position == -1 && resolutions[i-1] < currentX && resolutions[i] >= currentX)
00366                 {
00367                         sprintf(res, "%d x %d (current)", currentX, currentY);
00368                         position = i - 1;
00369                 }
00370                 else if (resolutions[i] < screenX)
00371                 {
00372                         sprintf(res, "%d x %d", resolutions[i], int(0.75 * resolutions[i]));
00373                         i++;
00374                 }
00375                 else
00376                         break;
00377                 
00378                 gtk_combo_box_append_text(GTK_COMBO_BOX(menubox), res);
00379         }
00380 
00381         gtk_combo_box_set_active(GTK_COMBO_BOX(menubox), position);
00382 
00383         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
00384         gtk_widget_show_all(dialog);
00385 
00386         if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
00387         {
00388                 int active = gtk_combo_box_get_active(GTK_COMBO_BOX(menubox));
00389 
00390                 if (active > -1 && active != position)
00391                 {
00392                         /* Adjust for default entry */
00393                         if (active > position) active--;
00394 
00395                         newX = resolutions[active + 1];
00396                         gtk_window_get_size(GTK_WINDOW(app->mainWindow), &winX, &winY);
00397                         
00398                         /* Resizing takes into account border, titlebar, and menubar
00399                            sizes. Without them only an allocation can be requested */
00400                         gtk_window_resize(GTK_WINDOW(app->mainWindow), newX + winX - currentX, int(0.75 * newX) + winY - currentY);
00401                 }
00402         }
00403         
00404         gtk_widget_destroy(GTK_WIDGET(dialog));
00405 }
00406 
00407 
00408 void actionFullScreen(GtkAction* action, AppData* app)
00409 {
00410         int positionX, positionY;
00411         app->fullScreen = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
00412         
00413         if (app->fullScreen)
00414         {
00415                 /* Save size/position, so original numbers are available for prefs */
00416                 g_object_set_data(G_OBJECT(app->mainWindow), "sizeX", GINT_TO_POINTER(app->glArea->allocation.width));
00417                 g_object_set_data(G_OBJECT(app->mainWindow), "sizeY", GINT_TO_POINTER(app->glArea->allocation.height));
00418                 gtk_window_get_position(GTK_WINDOW(app->mainWindow), &positionX, &positionY);
00419                 g_object_set_data(G_OBJECT(app->mainWindow), "positionX", GINT_TO_POINTER(positionX));
00420                 g_object_set_data(G_OBJECT(app->mainWindow), "positionY", GINT_TO_POINTER(positionY));
00421 
00422                 gtk_window_fullscreen(GTK_WINDOW(app->mainWindow));
00423         }
00424         else
00425                 gtk_window_unfullscreen(GTK_WINDOW(app->mainWindow));
00426 
00427         /* Enable/Disable the Viewer Size action */
00428         gtk_action_set_sensitive(gtk_action_group_get_action(app->agMain, "ViewerSize"), !app->fullScreen);
00429         
00430         #ifdef GNOME
00431         gconf_client_set_bool(app->client, "/apps/celestia/fullScreen", app->fullScreen, NULL);
00432         #endif
00433 }
00434 
00435 
00436 void actionViewOptions(GtkAction*, AppData* app)
00437 {
00438         dialogViewOptions(app);
00439 }
00440 
00441 
00442 void actionStarsMore(GtkAction*, AppData* app)
00443 {
00444         app->core->charEntered(']');    
00445 
00446         #ifdef GNOME
00447         gconf_client_set_float(app->client, "/apps/celestia/visualMagnitude", app->simulation->getFaintestVisible(), NULL);
00448         #endif
00449 }
00450 
00451 
00452 void actionStarsFewer(GtkAction*, AppData* app)
00453 {
00454         app->core->charEntered('[');
00455 
00456         #ifdef GNOME
00457         gconf_client_set_float(app->client, "/apps/celestia/visualMagnitude", app->simulation->getFaintestVisible(), NULL);
00458         #endif
00459 }
00460 
00461 
00462 void actionMenuBarVisible(GtkToggleAction* action, AppData* app)
00463 {
00464         g_object_set(G_OBJECT(app->mainMenu), "visible", gtk_toggle_action_get_active(action), NULL);
00465 }
00466 
00467 
00468 void actionMultiSplitH(GtkAction*, AppData* app)
00469 {
00470         app->core->splitView(View::HorizontalSplit);
00471 }
00472 
00473 
00474 void actionMultiSplitV(GtkAction*, AppData* app)
00475 {
00476         app->core->splitView(View::VerticalSplit);
00477 }
00478 
00479 
00480 void actionMultiCycle(GtkAction*, AppData* app)
00481 {
00482         /* Pass a Tab character */
00483         app->core->charEntered('\011');
00484 }
00485 
00486 
00487 void actionMultiDelete(GtkAction*, AppData* app)
00488 {
00489         app->core->deleteView();
00490 }
00491 
00492 
00493 void actionMultiSingle(GtkAction*, AppData* app)
00494 {
00495         app->core->singleView();
00496 }
00497 
00498 
00499 void actionMultiShowFrames(GtkToggleAction* action, AppData* app)
00500 {
00501         app->core->setFramesVisible(gtk_toggle_action_get_active(action));
00502 }
00503 
00504 
00505 void actionMultiShowActive(GtkToggleAction* action, AppData* app)
00506 {
00507         app->core->setActiveFrameVisible(gtk_toggle_action_get_active(action));
00508 }
00509 
00510 
00511 void actionMultiSyncTime(GtkToggleAction* action, AppData* app)
00512 {
00513         app->simulation->setSyncTime(gtk_toggle_action_get_active(action));
00514 }
00515 
00516 
00517 void actionRunDemo(GtkAction*, AppData* app)
00518 {
00519         app->core->charEntered('D');
00520 }
00521 
00522 
00523 void actionHelpControls(GtkAction*, AppData* app)
00524 {
00525         char *txt = readFromFile("controls.txt");
00526         textInfoDialog(txt, "Mouse and Keyboard Controls", app);
00527         g_free(txt);
00528 }
00529 
00530 
00531 void actionHelpOpenGL(GtkAction*, AppData* app)
00532 {
00533         /* Code grabbed from winmain.cpp */
00534         char* vendor = (char*) glGetString(GL_VENDOR);
00535         char* render = (char*) glGetString(GL_RENDERER);
00536         char* version = (char*) glGetString(GL_VERSION);
00537         char* ext = (char*) glGetString(GL_EXTENSIONS);
00538         
00539         string s;
00540         s = "Vendor: ";
00541         if (vendor != NULL)
00542                 s += vendor;
00543         s += "\n";
00544 
00545         s += "Renderer: ";
00546         if (render != NULL)
00547                 s += render;
00548         s += "\n";
00549 
00550         s += "Version: ";
00551         if (version != NULL)
00552                 s += version;
00553         s += "\n";
00554 
00555         char buf[100];
00556         GLint simTextures = 1;
00557         if (ExtensionSupported("GL_ARB_multitexture"))
00558                 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &simTextures);
00559         sprintf(buf, "Max simultaneous textures: %d\n", simTextures);
00560         s += buf;
00561 
00562         GLint maxTextureSize = 0;
00563         glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
00564         sprintf(buf, "Max texture size: %d\n\n", maxTextureSize);
00565         s += buf;
00566 
00567         s += "Supported Extensions:\n    ";
00568         if (ext != NULL)
00569         {
00570                 string extString(ext);
00571                 unsigned int pos = extString.find(' ', 0);
00572                 while (pos != (unsigned int)string::npos)
00573                 {
00574                         extString.replace(pos, 1, "\n    ");
00575                         pos = extString.find(' ', pos + 5);
00576                 }
00577                 s += extString;
00578         }
00579 
00580         textInfoDialog(s.c_str(), "Open GL Info", app);
00581 }
00582 
00583 
00584 void actionHelpAbout(GtkAction*, AppData* app)
00585 {
00586         const gchar* authors[] = {
00587                 "Active Developers ***\n",
00588                 "Grant Hutchison <grantcelestia@xemaps.com>\n"
00589                         "\tAstronomical Research\n",
00590                 "Da-Woon Jung <dirkpitt2050@gmail.com>\n"
00591                         "\tMacOSX Front-End\n",
00592                 "Chris Laurel <claurel@shatters.net>\n"
00593                         "\tOpenGL Engine, Windows Front-End\n",
00594                 "Fridger Schrempp <fridger.schrempp@desy.de>\n"
00595                         "\tResearch, Engine, GTK+ 1 Front-End\n",
00596                 "Pat Suwalski <pat@suwalski.net>\n"
00597                         "\tGTK+ 2 Front-End\n",
00598                 "Christophe Teyssier <chris@teyssier.org>\n"
00599                         "\tKDE Front-End, Browser Integration\n",
00600                 "\nPast Developers ***\n",
00601                 "Bob Ippolito <bob@redivi.com>",
00602                 "Deon Ramsey <dramsey@sourceforge.net>",
00603                 "Clint Weisbrod <cweisbrod@cogeco.ca>",
00604                 NULL
00605     };
00606 
00607         GdkPixbuf *logo = gdk_pixbuf_new_from_file ("celestia-logo.png", NULL);
00608         
00609         gtk_show_about_dialog(GTK_WINDOW(app->mainWindow),
00610                              "name", "Celestia",
00611                              "version", VERSION,
00612                              "copyright", "Copyright \xc2\xa9 2001-2005 Chris Laurel",
00613                              "comments", FRONTEND " Front-End",
00614                              "website", "http://celestia.sf.net",
00615                              "authors", authors,
00616                              "license", readFromFile("COPYING"),
00617                              "logo", logo,
00618                              NULL);
00619 }
00620 
00621 
00622 void actionVerbosity(GtkRadioAction* action, GtkRadioAction*, AppData* app)
00623 {
00624         int value = gtk_radio_action_get_current_value(action);
00625         app->core->setHudDetail(value);
00626         
00627         #ifdef GNOME
00628         gconf_client_set_int(app->client, "/apps/celestia/verbosity", value, NULL);
00629         #endif
00630 }
00631 
00632 
00633 void actionStarStyle(GtkRadioAction* action, GtkRadioAction*, AppData* app)
00634 {
00635         int value = gtk_radio_action_get_current_value(action);
00636         app->renderer->setStarStyle((Renderer::StarStyle)value);
00637         
00638         #ifdef GNOME
00639         gconf_client_set_int(app->client, "/apps/celestia/starStyle", value, NULL);
00640         #endif
00641 }
00642 
00643 
00644 void actionAmbientLight(GtkRadioAction* action, GtkRadioAction*, AppData* app)
00645 {
00646         float value = amLevels[gtk_radio_action_get_current_value(action)];
00647         app->renderer->setAmbientLightLevel(value);
00648 
00649         #ifdef GNOME
00650         gconf_client_set_float(app->client, "/apps/celestia/ambientLight", value, NULL);
00651         #endif
00652 }
00653 
00654 /* Render-Flag Actions */
00655 void actionRenderAA(GtkToggleAction* action, AppData* app)
00656 {
00657         setRenderFlag(app, Renderer::ShowSmoothLines, gtk_toggle_action_get_active(action));
00658 }
00659 
00660 
00661 void actionRenderAtmospheres(GtkToggleAction* action, AppData* app)
00662 {
00663         setRenderFlag(app, Renderer::ShowAtmospheres, gtk_toggle_action_get_active(action));
00664 }
00665 
00666 
00667 void actionRenderAutoMagnitude(GtkToggleAction* action, AppData* app)
00668 {
00669         setRenderFlag(app, Renderer::ShowAutoMag, gtk_toggle_action_get_active(action));
00670 }
00671 
00672 
00673 void actionRenderCelestialGrid(GtkToggleAction* action, AppData* app)
00674 {
00675         setRenderFlag(app, Renderer::ShowCelestialSphere, gtk_toggle_action_get_active(action));
00676 }
00677 
00678 
00679 void actionRenderClouds(GtkToggleAction* action, AppData* app)
00680 {
00681         setRenderFlag(app, Renderer::ShowCloudMaps, gtk_toggle_action_get_active(action));
00682 }
00683 
00684 
00685 void actionRenderCometTails(GtkToggleAction* action, AppData* app)
00686 {
00687         setRenderFlag(app, Renderer::ShowCometTails, gtk_toggle_action_get_active(action));
00688 }
00689 
00690 
00691 void actionRenderConstellationBoundaries(GtkToggleAction* action, AppData* app)
00692 {
00693         setRenderFlag(app, Renderer::ShowBoundaries, gtk_toggle_action_get_active(action));
00694 }
00695 
00696 
00697 void actionRenderConstellations(GtkToggleAction* action, AppData* app)
00698 {
00699         setRenderFlag(app, Renderer::ShowDiagrams, gtk_toggle_action_get_active(action));
00700 }
00701 
00702 
00703 void actionRenderEclipseShadows(GtkToggleAction* action, AppData* app)
00704 {
00705         setRenderFlag(app, Renderer::ShowEclipseShadows, gtk_toggle_action_get_active(action));
00706 }
00707 
00708 
00709 void actionRenderGalaxies(GtkToggleAction* action, AppData* app)
00710 {
00711         setRenderFlag(app, Renderer::ShowGalaxies, gtk_toggle_action_get_active(action));
00712 }
00713 
00714 
00715 void actionRenderMarkers(GtkToggleAction* action, AppData* app)
00716 {
00717         setRenderFlag(app, Renderer::ShowMarkers, gtk_toggle_action_get_active(action));
00718 }
00719 
00720 
00721 void actionRenderNebulae(GtkToggleAction* action, AppData* app)
00722 {
00723         setRenderFlag(app, Renderer::ShowNebulae, gtk_toggle_action_get_active(action));
00724 }
00725 
00726 
00727 void actionRenderNightLights(GtkToggleAction* action, AppData* app)
00728 {
00729         setRenderFlag(app, Renderer::ShowNightMaps, gtk_toggle_action_get_active(action));
00730 }
00731 
00732 
00733 void actionRenderOpenClusters(GtkToggleAction* action, AppData* app)
00734 {
00735         setRenderFlag(app, Renderer::ShowOpenClusters, gtk_toggle_action_get_active(action));
00736 }
00737 
00738 
00739 void actionRenderOrbits(GtkToggleAction* action, AppData* app)
00740 {
00741         setRenderFlag(app, Renderer::ShowOrbits, gtk_toggle_action_get_active(action));
00742 }
00743 
00744 
00745 void actionRenderPlanets(GtkToggleAction* action, AppData* app)
00746 {
00747         setRenderFlag(app, Renderer::ShowPlanets, gtk_toggle_action_get_active(action));
00748 }
00749 
00750 
00751 void actionRenderRingShadows(GtkToggleAction* action, AppData* app)
00752 {
00753         setRenderFlag(app, Renderer::ShowRingShadows, gtk_toggle_action_get_active(action));
00754 }
00755 
00756 
00757 void actionRenderStars(GtkToggleAction* action, AppData* app)
00758 {
00759         setRenderFlag(app, Renderer::ShowStars, gtk_toggle_action_get_active(action));
00760 }
00761 
00762 
00763 void actionOrbitAsteroids(GtkToggleAction* action, AppData* app)
00764 {
00765         setOrbitMask(app, Body::Asteroid, gtk_toggle_action_get_active(action));
00766 }
00767 
00768 
00769 void actionOrbitComets(GtkToggleAction* action, AppData* app)
00770 {
00771         setOrbitMask(app, Body::Comet, gtk_toggle_action_get_active(action));
00772 }
00773 
00774 
00775 void actionOrbitMoons(GtkToggleAction* action, AppData* app)
00776 {
00777         setOrbitMask(app, Body::Moon, gtk_toggle_action_get_active(action));
00778 }
00779 
00780 
00781 void actionOrbitPlanets(GtkToggleAction* action, AppData* app)
00782 {
00783         setOrbitMask(app, Body::Planet, gtk_toggle_action_get_active(action));
00784 }
00785 
00786 
00787 void actionOrbitSpacecraft(GtkToggleAction* action, AppData* app)
00788 {
00789         setOrbitMask(app, Body::Spacecraft, gtk_toggle_action_get_active(action));
00790 }
00791 
00792 
00793 void actionLabelAsteroids(GtkToggleAction* action, AppData* app)
00794 {
00795         setLabelMode(app, Renderer::AsteroidLabels, gtk_toggle_action_get_active(action));
00796 }
00797 
00798 
00799 void actionLabelComets(GtkToggleAction* action, AppData* app)
00800 {
00801         setLabelMode(app, Renderer::CometLabels, gtk_toggle_action_get_active(action));
00802 }
00803 
00804 
00805 void actionLabelConstellations(GtkToggleAction* action, AppData* app)
00806 {
00807         setLabelMode(app, Renderer::ConstellationLabels, gtk_toggle_action_get_active(action));
00808 }
00809 
00810 
00811 void actionLabelGalaxies(GtkToggleAction* action, AppData* app)
00812 {
00813         setLabelMode(app, Renderer::GalaxyLabels, gtk_toggle_action_get_active(action));
00814 }
00815 
00816 
00817 void actionLabelLocations(GtkToggleAction* action, AppData* app)
00818 {
00819         setLabelMode(app, Renderer::LocationLabels, gtk_toggle_action_get_active(action));
00820 }
00821 
00822 
00823 void actionLabelMoons(GtkToggleAction* action, AppData* app)
00824 {
00825         setLabelMode(app, Renderer::MoonLabels, gtk_toggle_action_get_active(action));
00826 }
00827 
00828 
00829 void actionLabelNebulae(GtkToggleAction* action, AppData* app)
00830 {
00831         setLabelMode(app, Renderer::NebulaLabels, gtk_toggle_action_get_active(action));
00832 }
00833 
00834 
00835 void actionLabelOpenClusters(GtkToggleAction* action, AppData* app)
00836 {
00837         setLabelMode(app, Renderer::OpenClusterLabels, gtk_toggle_action_get_active(action));
00838 }
00839 
00840 
00841 void actionLabelPlanets(GtkToggleAction* action, AppData* app)
00842 {
00843         setLabelMode(app, Renderer::PlanetLabels, gtk_toggle_action_get_active(action));
00844 }
00845 
00846 
00847 void actionLabelSpacecraft(GtkToggleAction* action, AppData* app)
00848 {
00849         setLabelMode(app, Renderer::SpacecraftLabels, gtk_toggle_action_get_active(action));
00850 }
00851 
00852 
00853 void actionLabelStars(GtkToggleAction* action, AppData* app)
00854 {
00855         setLabelMode(app, Renderer::StarLabels, gtk_toggle_action_get_active(action));
00856 }
00857 
00858 
00859 /* Script opening helper called by actionOpenScript() */
00860 static void openScript(const char* filename, AppData* app)
00861 {
00862         /* Modified From Win32 HandleOpenScript */
00863         if (filename)
00864         {
00865                 /* If you got here, a path and file has been specified.
00866                  * filename contains full path to specified file. */
00867                 ContentType type = DetermineFileType(filename);
00868 
00869                 if (type == Content_CelestiaScript)
00870                 {
00871                         app->core->runScript(filename);
00872                 }
00873                 else if (type == Content_CelestiaLegacyScript)
00874                 {
00875                         ifstream scriptfile(filename);
00876                         if (!scriptfile.good())
00877                         {
00878                                 GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00879                                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
00880                                                                            GTK_MESSAGE_ERROR,
00881                                                                            GTK_BUTTONS_OK,
00882                                                                            "Error opening script file.");
00883                                 gtk_dialog_run(GTK_DIALOG(errBox));
00884                                 gtk_widget_destroy(errBox);
00885                         }
00886                         else
00887                         {
00888                                 CommandParser parser(scriptfile);
00889                                 CommandSequence* script = parser.parse();
00890                                 if (script == NULL)
00891                                 {
00892                                         const vector<string>* errors = parser.getErrors();
00893                                         const char* errorMsg = "";
00894                                         if (errors->size() > 0)
00895                                                 errorMsg = (*errors)[0].c_str();
00896                                         GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00897                                                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
00898                                                                                    GTK_MESSAGE_ERROR,
00899                                                                                    GTK_BUTTONS_OK, "%s",
00900                                                                                    errorMsg);
00901                                         gtk_dialog_run(GTK_DIALOG(errBox));
00902                                         gtk_widget_destroy(errBox);
00903                                 }
00904                                 else
00905                                 {
00906                                         /* Cancel any running script */
00907                                         app->core->cancelScript();
00908                                         app->core->runScript(script);
00909                                 }
00910                         }
00911                 }
00912                 else
00913                 {
00914                         GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00915                                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
00916                                                                    GTK_MESSAGE_ERROR,
00917                                                                    GTK_BUTTONS_OK,
00918                                                                    "Bad File Type. Use *.(cel|celx|clx).");
00919                         gtk_dialog_run(GTK_DIALOG(errBox));
00920                         gtk_widget_destroy(errBox);
00921                 }
00922         }
00923 }
00924 
00925 
00926 /* Image capturing helper called by actionCaptureImage() */
00927 static void captureImage(const char* filename, AppData* app)
00928 {
00929         /* Get the dimensions of the current viewport */
00930         int viewport[4];
00931         glGetIntegerv(GL_VIEWPORT, viewport);
00932 
00933         bool success = false;
00934         ContentType type = DetermineFileType(filename);
00935         if (type == Content_Unknown)
00936         {
00937                 GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00938                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
00939                                                            GTK_MESSAGE_ERROR,
00940                                                            GTK_BUTTONS_OK,
00941                                                            "Unable to determine image file type from name, please use a name ending in '.jpg' or '.png'.");
00942                 gtk_dialog_run(GTK_DIALOG(errBox));
00943                 gtk_widget_destroy(errBox);
00944                 return;
00945         }
00946         else if (type == Content_JPEG)
00947         {
00948                 success = CaptureGLBufferToJPEG(filename,
00949                                                 viewport[0], viewport[1],
00950                                                 viewport[2], viewport[3]);
00951         }
00952         else if (type == Content_PNG)
00953         {
00954                 success = CaptureGLBufferToPNG(filename,
00955                                                viewport[0], viewport[1],
00956                                                viewport[2], viewport[3]);
00957         }
00958         else
00959         {
00960                 GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00961                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
00962                                                            GTK_MESSAGE_ERROR,
00963                                                            GTK_BUTTONS_OK,
00964                                                            "Currently screen capturing to only JPEG or PNG files is supported.");
00965                 gtk_dialog_run(GTK_DIALOG(errBox));
00966                 gtk_widget_destroy(errBox);
00967                 return;
00968         }
00969 
00970         if (!success)
00971         {
00972                 GtkWidget* errBox = gtk_message_dialog_new(GTK_WINDOW(app->mainWindow),
00973                                                            GTK_DIALOG_DESTROY_WITH_PARENT,
00974                                                            GTK_MESSAGE_ERROR,
00975                                                            GTK_BUTTONS_OK,
00976                                                            "Error writing captured image.");
00977                 gtk_dialog_run(GTK_DIALOG(errBox));
00978                 gtk_widget_destroy(errBox);
00979         }
00980 }
00981 
00982 
00983 /* Runs a dialog that displays text; should be replaced at some point with
00984    a more elegant solution. */
00985 static void textInfoDialog(const char *txt, const char *title, AppData* app)
00986 {
00987         /* I would use a gnome_message_box dialog for this, except they don't seem
00988          * to notice that the texts are so big that they create huge windows, and
00989          * would work better with a scrolled window. Deon */
00990         GtkWidget* dialog = gtk_dialog_new_with_buttons(title,
00991                                                         GTK_WINDOW(app->mainWindow),
00992                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
00993                                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
00994                                                         NULL);
00995 
00996         GtkWidget* scrolled_window = gtk_scrolled_window_new (NULL, NULL);
00997         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolled_window, TRUE, TRUE, 0);
00998         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window),
00999                                        GTK_POLICY_AUTOMATIC,
01000                                        GTK_POLICY_AUTOMATIC);
01001         gtk_widget_show(scrolled_window);
01002 
01003         GtkWidget *text = gtk_label_new(txt);
01004         gtk_widget_modify_font(text, pango_font_description_from_string("mono"));
01005         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), GTK_WIDGET(text));
01006         gtk_widget_show(text);
01007         
01008         gtk_window_set_default_size(GTK_WINDOW(dialog), 600, 400); /* Absolute Size, urghhh */
01009         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
01010 
01011         gtk_dialog_run(GTK_DIALOG(dialog));
01012         gtk_widget_destroy(dialog);
01013 }
01014 
01015 
01016 /* Calculates and sets the render-flag int */
01017 static void setRenderFlag(AppData* a, int flag, gboolean state)
01018 {
01019         int rf = (a->renderer->getRenderFlags() & ~flag) | (state ? flag : 0);
01020         a->renderer->setRenderFlags(rf);
01021         
01022         #ifdef GNOME
01023         /* Update GConf */
01024         gcSetRenderFlag(flag, state, a->client);
01025         #endif /* GNOME */
01026 }
01027 
01028 
01029 /* Calculates and sets the orbit-mask int */
01030 static void setOrbitMask(AppData* a, int mask, gboolean state)
01031 {
01032         int om = (a->renderer->getOrbitMask() & ~mask) | (state ? mask : 0);
01033         a->renderer->setOrbitMask(om);
01034         
01035         #ifdef GNOME
01036         /* Update GConf */
01037         gcSetOrbitMask(mask, state, a->client);
01038         #endif /* GNOME */
01039 }
01040 
01041 
01042 /* Calculates and sets the label-mode int */
01043 static void setLabelMode(AppData* a, int mode, gboolean state)
01044 {
01045         int lm = (a->renderer->getLabelMode() & ~mode) | (state ? mode : 0);
01046         a->renderer->setLabelMode(lm);
01047         
01048         #ifdef GNOME
01049         /* Update GConf */
01050         gcSetLabelMode(mode, state, a->client);
01051         #endif /* GNOME */
01052 }
01053 
01054 
01055 /* Synchronizes the Label Actions with the state of the core */
01056 void resyncLabelActions(AppData* app)
01057 {
01058         GtkAction* action;
01059         const char* actionName;
01060         
01061         /* Simply for readability */
01062         int f = app->renderer->getLabelMode();
01063         
01064         for (int i = Renderer::StarLabels; i <= Renderer::I18nConstellationLabels; i *= 2)
01065         {
01066                 switch (i)
01067                 {
01068                         case Renderer::StarLabels: actionName = "LabelStars"; break;
01069                         case Renderer::PlanetLabels: actionName = "LabelPlanets"; break;
01070                         case Renderer::MoonLabels: actionName = "LabelMoons"; break;
01071                         case Renderer::ConstellationLabels: actionName = "LabelConstellations"; break;
01072                         case Renderer::GalaxyLabels: actionName = "LabelGalaxies"; break;
01073                         case Renderer::AsteroidLabels: actionName = "LabelAsteroids"; break;
01074                         case Renderer::SpacecraftLabels: actionName = "LabelSpacecraft"; break;
01075                         case Renderer::LocationLabels: actionName = "LabelLocations"; break;
01076                         case Renderer::CometLabels: actionName = "LabelComets"; break;
01077                         case Renderer::NebulaLabels: actionName = "LabelNebulae"; break;
01078                         case Renderer::OpenClusterLabels: actionName = "LabelOpenClusters"; break;
01079                         case Renderer::I18nConstellationLabels: /* Not used yet */
01080                         default: actionName = NULL;
01081                 }
01082                 
01083                 if (actionName != NULL)
01084                 {
01085                         /* Get the action */
01086                         action = gtk_action_group_get_action(app->agLabel, actionName);
01087                         
01088                         /* The current i anded with the labelMode gives state of flag */
01089                         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & f));
01090                 }
01091         }
01092 }
01093 
01094 
01095 /* Synchronizes the Render Actions with the state of the core */
01096 void resyncRenderActions(AppData* app)
01097 {
01098         GtkAction* action;
01099         const char* actionName;
01100         
01101         /* Simply for readability */
01102         int rf = app->renderer->getRenderFlags();
01103         
01104         /* Unlike the other interfaces, which go through each menu item and set
01105          * the corresponding renderFlag, we go the other way and set the menu
01106          * based on the renderFlag. Last one is ShowOpenClusters. */
01107         
01108         for (int i = Renderer::ShowStars; i <= Renderer::ShowOpenClusters; i *= 2)
01109         {
01110                 switch (i)
01111                 {
01112                         case Renderer::ShowStars: actionName = "RenderStars"; break;
01113                         case Renderer::ShowPlanets: actionName = "RenderPlanets"; break;
01114                         case Renderer::ShowGalaxies: actionName = "RenderGalaxies"; break;
01115                         case Renderer::ShowDiagrams: actionName = "RenderConstellations"; break;
01116                         case Renderer::ShowCloudMaps: actionName = "RenderClouds"; break;
01117                         case Renderer::ShowOrbits: actionName = "RenderOrbits"; break;
01118                         case Renderer::ShowCelestialSphere: actionName = "RenderCelestialGrid"; break;
01119                         case Renderer::ShowNightMaps: actionName = "RenderNightLights"; break;
01120                         case Renderer::ShowAtmospheres: actionName = "RenderAtmospheres"; break;
01121                         case Renderer::ShowSmoothLines: actionName = "RenderAA"; break;
01122                         case Renderer::ShowEclipseShadows: actionName = "RenderEclipseShadows"; break;
01123                         case Renderer::ShowStarsAsPoints: actionName = NULL; break; /* Deprecated */
01124                         case Renderer::ShowRingShadows: actionName = "RenderRingShadows"; break;
01125                         case Renderer::ShowBoundaries: actionName = "RenderConstellationBoundaries"; break;
01126                         case Renderer::ShowAutoMag: actionName = "RenderAutoMagnitude"; break;
01127                         case Renderer::ShowCometTails: actionName = "RenderCometTails"; break;
01128                         case Renderer::ShowMarkers: actionName = "RenderMarkers"; break;
01129                         case Renderer::ShowPartialTrajectories: actionName = NULL; break; /* Not useful yet */
01130                         case Renderer::ShowNebulae: actionName = "RenderNebulae"; break;
01131                         case Renderer::ShowOpenClusters: actionName = "RenderOpenClusters"; break;
01132                         default: actionName = NULL;
01133                 }
01134                 
01135                 if (actionName != NULL)
01136                 {
01137                         /* Get the action */
01138                         action = gtk_action_group_get_action(app->agRender, actionName);
01139                         
01140                         /* The current i anded with the renderFlags gives state of flag */
01141                         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & rf));
01142                 }
01143         }
01144 }
01145 
01146 
01147 /* Synchronizes the Orbit Actions with the state of the core */
01148 void resyncOrbitActions(AppData* app)
01149 {
01150         GtkAction* action;
01151         const char* actionName;
01152         
01153         /* Simply for readability */
01154         int om = app->renderer->getOrbitMask();
01155         
01156         for (int i = Body::Planet; i <= Body::Spacecraft; i *= 2)
01157         {
01158                 switch (i)
01159                 {
01160                         case Body::Planet: actionName = "OrbitPlanets"; break;
01161                         case Body::Moon: actionName = "OrbitMoons"; break;
01162                         case Body::Asteroid: actionName = "OrbitAsteroids"; break;
01163                         case Body::Comet: actionName = "OrbitComets"; break;
01164                         case Body::Spacecraft: actionName = "OrbitSpacecraft"; break;
01165                         default: actionName = NULL;
01166                 }
01167                 
01168                 if (actionName != NULL)
01169                 {
01170                         /* Get the action */
01171                         action = gtk_action_group_get_action(app->agOrbit, actionName);
01172                         
01173                         /* The current i anded with the orbitMask gives state of flag */
01174                         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), (i & om));
01175                 }
01176         }
01177 }
01178 
01179 
01180 /* Synchronizes the Verbosity Actions with the state of the core */
01181 void resyncVerbosityActions(AppData* app)
01182 {
01183         GtkAction* action;
01184         const char* actionName;
01185         
01186         switch (app->core->getHudDetail())
01187         {
01188                 case 0: actionName = "HudNone"; break;
01189                 case 1: actionName = "HudTerse"; break;
01190                 case 2: actionName = "HudVerbose"; break;
01191                 default: return;
01192         }
01193         
01194         /* Get the action, set the widget */
01195         action = gtk_action_group_get_action(app->agVerbosity, actionName);
01196         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
01197 }
01198 
01199 
01200 /* Synchronizes the TimeZone Action with the state of the core */
01201 void resyncTimeZoneAction(AppData* app)
01202 {
01203         /* Get the action, set the widget */
01204         GtkAction* action = gtk_action_group_get_action(app->agMain, "TimeLocal");
01205         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), app->showLocalTime);
01206 }
01207 
01208 
01209 /* Synchronizes the Ambient Light Actions with the state of the core */
01210 void resyncAmbientActions(AppData* app)
01211 {
01212         GtkAction* action;
01213 
01214         float ambient = app->renderer->getAmbientLightLevel();
01215         
01216         /* Try to be smart about being close to the value of a float */
01217         if (ambient > amLevels[0] && ambient < (amLevels[1] / 2.0))
01218                 action = gtk_action_group_get_action(app->agAmbient, "AmbientNone");
01219         
01220         else if (ambient < amLevels[1] + ((amLevels[2] - amLevels[1]) / 2.0))
01221                 action = gtk_action_group_get_action(app->agAmbient, "AmbientLow");
01222         
01223         else
01224                 action = gtk_action_group_get_action(app->agAmbient, "AmbientMedium");
01225         
01226         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
01227         
01228         #ifdef GNOME
01229         /* The action callback only occurs when one of the None/Low/Medium barriers
01230          * is surpassed, so an update is forced. */
01231         gconf_client_set_float(app->client, "/apps/celestia/ambientLight", ambient, NULL);
01232         #endif
01233 }
01234 
01235 
01236 /* Synchronizes the Verbosity Actions with the state of the core */
01237 void resyncStarStyleActions(AppData* app)
01238 {
01239         GtkAction* action;
01240         const char* actionName;
01241         
01242         switch (app->renderer->getStarStyle())
01243         {
01244                 case Renderer::FuzzyPointStars: actionName = "StarsFuzzy"; break;
01245                 case Renderer::PointStars: actionName = "StarsPoints"; break;
01246                 case Renderer::ScaledDiscStars: actionName = "StarsDiscs"; break;
01247                 default: return;
01248         }
01249         
01250         /* Get the action, set the widget */
01251         action = gtk_action_group_get_action(app->agStarStyle, actionName);
01252         gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE);
01253 }
01254 
01255 
01256 /* Placeholder for when galaxy brightness is added as an action */
01257 void resyncGalaxyGainActions(AppData* app)
01258 {
01259         float gain = Galaxy::getLightGain();
01260         
01261         #ifdef GNOME
01262         gconf_client_set_float(app->client, "/apps/celestia/galaxyLightGain", gain, NULL);
01263         #endif
01264 }

Generated on Sat Jan 14 22:30:30 2006 for Celestia by  doxygen 1.4.1