00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "winlocations.h"
00013 #include "res/resource.h"
00014 #include <celutil/winutil.h>
00015
00016 using namespace std;
00017
00018 static const int FeatureSizeSliderRange = 100;
00019 static const float MinFeatureSize = 1.0f;
00020 static const float MaxFeatureSize = 100.0f;
00021
00022 static const uint32 FilterOther = ~(Location::City |
00023 Location::Observatory |
00024 Location::LandingSite |
00025 Location::Crater |
00026 Location::Mons |
00027 Location::Terra |
00028 Location::Vallis |
00029 Location::Mare);
00030
00031 static BOOL APIENTRY LocationsProc(HWND hDlg,
00032 UINT message,
00033 UINT wParam,
00034 LONG lParam)
00035 {
00036 LocationsDialog* dlg = reinterpret_cast<LocationsDialog*>(GetWindowLong(hDlg, DWL_USER));
00037
00038 switch (message)
00039 {
00040 case WM_INITDIALOG:
00041 {
00042 dlg = reinterpret_cast<LocationsDialog*>(lParam);
00043 if (dlg == NULL)
00044 return EndDialog(hDlg, 0);
00045 SetWindowLong(hDlg, DWL_USER, lParam);
00046
00047
00048
00049 dlg->initialLocationFlags = 0;
00050 dlg->initialFeatureSize = dlg->appCore->getRenderer()->getMinimumFeatureSize();
00051
00052
00053 dlg->SetControls(hDlg);
00054
00055 return(TRUE);
00056 }
00057 break;
00058
00059 case WM_COMMAND:
00060 {
00061 Observer* obs = dlg->appCore->getSimulation()->getActiveObserver();
00062 uint32 locationFilter = obs->getLocationFilter();
00063
00064 switch (LOWORD(wParam))
00065 {
00066 case IDC_SHOW_CITIES:
00067 obs->setLocationFilter(locationFilter ^ Location::City);
00068 break;
00069 case IDC_SHOW_OBSERVATORIES:
00070 obs->setLocationFilter(locationFilter ^ Location::Observatory);
00071 break;
00072 case IDC_SHOW_LANDING_SITES:
00073 obs->setLocationFilter(locationFilter ^ Location::LandingSite);
00074 break;
00075 case IDC_SHOW_MONTES:
00076 obs->setLocationFilter(locationFilter ^ Location::Mons);
00077 break;
00078 case IDC_SHOW_MARIA:
00079 obs->setLocationFilter(locationFilter ^ Location::Mare);
00080 break;
00081 case IDC_SHOW_CRATERS:
00082 obs->setLocationFilter(locationFilter ^ Location::Crater);
00083 break;
00084 case IDC_SHOW_VALLES:
00085 obs->setLocationFilter(locationFilter ^ Location::Vallis);
00086 break;
00087 case IDC_SHOW_TERRAE:
00088 obs->setLocationFilter(locationFilter ^ Location::Terra);
00089 break;
00090 case IDC_SHOW_OTHERS:
00091 obs->setLocationFilter(locationFilter ^ FilterOther);
00092 break;
00093 case IDC_LABELFEATURES:
00094 {
00095 Renderer* renderer = dlg->appCore->getRenderer();
00096 uint32 labelMode = renderer->getLabelMode();
00097 renderer->setLabelMode(labelMode ^ Renderer::LocationLabels);
00098 break;
00099 }
00100 case IDOK:
00101 if (dlg != NULL && dlg->parent != NULL)
00102 {
00103 SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
00104 reinterpret_cast<LPARAM>(dlg));
00105 }
00106 EndDialog(hDlg, 0);
00107 return TRUE;
00108 case IDCANCEL:
00109 if (dlg != NULL && dlg->parent != NULL)
00110 {
00111
00112
00113 dlg->RestoreSettings(hDlg);
00114 SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
00115 reinterpret_cast<LPARAM>(dlg));
00116 }
00117 EndDialog(hDlg, 0);
00118 return TRUE;
00119 }
00120 break;
00121 }
00122
00123 case WM_DESTROY:
00124 if (dlg != NULL && dlg->parent != NULL)
00125 {
00126 SendMessage(dlg->parent, WM_COMMAND, IDCLOSE,
00127 reinterpret_cast<LPARAM>(dlg));
00128 }
00129 return TRUE;
00130
00131 case WM_HSCROLL:
00132 {
00133 WORD sbValue = LOWORD(wParam);
00134 LRESULT sliderPos;
00135
00136 if (sbValue == SB_THUMBTRACK)
00137 sliderPos = HIWORD(wParam);
00138 else
00139 sliderPos = SendMessage(GetDlgItem(hDlg, IDC_SLIDER_FEATURE_SIZE), TBM_GETPOS, 0, 0);
00140
00141 char val[16];
00142 HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FEATURE_SIZE);
00143 float featureSize = (float) sliderPos / (float) FeatureSizeSliderRange;
00144 featureSize = MinFeatureSize + (MaxFeatureSize - MinFeatureSize) * featureSize;
00145 sprintf(val, "%d", (int) featureSize);
00146 SetWindowText(hwnd, val);
00147
00148 dlg->appCore->getRenderer()->setMinimumFeatureSize(featureSize);
00149 }
00150 }
00151
00152 return FALSE;
00153 }
00154
00155
00156 LocationsDialog::LocationsDialog(HINSTANCE appInstance,
00157 HWND _parent,
00158 CelestiaCore* _appCore) :
00159 CelestiaWatcher(*_appCore),
00160 appCore(_appCore),
00161 parent(_parent)
00162 {
00163 hwnd = CreateDialogParam(appInstance,
00164 MAKEINTRESOURCE(IDD_LOCATIONS),
00165 parent,
00166 LocationsProc,
00167 reinterpret_cast<LONG>(this));
00168 }
00169
00170
00171 static void dlgCheck(HWND hDlg, WORD item, uint32 flags, uint32 f)
00172 {
00173 SendDlgItemMessage(hDlg, item, BM_SETCHECK,
00174 ((flags & f) != 0) ? BST_CHECKED : BST_UNCHECKED, 0);
00175 }
00176
00177
00178 void LocationsDialog::SetControls(HWND hDlg)
00179 {
00180 Observer* obs = appCore->getSimulation()->getActiveObserver();
00181 uint32 locFilter = obs->getLocationFilter();
00182
00183 dlgCheck(hDlg, IDC_SHOW_CITIES, locFilter, Location::City);
00184 dlgCheck(hDlg, IDC_SHOW_OBSERVATORIES, locFilter, Location::Observatory);
00185 dlgCheck(hDlg, IDC_SHOW_LANDING_SITES, locFilter, Location::LandingSite);
00186 dlgCheck(hDlg, IDC_SHOW_MONTES, locFilter, Location::Mons);
00187 dlgCheck(hDlg, IDC_SHOW_MARIA, locFilter, Location::Mare);
00188 dlgCheck(hDlg, IDC_SHOW_CRATERS, locFilter, Location::Crater);
00189 dlgCheck(hDlg, IDC_SHOW_VALLES, locFilter, Location::Vallis);
00190 dlgCheck(hDlg, IDC_SHOW_TERRAE, locFilter, Location::Terra);
00191 dlgCheck(hDlg, IDC_SHOW_OTHERS, locFilter, Location::Other);
00192
00193 uint32 labelMode = appCore->getRenderer()->getLabelMode();
00194 dlgCheck(hDlg, IDC_LABELFEATURES, labelMode, Renderer::LocationLabels);
00195
00196
00197 SendDlgItemMessage(hDlg,
00198 IDC_SLIDER_FEATURE_SIZE,
00199 TBM_SETRANGE,
00200 (WPARAM)TRUE,
00201 (LPARAM) MAKELONG(0, FeatureSizeSliderRange));
00202 float featureSize = appCore->getRenderer()->getMinimumFeatureSize();
00203 int sliderPos = (int) (FeatureSizeSliderRange *
00204 (featureSize - MinFeatureSize) /
00205 (MaxFeatureSize - MinFeatureSize));
00206 SendDlgItemMessage(hDlg,
00207 IDC_SLIDER_FEATURE_SIZE,
00208 TBM_SETPOS,
00209 (WPARAM) TRUE,
00210 (LPARAM) sliderPos);
00211
00212 char val[16];
00213 HWND hwnd = GetDlgItem(hDlg, IDC_EDIT_FEATURE_SIZE);
00214 sprintf(val, "%d", (int) featureSize);
00215 SetWindowText(hwnd, val);
00216 }
00217
00218
00219 void LocationsDialog::RestoreSettings(HWND hDlg)
00220 {
00221 }
00222
00223 void LocationsDialog::notifyChange(CelestiaCore*, int)
00224 {
00225 if (parent != NULL)
00226 SetControls(hwnd);
00227 }