source: OGRE/trunk/ogrenew/PlatformManagers/gtk/src/GTKConfig.cpp @ 692

Revision 692, 6.2 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 (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
26#include "GTKConfig.h"
27#include "OgreLogManager.h"
28#include <gtkmm/main.h>
29#include <gtkmm/menushell.h>
30#include <libglademm/xml.h>
31
32using namespace Ogre;
33
34bool GTKConfig::display(void)
35{
36    Gtk::Main kit(0, NULL);
37
38    std::string sharedir( SHAREDIR );
39    Glib::RefPtr<Gnome::Glade::Xml> xml = Gnome::Glade::Xml::create( sharedir + "/ogre-config.glade");
40    if (!xml)
41    {
42        LogManager::getSingleton().logMessage("Problem loading config " + sharedir + "/ogre-config.glade");
43        return false;
44    }
45
46    _winConfig = NULL;
47    xml->get_widget("dlgConfig", _winConfig);
48    if (!_winConfig)
49    {
50        LogManager::getSingleton().logMessage("Invalid window.");
51        return false;
52    }
53
54    xml->get_widget("lstOptions", _lstOptions);
55    xml->get_widget("optRenderer", _optRenderer);
56    xml->get_widget("lblOptName", _lblOptName);
57    xml->get_widget("optOptValues", _optOptValues);
58    Gtk::Button* btn_ok;
59    xml->get_widget("btnOK", btn_ok);
60    Gtk::Button* btn_cancel;
61    xml->get_widget("btnCancel", btn_cancel);
62
63    // Set menu (empty)
64    _opt_menu = Gtk::manage(new Gtk::Menu());
65    _optOptValues->set_menu(*_opt_menu);
66
67    // Hookup signals
68    _winConfig->signal_delete_event().connect(SigC::slot(*this,
69                &GTKConfig::on_window_delete));
70    _option_selection = _lstOptions->get_selection();
71    _option_selection->signal_changed().connect(SigC::slot(*this,
72                &GTKConfig::on_option_changed));
73    _optRenderer->signal_changed().connect(SigC::slot(*this,
74                &GTKConfig::on_renderer_changed));
75    _optOptValues->signal_changed().connect(SigC::slot(*this,
76                &GTKConfig::on_value_changed));
77    btn_ok->signal_clicked().connect(SigC::slot(*this, &GTKConfig::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    Gtk::Menu_Helpers::MenuList items = menu->items();
91    for (RenderSystemList::iterator pRend = _renderers->begin();
92            pRend != _renderers->end(); pRend++)
93    {
94        items.push_back(Gtk::Menu_Helpers::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 GTKConfig::on_window_delete(GdkEventAny* event)
111{
112    Gtk::Main::quit();
113
114    return true;
115}
116
117void GTKConfig::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    Gtk::Menu_Helpers::MenuList items = _opt_menu->items();
135    items.erase(items.begin(), items.end());
136
137    _cur_index = -1;
138    int i = 0;
139    for (StringVector::iterator it = opt.possibleValues.begin();
140            it != opt.possibleValues.end(); it++)
141    {
142        if ((*it) == value.raw())
143            _cur_index = i;
144        else
145            i++;
146
147        items.push_back(Gtk::Menu_Helpers::MenuElem((*it)));
148    }
149
150    _optOptValues->set_menu(*_opt_menu);
151    _optOptValues->set_history(_cur_index);
152}
153
154void GTKConfig::on_renderer_changed()
155{
156    RenderSystemList::iterator pRend = _renderers->begin();
157    _selected_renderer = pRend[_optRenderer->get_history()];
158    if (!_selected_renderer)
159    {
160        LogManager::getSingleton().logMessage("Selected no renderer!");
161        return;
162    }
163
164    update_option_list();
165}
166
167void GTKConfig::on_value_changed()
168{
169    static int last_history = -1;   
170   
171    int hist = _optOptValues->get_history();
172    if (hist == _cur_index)
173        return;
174
175    _cur_index = hist;
176
177    ConfigOption opt = _options[_cur_name.raw()];
178    StringVector::iterator pos_it = opt.possibleValues.begin();
179
180    _selected_renderer->setConfigOption(opt.name, pos_it[hist]);
181
182    update_option_list();
183}
184
185void GTKConfig::on_btn_ok()
186{
187    Root::getSingleton().setRenderSystem(_selected_renderer);
188    Root::getSingleton().saveConfig();
189
190    _winConfig->hide();
191   
192
193    Gtk::Main::quit();
194}
195
196void GTKConfig::update_option_list()
197{
198    _options = _selected_renderer->getConfigOptions();
199
200    _list_store->clear();
201    for (ConfigOptionMap::iterator it = _options.begin();
202            it != _options.end(); it++)
203    {
204        Gtk::TreeModel::Row row = *(_list_store->append());
205        row[_columns.col_name] = it->second.name;
206        row[_columns.col_value] = it->second.currentValue;
207    }
208}
Note: See TracBrowser for help on using the repository browser.