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

OpenGL

开发平台:

Visual C++

  1. // wintourguide.cpp
  2. // 
  3. // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
  4. //
  5. // Space 'tour guide' dialog for Windows.
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. #include <string>
  12. #include <sstream>
  13. #include <algorithm>
  14. #include <set>
  15. #include <windows.h>
  16. #include <commctrl.h>
  17. #include "wintourguide.h"
  18. #include <celutil/winutil.h>
  19. #include "res/resource.h"
  20. using namespace std;
  21. BOOL APIENTRY TourGuideProc(HWND hDlg,
  22.                             UINT message,
  23.                             UINT wParam,
  24.                             LONG lParam)
  25. {
  26.     TourGuide* tourGuide = reinterpret_cast<TourGuide*>(GetWindowLong(hDlg, DWL_USER));
  27.     switch (message)
  28.     {
  29.     case WM_INITDIALOG:
  30.         {
  31.             TourGuide* guide = reinterpret_cast<TourGuide*>(lParam);
  32.             if (guide == NULL)
  33.                 return EndDialog(hDlg, 0);
  34.             SetWindowLong(hDlg, DWL_USER, lParam);
  35.             guide->selectedDest = NULL;
  36.             HWND hwnd = GetDlgItem(hDlg, IDC_COMBO_TOURGUIDE);
  37.             const DestinationList* destinations = guide->appCore->getDestinations();
  38.             if (hwnd != NULL && destinations != NULL)
  39.             {
  40.                 for (DestinationList::const_iterator iter = destinations->begin();
  41.                      iter != destinations->end(); iter++)
  42.                 {
  43.                     Destination* dest = *iter;
  44.                     if (dest != NULL)
  45.                     {
  46.                         SendMessage(hwnd, CB_INSERTSTRING, -1,
  47.                                     reinterpret_cast<LPARAM>(UTF8ToCurrentCP(dest->name).c_str()));
  48.                     }
  49.                 }
  50.                 if (destinations->size() > 0)
  51.                 {
  52.                     SendMessage(hwnd, CB_SETCURSEL, 0, 0);
  53.                     SetDlgItemText(hDlg,
  54.                                    IDC_TEXT_DESCRIPTION,
  55.                                    UTF8ToCurrentCP((*destinations)[0]->description).c_str());
  56.                 }
  57.             }
  58.         }
  59.         return(TRUE);
  60.     case WM_DESTROY:
  61.         if (tourGuide != NULL && tourGuide->parent != NULL)
  62.         {
  63.             SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
  64.                         reinterpret_cast<LPARAM>(tourGuide));
  65.         }
  66.         break;
  67.     case WM_COMMAND:
  68.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  69.         {
  70.             if (tourGuide != NULL && tourGuide->parent != NULL)
  71.             {
  72.                 SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
  73.                             reinterpret_cast<LPARAM>(tourGuide));
  74.             }
  75.             EndDialog(hDlg, 0);
  76.             return TRUE;
  77.         }
  78.         else if (LOWORD(wParam) == IDC_BUTTON_GOTO)
  79.         {
  80.             Simulation* sim = tourGuide->appCore->getSimulation();
  81.             if (tourGuide->selectedDest != NULL && sim != NULL)
  82.             {
  83.                 Selection sel = sim->findObjectFromPath(tourGuide->selectedDest->target);
  84.                 if (!sel.empty())
  85.                 {
  86.                     sim->follow();
  87.                     sim->setSelection(sel);
  88.                     if (tourGuide->selectedDest->distance <= 0)
  89.                     {
  90.                         // Use the default distance
  91.                         sim->gotoSelection(5.0,
  92.                                            Vec3f(0, 1, 0),
  93.                                            ObserverFrame::ObserverLocal);
  94.                     }
  95.                     else
  96.                     {
  97.                         sim->gotoSelection(5.0,
  98.                                            tourGuide->selectedDest->distance,
  99.                                            Vec3f(0, 1, 0),
  100.                                            ObserverFrame::ObserverLocal);
  101.                     }
  102.                 }
  103.             }
  104.         }
  105.         else if (LOWORD(wParam) == IDC_COMBO_TOURGUIDE)
  106.         {
  107.             if (HIWORD(wParam) == CBN_SELCHANGE)
  108.             {
  109.                 HWND hwnd = reinterpret_cast<HWND>(lParam);
  110.                 int item = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
  111.                 const DestinationList* destinations = tourGuide->appCore->getDestinations();
  112.                 if (item != CB_ERR && item < (int) destinations->size())
  113.                 {
  114.                     Destination* dest = (*destinations)[item];
  115.                     SetDlgItemText(hDlg,
  116.                                    IDC_TEXT_DESCRIPTION,
  117.                                    UTF8ToCurrentCP(dest->description).c_str());
  118.                     tourGuide->selectedDest = dest;
  119.                 }
  120.             }
  121.         }
  122.         break;
  123.     }
  124.     return FALSE;
  125. }
  126. TourGuide::TourGuide(HINSTANCE appInstance,
  127.                      HWND _parent,
  128.                      CelestiaCore* _appCore) :
  129.     appCore(_appCore),
  130.     selectedDest(NULL),
  131.     parent(_parent)
  132. {
  133.     hwnd = CreateDialogParam(appInstance,
  134.                              MAKEINTRESOURCE(IDD_TOURGUIDE),
  135.                              parent,
  136.                              TourGuideProc,
  137.                              reinterpret_cast<LONG>(this));
  138. }