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

dialog-tour.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: dialog-tour.cpp,v 1.1 2005/12/06 03:19:35 suwalski Exp $
00011  */
00012 
00013 #include <glib.h>
00014 #include <gtk/gtk.h>
00015 
00016 #include <celestia/destination.h>
00017 #include <celmath/vecmath.h>
00018 
00019 #include "dialog-tour.h"
00020 #include "common.h"
00021 
00022 
00023 /* Declarations: Callbacks */
00024 static gint TourGuideSelect(GtkWidget* w, TourData* td);
00025 static gint TourGuideGoto(GtkWidget*, TourData* td);
00026 static void TourGuideDestroy(GtkWidget* w, gint, TourData* td);
00027 
00028 
00029 /* ENTRY: Navigation->Tour Guide... */
00030 void dialogTourGuide(AppData* app)
00031 {
00032         TourData* td = g_new0(TourData, 1);
00033         td->app = app;
00034 
00035         GtkWidget* dialog = gtk_dialog_new_with_buttons("Tour Guide...",
00036                                                         GTK_WINDOW(app->mainWindow),
00037                                                         GTK_DIALOG_DESTROY_WITH_PARENT,
00038                                                         GTK_STOCK_CLOSE,
00039                                                         GTK_RESPONSE_CLOSE,
00040                                                         NULL);
00041 
00042         GtkWidget* hbox = gtk_hbox_new(FALSE, CELSPACING); 
00043         gtk_container_set_border_width(GTK_CONTAINER(hbox), CELSPACING);
00044 
00045         GtkWidget* label = gtk_label_new("Select your destination:");
00046         gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
00047 
00048         GtkWidget* menubox = gtk_option_menu_new();
00049         gtk_box_pack_start(GTK_BOX(hbox), menubox, TRUE, TRUE, 0);
00050 
00051         GtkWidget* gotoButton = gtk_button_new_with_label("Go To");
00052         gtk_box_pack_start(GTK_BOX(hbox), gotoButton, TRUE, TRUE, 0);
00053 
00054         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 0);
00055 
00056         gtk_widget_show(hbox);
00057 
00058         td->descLabel = gtk_label_new("");
00059         gtk_label_set_line_wrap(GTK_LABEL(td->descLabel), TRUE);
00060         gtk_label_set_justify(GTK_LABEL(td->descLabel), GTK_JUSTIFY_FILL);
00061         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), td->descLabel, TRUE, TRUE, 0);
00062 
00063         GtkWidget* menu = gtk_menu_new();
00064         const DestinationList* destinations = app->core->getDestinations();
00065         if (destinations != NULL)
00066         {
00067                 for (DestinationList::const_iterator iter = destinations->begin();
00068                      iter != destinations->end(); iter++)
00069                 {
00070                         Destination* dest = *iter;
00071                         if (dest != NULL)
00072                         {
00073                                 GtkWidget* item = gtk_menu_item_new_with_label(dest->name.c_str());
00074                                 gtk_menu_append(GTK_MENU(menu), item);
00075                                 gtk_widget_show(item);
00076                         }
00077                 }
00078         }
00079 
00080         g_signal_connect(GTK_OBJECT(menu),
00081                          "selection-done",
00082                          G_CALLBACK(TourGuideSelect),
00083                          td);
00084         g_signal_connect(GTK_OBJECT(gotoButton),
00085                          "pressed",
00086                          G_CALLBACK(TourGuideGoto),
00087                          td);
00088         g_signal_connect(dialog,
00089                          "response",
00090                          G_CALLBACK(TourGuideDestroy),
00091                          td);
00092 
00093         gtk_option_menu_set_menu(GTK_OPTION_MENU(menubox), menu);
00094 
00095         gtk_widget_set_usize(dialog, 440, 300);
00096 
00097         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
00098         gtk_widget_show_all(dialog);
00099 }
00100 
00101 
00102 /* CALLBACK: tour list object selected */
00103 static gint TourGuideSelect(GtkWidget* w, TourData* td)
00104 {
00105         GtkMenu* menu = GTK_MENU(w);
00106         if (menu == NULL)
00107                 return FALSE;
00108 
00109         GtkWidget* item = gtk_menu_get_active(GTK_MENU(menu));
00110         if (item == NULL)
00111                 return FALSE;
00112 
00113         GList* list = gtk_container_children(GTK_CONTAINER(menu));
00114         int itemIndex = g_list_index(list, item);
00115 
00116         const DestinationList* destinations = td->app->core->getDestinations();
00117         if (destinations != NULL &&
00118             itemIndex >= 0 && itemIndex < (int) destinations->size())
00119         {
00120                 td->selected = (*destinations)[itemIndex];
00121         }
00122 
00123         if (td->descLabel != NULL && td->selected != NULL)
00124         {
00125                 gtk_label_set_text(GTK_LABEL(td->descLabel), td->selected->description.c_str());
00126         }
00127 
00128         return TRUE;
00129 }
00130 
00131 
00132 /* CALLBACK: Goto button clicked */
00133 static gint TourGuideGoto(GtkWidget*, TourData* td)
00134 {
00135         Simulation* simulation = td->app->simulation;
00136         
00137         if (td->selected != NULL && simulation != NULL)
00138         {
00139                 Selection sel = simulation->findObjectFromPath(td->selected->target);
00140                 if (!sel.empty())
00141                 {
00142                         simulation->follow();
00143                         simulation->setSelection(sel);
00144                         if (td->selected->distance <= 0)
00145                         {
00146                                 /* Use the default distance */
00147                                 simulation->gotoSelection(5.0,
00148                                                           Vec3f(0, 1, 0),
00149                                                           astro::ObserverLocal);
00150                         }
00151                         else
00152                         {
00153                                 simulation->gotoSelection(5.0,
00154                                                           td->selected->distance,
00155                                                           Vec3f(0, 1, 0),
00156                                                           astro::ObserverLocal);
00157                         }
00158                 }
00159         }
00160 
00161         return TRUE;
00162 }
00163 
00164 
00165 /* CALLBACK: Destroy Window */
00166 static void TourGuideDestroy(GtkWidget* w, gint, TourData* td)
00167 {
00168         gtk_widget_destroy(GTK_WIDGET(w));
00169         g_free(td);
00170 }

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