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

OpenGL

开发平台:

Visual C++

  1. // winlocations.cpp
  2. // 
  3. // Copyright (C) 2002, Chris Laurel <claurel@shatters.net>
  4. //
  5. // Miscellaneous utilities for Locations UI implementation.
  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 "winlocations.h"
  12. #include "res/resource.h"
  13. #include <celutil/winutil.h>
  14. using namespace std;
  15. static const int FeatureSizeSliderRange = 100;
  16. static const float MinFeatureSize = 1.0f;
  17. static const float MaxFeatureSize = 100.0f;
  18. static const uint32 FilterOther = ~(Location::City |
  19.                                     Location::Observatory |
  20.                                     Location::LandingSite |
  21.                                     Location::Crater |
  22.                                     Location::Mons |
  23.                                     Location::Terra |
  24.                                     Location::EruptiveCenter |
  25.                                     Location::Vallis |
  26.                                     Location::Mare);
  27. static BOOL APIENTRY LocationsProc(HWND hDlg,
  28.                                    UINT message,
  29.                                    UINT wParam,
  30.                                    LONG lParam)
  31. {
  32.     LocationsDialog* dlg = reinterpret_cast<LocationsDialog*>(GetWindowLong(hDlg, DWL_USER));
  33.     switch (message)
  34.     {
  35.     case WM_INITDIALOG:
  36.         {
  37.             dlg = reinterpret_cast<LocationsDialog*>(lParam);
  38.             if (dlg == NULL)
  39.                 return EndDialog(hDlg, 0);
  40.             SetWindowLong(hDlg, DWL_USER, lParam);
  41.             // Store original settings in case user cancels the dialog
  42.             // dlg->initialLocationFlags = dlg->appCore->getSimulation()->getActiveObserver();
  43.             dlg->initialLocationFlags = 0;
  44.             dlg->initialFeatureSize = dlg->appCore->getRenderer()->getMinimumFeatureSize();
  45.             // Set dialog controls to reflect current label and render modes
  46.             dlg->SetControls(hDlg);
  47.             return(TRUE);
  48.         }
  49.         break;
  50.     case WM_COMMAND:
  51.     {
  52.         Observer* obs = dlg->appCore->getSimulation()->getActiveObserver();
  53.         uint32 locationFilter = obs->getLocationFilter();
  54.         
  55.         switch (LOWORD(wParam))
  56.         {
  57.         case IDC_SHOW_CITIES:
  58.             obs->setLocationFilter(locationFilter ^ Location::City);
  59.             break;
  60.         case IDC_SHOW_OBSERVATORIES:
  61.             obs->setLocationFilter(locationFilter ^ Location::Observatory);
  62.             break;
  63.         case IDC_SHOW_LANDING_SITES:
  64.             obs->setLocationFilter(locationFilter ^ Location::LandingSite);
  65.             break;
  66.         case IDC_SHOW_MONTES:
  67.             obs->setLocationFilter(locationFilter ^ Location::Mons);
  68.             break;
  69.         case IDC_SHOW_MARIA:
  70.             obs->setLocationFilter(locationFilter ^ Location::Mare);
  71.             break;
  72.         case IDC_SHOW_CRATERS:
  73.             obs->setLocationFilter(locationFilter ^ Location::Crater);
  74.             break;
  75.         case IDC_SHOW_VALLES:
  76.             obs->setLocationFilter(locationFilter ^ Location::Vallis);
  77.             break;
  78.         case IDC_SHOW_TERRAE:
  79.             obs->setLocationFilter(locationFilter ^ Location::Terra);
  80.             break;
  81.         case IDC_SHOW_VOLCANOES:
  82.             obs->setLocationFilter(locationFilter ^ Location::EruptiveCenter);
  83.             break;
  84.         case IDC_SHOW_OTHERS:
  85.             obs->setLocationFilter(locationFilter ^ FilterOther);
  86.             break;
  87.         case IDC_LABELFEATURES:
  88.             {
  89.                 Renderer* renderer = dlg->appCore->getRenderer();
  90.                 uint32 labelMode = renderer->getLabelMode();
  91.                 renderer->setLabelMode(labelMode ^ Renderer::LocationLabels);
  92.                 break;
  93.             }
  94.         case IDOK:
  95.             if (dlg != NULL && dlg->parent != NULL)
  96.             {
  97.                 SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
  98.                             reinterpret_cast<LPARAM>(dlg));
  99.             }
  100.             EndDialog(hDlg, 0);
  101.             return TRUE;
  102.         case IDCANCEL:
  103.             if (dlg != NULL && dlg->parent != NULL)
  104.             {
  105.                 // Reset render flags, label mode, and hud detail to
  106.                 // initial values
  107.                 dlg->RestoreSettings(hDlg);
  108.                 SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
  109.                             reinterpret_cast<LPARAM>(dlg));
  110.             }
  111.             EndDialog(hDlg, 0);
  112.             return TRUE;
  113.         }
  114.         break;
  115.     }
  116.     case WM_DESTROY:
  117.         if (dlg != NULL && dlg->parent != NULL)
  118.         {
  119.             SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
  120.                         reinterpret_cast<LPARAM>(dlg));
  121.         }
  122.         return TRUE;
  123.     case WM_HSCROLL:
  124.         {
  125.             WORD sbValue = LOWORD(wParam);
  126.             LRESULT sliderPos;
  127.             
  128.             if (sbValue == SB_THUMBTRACK)
  129.                 sliderPos = HIWORD(wParam);
  130.             else                            
  131.                 sliderPos = SendMessage(GetDlgItem(hDlg, IDC_SLIDER_FEATURE_SIZE), TBM_GETPOS, 0, 0);
  132.                 
  133.             char val[16];
  134.             HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FEATURE_SIZE);
  135.             float featureSize = (float) sliderPos / (float) FeatureSizeSliderRange;
  136.             featureSize = MinFeatureSize + (MaxFeatureSize - MinFeatureSize) * featureSize;
  137.             sprintf(val, "%d", (int) featureSize);
  138.             SetWindowText(hwnd, val);
  139.             
  140.             dlg->appCore->getRenderer()->setMinimumFeatureSize(featureSize);
  141.         }
  142.     }
  143.     return FALSE;
  144. }
  145. LocationsDialog::LocationsDialog(HINSTANCE appInstance,
  146.                                  HWND _parent,
  147.                                  CelestiaCore* _appCore) :
  148.     CelestiaWatcher(*_appCore),
  149.     appCore(_appCore),
  150.     parent(_parent)
  151. {
  152.     hwnd = CreateDialogParam(appInstance,
  153.                              MAKEINTRESOURCE(IDD_LOCATIONS),
  154.                              parent,
  155.                              LocationsProc,
  156.                              reinterpret_cast<LONG>(this));
  157. }
  158. static void dlgCheck(HWND hDlg, WORD item, uint32 flags, uint32 f)
  159. {
  160.     SendDlgItemMessage(hDlg, item, BM_SETCHECK,
  161.                        ((flags & f) != 0) ? BST_CHECKED : BST_UNCHECKED, 0);
  162. }
  163. void LocationsDialog::SetControls(HWND hDlg)
  164. {
  165.     Observer* obs = appCore->getSimulation()->getActiveObserver();
  166.     uint32 locFilter = obs->getLocationFilter();
  167.     dlgCheck(hDlg, IDC_SHOW_CITIES,        locFilter, Location::City);
  168.     dlgCheck(hDlg, IDC_SHOW_OBSERVATORIES, locFilter, Location::Observatory);
  169.     dlgCheck(hDlg, IDC_SHOW_LANDING_SITES, locFilter, Location::LandingSite);
  170.     dlgCheck(hDlg, IDC_SHOW_MONTES,        locFilter, Location::Mons);
  171.     dlgCheck(hDlg, IDC_SHOW_MARIA,         locFilter, Location::Mare);
  172.     dlgCheck(hDlg, IDC_SHOW_CRATERS,       locFilter, Location::Crater);
  173.     dlgCheck(hDlg, IDC_SHOW_VALLES,        locFilter, Location::Vallis);
  174.     dlgCheck(hDlg, IDC_SHOW_TERRAE,        locFilter, Location::Terra);
  175.     dlgCheck(hDlg, IDC_SHOW_VOLCANOES,        locFilter, Location::EruptiveCenter);
  176.     dlgCheck(hDlg, IDC_SHOW_OTHERS,        locFilter, Location::Other);
  177.     uint32 labelMode = appCore->getRenderer()->getLabelMode();
  178.     dlgCheck(hDlg, IDC_LABELFEATURES,     labelMode, Renderer::LocationLabels);
  179.     // Set up feature size slider
  180.     SendDlgItemMessage(hDlg,
  181.                        IDC_SLIDER_FEATURE_SIZE,
  182.                        TBM_SETRANGE,
  183.                        (WPARAM)TRUE,
  184.                        (LPARAM) MAKELONG(0, FeatureSizeSliderRange));
  185.     float featureSize = appCore->getRenderer()->getMinimumFeatureSize();
  186.     int sliderPos = (int) (FeatureSizeSliderRange *
  187.                            (featureSize - MinFeatureSize) /
  188.                            (MaxFeatureSize - MinFeatureSize));
  189.     SendDlgItemMessage(hDlg,
  190.                        IDC_SLIDER_FEATURE_SIZE,
  191.                        TBM_SETPOS,
  192.                        (WPARAM) TRUE,
  193.                        (LPARAM) sliderPos);
  194.     
  195.     char val[16];
  196.     HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FEATURE_SIZE);
  197.     sprintf(val, "%d", (int) featureSize);
  198.     SetWindowText(hwnd, val);
  199. }
  200. void LocationsDialog::RestoreSettings(HWND hDlg)
  201. {
  202. }
  203. void LocationsDialog::notifyChange(CelestiaCore*, int)
  204. {
  205.     if (parent != NULL)
  206.         SetControls(hwnd);
  207. }