00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <string>
00013 #include <sstream>
00014 #include <algorithm>
00015 #include <set>
00016 #include <windows.h>
00017 #include <commctrl.h>
00018 #include "wintourguide.h"
00019
00020 #include "res/resource.h"
00021
00022 using namespace std;
00023
00024
00025 BOOL APIENTRY TourGuideProc(HWND hDlg,
00026 UINT message,
00027 UINT wParam,
00028 LONG lParam)
00029 {
00030 TourGuide* tourGuide = reinterpret_cast<TourGuide*>(GetWindowLong(hDlg, DWL_USER));
00031
00032 switch (message)
00033 {
00034 case WM_INITDIALOG:
00035 {
00036 TourGuide* guide = reinterpret_cast<TourGuide*>(lParam);
00037 if (guide == NULL)
00038 return EndDialog(hDlg, 0);
00039 SetWindowLong(hDlg, DWL_USER, lParam);
00040
00041 guide->selectedDest = NULL;
00042
00043 HWND hwnd = GetDlgItem(hDlg, IDC_COMBO_TOURGUIDE);
00044 const DestinationList* destinations = guide->appCore->getDestinations();
00045 if (hwnd != NULL && destinations != NULL)
00046 {
00047 for (DestinationList::const_iterator iter = destinations->begin();
00048 iter != destinations->end(); iter++)
00049 {
00050 Destination* dest = *iter;
00051 if (dest != NULL)
00052 {
00053 SendMessage(hwnd, CB_INSERTSTRING, -1,
00054 reinterpret_cast<LPARAM>(dest->name.c_str()));
00055 }
00056 }
00057
00058 if (destinations->size() > 0)
00059 {
00060 SendMessage(hwnd, CB_SETCURSEL, 0, 0);
00061 SetDlgItemText(hDlg,
00062 IDC_TEXT_DESCRIPTION,
00063 (*destinations)[0]->description.c_str());
00064 }
00065 }
00066 }
00067 return(TRUE);
00068
00069 case WM_DESTROY:
00070 if (tourGuide != NULL && tourGuide->parent != NULL)
00071 {
00072 SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
00073 reinterpret_cast<LPARAM>(tourGuide));
00074 }
00075 break;
00076
00077 case WM_COMMAND:
00078 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00079 {
00080 if (tourGuide != NULL && tourGuide->parent != NULL)
00081 {
00082 SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
00083 reinterpret_cast<LPARAM>(tourGuide));
00084 }
00085 EndDialog(hDlg, 0);
00086 return TRUE;
00087 }
00088 else if (LOWORD(wParam) == IDC_BUTTON_GOTO)
00089 {
00090 Simulation* sim = tourGuide->appCore->getSimulation();
00091 if (tourGuide->selectedDest != NULL && sim != NULL)
00092 {
00093 Selection sel = sim->findObjectFromPath(tourGuide->selectedDest->target);
00094 if (!sel.empty())
00095 {
00096 sim->follow();
00097 sim->setSelection(sel);
00098 if (tourGuide->selectedDest->distance <= 0)
00099 {
00100
00101 sim->gotoSelection(5.0,
00102 Vec3f(0, 1, 0),
00103 astro::ObserverLocal);
00104 }
00105 else
00106 {
00107 sim->gotoSelection(5.0,
00108 tourGuide->selectedDest->distance,
00109 Vec3f(0, 1, 0),
00110 astro::ObserverLocal);
00111 }
00112 }
00113 }
00114 }
00115 else if (LOWORD(wParam) == IDC_COMBO_TOURGUIDE)
00116 {
00117 if (HIWORD(wParam) == CBN_SELCHANGE)
00118 {
00119 HWND hwnd = reinterpret_cast<HWND>(lParam);
00120 int item = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
00121 const DestinationList* destinations = tourGuide->appCore->getDestinations();
00122 if (item != CB_ERR && item < destinations->size())
00123 {
00124 Destination* dest = (*destinations)[item];
00125 SetDlgItemText(hDlg,
00126 IDC_TEXT_DESCRIPTION,
00127 dest->description.c_str());
00128 tourGuide->selectedDest = dest;
00129 }
00130 }
00131 }
00132 break;
00133 }
00134
00135 return FALSE;
00136 }
00137
00138
00139 TourGuide::TourGuide(HINSTANCE appInstance,
00140 HWND _parent,
00141 CelestiaCore* _appCore) :
00142 appCore(_appCore),
00143 selectedDest(NULL),
00144 parent(_parent)
00145 {
00146 hwnd = CreateDialogParam(appInstance,
00147 MAKEINTRESOURCE(IDD_TOURGUIDE),
00148 parent,
00149 TourGuideProc,
00150 reinterpret_cast<LONG>(this));
00151 }