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

OpenGL

开发平台:

Visual C++

  1. // winviewoptsdlg.cpp
  2. // 
  3. // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
  4. //
  5. // View Options 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 <windows.h>
  12. #include <commctrl.h>
  13. #include "winviewoptsdlg.h"
  14. #include "..celenginerender.h"
  15. #include "res/resource.h"
  16. using namespace std;
  17. static const int DistanceSliderRange = 10000;
  18. static const float MinDistanceLimit = 1.0f;
  19. static const float MaxDistanceLimit = 1.0e6f;
  20. static BOOL APIENTRY ViewOptionsProc(HWND hDlg,
  21.                                      UINT message,
  22.                                      UINT wParam,
  23.                                      LONG lParam)
  24. {
  25.     ViewOptionsDialog* Dlg = reinterpret_cast<ViewOptionsDialog*>(GetWindowLong(hDlg, DWL_USER));
  26.     switch (message)
  27.     {
  28.     case WM_INITDIALOG:
  29.         {
  30.             ViewOptionsDialog* Dlg = reinterpret_cast<ViewOptionsDialog*>(lParam);
  31.             if (Dlg == NULL)
  32.                 return EndDialog(hDlg, 0);
  33.             SetWindowLong(hDlg, DWL_USER, lParam);
  34.             //Read labelMode, renderFlags and hud detail
  35.             Dlg->initialRenderFlags = Dlg->appCore->getRenderer()->getRenderFlags();
  36.             Dlg->initialLabelMode = Dlg->appCore->getRenderer()->getLabelMode();
  37.             Dlg->initialHudDetail = Dlg->appCore->getHudDetail();
  38.             //Set dialog controls to reflect current label and render modes
  39.             Dlg->SetControls(hDlg);
  40.             return(TRUE);
  41.         }
  42.         break;
  43.     case WM_COMMAND:
  44.     {
  45.         Renderer* renderer = Dlg->appCore->getRenderer();
  46.         uint32 renderFlags = renderer->getRenderFlags();
  47.         uint32 labelMode = renderer->getLabelMode();
  48.         uint32 orbitMask = renderer->getOrbitMask();
  49.         switch (LOWORD(wParam))
  50.         {
  51.         case IDC_SHOWATMOSPHERES:
  52.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowAtmospheres);
  53.             break;
  54.         case IDC_SHOWCELESTIALGRID:
  55.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowCelestialSphere);
  56.             break;
  57.         case IDC_SHOWHORIZONGRID:
  58.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowHorizonGrid);
  59.             break;
  60.         case IDC_SHOWGALACTICGRID:
  61.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowGalacticGrid);
  62.             break;
  63.         case IDC_SHOWECLIPTICGRID:
  64.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowEclipticGrid);
  65.             break;
  66.         case IDC_SHOWCLOUDS:
  67.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowCloudMaps);
  68.             break;
  69.         case IDC_SHOWCLOUDSHADOWS:
  70.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowCloudShadows);
  71.             break;
  72.         case IDC_SHOWCONSTELLATIONS:
  73.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowDiagrams);
  74.             break;
  75.         case IDC_SHOWECLIPSESHADOWS:
  76.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowEclipseShadows);
  77.             break;
  78.         case IDC_SHOWGALAXIES:
  79.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowGalaxies);
  80.             break;
  81.         case IDC_SHOWGLOBULARS:
  82.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowGlobulars);
  83.             break;
  84.         case IDC_SHOWNEBULAE:
  85.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowNebulae);
  86.             break;
  87.         case IDC_SHOWOPENCLUSTERS:
  88.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowOpenClusters);
  89.             break;
  90.         case IDC_SHOWNIGHTSIDELIGHTS:
  91.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowNightMaps);
  92.             break;
  93.         case IDC_SHOWORBITS:
  94.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowOrbits);
  95.             break;
  96.         case IDC_PLANETORBITS:
  97.             renderer->setOrbitMask(orbitMask ^ Body::Planet);
  98.             break;
  99.         case IDC_DWARFPLANETORBITS:
  100.             renderer->setOrbitMask(orbitMask ^ Body::DwarfPlanet);
  101.             break;
  102.         case IDC_STARORBITS:
  103.             renderer->setOrbitMask(orbitMask ^ Body::Stellar);
  104.             break;
  105.         case IDC_MOONORBITS:
  106.             renderer->setOrbitMask(orbitMask ^ Body::Moon);
  107.             break;
  108.         case IDC_MINORMOONORBITS:
  109.             renderer->setOrbitMask(orbitMask ^ Body::MinorMoon);
  110.             break;
  111.         case IDC_ASTEROIDORBITS:
  112.             renderer->setOrbitMask(orbitMask ^ Body::Asteroid);
  113.             break;
  114.         case IDC_COMETORBITS:
  115.             renderer->setOrbitMask(orbitMask ^ Body::Comet);
  116.             break;
  117.         case IDC_SPACECRAFTORBITS:
  118.             renderer->setOrbitMask(orbitMask ^ Body::Spacecraft);
  119.             break;
  120.         case IDC_SHOWPLANETS:
  121.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowPlanets);
  122.             break;
  123.         case IDC_SHOWSTARS:
  124.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowStars);
  125.             break;
  126.         case IDC_SHOWCONSTELLATIONBORDERS:
  127.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowBoundaries);
  128.             break;
  129.         case IDC_SHOWRINGSHADOWS:
  130.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowRingShadows);
  131.             break;
  132.         case IDC_SHOWCOMETTAILS:
  133.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowCometTails);
  134.             break;
  135.         case IDC_SHOWMARKERS:
  136.             renderer->setRenderFlags(renderFlags ^ Renderer::ShowMarkers);
  137.             break;
  138.         case IDC_LABELCONSTELLATIONS:
  139.             renderer->setLabelMode(labelMode ^ Renderer::ConstellationLabels);
  140.             break;
  141.         case IDC_LABELCONSTELLATIONSLATIN:
  142.             renderer->setLabelMode(labelMode ^ Renderer::I18nConstellationLabels);
  143.             break;
  144.         case IDC_LABELGALAXIES:
  145.             renderer->setLabelMode(labelMode ^ Renderer::GalaxyLabels);
  146.             break;
  147.     case IDC_LABELGLOBULARS:
  148.       renderer->setLabelMode(labelMode ^ Renderer::GlobularLabels);
  149.       break;
  150.     case IDC_LABELNEBULAE:
  151.       renderer->setLabelMode(labelMode ^ Renderer::NebulaLabels);
  152.       break;
  153.     case IDC_LABELOPENCLUSTERS:
  154.       renderer->setLabelMode(labelMode ^ Renderer::OpenClusterLabels);
  155.       break;
  156.         case IDC_LABELPLANETS:
  157.             renderer->setLabelMode(labelMode ^ Renderer::PlanetLabels);
  158.             break;
  159.         case IDC_LABELDWARFPLANETS:
  160.             renderer->setLabelMode(labelMode ^ Renderer::DwarfPlanetLabels);
  161.             break;
  162.         case IDC_LABELMOONS:
  163.             renderer->setLabelMode(labelMode ^ Renderer::MoonLabels);
  164.             break;
  165.         case IDC_LABELMINORMOONS:
  166.             renderer->setLabelMode(labelMode ^ Renderer::MinorMoonLabels);
  167.             break;
  168.         case IDC_LABELSTARS:
  169.             renderer->setLabelMode(labelMode ^ Renderer::StarLabels);
  170.             break;
  171.         case IDC_LABELASTEROIDS:
  172.             renderer->setLabelMode(labelMode ^ Renderer::AsteroidLabels);
  173.             break;
  174.         case IDC_LABELCOMETS:
  175.             renderer->setLabelMode(labelMode ^ Renderer::CometLabels);
  176.             break;
  177.         case IDC_LABELSPACECRAFT:
  178.             renderer->setLabelMode(labelMode ^ Renderer::SpacecraftLabels);
  179.             break;
  180.         case IDC_INFOTEXT0:
  181.             Dlg->appCore->setHudDetail(0);
  182.             break;
  183.         case IDC_INFOTEXT1:
  184.             Dlg->appCore->setHudDetail(1);
  185.             break;
  186.         case IDC_INFOTEXT2:
  187.             Dlg->appCore->setHudDetail(2);
  188.             break;
  189.         case IDOK:
  190.             if (Dlg != NULL && Dlg->parent != NULL)
  191.             {
  192.                 SendMessage(Dlg->parent, WM_COMMAND, IDCLOSE,
  193.                             reinterpret_cast<LPARAM>(Dlg));
  194.             }
  195.             EndDialog(hDlg, 0);
  196.             return TRUE;
  197.         case IDCANCEL:
  198.             if (Dlg != NULL && Dlg->parent != NULL)
  199.             {
  200.                 // Reset render flags, label mode, and hud detail to
  201.                 // initial values
  202.                 Dlg->RestoreSettings(hDlg);
  203.                 SendMessage(Dlg->parent, WM_COMMAND, IDCLOSE,
  204.                             reinterpret_cast<LPARAM>(Dlg));
  205.             }
  206.             EndDialog(hDlg, 0);
  207.             return TRUE;
  208.         }
  209.         break;
  210.     }
  211.     case WM_DESTROY:
  212.         if (Dlg != NULL && Dlg->parent != NULL)
  213.         {
  214.             SendMessage(Dlg->parent, WM_COMMAND, IDCLOSE,
  215.                         reinterpret_cast<LPARAM>(Dlg));
  216.         }
  217.         return TRUE;
  218.     case WM_HSCROLL:
  219.         {
  220.             WORD sbValue = LOWORD(wParam);
  221.             switch (sbValue)
  222.             {
  223.             case SB_THUMBTRACK:
  224.                 // case SB_ENDSCROLL:
  225.                 {
  226.                     char val[16];
  227.                     HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FILTER_DISTANCE);
  228.                     float logDistanceLimit = (float) HIWORD(wParam) /
  229.                         (float) DistanceSliderRange;
  230.                     float distanceLimit = (float) pow(MaxDistanceLimit, 
  231.                                                  logDistanceLimit);
  232.                     sprintf(val, "%d", (int) distanceLimit);
  233.                     SetWindowText(hwnd, val);
  234.                     Dlg->appCore->getRenderer()->setDistanceLimit(distanceLimit);
  235.                     break;
  236.                 }
  237.             default:
  238.                 cout << "Slider msg: " << sbValue << 'n';
  239.                 break;
  240. #if 0
  241.             case SB_THUMBPOSITION:
  242.                 {
  243.                     browser->nStars = (int)HIWORD(wParam);
  244.                     RefreshItems(hDlg, browser);
  245.                     break;
  246.                 }
  247. #endif
  248.             }
  249.         }
  250.     }
  251.     return FALSE;
  252. }
  253. ViewOptionsDialog::ViewOptionsDialog(HINSTANCE appInstance,
  254.                                      HWND _parent,
  255.                                      CelestiaCore* _appCore) :
  256.     CelestiaWatcher(*_appCore),
  257.     appCore(_appCore),
  258.     parent(_parent)
  259. {
  260.     hwnd = CreateDialogParam(appInstance,
  261.                              MAKEINTRESOURCE(IDD_VIEWOPTIONS),
  262.                              parent,
  263.                              ViewOptionsProc,
  264.                              reinterpret_cast<LONG>(this));
  265. }
  266. static void dlgCheck(HWND hDlg, WORD item, uint32 flags, uint32 f)
  267. {
  268.     SendDlgItemMessage(hDlg, item, BM_SETCHECK,
  269.                        ((flags & f) != 0) ? BST_CHECKED : BST_UNCHECKED, 0);
  270. }
  271. void ViewOptionsDialog::SetControls(HWND hDlg)
  272. {
  273.     int renderFlags = appCore->getRenderer()->getRenderFlags();
  274.     int labelMode = appCore->getRenderer()->getLabelMode();
  275.     int hudDetail = appCore->getHudDetail();
  276.     int orbitMask = appCore->getRenderer()->getOrbitMask();
  277.     //Set checkboxes and radiobuttons
  278.     SendDlgItemMessage(hDlg, IDC_SHOWATMOSPHERES, BM_SETCHECK,
  279.         (renderFlags & Renderer::ShowAtmospheres)? BST_CHECKED:BST_UNCHECKED, 0);
  280.     SendDlgItemMessage(hDlg, IDC_SHOWCELESTIALGRID, BM_SETCHECK,
  281.         (renderFlags & Renderer::ShowCelestialSphere)? BST_CHECKED:BST_UNCHECKED, 0);
  282.     SendDlgItemMessage(hDlg, IDC_SHOWHORIZONGRID, BM_SETCHECK,
  283.         (renderFlags & Renderer::ShowHorizonGrid)? BST_CHECKED:BST_UNCHECKED, 0);
  284.     SendDlgItemMessage(hDlg, IDC_SHOWGALACTICGRID, BM_SETCHECK,
  285.         (renderFlags & Renderer::ShowGalacticGrid)? BST_CHECKED:BST_UNCHECKED, 0);
  286.     SendDlgItemMessage(hDlg, IDC_SHOWECLIPTICGRID, BM_SETCHECK,
  287.         (renderFlags & Renderer::ShowEclipticGrid)? BST_CHECKED:BST_UNCHECKED, 0);
  288.     SendDlgItemMessage(hDlg, IDC_SHOWCLOUDS, BM_SETCHECK,
  289.         (renderFlags & Renderer::ShowCloudMaps)? BST_CHECKED:BST_UNCHECKED, 0);
  290.     SendDlgItemMessage(hDlg, IDC_SHOWCLOUDSHADOWS, BM_SETCHECK,
  291.         (renderFlags & Renderer::ShowCloudShadows)? BST_CHECKED:BST_UNCHECKED, 0);
  292.     SendDlgItemMessage(hDlg, IDC_SHOWCONSTELLATIONS, BM_SETCHECK,
  293.         (renderFlags & Renderer::ShowDiagrams)? BST_CHECKED:BST_UNCHECKED, 0);
  294.     SendDlgItemMessage(hDlg, IDC_SHOWECLIPSESHADOWS, BM_SETCHECK,
  295.         (renderFlags & Renderer::ShowEclipseShadows)? BST_CHECKED:BST_UNCHECKED, 0);
  296.     SendDlgItemMessage(hDlg, IDC_SHOWGALAXIES, BM_SETCHECK,
  297.         (renderFlags & Renderer::ShowGalaxies)? BST_CHECKED:BST_UNCHECKED, 0);
  298.     SendDlgItemMessage(hDlg, IDC_SHOWGLOBULARS, BM_SETCHECK,
  299.         (renderFlags & Renderer::ShowGlobulars)? BST_CHECKED:BST_UNCHECKED, 0);
  300.     SendDlgItemMessage(hDlg, IDC_SHOWNEBULAE, BM_SETCHECK,
  301.         (renderFlags & Renderer::ShowNebulae)? BST_CHECKED:BST_UNCHECKED, 0);
  302.     SendDlgItemMessage(hDlg, IDC_SHOWOPENCLUSTERS, BM_SETCHECK,
  303.         (renderFlags & Renderer::ShowOpenClusters)? BST_CHECKED:BST_UNCHECKED, 0);
  304.     SendDlgItemMessage(hDlg, IDC_SHOWNIGHTSIDELIGHTS, BM_SETCHECK,
  305.         (renderFlags & Renderer::ShowNightMaps)? BST_CHECKED:BST_UNCHECKED, 0);
  306.     dlgCheck(hDlg, IDC_SHOWORBITS,       renderFlags, Renderer::ShowOrbits);
  307.     dlgCheck(hDlg, IDC_PLANETORBITS,     orbitMask,   Body::Planet);
  308.     dlgCheck(hDlg, IDC_DWARFPLANETORBITS,     orbitMask,   Body::DwarfPlanet);
  309.     dlgCheck(hDlg, IDC_MOONORBITS,       orbitMask,   Body::Moon);
  310.     dlgCheck(hDlg, IDC_MINORMOONORBITS,       orbitMask,   Body::MinorMoon);
  311.     dlgCheck(hDlg, IDC_ASTEROIDORBITS,   orbitMask,   Body::Asteroid);
  312.     dlgCheck(hDlg, IDC_COMETORBITS,      orbitMask,   Body::Comet);
  313.     dlgCheck(hDlg, IDC_SPACECRAFTORBITS, orbitMask,   Body::Spacecraft);
  314.     dlgCheck(hDlg, IDC_STARORBITS,       orbitMask,   Body::Stellar);
  315.     SendDlgItemMessage(hDlg, IDC_SHOWPLANETS, BM_SETCHECK,
  316.         (renderFlags & Renderer::ShowPlanets)? BST_CHECKED:BST_UNCHECKED, 0);
  317.     SendDlgItemMessage(hDlg, IDC_SHOWSTARS, BM_SETCHECK,
  318.         (renderFlags & Renderer::ShowStars)? BST_CHECKED:BST_UNCHECKED, 0);
  319.     SendDlgItemMessage(hDlg, IDC_SHOWCONSTELLATIONBORDERS, BM_SETCHECK,
  320.         (renderFlags & Renderer::ShowBoundaries)? BST_CHECKED:BST_UNCHECKED, 0);
  321.     SendDlgItemMessage(hDlg, IDC_SHOWRINGSHADOWS, BM_SETCHECK,
  322.         (renderFlags & Renderer::ShowRingShadows)? BST_CHECKED:BST_UNCHECKED, 0);
  323.     SendDlgItemMessage(hDlg, IDC_SHOWCOMETTAILS, BM_SETCHECK,
  324.         (renderFlags & Renderer::ShowCometTails)? BST_CHECKED:BST_UNCHECKED, 0);
  325.     SendDlgItemMessage(hDlg, IDC_SHOWMARKERS, BM_SETCHECK,
  326.         (renderFlags & Renderer::ShowMarkers)? BST_CHECKED:BST_UNCHECKED, 0);
  327.     dlgCheck(hDlg, IDC_LABELCONSTELLATIONS, labelMode, Renderer::ConstellationLabels);
  328.     SendDlgItemMessage(hDlg, IDC_LABELCONSTELLATIONSLATIN, BM_SETCHECK,
  329.                        ((labelMode & Renderer::I18nConstellationLabels) == 0) ? BST_CHECKED : BST_UNCHECKED, 0);
  330.     dlgCheck(hDlg, IDC_LABELGALAXIES,   labelMode, Renderer::GalaxyLabels);
  331.   dlgCheck(hDlg, IDC_LABELGLOBULARS, labelMode, Renderer::GlobularLabels);
  332.   dlgCheck(hDlg, IDC_LABELNEBULAE,    labelMode, Renderer::NebulaLabels);
  333.   dlgCheck(hDlg, IDC_LABELOPENCLUSTERS, labelMode, Renderer::OpenClusterLabels);
  334.     dlgCheck(hDlg, IDC_LABELSTARS,      labelMode, Renderer::StarLabels);
  335.     dlgCheck(hDlg, IDC_LABELPLANETS,    labelMode, Renderer::PlanetLabels);
  336.     dlgCheck(hDlg, IDC_LABELDWARFPLANETS,    labelMode, Renderer::DwarfPlanetLabels);
  337.     dlgCheck(hDlg, IDC_LABELMOONS,      labelMode, Renderer::MoonLabels);
  338.     dlgCheck(hDlg, IDC_LABELMINORMOONS,      labelMode, Renderer::MinorMoonLabels);
  339.     dlgCheck(hDlg, IDC_LABELASTEROIDS,  labelMode, Renderer::AsteroidLabels);
  340.     dlgCheck(hDlg, IDC_LABELCOMETS,     labelMode, Renderer::CometLabels);
  341.     dlgCheck(hDlg, IDC_LABELSPACECRAFT, labelMode, Renderer::SpacecraftLabels);
  342.     CheckRadioButton(hDlg, IDC_INFOTEXT0, IDC_INFOTEXT2, IDC_INFOTEXT0 + hudDetail);
  343.     // Set up distance slider
  344.     SendDlgItemMessage(hDlg,
  345.                        IDC_SLIDER_FILTER_DISTANCE,
  346.                        TBM_SETRANGE,
  347.                        (WPARAM)TRUE,
  348.                        (LPARAM) MAKELONG(0, DistanceSliderRange));
  349.     float distanceLimit = appCore->getRenderer()->getDistanceLimit();
  350.     float logDistanceLimit = (float) (log(distanceLimit) / 
  351.                                       log(MaxDistanceLimit));
  352.     SendDlgItemMessage(hDlg,
  353.                        IDC_SLIDER_FILTER_DISTANCE,
  354.                        TBM_SETPOS,
  355.                        (WPARAM) TRUE,
  356.                        (LPARAM) (logDistanceLimit * DistanceSliderRange));
  357.     char val[16];
  358.     HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FILTER_DISTANCE);
  359.     sprintf(val, "%d", (int) distanceLimit);
  360.     SetWindowText(hwnd, val);
  361. }
  362. void ViewOptionsDialog::RestoreSettings(HWND hDlg)
  363. {
  364.     appCore->getRenderer()->setRenderFlags(initialRenderFlags);
  365.     appCore->getRenderer()->setLabelMode(initialLabelMode);
  366.     appCore->setHudDetail(initialHudDetail);
  367. }
  368. void ViewOptionsDialog::notifyChange(CelestiaCore*, int)
  369. {
  370.     if (parent != NULL)
  371.         SetControls(hwnd);
  372. }