source: OGRE/trunk/ogrenew/Mac/XCode/Ogre/macOgreSDLConfig.mm @ 692

Revision 692, 3.9 KB checked in by mattausch, 19 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://ogre.sourceforge.net/
6
7Copyright © 2000-2002 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  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  License for more details.
18
19You should have received a copy of the GNU Lesser General  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
26
27#import <Cocoa/Cocoa.h>
28#import "macOgreConfigWindowController.h"
29#include "macOgreSDLConfig.h"
30
31
32
33using namespace Ogre;
34
35bool SDLConfig::display(void)
36{
37    OgreConfigWindowController *config = [[OgreConfigWindowController alloc]
38                                            initWithWindowNibName: [ NSString stringWithCString: "config"]];
39   
40        // Get the renderer
41    [config setMessage: [NSString stringWithCString: "Select Renderer:"]];
42   
43   
44    RenderSystemList* renderers = Root::getSingleton().getAvailableRenderers();
45    for (RenderSystemList::iterator pRend = renderers->begin();
46            pRend != renderers->end(); pRend++)
47    {
48        [config addOption: [NSString stringWithCString: ((*pRend)->getName()).c_str()]];
49    }
50
51    int rendererIndex = [config pickOption];
52    if(rendererIndex < 0) {
53        return false;
54    }
55
56
57    RenderSystemList::iterator pRend =  renderers->begin();
58
59    RenderSystem* renderer = pRend[rendererIndex];
60
61    ConfigOptionMap options = renderer->getConfigOptions();
62
63    // Process each option
64    for (ConfigOptionMap::iterator it = options.begin();
65            it != options.end(); it++)
66    {
67        [config setMessage: [NSString stringWithCString: it->second.name.c_str()]];
68       
69        StringVector::iterator opt_it;
70        for (opt_it = it->second.possibleValues.begin();
71                opt_it != it->second.possibleValues.end(); opt_it++)
72        {
73            [config addOption: [NSString stringWithCString: (*opt_it).c_str()]];
74            if ((*opt_it) == it->second.currentValue) {
75                [config setDefault];
76            }
77        }
78
79        int x = [config pickOption];
80        if(x < 0) // x < 0 flag that user cancelled
81            return false;
82       
83        opt_it = it->second.possibleValues.begin();
84        renderer->setConfigOption(it->second.name, opt_it[x]);
85    }
86
87    // All done
88    Root::getSingleton().setRenderSystem(renderer);
89    Root::getSingleton().saveConfig();   
90    [config release];
91    return true;
92}
93
94
95@implementation OgreConfigWindowController : NSWindowController
96
97-(void) setMessage: (NSString *)message {
98    [self window];//ensure window is loaded
99    [messageTextField setStringValue: message];
100    [optionsPopUp removeAllItems];
101}
102
103-(void) addOption: (NSString *)title {
104    [optionsPopUp addItemWithTitle: title];
105}
106
107-(void) setDefault {
108    [optionsPopUp selectItem: [optionsPopUp lastItem]];
109}
110
111-(void) okClicked: (id)sender{
112    [[NSApplication sharedApplication]stopModal];
113    chosen = [optionsPopUp indexOfSelectedItem];
114}
115
116-(void) cancelClicked: (id)sender {
117    [[NSApplication sharedApplication]stopModal];
118    chosen = -1; //flag to abort
119}
120
121-(int) pickOption {
122    [self showWindow: self];
123    chosen = -1; //flag to abort
124    //run loop
125   
126    [[NSApplication sharedApplication]runModalForWindow: [self window]];
127
128    [[self window] close];
129    return chosen;
130}
131
132@end
Note: See TracBrowser for help on using the repository browser.