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

Revision 657, 12.3 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

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