source: OGRE/trunk/ogrenew/PlatformManagers/Win32/src/OgreWin32ConfigDialog.cpp @ 692

Revision 692, 12.5 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#include "OgreWin32ConfigDialog.h"
26#include "OgreRoot.h"
27#include "OgreRenderSystem.h"
28#include "resource.h"
29#include "OgreException.h"
30
31namespace
32{
33    Ogre::Win32ConfigDialog* dlg;  // This is a pointer to instance, since this is a static member
34}
35
36
37namespace Ogre
38{
39    Win32ConfigDialog::Win32ConfigDialog(HINSTANCE hInst)
40    {
41        mHInstance = hInst;
42        mSelectedRenderSystem = 0;
43    }
44
45#if OGRE_ARCHITECTURE_64 == OGRE_ARCH_TYPE
46    INT_PTR Win32ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
47#else
48    BOOL Win32ConfigDialog::DlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
49#endif
50    {
51        HWND hwndDlgItem;
52        static RenderSystemList* lstRend;
53        RenderSystemList::iterator pRend;
54        static ConfigOptionMap opts;
55        String err;
56
57        int i, sel, savedSel;
58        static bool fullScreen = true;
59
60
61        switch (iMsg)
62        {
63
64        case WM_INITDIALOG:
65            // Load saved settings
66            Root::getSingleton().restoreConfig();
67            dlg->mSelectedRenderSystem = Root::getSingleton().getRenderSystem();
68            // Get all render systems
69            lstRend = Root::getSingleton().getAvailableRenderers();
70            pRend = lstRend->begin();           
71            i = 0;
72            while (pRend != lstRend->end())
73            {
74                hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
75
76                SendMessage(hwndDlgItem, CB_ADDSTRING, 0,
77                    (LPARAM)(char*)(*pRend)->getName().c_str());
78
79                if (*pRend == dlg->mSelectedRenderSystem)
80                {
81                    // Select
82                    SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
83                    // Refresh Options
84                    // Get options from render system
85                    opts = (*pRend)->getConfigOptions();
86                    // Reset list box
87                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
88                    //SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
89                    // Iterate through options
90                    ConfigOptionMap::iterator pOpt = opts.begin();
91                    String strLine;
92                    while( pOpt!= opts.end() )
93                    {
94                        strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
95                        SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
96                        ++pOpt;
97                    }
98                }
99
100                ++pRend;
101                ++i;
102            }
103
104            // Center myself
105            int x, y, screenWidth, screenHeight;
106            RECT rcDlg;
107            GetWindowRect(hDlg, &rcDlg);
108            screenWidth = GetSystemMetrics(SM_CXFULLSCREEN);
109            screenHeight = GetSystemMetrics(SM_CYFULLSCREEN);
110
111            x = (screenWidth / 2) - ((rcDlg.right - rcDlg.left) / 2);
112            y = (screenHeight / 2) - ((rcDlg.bottom - rcDlg.top) / 2);
113
114            MoveWindow(hDlg, x, y, (rcDlg.right - rcDlg.left),
115                (rcDlg.bottom - rcDlg.top), TRUE);
116
117            return TRUE;
118
119        case WM_COMMAND:
120            switch (LOWORD(wParam))
121            {
122            case IDC_CBO_RENDERSYSTEM:
123                hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
124                sel = SendMessage( hwndDlgItem, CB_GETCOUNT, 0, 0 );
125
126                if (HIWORD(wParam) == CBN_SELCHANGE )
127                {
128                    // RenderSystem selected
129                    // Get selected index
130                    hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_RENDERSYSTEM);
131                    sel = SendMessage(hwndDlgItem, CB_GETCURSEL,0,0);
132                    if (sel != -1)
133                    {
134                        // Get RenderSystem selected
135                        pRend = lstRend->begin();
136                        dlg->mSelectedRenderSystem = pRend[sel];
137                        // refresh options
138                        // Get options from render system
139                        opts = pRend[sel]->getConfigOptions();
140                        // Reset list box
141                        hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
142                        SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
143                        // Iterate through options
144                        ConfigOptionMap::iterator pOpt = opts.begin();
145                        String strLine;
146                        while (pOpt!=opts.end())
147                        {
148                            strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
149                            SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
150                            ++pOpt;
151                        }
152                    }                   
153                }
154
155                return TRUE;
156
157            case IDC_LST_OPTIONS:
158                if (HIWORD(wParam) == LBN_SELCHANGE)
159                {
160                    // Selection in list box of options changed
161                    // Update combo and label in edit section
162                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
163                    sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
164                    if (sel != -1)
165                    {
166                        ConfigOptionMap::iterator pOpt = opts.begin();
167                        for (i = 0; i < sel; i++)
168                            ++pOpt;
169                        // Set label text
170                        hwndDlgItem = GetDlgItem(hDlg, IDC_LBL_OPTION);
171                        SetWindowText(hwndDlgItem, pOpt->second.name.c_str());
172                        // Set combo options
173                        hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
174                        SendMessage(hwndDlgItem, CB_RESETCONTENT, 0, 0);
175                        StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
176                        i = 0;
177                        while (pPoss!=pOpt->second.possibleValues.end())
178                        {
179                            SendMessage(hwndDlgItem, CB_ADDSTRING, 0, (LPARAM)pPoss[0].c_str());
180                            if (pPoss[0] == pOpt->second.currentValue)
181                                // Select current value
182                                SendMessage(hwndDlgItem, CB_SETCURSEL, (WPARAM)i, 0);
183                            ++pPoss;
184                            ++i;
185                        }
186                        // Enable/disable combo depending on (not)immutable
187                        EnableWindow(hwndDlgItem, !(pOpt->second.immutable));
188                    }
189                }
190
191                return TRUE;
192
193            case IDC_CBO_OPTION:
194                if (HIWORD(wParam) == CBN_SELCHANGE)
195                {
196                    // Updated an option
197                    // Get option
198                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
199                    sel = SendMessage(hwndDlgItem, LB_GETCURSEL, 0, 0);
200                    savedSel = sel;
201                    ConfigOptionMap::iterator pOpt = opts.begin();
202                    for (i = 0; i < sel; i++)
203                        ++pOpt;
204                    // Get selected value
205                    hwndDlgItem = GetDlgItem(hDlg, IDC_CBO_OPTION);
206                    sel = SendMessage(hwndDlgItem, CB_GETCURSEL, 0, 0);
207
208                    if (sel != -1)
209                    {
210                        StringVector::iterator pPoss = pOpt->second.possibleValues.begin();
211
212                        // Set option
213                        dlg->mSelectedRenderSystem->setConfigOption(
214                            pOpt->second.name, pPoss[sel]);
215                        // Re-retrieve options
216                        opts = dlg->mSelectedRenderSystem->getConfigOptions();
217
218                        // Reset options list box
219                        hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
220                        SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
221                        // Iterate through options
222                        pOpt = opts.begin();
223                        String strLine;
224                        while (pOpt!=opts.end())
225                        {
226                            strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
227                            SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
228                            ++pOpt;
229                        }
230                        // Select previously selected item
231                        SendMessage(hwndDlgItem, LB_SETCURSEL, savedSel, 0);
232                    }
233
234                }
235                return TRUE;
236
237            case IDOK:
238                // Set render system
239                if (!dlg->mSelectedRenderSystem)
240                {
241                    MessageBox(NULL, "Please choose a rendering system.", "OGRE", MB_OK | MB_ICONEXCLAMATION);
242                    return TRUE;
243                }
244                err = dlg->mSelectedRenderSystem->validateConfigOptions();
245                if (err.length() > 0)
246                {
247                    // refresh options incase updated by validation
248                    // Get options from render system
249                    opts = dlg->mSelectedRenderSystem->getConfigOptions();
250                    // Reset list box
251                    hwndDlgItem = GetDlgItem(hDlg, IDC_LST_OPTIONS);
252                    SendMessage(hwndDlgItem, LB_RESETCONTENT, 0, 0);
253                    // Iterate through options
254                    ConfigOptionMap::iterator pOpt = opts.begin();
255                    String strLine;
256                    while (pOpt!=opts.end())
257                    {
258                        strLine = pOpt->second.name + ": " + pOpt->second.currentValue;
259                        SendMessage(hwndDlgItem, LB_ADDSTRING, 0, (LPARAM)strLine.c_str());
260                        ++pOpt;
261                    }
262                    MessageBox(NULL, err.c_str(), "OGRE", MB_OK | MB_ICONEXCLAMATION);
263                    return TRUE;
264                }
265
266                Root::getSingleton().setRenderSystem(dlg->mSelectedRenderSystem);
267                Root::getSingleton().saveConfig();
268
269                EndDialog(hDlg, TRUE);
270                return TRUE;
271
272            case IDCANCEL:
273                EndDialog(hDlg, FALSE);
274                return TRUE;
275            }
276        }
277
278        return FALSE;
279    }
280
281
282    bool Win32ConfigDialog::display(void)
283    {
284        // Display dialog
285        // Don't return to caller until dialog dismissed
286        int i;
287        dlg = this;
288       
289        i = DialogBox(mHInstance, MAKEINTRESOURCE(IDD_DLG_CONFIG), NULL, DlgProc);
290
291        if (i == -1)
292        {
293            int winError = GetLastError();
294            char* errDesc;
295            int i;
296
297            errDesc = new char[255];
298            // Try windows errors first
299            i = FormatMessage(
300                FORMAT_MESSAGE_FROM_SYSTEM |
301                FORMAT_MESSAGE_IGNORE_INSERTS,
302                NULL,
303                winError,
304                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
305                (LPTSTR) errDesc,
306                255,
307                NULL
308            );
309
310            throw Exception(winError,errDesc, "Win32ConfigDialog::display");
311        }
312        if (i)
313            return true;
314        else
315            return false;
316
317    }
318}
Note: See TracBrowser for help on using the repository browser.