Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/RenderSystems/GL/src/gtk/OgreGTKWindow.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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