dialog-tour.cpp
上传用户:center1979
上传日期:2022-07-26
资源大小:50633k
文件大小:5k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /*
  2.  *  Celestia GTK+ Front-End
  3.  *  Copyright (C) 2005 Pat Suwalski <pat@suwalski.net>
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  $Id: dialog-tour.cpp,v 1.1 2005-12-06 03:19:35 suwalski Exp $
  11.  */
  12. #include <glib.h>
  13. #include <gtk/gtk.h>
  14. #include <celestia/destination.h>
  15. #include <celmath/vecmath.h>
  16. #include "dialog-tour.h"
  17. #include "common.h"
  18. /* Declarations: Callbacks */
  19. static gint TourGuideSelect(GtkWidget* w, TourData* td);
  20. static gint TourGuideGoto(GtkWidget*, TourData* td);
  21. static void TourGuideDestroy(GtkWidget* w, gint, TourData* td);
  22. /* ENTRY: Navigation->Tour Guide... */
  23. void dialogTourGuide(AppData* app)
  24. {
  25. TourData* td = g_new0(TourData, 1);
  26. td->app = app;
  27. GtkWidget* dialog = gtk_dialog_new_with_buttons("Tour Guide...",
  28.                                                 GTK_WINDOW(app->mainWindow),
  29.                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
  30.                                                 GTK_STOCK_CLOSE,
  31.                                                 GTK_RESPONSE_CLOSE,
  32.                                                 NULL);
  33. GtkWidget* hbox = gtk_hbox_new(FALSE, CELSPACING); 
  34. gtk_container_set_border_width(GTK_CONTAINER(hbox), CELSPACING);
  35. GtkWidget* label = gtk_label_new("Select your destination:");
  36. gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
  37. GtkWidget* menubox = gtk_option_menu_new();
  38. gtk_box_pack_start(GTK_BOX(hbox), menubox, TRUE, TRUE, 0);
  39. GtkWidget* gotoButton = gtk_button_new_with_label("Go To");
  40. gtk_box_pack_start(GTK_BOX(hbox), gotoButton, TRUE, TRUE, 0);
  41. gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 0);
  42. gtk_widget_show(hbox);
  43. td->descLabel = gtk_label_new("");
  44. gtk_label_set_line_wrap(GTK_LABEL(td->descLabel), TRUE);
  45. gtk_label_set_justify(GTK_LABEL(td->descLabel), GTK_JUSTIFY_FILL);
  46. gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), td->descLabel, TRUE, TRUE, 0);
  47. GtkWidget* menu = gtk_menu_new();
  48. const DestinationList* destinations = app->core->getDestinations();
  49. if (destinations != NULL)
  50. {
  51. for (DestinationList::const_iterator iter = destinations->begin();
  52.      iter != destinations->end(); iter++)
  53. {
  54. Destination* dest = *iter;
  55. if (dest != NULL)
  56. {
  57. GtkWidget* item = gtk_menu_item_new_with_label(dest->name.c_str());
  58. gtk_menu_append(GTK_MENU(menu), item);
  59. gtk_widget_show(item);
  60. }
  61. }
  62. }
  63. g_signal_connect(GTK_OBJECT(menu),
  64.                  "selection-done",
  65.                  G_CALLBACK(TourGuideSelect),
  66.                  td);
  67. g_signal_connect(GTK_OBJECT(gotoButton),
  68.                  "pressed",
  69.                  G_CALLBACK(TourGuideGoto),
  70.                  td);
  71. g_signal_connect(dialog,
  72.                  "response",
  73.                  G_CALLBACK(TourGuideDestroy),
  74.                  td);
  75. gtk_option_menu_set_menu(GTK_OPTION_MENU(menubox), menu);
  76. gtk_widget_set_usize(dialog, 440, 300);
  77. gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
  78. gtk_widget_show_all(dialog);
  79. }
  80. /* CALLBACK: tour list object selected */
  81. static gint TourGuideSelect(GtkWidget* w, TourData* td)
  82. {
  83. GtkMenu* menu = GTK_MENU(w);
  84. if (menu == NULL)
  85. return FALSE;
  86. GtkWidget* item = gtk_menu_get_active(GTK_MENU(menu));
  87. if (item == NULL)
  88. return FALSE;
  89. GList* list = gtk_container_children(GTK_CONTAINER(menu));
  90. int itemIndex = g_list_index(list, item);
  91. const DestinationList* destinations = td->app->core->getDestinations();
  92. if (destinations != NULL &&
  93.     itemIndex >= 0 && itemIndex < (int) destinations->size())
  94. {
  95. td->selected = (*destinations)[itemIndex];
  96. }
  97. if (td->descLabel != NULL && td->selected != NULL)
  98. {
  99. gtk_label_set_text(GTK_LABEL(td->descLabel), td->selected->description.c_str());
  100. }
  101. return TRUE;
  102. }
  103. /* CALLBACK: Goto button clicked */
  104. static gint TourGuideGoto(GtkWidget*, TourData* td)
  105. {
  106. Simulation* simulation = td->app->simulation;
  107. if (td->selected != NULL && simulation != NULL)
  108. {
  109. Selection sel = simulation->findObjectFromPath(td->selected->target);
  110. if (!sel.empty())
  111. {
  112. simulation->follow();
  113. simulation->setSelection(sel);
  114. if (td->selected->distance <= 0)
  115. {
  116. /* Use the default distance */
  117. simulation->gotoSelection(5.0,
  118.                           Vec3f(0, 1, 0),
  119.                           ObserverFrame::ObserverLocal);
  120. }
  121. else
  122. {
  123. simulation->gotoSelection(5.0,
  124.                           td->selected->distance,
  125.                           Vec3f(0, 1, 0),
  126.                           ObserverFrame::ObserverLocal);
  127. }
  128. }
  129. }
  130. return TRUE;
  131. }
  132. /* CALLBACK: Destroy Window */
  133. static void TourGuideDestroy(GtkWidget* w, gint, TourData* td)
  134. {
  135. gtk_widget_destroy(GTK_WIDGET(w));
  136. g_free(td);
  137. }