source: OGRE/trunk/ogrenew/PlatformManagers/SDL/src/OgreSDLConfig_gtk.cpp @ 657

Revision 657, 6.1 KB checked in by mattausch, 19 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
12Free Software Foundation.
13
14This program is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public License along
19with this program; if not, write to the Free Software Foundation, Inc., 59
20Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21http://www.gnu.org/licenses/lgpl.html.
22-----------------------------------------------------------------------------
23*/
24
25#include "OgreSDLConfig.h"
26
27#include <libglademm/xml.h>
28
29#include <gtkmm/main.h>
30#include <gtkmm/menushell.h>
31#include <gtkmm/window.h>
32
33using namespace Ogre;
34using namespace Gtk::Menu_Helpers;
35
36bool SDLConfig::display(void)
37{
38    Gtk::Main kit(0, NULL);
39
40    std::string sharedir( SHAREDIR );
41    Glib::RefPtr<Gnome::Glade::Xml> xml = Gnome::Glade::Xml::create( sharedir + "/ogre-config.glade");
42    if (!xml)
43    {
44        LogManager::getSingleton().logMessage("Problem loading config");
45        exit(1);
46    }
47
48    _winConfig = NULL;
49    xml->get_widget("winConfig", _winConfig);
50    if (!_winConfig)
51    {
52        LogManager::getSingleton().logMessage("Invalid window.");
53        exit(1);
54    }
55
56    xml->get_widget("lstOptions", _lstOptions);
57    xml->get_widget("optRenderer", _optRenderer);
58    xml->get_widget("lblOptName", _lblOptName);
59    xml->get_widget("optOptValues", _optOptValues);
60    Gtk::Button* btn_ok;
61    xml->get_widget("btnOk", btn_ok);
62    Gtk::Button* btn_cancel;
63    xml->get_widget("btnCancel", btn_cancel);
64
65    _opt_menu = NULL;
66
67    // Hookup signals
68    _winConfig->signal_delete_event().connect(SigC::slot(*this,
69                &SDLConfig::on_window_delete));
70    _option_selection = _lstOptions->get_selection();
71    _option_selection->signal_changed().connect(SigC::slot(*this,
72                &SDLConfig::on_option_changed));
73    _optRenderer->signal_changed().connect(SigC::slot(*this,
74                &SDLConfig::on_renderer_changed));
75    _optOptValues->signal_changed().connect(SigC::slot(*this,
76                &SDLConfig::on_value_changed));
77    btn_ok->signal_clicked().connect(SigC::slot(*this, &SDLConfig::on_btn_ok));
78    btn_cancel->signal_clicked().connect(SigC::slot(&Gtk::Main::quit));
79
80
81    // Initialize
82    _list_store = Gtk::ListStore::create(_columns);
83    _lstOptions->set_model(_list_store);
84    _lstOptions->append_column("Option", _columns.col_name);
85    _lstOptions->append_column("Value", _columns.col_value);
86
87    // Setup initial values
88    _renderers = Root::getSingleton().getAvailableRenderers();
89    Gtk::Menu* menu = Gtk::manage(new Gtk::Menu());
90    MenuList items = menu->items();
91    for (RenderSystemList::iterator pRend = _renderers->begin();
92            pRend != _renderers->end(); pRend++)
93    {
94        items.push_back(MenuElem((*pRend)->getName()));
95    }
96    _optRenderer->set_menu(*menu);
97    _selected_renderer = *(_renderers->begin());
98
99    update_option_list();
100
101    _option_selection->select(_list_store->children().begin());
102
103    _winConfig->show();
104
105    kit.run();
106
107    return true;
108}
109
110bool SDLConfig::on_window_delete(GdkEventAny* event)
111{
112    Gtk::Main::quit();
113
114    return true;
115}
116
117void SDLConfig::on_option_changed()
118{
119    Gtk::TreeModel::iterator treeIT = _option_selection->get_selected();
120    if (!treeIT)
121        return;
122
123    Gtk::TreeModel::Row row = *(treeIT);
124    Glib::ustring name = row[_columns.col_name];
125
126    if (name == _cur_name)
127        return;
128    _cur_name = name;
129
130    Glib::ustring value = row[_columns.col_value];
131    _lblOptName->set_text(name);
132    ConfigOption opt = _options[name.raw()];
133
134    if (!_opt_menu)
135        _opt_menu = Gtk::manage(new Gtk::Menu());
136
137    MenuList items = _opt_menu->items();
138    items.erase(items.begin(), items.end());
139
140    _cur_index = -1;
141    int i = 0;
142    for (StringVector::iterator it = opt.possibleValues.begin();
143            it != opt.possibleValues.end(); it++)
144    {
145        if ((*it) == value.raw())
146            _cur_index = i;
147        else
148            i++;
149
150        items.push_back(MenuElem((*it)));
151    }
152
153    _optOptValues->set_menu(*_opt_menu);
154    _optOptValues->set_history(_cur_index);
155}
156
157void SDLConfig::on_renderer_changed()
158{
159    RenderSystemList::iterator pRend = _renderers->begin();
160    _selected_renderer = pRend[_optRenderer->get_history()];
161    if (!_selected_renderer)
162    {
163        std::cerr << "Selected no renderer!" << std::endl;
164        return;
165    }
166
167    update_option_list();
168}
169
170void SDLConfig::on_value_changed()
171{
172    static int last_history = -1;   
173   
174    int hist = _optOptValues->get_history();
175    if (hist == _cur_index)
176        return;
177
178    _cur_index = hist;
179
180    ConfigOption opt = _options[_cur_name.raw()];
181    StringVector::iterator pos_it = opt.possibleValues.begin();
182
183    _selected_renderer->setConfigOption(opt.name, pos_it[hist]);
184
185    update_option_list();
186}
187
188void SDLConfig::on_btn_ok()
189{
190    Root::getSingleton().setRenderSystem(_selected_renderer);
191    Root::getSingleton().saveConfig();
192
193    _winConfig->hide();
194   
195
196    Gtk::Main::quit();
197}
198
199void SDLConfig::update_option_list()
200{
201    _options = _selected_renderer->getConfigOptions();
202
203    _list_store->clear();
204    for (ConfigOptionMap::iterator it = _options.begin();
205            it != _options.end(); it++)
206    {
207        Gtk::TreeModel::Row row = *(_list_store->append());
208        row[_columns.col_name] = it->second.name;
209        row[_columns.col_value] = it->second.currentValue;
210    }
211}
Note: See TracBrowser for help on using the repository browser.