Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreSDLConfig_gtk.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the 
00012 Free Software Foundation.
00013 
00014 This program is distributed in the hope that it will be useful, but WITHOUT
00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public License along 
00019 with this program; if not, write to the Free Software Foundation, Inc., 59 
00020 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00021 http://www.gnu.org/licenses/lgpl.html.
00022 -----------------------------------------------------------------------------
00023 */
00024 
00025 #include "OgreSDLConfig.h"
00026 
00027 #include <libglademm/xml.h>
00028 
00029 #include <gtkmm/main.h>
00030 #include <gtkmm/menushell.h>
00031 #include <gtkmm/window.h>
00032 
00033 using namespace Ogre;
00034 using namespace Gtk::Menu_Helpers;
00035 
00036 bool SDLConfig::display(void)
00037 {
00038     Gtk::Main kit(0, NULL);
00039 
00040     std::string sharedir( SHAREDIR );
00041     Glib::RefPtr<Gnome::Glade::Xml> xml = Gnome::Glade::Xml::create( sharedir + "/ogre-config.glade");
00042     if (!xml)
00043     {
00044         std::cerr << "Problem loading config" << std::endl;
00045         exit(1);
00046     }
00047 
00048     _winConfig = NULL;
00049     xml->get_widget("winConfig", _winConfig);
00050     if (!_winConfig)
00051     {
00052         std::cerr << "Invalid window." << std::endl;
00053         exit(1);
00054     }
00055 
00056     xml->get_widget("lstOptions", _lstOptions);
00057     xml->get_widget("optRenderer", _optRenderer);
00058     xml->get_widget("lblOptName", _lblOptName);
00059     xml->get_widget("optOptValues", _optOptValues);
00060     Gtk::Button* btn_ok;
00061     xml->get_widget("btnOk", btn_ok);
00062     Gtk::Button* btn_cancel;
00063     xml->get_widget("btnCancel", btn_cancel);
00064 
00065     _opt_menu = NULL;
00066 
00067     // Hookup signals
00068     _winConfig->signal_delete_event().connect(SigC::slot(*this,
00069                 &SDLConfig::on_window_delete));
00070     _option_selection = _lstOptions->get_selection();
00071     _option_selection->signal_changed().connect(SigC::slot(*this,
00072                 &SDLConfig::on_option_changed));
00073     _optRenderer->signal_changed().connect(SigC::slot(*this,
00074                 &SDLConfig::on_renderer_changed));
00075     _optOptValues->signal_changed().connect(SigC::slot(*this,
00076                 &SDLConfig::on_value_changed));
00077     btn_ok->signal_clicked().connect(SigC::slot(*this, &SDLConfig::on_btn_ok));
00078     btn_cancel->signal_clicked().connect(SigC::slot(&Gtk::Main::quit));
00079 
00080 
00081     // Initialize
00082     _list_store = Gtk::ListStore::create(_columns);
00083     _lstOptions->set_model(_list_store);
00084     _lstOptions->append_column("Option", _columns.col_name);
00085     _lstOptions->append_column("Value", _columns.col_value);
00086 
00087     // Setup initial values
00088     _renderers = Root::getSingleton().getAvailableRenderers();
00089     Gtk::Menu* menu = Gtk::manage(new Gtk::Menu());
00090     MenuList items = menu->items();
00091     for (RenderSystemList::iterator pRend = _renderers->begin(); 
00092             pRend != _renderers->end(); pRend++)
00093     {
00094         items.push_back(MenuElem((*pRend)->getName()));
00095     }
00096     _optRenderer->set_menu(*menu);
00097     _selected_renderer = *(_renderers->begin());
00098 
00099     update_option_list();
00100 
00101     _option_selection->select(_list_store->children().begin());
00102 
00103     _winConfig->show();
00104 
00105     kit.run();
00106 
00107     return true;
00108 }
00109 
00110 bool SDLConfig::on_window_delete(GdkEventAny* event)
00111 {
00112     Gtk::Main::quit();
00113 
00114     return true;
00115 }
00116 
00117 void SDLConfig::on_option_changed()
00118 {
00119     Gtk::TreeModel::iterator treeIT = _option_selection->get_selected();
00120     if (!treeIT)
00121         return;
00122 
00123     Gtk::TreeModel::Row row = *(treeIT);
00124     Glib::ustring name = row[_columns.col_name];
00125 
00126     if (name == _cur_name)
00127         return;
00128     _cur_name = name;
00129 
00130     Glib::ustring value = row[_columns.col_value];
00131     _lblOptName->set_text(name);
00132     ConfigOption opt = _options[name.raw()];
00133 
00134     if (!_opt_menu)
00135         _opt_menu = Gtk::manage(new Gtk::Menu());
00136 
00137     MenuList items = _opt_menu->items();
00138     items.erase(items.begin(), items.end());
00139 
00140     _cur_index = -1;
00141     int i = 0;
00142     for (StringVector::iterator it = opt.possibleValues.begin(); 
00143             it != opt.possibleValues.end(); it++)
00144     {
00145         if ((*it) == value.raw())
00146             _cur_index = i;
00147         else
00148             i++;
00149 
00150         items.push_back(MenuElem((*it)));
00151     }
00152 
00153     _optOptValues->set_menu(*_opt_menu);
00154     _optOptValues->set_history(_cur_index);
00155 }
00156 
00157 void SDLConfig::on_renderer_changed()
00158 {
00159     RenderSystemList::iterator pRend = _renderers->begin();
00160     _selected_renderer = pRend[_optRenderer->get_history()];
00161     if (!_selected_renderer)
00162     {
00163         std::cerr << "Selected no renderer!" << std::endl;
00164         return;
00165     }
00166 
00167     update_option_list();
00168 }
00169 
00170 void SDLConfig::on_value_changed()
00171 {
00172     static int last_history = -1;    
00173     
00174     int hist = _optOptValues->get_history();
00175     if (hist == _cur_index)
00176         return;
00177 
00178     _cur_index = hist;
00179 
00180     ConfigOption opt = _options[_cur_name.raw()];
00181     StringVector::iterator pos_it = opt.possibleValues.begin();
00182 
00183     _selected_renderer->setConfigOption(opt.name, pos_it[hist]);
00184 
00185     update_option_list();
00186 }
00187 
00188 void SDLConfig::on_btn_ok()
00189 {
00190     Root::getSingleton().setRenderSystem(_selected_renderer);
00191     Root::getSingleton().saveConfig();
00192 
00193     _winConfig->hide();
00194     
00195 
00196     Gtk::Main::quit();
00197 }
00198 
00199 void SDLConfig::update_option_list()
00200 {
00201     _options = _selected_renderer->getConfigOptions();
00202 
00203     _list_store->clear();
00204     for (ConfigOptionMap::iterator it = _options.begin(); 
00205             it != _options.end(); it++)
00206     {
00207         Gtk::TreeModel::Row row = *(_list_store->append());
00208         row[_columns.col_name] = it->second.name;
00209         row[_columns.col_value] = it->second.currentValue;
00210     }
00211 }

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:27 2004