source: OGRE/trunk/ogrenew/RenderSystems/GL/src/gtk/OgreGTKWindow.cpp @ 692

Revision 692, 5.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 (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 "OgreGTKWindow.h"
27#include "OgreGTKGLSupport.h"
28#include "OgreRenderSystem.h"
29#include "OgreRoot.h"
30#include "OgreLogManager.h"
31
32using namespace Ogre;
33
34OGREWidget::OGREWidget(bool useDepthBuffer) :
35        Gtk::GL::DrawingArea()
36{
37    Glib::RefPtr<Gdk::GL::Config> glconfig;
38
39    Gdk::GL::ConfigMode mode = Gdk::GL::MODE_RGBA | Gdk::GL::MODE_DOUBLE;
40    if (useDepthBuffer)
41        mode |= Gdk::GL::MODE_DEPTH;
42
43    glconfig = Gdk::GL::Config::create(mode);
44    if (glconfig.is_null())
45    {
46        LogManager::getSingleton().logMessage("[gtk] GLCONFIG BLOWUP");
47    }
48
49    // Inherit GL context from Ogre main context
50    set_gl_capability(glconfig, GTKGLSupport::getSingleton().getMainContext());
51
52    add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
53}
54
55// OGREWidget TODO:
56// - resize events et al
57// - Change aspect ratio
58
59GTKWindow::GTKWindow():
60        mGtkWindow(0)
61{
62        //kit = Gtk::Main::instance();
63       
64        // Should  this move to GTKGLSupport?
65        // Gtk::GL::init(0, NULL);
66        // Already done in GTKGLSupport
67
68        mWidth = 0;
69        mHeight  = 0;
70}
71
72GTKWindow::~GTKWindow()
73{
74}
75bool GTKWindow::pump_events()
76{
77    Gtk::Main *kit = Gtk::Main::instance();
78    if (kit->events_pending())
79    {
80        kit->iteration(false);
81        return true;
82    }
83    return false;
84}
85
86OGREWidget* GTKWindow::get_ogre_widget()
87{
88    return ogre;
89}
90
91void GTKWindow::create(const String& name, unsigned int width, unsigned int height, unsigned int colourDepth,
92                       bool fullScreen, int left, int top, bool depthBuffer,
93                       void* miscParam, ...)
94{
95        mName = name;
96        mWidth = width;
97        mHeight = height;
98
99        if(!miscParam) {
100                mGtkWindow = new Gtk::Window();
101                mGtkWindow->set_title(mName);
102
103                if (fullScreen)
104                {
105                        mGtkWindow->set_decorated(false);
106                        mGtkWindow->fullscreen();
107                }
108                else
109                {
110                        mGtkWindow->set_default_size(mWidth, mHeight);
111                        mGtkWindow->move(left, top);
112                }
113        } else {
114                // If miscParam is not 0, a parent widget has been passed in,
115                // we will handle this later on after the widget has been created.
116        }
117
118        ogre = Gtk::manage(new OGREWidget(depthBuffer));
119        ogre->set_size_request(width, height);
120
121        ogre->signal_delete_event().connect(SigC::slot(*this, &GTKWindow::on_delete_event));
122        ogre->signal_expose_event().connect(SigC::slot(*this, &GTKWindow::on_expose_event));
123
124        if(mGtkWindow) {
125                mGtkWindow->add(*ogre);
126                mGtkWindow->show_all();
127        }
128        if(miscParam) {
129                // Attach it!
130                // Note that the parent widget *must* be visible already at this point,
131                // or the widget won't get realized in time for the GLinit that follows
132                // this call. This is usually the case for Glade generated windows, anyway.
133                reinterpret_cast<Gtk::Container*>(miscParam)->add(*ogre);
134                ogre->show();
135        }
136        //ogre->realize();
137}
138
139void GTKWindow::destroy()
140{
141        Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() );
142        // We could detach the widget from its parent and destroy it here too,
143        // but then again, it is managed so we rely on GTK to destroy it.
144        delete mGtkWindow;
145        mGtkWindow = 0;
146
147}
148
149bool GTKWindow::isActive() const
150{
151    return ogre->is_realized();
152}
153
154bool GTKWindow::isClosed() const
155{
156    return ogre->is_visible();
157}
158
159void GTKWindow::reposition(int left, int top)
160{
161        if(mGtkWindow)
162                mGtkWindow->move(left, top);
163}
164
165void GTKWindow::resize(unsigned int width, unsigned int height)
166{
167        if(mGtkWindow)
168                mGtkWindow->resize(width, height);
169}
170
171void GTKWindow::swapBuffers(bool waitForVSync)
172{
173        Glib::RefPtr<Gdk::GL::Window> glwindow = ogre->get_gl_window();
174        glwindow->swap_buffers();
175}
176
177void GTKWindow::writeContentsToFile(const String& filename)
178{
179        // XXX impl me
180}
181
182void GTKWindow::getCustomAttribute( const String& name, void* pData )
183{
184        if( name == "GTKMMWINDOW" )
185        {
186                Gtk::Window **win = static_cast<Gtk::Window **>(pData);
187                // Oh, the burdens of multiple inheritance
188                *win = mGtkWindow;
189                return;
190        }
191        else if( name == "GTKGLMMWIDGET" )
192        {
193                Gtk::GL::DrawingArea **widget = static_cast<Gtk::GL::DrawingArea **>(pData);
194                *widget = ogre;
195                return;
196        }
197        else if( name == "isTexture" )
198        {
199                bool *b = reinterpret_cast< bool * >( pData );
200                *b = false;
201                return;
202        }
203        RenderWindow::getCustomAttribute(name, pData);
204}
205
206
207bool GTKWindow::on_delete_event(GdkEventAny* event)
208{
209    Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() );
210    return false;
211}
212
213bool GTKWindow::on_expose_event(GdkEventExpose* event)
214{
215    // Window exposed, update interior
216    //std::cout << "Window exposed, update interior" << std::endl;
217    // TODO: time between events, as expose events can be sent crazily fast
218    update();
219    return false;
220}
Note: See TracBrowser for help on using the repository browser.