Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgreWin32ConfigDialog.cpp

Go to the documentation of this file.

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

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:51 2004