Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OSX/OgreConfigDialog.cpp @ 5

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

=hoffentlich gehts jetzt

File size: 10.3 KB
Line 
1#include <Quicktime/Quicktime.h>
2#include "OgreLogManager.h"
3#include "OgreConfigDialog.h"
4
5namespace Ogre {
6
7        ConfigDialog* dlg = NULL;
8        static EventHandlerUPP WindowEventHandlerUPP;
9
10        ConfigDialog::ConfigDialog() : iSelectedRenderSystem( NULL ), iVideoModeRef( NULL ), iLogoViewRef( NULL ), iWindowRef( NULL ), iNibRef( NULL ), iMenuRef( NULL )
11        {
12                dlg = this;
13        }
14       
15        ConfigDialog::~ConfigDialog()
16        {
17        }
18       
19        void ConfigDialog::initialise()
20        {
21                RenderSystemList* renderers = Root::getSingleton().getAvailableRenderers();
22                RenderSystem* renderer = renderers->front();
23                ConfigOptionMap config = renderer->getConfigOptions();
24
25                ConfigOptionMap::iterator cfi;
26               
27                cfi = config.find( "Full Screen" );
28                if( cfi != config.end() )
29                {
30                        if( cfi->second.currentValue == "Yes" )
31                        {
32                                SetControlValue( iFullScreenRef, 1 );
33                        }
34                        else
35                        {
36                                SetControlValue( iFullScreenRef, 2 );
37                        }
38                }
39
40                cfi = config.find( "FSAA" );
41                if( cfi != config.end() )
42                {
43                        if( cfi->second.currentValue == "0" )
44                        {
45                                SetControlValue( iFSAARef, 1 );
46                        }
47                        else if( cfi->second.currentValue == "2" )
48                        {
49                                SetControlValue( iFSAARef, 2 );
50                        }
51                        else if( cfi->second.currentValue == "4" )
52                        {
53                                SetControlValue( iFSAARef, 3 );
54                        }
55                        else if( cfi->second.currentValue == "6" )
56                        {
57                                SetControlValue( iFSAARef, 4 );
58                        }
59                }
60
61                cfi = config.find( "Colour Depth" );
62                if( cfi != config.end() )
63                {
64                        if( cfi->second.currentValue == "32" )
65                        {
66                                SetControlValue( iColorDepthRef, 1 );
67                        }
68                        else
69                        {
70                                SetControlValue( iColorDepthRef, 2 );
71                        }
72                }
73               
74                cfi = config.find( "RTT Preferred Mode" );
75                if( cfi != config.end() )
76                {
77                        if( cfi->second.currentValue == "FBO" )
78                        {
79                                SetControlValue( iRTTPrefModeRef, 1 );
80                        }
81                        else if( cfi->second.currentValue == "PBuffer" )
82                        {
83                                SetControlValue( iRTTPrefModeRef, 2 );
84                        }
85                        else if( cfi->second.currentValue == "Copy" )
86                        {
87                                SetControlValue( iRTTPrefModeRef, 3 );
88                        }
89                }
90        }
91       
92        void ConfigDialog::run()
93        {
94                RenderSystemList* renderers = Root::getSingleton().getAvailableRenderers();
95                RenderSystem* renderer = renderers->front();
96
97                SInt16 value = 0;
98
99                // temp
100                value = GetControlValue( iVideoModeRef );
101                renderer->setConfigOption( "Video Mode", "800 x 600" );
102
103                // full screen
104                value = GetControlValue( iFullScreenRef );
105                if( value == 1 ) // Yes
106                {
107                        LogManager::getSingleton().logMessage( "CONFIG => FullScreen [ Yes ]" );
108                        renderer->setConfigOption( "Full Screen", "Yes" );
109                }
110                else
111                {
112                        LogManager::getSingleton().logMessage( "CONFIG => FullScreen [ No ]" );
113                        renderer->setConfigOption( "Full Screen", "No" );
114                }
115               
116                // fsaa
117                value = GetControlValue( iFSAARef );
118                switch( value )
119                {
120                        case 1:
121                                renderer->setConfigOption( "FSAA", "0" );
122                                break;
123                        case 2:
124                                renderer->setConfigOption( "FSAA", "2" );
125                                break;
126                        case 3:
127                                renderer->setConfigOption( "FSAA", "4" );
128                                break;
129                        case 4:
130                                LogManager::getSingleton().logMessage( "CONFIG => FSAA [ 6 ]" );
131                                renderer->setConfigOption( "FSAA", "6" );
132                                break;
133                        default:
134                                renderer->setConfigOption( "FSAA", "0" );
135                                break;
136                }
137
138                // fsaa
139                value = GetControlValue( iColorDepthRef );
140                if( value == 1 )
141                {
142                        renderer->setConfigOption( "Colour Depth", "32" );
143                }
144                else
145                {
146                        renderer->setConfigOption( "Colour Depth", "16" );
147                }
148
149                // rtt pref mode
150                value = GetControlValue( iRTTPrefModeRef );
151                switch( value )
152                {
153                        case 1:
154                                renderer->setConfigOption( "RTT Preferred Mode", "FBO" );
155                                break;
156                        case 2:
157                                renderer->setConfigOption( "RTT Preferred Mode", "PBuffer" );
158                                break;
159                        case 3:
160                                renderer->setConfigOption( "RTT Preferred Mode", "Copy" );
161                                break;
162                }
163
164                Root::getSingleton().setRenderSystem( renderer );
165
166                iDisplayStatus = true;
167
168                QuitAppModalLoopForWindow( iWindowRef );
169        }
170       
171        void ConfigDialog::cancel()
172        {
173                iDisplayStatus = false;
174                QuitAppModalLoopForWindow( iWindowRef );
175        }
176       
177        pascal OSStatus ConfigDialog::windowEventHandler( EventHandlerCallRef aNextHandler, EventRef aEvent, void* aUserData )
178        {
179                #pragma unused ( inCallRef )
180                OSStatus status = eventNotHandledErr;
181                UInt32 eventKind = GetEventKind( aEvent );
182                UInt32 eventClass = GetEventClass( aEvent );
183                WindowRef window = ( WindowRef ) aUserData;
184                HICommand command;
185                if( eventClass == kEventClassWindow && eventKind == kEventWindowClose )
186                {
187                        QuitAppModalLoopForWindow( window );
188                }
189                else if( eventClass == kEventClassCommand && eventKind == kEventCommandProcess )
190                {
191                        GetEventParameter( aEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( HICommand ), NULL, &command );
192                        switch( command.commandID )
193                        {
194                                case 'run!':
195                                        {
196                                        dlg->run();
197                                        break;
198                                        }
199                                case 'not!':
200                                        {
201                                        dlg->cancel();
202                                        break;
203                                        }
204                                default:
205                                        break;
206                        }
207                }
208                return ( status );
209        }
210
211        bool ConfigDialog::display()
212        {
213                // TODO: Fix OS X Config dialog
214                RenderSystemList* renderers = Root::getSingleton().getAvailableRenderers();
215                RenderSystem* renderer = renderers->front();
216
217                // WARNING: restoreConfig() should not be invoked here as Root calls
218                // it before this method anyway, and invoking restoreConfig() here
219                // forces the client application to use Ogre.cfg, while it may have
220                // different plans.
221                if(!Root::getSingleton().restoreConfig())
222                {
223                        // Set some defaults
224                        renderer->setConfigOption("Video Mode", "800 x 600");
225                        renderer->setConfigOption("Colour Depth", "32");
226                        renderer->setConfigOption("FSAA", "0");
227                        renderer->setConfigOption("Full Screen", "No");
228                        renderer->setConfigOption("RTT Preferred Mode", "PBuffer");
229                        // Set the rendersystem and save the config.
230                        Root::getSingleton().setRenderSystem(renderer);
231                }
232                return true;
233        /*
234                iDisplayStatus = false;
235                OSStatus status;
236                CFStringRef logoRef = NULL;
237                CFURLRef logoUrlRef = NULL;
238                OSType dataRefType;
239                GraphicsImportComponent ci = NULL;
240                CGImageRef cgImageRef = NULL;
241                Handle dataRef = NULL;
242
243                HIViewID logoViewID = { 'CONF', 100 };
244                HIViewID videoModeViewID = { 'CONF', 104 };
245                HIViewID colorDepthViewID = { 'CONF', 105 };
246                HIViewID fsaaViewID = { 'CONF', 106 };
247                HIViewID rttPrefModeViewID = { 'CONF', 107 };
248                HIViewID fullScreenViewID = { 'CONF', 108 };
249
250                const EventTypeSpec windowEvents[] =
251                {
252                        { kEventClassCommand, kEventCommandProcess },
253                        { kEventClassWindow, kEventWindowClose }
254                };
255
256                // We need to get the Ogre Bundle
257                CFBundleRef baseBundle = CFBundleGetBundleWithIdentifier(CFSTR("org.ogre3d.Ogre"));
258                status  = CreateNibReferenceWithCFBundle(baseBundle, CFSTR("main"), &iNibRef );
259                require_noerr( status, CantGetNibRef );
260
261                status  = CreateWindowFromNib( iNibRef, CFSTR( "ConfigWindow" ), &iWindowRef );
262                require_noerr( status, CantCreateWindow );
263
264                if( WindowEventHandlerUPP == NULL )
265                        WindowEventHandlerUPP = NewEventHandlerUPP( windowEventHandler );
266
267                status = InstallWindowEventHandler( iWindowRef, WindowEventHandlerUPP, GetEventTypeCount( windowEvents ), windowEvents, iWindowRef, NULL );
268                //status = InstallStandardEventHandler(GetWindowEventTarget(iWindowRef));
269                require_noerr( status, CantInstallWindowEventHandler );
270
271                //logoRef = CFStringCreateWithCString( kCFAllocatorDefault, "file:///Users/aljen/Code/OSXConfig/logo.bmp", NULL );
272                //logoUrlRef = CFURLCreateWithString( kCFAllocatorDefault, logoRef, NULL );
273
274                //status = QTNewDataReferenceFromCFURL( logoUrlRef, 0, &dataRef, &dataRefType );
275                //status        = GetGraphicsImporterForDataRef( dataRef, dataRefType, &ci );
276                //require( ci != NULL, ImporterError );
277                //status        = GraphicsImportCreateCGImage( ci, &cgImageRef, kGraphicsImportCreateCGImageUsingCurrentSettings );
278               
279                // logo view
280                status  = HIViewFindByID( HIViewGetRoot( iWindowRef ), logoViewID, &iLogoViewRef );
281                require_noerr( status, LogoViewNotFound );
282                status  = HIImageViewSetImage( iLogoViewRef, cgImageRef );
283                require_noerr( status, SetImageFailed );
284                status  = HIImageViewSetScaleToFit( iLogoViewRef, false );
285                require_noerr( status, ScaleFailed );
286                status  = HIViewSetVisible( iLogoViewRef, true );
287                require_noerr( status, SetVisibleFailed );
288               
289                // video mode view
290                status  = HIViewFindByID( HIViewGetRoot( iWindowRef ), videoModeViewID, &iVideoModeRef );
291
292                CreateNewMenu( iMenuID, 0, &iMenuRef );
293
294                if( iMenuRef != NULL )
295                {
296                        CFStringRef itemNames[] =
297                        {
298                                CFSTR( "640 x 480" ),
299                                CFSTR( "800 x 600" ),
300                                CFSTR( "1024 x 768" )
301                        };
302
303                        MenuItemIndex numItems = ( sizeof( itemNames ) / sizeof( CFStringRef ) );
304                        for( int i = 0; i < numItems; i++ )
305                        {
306                                MenuItemIndex newItem;
307                                AppendMenuItemTextWithCFString( iMenuRef, itemNames[ i ], 0, 0, &newItem );
308                        }
309                       
310                        SetControlData( iVideoModeRef, kControlEntireControl, kControlPopupButtonMenuRefTag, sizeof( MenuRef ), &iMenuRef );
311                }
312
313                // color depth view
314                status = HIViewFindByID( HIViewGetRoot( iWindowRef ), colorDepthViewID, &iColorDepthRef );
315
316                // fsaa view
317                status = HIViewFindByID( HIViewGetRoot( iWindowRef ), fsaaViewID, &iFSAARef );
318
319                // rtt pref mode view
320                status = HIViewFindByID( HIViewGetRoot( iWindowRef ), rttPrefModeViewID, &iRTTPrefModeRef );
321
322                // full screen view
323                status = HIViewFindByID( HIViewGetRoot( iWindowRef ), fullScreenViewID, &iFullScreenRef );
324
325                DisposeNibReference( iNibRef );
326
327                initialise();
328               
329                RepositionWindow( iWindowRef, NULL, kWindowCenterOnMainScreen );
330                TransitionWindow( iWindowRef, kWindowFadeTransitionEffect, kWindowShowTransitionAction, NULL );
331                SelectWindow( iWindowRef );
332                ActivateWindow( iWindowRef, true );
333                RunAppModalLoopForWindow( iWindowRef );
334               
335                TransitionWindow( iWindowRef, kWindowFadeTransitionEffect, kWindowHideTransitionAction, NULL );
336                DisposeWindow( iWindowRef );
337
338                return iDisplayStatus;
339
340        CantGetNibRef:
341                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:CantGetNibRef" );
342        CantCreateWindow:
343                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:CantCreateWindow" );
344        CantInstallWindowEventHandler:
345                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:CantInstallWindowEventHandler" );
346        ImporterError:
347                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:ImporterError" );
348        LogoViewNotFound:
349                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:LogoViewNotFound" );
350        SetImageFailed:
351                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:SetImageFailed" );
352        ScaleFailed:
353                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:SetScaleFailed" );
354        SetVisibleFailed:
355                LogManager::getSingleton().logMessage( "ConfigDialog::display() => err:SetVisibleFailed" );
356                return( iDisplayStatus );
357
358
359                return true;
360        */
361        }
362
363};
Note: See TracBrowser for help on using the repository browser.