Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/environment2/src/orxonox/graphics/CEGuiSample.cc @ 12412

Last change on this file since 12412 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 9.4 KB
Line 
1/***********************************************************************
2    filename:   CEGuiSample.cpp
3    created:    24/9/2004
4    author:     Paul D Turner
5*************************************************************************/
6/***************************************************************************
7 *   Copyright (C) 2004 - 2008 Paul D Turner & The CEGUI Development Team
8 *
9 *   Permission is hereby granted, free of charge, to any person obtaining
10 *   a copy of this software and associated documentation files (the
11 *   "Software"), to deal in the Software without restriction, including
12 *   without limitation the rights to use, copy, modify, merge, publish,
13 *   distribute, sublicense, and/or sell copies of the Software, and to
14 *   permit persons to whom the Software is furnished to do so, subject to
15 *   the following conditions:
16 *
17 *   The above copyright notice and this permission notice shall be
18 *   included in all copies or substantial portions of the Software.
19 *
20 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 *   OTHER DEALINGS IN THE SOFTWARE.
27 ***************************************************************************/
28#include "CEGuiSample.h"
29
30#ifdef HAVE_CONFIG_H
31#   include "config.h"
32#endif
33#include "CEGUISamplesConfig.h"
34
35// includes for renderer selector classes
36#if defined( __WIN32__ ) || defined( _WIN32 )
37#   include "Win32CEGuiRendererSelector.h"
38#elif defined(__linux__)
39#   ifdef CEGUI_SAMPLES_USE_GTK2
40#       include "GTK2CEGuiRendererSelector.h"
41#   else
42#       include "CLICEGuiRendererSelector.h"
43#   endif
44#elif defined(__APPLE__)
45#   include "MacCEGuiRendererSelector.h"
46#endif
47
48// includes for application types
49#ifdef CEGUI_SAMPLES_USE_OGRE
50#   include "CEGuiOgreBaseApplication.h"
51#endif
52#ifdef CEGUI_SAMPLES_USE_OPENGL
53#   include "CEGuiOpenGLBaseApplication.h"
54#endif
55#ifdef CEGUI_SAMPLES_USE_IRRLICHT
56#   include "CEGuiIrrlichtBaseApplication.h"
57#endif
58#ifdef CEGUI_SAMPLES_USE_DIRECTFB
59#   include "CEGuiDirectFBBaseApplication.h"
60#endif
61#if defined( __WIN32__ ) || defined( _WIN32 )
62#   ifdef CEGUI_SAMPLES_USE_DIRECTX_8
63#       include "CEGuiD3D81BaseApplication.h"
64#   endif
65#   ifdef CEGUI_SAMPLES_USE_DIRECTX_9
66#       include "CEGuiD3D9BaseApplication.h"
67#   endif
68#   ifdef CEGUI_SAMPLES_USE_DIRECTX_10
69#       include "CEGuiD3D10BaseApplication.h"
70#   endif
71#endif
72// now we include the base CEGuiBaseApplication just in case someone has managed to
73// get this far without any of the renderers.  This ensures the framework will build,
74// although there will be no renderers available for selection in the samples.
75#include "CEGuiBaseApplication.h"
76
77#include "CEGUI.h"
78
79#ifdef CEGUI_WITH_XERCES
80#   include "CEGUIXercesParser.h"
81#endif
82
83// Include iostream if not on windows.
84#if defined( __WIN32__ ) || defined( _WIN32 )
85#else
86#    include <iostream>
87#endif
88
89
90/*************************************************************************
91    Constructor
92*************************************************************************/
93CEGuiSample::CEGuiSample() :
94        d_rendererSelector(0),
95        d_sampleApp(0)
96{}
97
98
99/*************************************************************************
100    Destructor
101*************************************************************************/
102CEGuiSample::~CEGuiSample()
103{
104    if (d_sampleApp)
105    {
106        d_sampleApp->cleanup();
107        delete d_sampleApp;
108    }
109
110    if (d_rendererSelector)
111    {
112        delete d_rendererSelector;
113    }
114
115}
116
117
118/*************************************************************************
119    Application entry point
120*************************************************************************/
121int CEGuiSample::run()
122{
123    try
124    {
125        if (initialise())
126            cleanup();
127    }
128    catch (CEGUI::Exception& exc)
129    {
130        outputExceptionMessage(exc.getMessage().c_str());
131    }
132    catch (std::exception& exc)
133    {
134        outputExceptionMessage(exc.what());
135    }
136    catch(...)
137    {
138        outputExceptionMessage("Unknown exception was caught!");
139    }
140
141    return 0;
142}
143
144
145/*************************************************************************
146    Initialise the sample application
147*************************************************************************/
148bool CEGuiSample::initialise()
149{
150    // Setup renderer selection dialog for Win32
151#if defined( __WIN32__ ) || defined( _WIN32 )
152    d_rendererSelector = new Win32CEGuiRendererSelector;
153
154    // enable renderer types supported for Win32
155#ifdef CEGUI_SAMPLES_USE_DIRECTX_8
156    d_rendererSelector->setRendererAvailability(Direct3D81GuiRendererType);
157#endif
158#ifdef CEGUI_SAMPLES_USE_DIRECTX_9
159    d_rendererSelector->setRendererAvailability(Direct3D9GuiRendererType);
160#endif
161#ifdef CEGUI_SAMPLES_USE_DIRECTX_10
162    d_rendererSelector->setRendererAvailability(Direct3D10GuiRendererType);
163#endif
164
165#elif defined(__linux__)
166    // decide which method to use for renderer selection
167#   ifdef CEGUI_SAMPLES_USE_GTK2
168        d_rendererSelector = new GTK2CEGuiRendererSelector();
169#   else
170        d_rendererSelector = new CLICEGuiRendererSelector();
171#   endif
172
173#elif defined(__APPLE__)
174     d_rendererSelector = new MacCEGuiRendererSelector();
175#endif
176
177    // enable available renderer types
178#ifdef CEGUI_SAMPLES_USE_OGRE
179    d_rendererSelector->setRendererAvailability(OgreGuiRendererType);
180#endif
181#ifdef CEGUI_SAMPLES_USE_OPENGL
182    d_rendererSelector->setRendererAvailability(OpenGLGuiRendererType);
183#endif
184#ifdef CEGUI_SAMPLES_USE_IRRLICHT
185    d_rendererSelector->setRendererAvailability(IrrlichtGuiRendererType);
186#endif
187#ifdef CEGUI_SAMPLES_USE_DIRECTFB
188    d_rendererSelector->setRendererAvailability(DirectFBGuiRendererType);
189#endif
190
191    // get selection from user
192    if (d_rendererSelector->invokeDialog())
193    {
194        // create appropriate application type based upon users selection
195        switch(d_rendererSelector->getSelectedRendererType())
196        {
197#ifdef CEGUI_SAMPLES_USE_OGRE
198        case OgreGuiRendererType:
199            d_sampleApp = new CEGuiOgreBaseApplication();
200            break;
201#endif
202#if defined( __WIN32__ ) || defined( _WIN32 )
203#ifdef CEGUI_SAMPLES_USE_DIRECTX_8
204        case Direct3D81GuiRendererType:
205            d_sampleApp = new CEGuiD3D81BaseApplication();
206            break;
207#endif
208#ifdef CEGUI_SAMPLES_USE_DIRECTX_9
209        case Direct3D9GuiRendererType:
210            d_sampleApp = new CEGuiD3D9BaseApplication();
211            break;
212#endif // DX9
213#ifdef CEGUI_SAMPLES_USE_DIRECTX_10
214        case Direct3D10GuiRendererType:
215            d_sampleApp = new CEGuiD3D10BaseApplication();
216            break;
217#endif // DX10
218#endif // Win32
219#ifdef CEGUI_SAMPLES_USE_OPENGL
220        case OpenGLGuiRendererType:
221            d_sampleApp = new CEGuiOpenGLBaseApplication();
222            break;
223#endif
224#ifdef CEGUI_SAMPLES_USE_IRRLICHT
225        case IrrlichtGuiRendererType:
226            d_sampleApp = new CEGuiIrrlichtBaseApplication();
227            break;
228#endif
229#ifdef CEGUI_SAMPLES_USE_DIRECTFB
230        case DirectFBGuiRendererType:
231            d_sampleApp = new CEGuiDirectFBBaseApplication();
232            break;
233#endif
234
235        default:
236            throw CEGUI::GenericException("No renderer was selected!");
237            break;
238        }
239
240        // set the default resource groups to be used
241        CEGUI::Imageset::setDefaultResourceGroup("imagesets");
242        CEGUI::Font::setDefaultResourceGroup("fonts");
243        CEGUI::Scheme::setDefaultResourceGroup("schemes");
244        CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels");
245        CEGUI::WindowManager::setDefaultResourceGroup("layouts");
246        CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts");
247#ifdef CEGUI_WITH_XERCES
248        CEGUI::XercesParser::setSchemaDefaultResourceGroup("schemas");
249#endif
250
251        // execute the base application (which sets up the demo via 'this' and runs it.
252        if (d_sampleApp->execute(this))
253        {
254            // signal that app initialised and ran
255            return true;
256        }
257
258        // sample app did not initialise, delete the object.
259        delete d_sampleApp;
260        d_sampleApp = 0;
261    }
262
263    // delete renderer selector object
264    delete d_rendererSelector;
265    d_rendererSelector = 0;
266
267    // signal app did not initialise and run.
268    return false;
269}
270
271
272/*************************************************************************
273    Cleanup the sample application.
274*************************************************************************/
275void CEGuiSample::cleanup()
276{
277    if (d_sampleApp)
278    {
279        d_sampleApp->cleanup();
280        delete d_sampleApp;
281        d_sampleApp = 0;
282    }
283
284    if (d_rendererSelector)
285    {
286        delete d_rendererSelector;
287        d_rendererSelector = 0;
288    }
289
290}
291
292
293/*************************************************************************
294    Output a message to the user in some OS independant way.
295*************************************************************************/
296void CEGuiSample::outputExceptionMessage(const char* message) const
297{
298#if defined(__WIN32__) || defined(_WIN32)
299    MessageBoxA(0, message, "CEGUI - Exception", MB_OK|MB_ICONERROR);
300#else
301    std::cout << "An exception was thrown within the sample framework:" << std::endl;
302    std::cout << message << std::endl;
303#endif
304}
Note: See TracBrowser for help on using the repository browser.