Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/WIN32/OgreConfigDialog.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 12.5 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30#include "OgreConfigDialog.h"
31#include "OgreRoot.h"
32#include "OgreRenderSystem.h"
33#include "OgreException.h"
34#include "resource.h"
35
36namespace
37{
38    Ogre::ConfigDialog* dlg;  // This is a pointer to instance, since this is a static member
39}
40
41
42namespace Ogre
43{
44    ConfigDialog::ConfigDialog()
45    {
46#ifdef OGRE_STATIC_LIB
47                mHInstance = GetModuleHandle( NULL );
48#else
49#  if OGRE_DEBUG_MODE == 1
50        mHInstance = GetModuleHandle("OgreMain_d.dll");
51#  else
52        mHInstance = GetModuleHandle("OgreMain.dll");
53#  endif
54#endif
55        mSelectedRenderSystem = 0;
56    }
57
58        ConfigDialog::~ConfigDialog()
59    {
60        }
61
62#if OGRE_ARCHITECTURE_64 == OGRE_ARCH_TYPE
63    INT_PTR ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
64#else
65    BOOL ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
66#endif
67    {
68        HWND hwndDlgItem;
69        static RenderSystemList* lstRend;
70        RenderSystemList::iterator pRend;
71        static ConfigOptionMap opts;
72        String err;
73
74        int i, sel, savedSel;
75
76        switch (iMsg)
77        {
78
79        case WM_INITDIALOG:
80            // Load saved settings
81            dlg->mSelectedRenderSystem = Root::getSingleton().getRenderSystem();
82            // Get all render systems
83            lstRend = Root::getSingleton().getAvailableRenderers();
84            pRend = lstRend->begin();           
85            i = 0;
86            while (pRend != lstRend->end())
87            {
88                hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
89
90                SendMessage(hwndDlgItem, CB_ADDSTRING, 0,
91                    (LPARAM)(char*)(*pRend)->getName().c_str());
92
93                if (*pRend == dlg->mSelectedRenderSystem)
94                {
95                    // Select
96                    SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
97                    // Refresh Options
98                    // Get options from render system
99                    opts = (*pRend)->getConfigOptions();
100                    // Reset list box
101                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
102                    //SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
103                    // Iterate through options
104                    ConfigOptionMap::iterator pOpt = opts.begin();
105                    String strLine;
106                    while( pOpt!= opts.end() )
107                    {
108                        strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
109                        SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
110                        ++pOpt;
111                    }
112                }
113
114                ++pRend;
115                ++i;
116            }
117
118            // Center myself
119            int x, y, screenWidth, screenHeight;
120            RECT rcDlg;
121            GetWindowRect(hDlg, &rcDlg);
122            screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
123            screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
124
125            x = (screenWidth / 2) - ((rcDlg.right - rcDlg.left) / 2);
126            y = (screenHeight / 2) - ((rcDlg.bottom - rcDlg.top) / 2);
127
128            MoveWindow(hDlg, x, y, (rcDlg.right - rcDlg.left),
129                (rcDlg.bottom - rcDlg.top), TRUE);
130
131            return TRUE;
132
133        case WM_COMMAND:
134            switch (LOWORD(wParam))
135            {
136            case IDC_CBO_RENDERSYSTEM:
137                hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
138                sel = SendMessage( hwndDlgItem, CB_GETCOUNT, 0, 0 );
139
140                if (HIWORD(wParam) == CBN_SELCHANGE )
141                {
142                    // RenderSystem selected
143                    // Get selected index
144                    hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
145                    sel = SendMessage(hwndDlgItem, CB_GETCURSEL,0,0);
146                    if (sel != -1)
147                    {
148                        // Get RenderSystem selected
149                        pRend = lstRend->begin();
150                        dlg->mSelectedRenderSystem = pRend[sel];
151                        // refresh options
152                        // Get options from render system
153                        opts = pRend[sel]->getConfigOptions();
154                        // Reset list box
155                        hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
156                        SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
157                        // Iterate through options
158                        ConfigOptionMap::iterator pOpt = opts.begin();
159                        String strLine;
160                        while (pOpt!=opts.end())
161                        {
162                            strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
163                            SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
164                            ++pOpt;
165                        }
166                    }                   
167                }
168
169                return TRUE;
170
171            case IDC_LST_OPTIONS:
172                if (HIWORD(wParam) == LBN_SELCHANGE)
173                {
174                    // Selection in list box of options changed
175                    // Update combo and label in edit section
176                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
177                    sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
178                    if (sel != -1)
179                    {
180                        ConfigOptionMap::iterator pOpt = opts.begin();
181                        for (i = 0; i < sel; i++)
182                            ++pOpt;
183                        // Set label text
184                        hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
185                        SetWindowText(hwndDlgItem, pOpt->second.name.c_str());
186                        // Set combo options
187                        hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
188                        SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
189                        StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
190                        i = 0;
191                        while (pPoss!=pOpt->second.possibleValues.end())
192                        {
193                            SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)pPoss[0].c_str());
194                            if (pPoss[0] == pOpt->second.currentValue)
195                                // Select current value
196                                SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
197                            ++pPoss;
198                            ++i;
199                        }
200                        // Enable/disable combo depending on (not)immutable
201                        EnableWindow(hwndDlgItem, !(pOpt->second.immutable));
202                    }
203                }
204
205                return TRUE;
206
207            case IDC_CBO_OPTION:
208                if (HIWORD(wParam) == CBN_SELCHANGE)
209                {
210                    // Updated an option
211                    // Get option
212                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
213                    sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
214                    savedSel = sel;
215                    ConfigOptionMap::iterator pOpt = opts.begin();
216                    for (i = 0; i < sel; i++)
217                        ++pOpt;
218                    // Get selected value
219                    hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
220                    sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0);
221
222                    if (sel != -1)
223                    {
224                        StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
225
226                        // Set option
227                        dlg->mSelectedRenderSystem->setConfigOption(
228                            pOpt->second.name, pPoss[sel]);
229                        // Re-retrieve options
230                        opts = dlg->mSelectedRenderSystem->getConfigOptions();
231
232                        // Reset options list box
233                        hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
234                        SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
235                        // Iterate through options
236                        pOpt = opts.begin();
237                        String strLine;
238                        while (pOpt!=opts.end())
239                        {
240                            strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
241                            SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
242                            ++pOpt;
243                        }
244                        // Select previously selected item
245                        SendMessage(hwndDlgItem, LB_SETCURSEL, savedSel, 0);
246                    }
247
248                }
249                return TRUE;
250
251            case IDOK:
252                // Set render system
253                if (!dlg->mSelectedRenderSystem)
254                {
255                    MessageBox(NULL, "Please choose a rendering system.", "OGRE", MB_OK | MB_ICONEXCLAMATION);
256                    return TRUE;
257                }
258                err = dlg->mSelectedRenderSystem->validateConfigOptions();
259                if (err.length() > 0)
260                {
261                    // refresh options incase updated by validation
262                    // Get options from render system
263                    opts = dlg->mSelectedRenderSystem->getConfigOptions();
264                    // Reset list box
265                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
266                    SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
267                    // Iterate through options
268                    ConfigOptionMap::iterator pOpt = opts.begin();
269                    String strLine;
270                    while (pOpt!=opts.end())
271                    {
272                        strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
273                        SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
274                        ++pOpt;
275                    }
276                    MessageBox(NULL, err.c_str(), "OGRE", MB_OK | MB_ICONEXCLAMATION);
277                    return TRUE;
278                }
279
280                Root::getSingleton().setRenderSystem(dlg->mSelectedRenderSystem);
281
282                EndDialog(hDlg, TRUE);
283                return TRUE;
284
285            case IDCANCEL:
286                EndDialog(hDlg, FALSE);
287                return TRUE;
288            }
289        }
290
291        return FALSE;
292    }
293
294
295    bool ConfigDialog::display(void)
296    {
297        // Display dialog
298        // Don't return to caller until dialog dismissed
299        int i;
300        dlg = this;
301       
302        i = DialogBox(mHInstance, MAKEINTRESOURCE(IDD_DLG_CONFIG), NULL, DlgProc);
303
304        if (i == -1)
305        {
306            int winError = GetLastError();
307            char* errDesc;
308            int i;
309
310            errDesc = new char[255];
311            // Try windows errors first
312            i = FormatMessage(
313                FORMAT_MESSAGE_FROM_SYSTEM |
314                FORMAT_MESSAGE_IGNORE_INSERTS,
315                NULL,
316                winError,
317                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
318                (LPTSTR) errDesc,
319                255,
320                NULL
321            );
322
323            throw Exception(winError,errDesc, "ConfigDialog::display");
324        }
325        if (i)
326            return true;
327        else
328            return false;
329
330    }
331}
Note: See TracBrowser for help on using the repository browser.