Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# KeosWin32ConfigDialog.cpp

Go to the documentation of this file.

    00001 /*
    00002  * This source file is part of KEOS (Free 3D Engine)
    00003  * For the latest info, see http://www.keosengine.org/
    00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
    00005  *
    00006  * This program is free software; you can redistribute it and/or modify it under
    00007  * the terms of the GNU Lesser General Public License as published by the Free Software
    00008  * Foundation; either version 2 of the License, or (at your option) any later
    00009  * version.
    00010  *
    00011  * This program is distributed in the hope that it will be useful, but WITHOUT
    00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Lesser General Public License along with
    00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00018  * http://www.gnu.org/copyleft/lesser.txt.
    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;  // This is a pointer to instance, since this is a static member
    00030 }
    00031
    00032 namespace Keos
    00033 {
    00034         //=======================================================================
    00035     // CWin32ConfigDialog implementation
    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
    00051         //-----------------------------------------------------------------------
    00052     BOOL CWin32ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
    00053     {
    00054         HWND hwndDlgItem;
    00055         static RenderSystemList* lstRend;
    00056         RenderSystemList::iterator pRend;
    00057         static ConfigOptionMap opts;
    00058         String err;
    00059
    00060         int i, sel, savedSel;
    00061         static bool fullScreen = true;
    00062
    00063         switch (iMsg)
    00064         {
    00065         case WM_INITDIALOG:
    00066                         {
    00067                                 // Load saved settings
    00068                                 CRoot::Instance().RestoreConfig();
    00069                                 dlg->m_pSelectedRenderSystem = CRoot::Instance().GetRenderSystem();
    00070                                 // Get all render systems
    00071                                 lstRend = CRoot::Instance().GetAvailableRenderers();
    00072                                 pRend = lstRend->begin();
    00073                                 i = 0;
    00074                                 while (pRend != lstRend->end())
    00075                                 {
    00076                                         hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
    00077
    00078                                         SendMessage(hwndDlgItem, CB_ADDSTRING, 0,
    00079                                                 (LPARAM)(char*)(*pRend)->GetName().c_str());
    00080
    00081                                         if (*pRend == dlg->m_pSelectedRenderSystem)
    00082                                         {
    00083                                                 // Select
    00084                                                 SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
    00085                                                 // Refresh Options
    00086                                                 // Get options from render system
    00087                                                 opts = (*pRend)->GetConfigOptions();
    00088                                                 // Reset list box
    00089                                                 hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
    00090                                                 //SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
    00091                                                 // Iterate through options
    00092                                                 ConfigOptionMap::iterator pOpt = opts.begin();
    00093                                                 String strLine;
    00094                                                 while( pOpt!= opts.end() )
    00095                                                 {
    00096                                                         if (pOpt->second.name != "RenderSystem")
    00097                                                         {
    00098                                                                 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
    00099                                                                 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
    00100                                                         }
    00101                                                         ++pOpt;
    00102                                                 }
    00103                                         }
    00104
    00105                                         ++pRend;
    00106                                         ++i;
    00107                                 }
    00108
    00109                                 // Keos version
    00110                                 hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_VERSION);
    00111                                 String strVersion = "v" + CRoot::Instance().GetVersion();
    00112                                 SetWindowText(hwndDlgItem, strVersion.c_str());
    00113
    00114                                 // Center myself
    00115                                 int x, y, screenWidth, screenHeight;
    00116                                 RECT rcDlg;
    00117                                 GetWindowRect(hDlg, &rcDlg);
    00118                                 screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
    00119                                 screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
    00120
    00121                                 x = (screenWidth / 2) - ((rcDlg.right - rcDlg.left) / 2);
    00122                                 y = (screenHeight / 2) - ((rcDlg.bottom - rcDlg.top) / 2);
    00123
    00124                                 MoveWindow(hDlg, x, y, (rcDlg.right - rcDlg.left),
    00125                                         (rcDlg.bottom - rcDlg.top), TRUE);
    00126
    00127                                 return TRUE;
    00128                         }
    00129
    00130         case WM_COMMAND:
    00131             switch (LOWORD(wParam))
    00132             {
    00133             case IDC_CBO_RENDERSYSTEM:
    00134                 hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
    00135                 sel = SendMessage( hwndDlgItem, CB_GETCOUNT, 0, 0 );
    00136
    00137                 if (HIWORD(wParam) == CBN_SELCHANGE )
    00138                 {
    00139                                         // Change label and combo "option"
    00140                                         hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
    00141                     SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
    00142                     hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
    00143                     SetWindowText(hwndDlgItem, "[Click On An Option]:");
    00144
    00145                     // RenderSystem selected
    00146                     // Get selected index
    00147                     hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
    00148                     sel = SendMessage(hwndDlgItem, CB_GETCURSEL,0,0);
    00149                     if (sel != -1)
    00150                     {
    00151                         // Get RenderSystem selected
    00152                         pRend = lstRend->begin();
    00153                         dlg->m_pSelectedRenderSystem = pRend[sel];
    00154                         // refresh options
    00155                         // Get options from render system
    00156                         opts = pRend[sel]->GetConfigOptions();
    00157                         // Reset list box
    00158                         hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
    00159                         SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
    00160                         // Iterate through options
    00161                         ConfigOptionMap::iterator pOpt = opts.begin();
    00162                         String strLine;
    00163                         while (pOpt!=opts.end())
    00164                         {
    00165                                                         if (pOpt->second.name != "RenderSystem")
    00166                                                         {
    00167                                                                 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
    00168                                                                 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
    00169                                                         }
    00170                             ++pOpt;
    00171                         }
    00172                     }
    00173                 }
    00174
    00175                 return TRUE;
    00176
    00177             case IDC_LST_OPTIONS:
    00178                 if (HIWORD(wParam) == LBN_SELCHANGE)
    00179                 {
    00180                     // Selection in list box of options changed
    00181                     // Update combo and label in edit section
    00182                     hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
    00183                     sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
    00184                     if (sel != -1)
    00185                     {
    00186                         ConfigOptionMap::iterator pOpt = opts.begin();
    00187                         for (i = 0; i < sel; i++)
    00188                             ++pOpt;
    00189                         // Set label text
    00190                         hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
    00191                         SetWindowText(hwndDlgItem, pOpt->second.name.c_str());
    00192                         // Set combo options
    00193                         hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
    00194                         SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
    00195                         StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
    00196                         i = 0;
    00197                         while (pPoss!=pOpt->second.possibleValues.end())
    00198                         {
    00199                             SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)pPoss[0].c_str());
    00200                             if (pPoss[0] == pOpt->second.currentValue)
    00201                                 // Select current value
    00202                                 SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
    00203                             ++pPoss;
    00204                             ++i;
    00205                         }
    00206                         // Enable/disable combo depending on (not)immutable
    00207                         EnableWindow(hwndDlgItem, !(pOpt->second.immutable));
    00208                     }
    00209                 }
    00210
    00211                 return TRUE;
    00212
    00213             case IDC_CBO_OPTION:
    00214                 if (HIWORD(wParam) == CBN_SELCHANGE)
    00215                 {
    00216                     // Updated an option
    00217                     // Get option
    00218                     hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
    00219                     sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
    00220                     savedSel = sel;
    00221                     ConfigOptionMap::iterator pOpt = opts.begin();
    00222                     for (i = 0; i < sel; i++)
    00223                         ++pOpt;
    00224                     // Get selected value
    00225                     hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
    00226                     sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0);
    00227
    00228                     if (sel != -1)
    00229                     {
    00230                         StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
    00231
    00232                         // Set option
    00233                         dlg->m_pSelectedRenderSystem->SetConfigOption(
    00234                             pOpt->second.name, pPoss[sel]);
    00235                         // Re-retrieve options
    00236                         opts = dlg->m_pSelectedRenderSystem->GetConfigOptions();
    00237
    00238                         // Reset options list box
    00239                         hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
    00240                         SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
    00241                         // Iterate through options
    00242                         pOpt = opts.begin();
    00243                         String strLine;
    00244                         while (pOpt!=opts.end())
    00245                         {
    00246                                                         if (pOpt->second.name != "RenderSystem")
    00247                                                         {
    00248                                                                 strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
    00249                                                                 SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
    00250                                                         }
    00251                             ++pOpt;
    00252                         }
    00253                         // Select previously selected item
    00254                         SendMessage(hwndDlgItem, LB_SETCURSEL, savedSel, 0);
    00255                     }
    00256
    00257                 }
    00258                 return TRUE;
    00259
    00260             case IDOK:
    00261                 // Set render system
    00262                 if (!dlg->m_pSelectedRenderSystem)
    00263                 {
    00264                     MessageBox(NULL, "Please choose a rendering system.", "KEOS", MB_OK | MB_ICONEXCLAMATION);
    00265                     return TRUE;
    00266                 }
    00267
    00268                 CRoot::Instance().SetRenderSystem(dlg->m_pSelectedRenderSystem);
    00269                 CRoot::Instance().SaveConfig();
    00270
    00271                 EndDialog(hDlg, TRUE);
    00272                 return TRUE;
    00273
    00274             case IDCANCEL:
    00275                 EndDialog(hDlg, FALSE);
    00276                 return TRUE;
    00277             }
    00278         }
    00279
    00280         return FALSE;
    00281     }
    00282
    00283         //-----------------------------------------------------------------------
    00284     bool CWin32ConfigDialog::Display(void)
    00285     {
    00286         // Display dialog
    00287         // Don't return to caller until dialog dismissed
    00288         int i;
    00289         dlg = this;
    00290         i = DialogBox(m_HInstance, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), NULL, DlgProc);
    00291
    00292         if (i == -1)
    00293         {
    00294             int winError = GetLastError();
    00295             char* errDesc;
    00296             int i;
    00297
    00298             errDesc = new char[255];
    00299             // Try windows errors first
    00300             i = FormatMessage(
    00301                 FORMAT_MESSAGE_FROM_SYSTEM |
    00302                 FORMAT_MESSAGE_IGNORE_INSERTS,
    00303                 NULL,
    00304                 winError,
    00305                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    00306                 (LPTSTR) errDesc,
    00307                 255,
    00308                 NULL
    00309             );
    00310
    00311             throw CException("CWin32ConfigDialog::Display");
    00312         }
    00313         if (i)
    00314             return true;
    00315         else
    00316             return false;
    00317     }
    00318 } // namespace Keos
    00319