00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "KeosWin32ConfigDialog.h"
00022 #include "KeosRoot.h"
00023 #include "KeosRenderSystem.h"
00024 #include "resource.h"
00025 #include "KeosException.h"
00026
00027 namespace
00028 {
00029 Keos::CWin32ConfigDialog* dlg;
00030 }
00031
00032 namespace Keos
00033 {
00034
00035
00036
00037
00038
00039 CWin32ConfigDialog::CWin32ConfigDialog(HINSTANCE hInst)
00040 {
00041 m_HInstance = hInst;
00042 m_pSelectedRenderSystem = 0;
00043 }
00044
00045
00046 CWin32ConfigDialog::~CWin32ConfigDialog()
00047 {}
00048
00049
00050 BOOL CWin32ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
00051 {
00052 HWND hwndDlgItem;
00053 static RenderSystemList* lstRend;
00054 RenderSystemList::iterator pRend;
00055 static ConfigOptionMap opts;
00056 String err;
00057
00058 int i, sel, savedSel;
00059 static bool fullScreen = true;
00060
00061 switch (iMsg)
00062 {
00063 case WM_INITDIALOG:
00064 {
00065
00066 CRoot::Instance().RestoreConfig();
00067 dlg->m_pSelectedRenderSystem = CRoot::Instance().GetRenderSystem();
00068
00069 lstRend = CRoot::Instance().GetAvailableRenderers();
00070 pRend = lstRend->begin();
00071 i = 0;
00072 while (pRend != lstRend->end())
00073 {
00074 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
00075
00076 SendMessage(hwndDlgItem, CB_ADDSTRING, 0,
00077 (LPARAM)(char*)(*pRend)->GetName().c_str());
00078
00079 if (*pRend == dlg->m_pSelectedRenderSystem)
00080 {
00081
00082 SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
00083
00084
00085 opts = (*pRend)->GetConfigOptions();
00086
00087 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
00088
00089
00090 ConfigOptionMap::iterator pOpt = opts.begin();
00091 String strLine;
00092 while ( pOpt != opts.end() )
00093 {
00094 if (pOpt->second.name != "RenderSystem")
00095 {
00096 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
00097 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
00098 }
00099 ++pOpt;
00100 }
00101 }
00102
00103 ++pRend;
00104 ++i;
00105 }
00106
00107
00108 hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_VERSION);
00109 String strVersion = "v" + CRoot::Instance().GetVersion();
00110 SetWindowText(hwndDlgItem, strVersion.c_str());
00111
00112
00113 int x, y, screenWidth, screenHeight;
00114 RECT rcDlg;
00115 GetWindowRect(hDlg, &rcDlg);
00116 screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
00117 screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
00118
00119 x = (screenWidth / 2) - ((rcDlg.right - rcDlg.left) / 2);
00120 y = (screenHeight / 2) - ((rcDlg.bottom - rcDlg.top) / 2);
00121
00122 MoveWindow(hDlg, x, y, (rcDlg.right - rcDlg.left),
00123 (rcDlg.bottom - rcDlg.top), TRUE);
00124
00125 return TRUE;
00126 }
00127
00128 case WM_COMMAND:
00129 switch (LOWORD(wParam))
00130 {
00131 case IDC_CBO_RENDERSYSTEM:
00132 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
00133 sel = SendMessage( hwndDlgItem, CB_GETCOUNT, 0, 0 );
00134
00135 if (HIWORD(wParam) == CBN_SELCHANGE )
00136 {
00137
00138 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
00139 SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
00140 hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
00141 SetWindowText(hwndDlgItem, "[Click On An Option]:");
00142
00143
00144
00145 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
00146 sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0);
00147 if (sel != -1)
00148 {
00149
00150 pRend = lstRend->begin();
00151 dlg->m_pSelectedRenderSystem = pRend[sel];
00152
00153
00154 opts = pRend[sel]->GetConfigOptions();
00155
00156 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
00157 SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
00158
00159 ConfigOptionMap::iterator pOpt = opts.begin();
00160 String strLine;
00161 while (pOpt != opts.end())
00162 {
00163 if (pOpt->second.name != "RenderSystem")
00164 {
00165 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
00166 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
00167 }
00168 ++pOpt;
00169 }
00170 }
00171 }
00172
00173 return TRUE;
00174
00175 case IDC_LST_OPTIONS:
00176 if (HIWORD(wParam) == LBN_SELCHANGE)
00177 {
00178
00179
00180 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
00181 sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
00182 if (sel != -1)
00183 {
00184 ConfigOptionMap::iterator pOpt = opts.begin();
00185 for (i = 0; i < sel; i++)
00186 ++pOpt;
00187
00188 hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
00189 SetWindowText(hwndDlgItem, pOpt->second.name.c_str());
00190
00191 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
00192 SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
00193 StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
00194 i = 0;
00195 while (pPoss != pOpt->second.possibleValues.end())
00196 {
00197 SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)pPoss[0].c_str());
00198 if (pPoss[0] == pOpt->second.currentValue)
00199
00200 SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
00201 ++pPoss;
00202 ++i;
00203 }
00204
00205 EnableWindow(hwndDlgItem, !(pOpt->second.immutable));
00206 }
00207 }
00208
00209 return TRUE;
00210
00211 case IDC_CBO_OPTION:
00212 if (HIWORD(wParam) == CBN_SELCHANGE)
00213 {
00214
00215
00216 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
00217 sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
00218 savedSel = sel;
00219 ConfigOptionMap::iterator pOpt = opts.begin();
00220 for (i = 0; i < sel; i++)
00221 ++pOpt;
00222
00223 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
00224 sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0);
00225
00226 if (sel != -1)
00227 {
00228 StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
00229
00230
00231 dlg->m_pSelectedRenderSystem->SetConfigOption(
00232 pOpt->second.name, pPoss[sel]);
00233
00234 opts = dlg->m_pSelectedRenderSystem->GetConfigOptions();
00235
00236
00237 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
00238 SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
00239
00240 pOpt = opts.begin();
00241 String strLine;
00242 while (pOpt != opts.end())
00243 {
00244 if (pOpt->second.name != "RenderSystem")
00245 {
00246 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
00247 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
00248 }
00249 ++pOpt;
00250 }
00251
00252 SendMessage(hwndDlgItem, LB_SETCURSEL, savedSel, 0);
00253 }
00254
00255 }
00256 return TRUE;
00257
00258 case IDOK:
00259
00260 if (!dlg->m_pSelectedRenderSystem)
00261 {
00262 MessageBox(NULL, "Please choose a rendering system.", "KEOS", MB_OK | MB_ICONEXCLAMATION);
00263 return TRUE;
00264 }
00265
00266 CRoot::Instance().SetRenderSystem(dlg->m_pSelectedRenderSystem);
00267 CRoot::Instance().SaveConfig();
00268
00269 EndDialog(hDlg, TRUE);
00270 return TRUE;
00271
00272 case IDCANCEL:
00273 EndDialog(hDlg, FALSE);
00274 return TRUE;
00275 }
00276 }
00277
00278 return FALSE;
00279 }
00280
00281
00282 bool CWin32ConfigDialog::Display(void)
00283 {
00284
00285
00286 int i;
00287 dlg = this;
00288 i = DialogBox(m_HInstance, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), NULL, DlgProc);
00289
00290 if (i == -1)
00291 {
00292 int winError = GetLastError();
00293 char* errDesc;
00294 int i;
00295
00296 errDesc = new char[255];
00297
00298 i = FormatMessage(
00299 FORMAT_MESSAGE_FROM_SYSTEM |
00300 FORMAT_MESSAGE_IGNORE_INSERTS,
00301 NULL,
00302 winError,
00303 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00304 (LPTSTR) errDesc,
00305 255,
00306 NULL
00307 );
00308
00309 throw CException("CWin32ConfigDialog::Display");
00310 }
00311 if (i)
00312 return true;
00313 else
00314 return false;
00315 }
00316 }
00317