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

# OgreGTKWindow.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://ogre.sourceforge.net/
    00006
    00007 Copyright © 2000-2004 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 Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025
    00026 #include "OgreGTKWindow.h"
    00027 #include "OgreGTKGLSupport.h"
    00028 #include "OgreRenderSystem.h"
    00029 #include "OgreRoot.h"
    00030 #include "OgreLogManager.h"
    00031
    00032 using namespace Ogre;
    00033
    00034 OGREWidget::OGREWidget(bool useDepthBuffer) :
    00035     Gtk::GL::DrawingArea()
    00036 {
    00037     Glib::RefPtr<Gdk::GL::Config> glconfig;
    00038
    00039     Gdk::GL::ConfigMode mode = Gdk::GL::MODE_RGBA | Gdk::GL::MODE_DOUBLE;
    00040     if (useDepthBuffer)
    00041         mode |= Gdk::GL::MODE_DEPTH;
    00042
    00043     glconfig = Gdk::GL::Config::create(mode);
    00044     if (glconfig.is_null())
    00045     {
    00046         LogManager::getSingleton().logMessage("[gtk] GLCONFIG BLOWUP");
    00047     }
    00048
    00049     // Inherit GL context from Ogre main context
    00050     set_gl_capability(glconfig, GTKGLSupport::getSingleton().getMainContext());
    00051
    00052     add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
    00053 }
    00054
    00055 // OGREWidget TODO:
    00056 // - resize events et al
    00057 // - Change aspect ratio
    00058
    00059 GTKWindow::GTKWindow():
    00060     mGtkWindow(0)
    00061 {
    00062         //kit = Gtk::Main::instance();
    00063
    00064     // Should  this move to GTKGLSupport?
    00065         // Gtk::GL::init(0, NULL);
    00066     // Already done in GTKGLSupport
    00067
    00068     mWidth = 0;
    00069     mHeight  = 0;
    00070 }
    00071
    00072 GTKWindow::~GTKWindow()
    00073 {
    00074 }
    00075 bool GTKWindow::pump_events()
    00076 {
    00077     Gtk::Main *kit = Gtk::Main::instance();
    00078     if (kit->events_pending())
    00079     {
    00080         kit->iteration(false);
    00081         return true;
    00082     }
    00083     return false;
    00084 }
    00085
    00086 OGREWidget* GTKWindow::get_ogre_widget()
    00087 {
    00088     return ogre;
    00089 }
    00090
    00091 void GTKWindow::create(const String& name, unsigned int width, unsigned int height, unsigned int colourDepth,
    00092                        bool fullScreen, int left, int top, bool depthBuffer,
    00093                        void* miscParam, ...)
    00094 {
    00095     mName = name;
    00096     mWidth = width;
    00097     mHeight = height;
    00098
    00099     if(!miscParam) {
    00100             mGtkWindow = new Gtk::Window();
    00101             mGtkWindow->set_title(mName);
    00102
    00103             if (fullScreen)
    00104             {
    00105                 mGtkWindow->set_decorated(false);
    00106                 mGtkWindow->fullscreen();
    00107             }
    00108             else
    00109             {
    00110                 mGtkWindow->set_default_size(mWidth, mHeight);
    00111                 mGtkWindow->move(left, top);
    00112             }
    00113     } else {
    00114         // If miscParam is not 0, a parent widget has been passed in,
    00115         // we will handle this later on after the widget has been created.
    00116     }
    00117
    00118         ogre = Gtk::manage(new OGREWidget(depthBuffer));
    00119         ogre->set_size_request(width, height);
    00120
    00121     ogre->signal_delete_event().connect(SigC::slot(*this, &GTKWindow::on_delete_event));
    00122     ogre->signal_expose_event().connect(SigC::slot(*this, &GTKWindow::on_expose_event));
    00123
    00124     if(mGtkWindow) {
    00125             mGtkWindow->add(*ogre);
    00126             mGtkWindow->show_all();
    00127     }
    00128     if(miscParam) {
    00129         // Attach it!
    00130         // Note that the parent widget *must* be visible already at this point,
    00131         // or the widget won't get realized in time for the GLinit that follows
    00132         // this call. This is usually the case for Glade generated windows, anyway.
    00133         reinterpret_cast<Gtk::Container*>(miscParam)->add(*ogre);
    00134         ogre->show();
    00135     }
    00136     //ogre->realize();
    00137 }
    00138
    00139 void GTKWindow::destroy()
    00140 {
    00141         Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() );
    00142     // We could detach the widget from its parent and destroy it here too,
    00143     // but then again, it is managed so we rely on GTK to destroy it.
    00144     delete mGtkWindow;
    00145     mGtkWindow = 0;
    00146
    00147 }
    00148
    00149 bool GTKWindow::isActive() const
    00150 {
    00151     return ogre->is_realized();
    00152 }
    00153
    00154 bool GTKWindow::isClosed() const
    00155 {
    00156     return ogre->is_visible();
    00157 }
    00158
    00159 void GTKWindow::reposition(int left, int top)
    00160 {
    00161     if(mGtkWindow)
    00162             mGtkWindow->move(left, top);
    00163 }
    00164
    00165 void GTKWindow::resize(unsigned int width, unsigned int height)
    00166 {
    00167     if(mGtkWindow)
    00168             mGtkWindow->resize(width, height);
    00169 }
    00170
    00171 void GTKWindow::swapBuffers(bool waitForVSync)
    00172 {
    00173         Glib::RefPtr<Gdk::GL::Window> glwindow = ogre->get_gl_window();
    00174         glwindow->swap_buffers();
    00175 }
    00176
    00177 void GTKWindow::writeContentsToFile(const String& filename)
    00178 {
    00179         // XXX impl me
    00180 }
    00181
    00182 void GTKWindow::getCustomAttribute( const String& name, void* pData )
    00183 {
    00184     if( name == "GTKMMWINDOW" )
    00185     {
    00186         Gtk::Window **win = static_cast<Gtk::Window **>(pData);
    00187         // Oh, the burdens of multiple inheritance
    00188         *win = mGtkWindow;
    00189         return;
    00190     }
    00191     else if( name == "GTKGLMMWIDGET" )
    00192     {
    00193             Gtk::GL::DrawingArea **widget = static_cast<Gtk::GL::DrawingArea **>(pData);
    00194         *widget = ogre;
    00195         return;
    00196     }
    00197     else if( name == "isTexture" )
    00198     {
    00199         bool *b = reinterpret_cast< bool * >( pData );
    00200         *b = false;
    00201         return;
    00202     }
    00203     RenderWindow::getCustomAttribute(name, pData);
    00204 }
    00205
    00206
    00207 bool GTKWindow::on_delete_event(GdkEventAny* event)
    00208 {
    00209     Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() );
    00210     return false;
    00211 }
    00212
    00213 bool GTKWindow::on_expose_event(GdkEventExpose* event)
    00214 {
    00215     // Window exposed, update interior
    00216     //std::cout << "Window exposed, update interior" << std::endl;
    00217     // TODO: time between events, as expose events can be sent crazily fast
    00218     update();
    00219     return false;
    00220 }

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:28 2004