| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
// Standard C++ library includes |
| 23 |
|
| 24 |
// 3rd party library includes |
| 25 |
#include <CEGUI/CEGUI.h> |
| 26 |
#include <CEGUI/RendererModules/OpenGL/GLRenderer.h> |
| 27 |
|
| 28 |
// FIFE includes |
| 29 |
// These includes are split up in two parts, separated by one empty line |
| 30 |
// First block: files included from the FIFE root src directory |
| 31 |
// Second block: files included from the same folder |
| 32 |
#include "base/ceguiinputprocessor.h" |
| 33 |
#include "util/time/timemanager.h" |
| 34 |
|
| 35 |
#include "ceguimanager.h" |
| 36 |
|
| 37 |
namespace FIFE { |
| 38 |
|
| 39 |
CEGuiManager::CEGuiManager() { |
| 40 |
#ifdef HAVE_OPENGL |
| 41 |
CEGUI::OpenGLRenderer::bootstrapSystem(); |
| 42 |
dynamic_cast<CEGUI::OpenGLRenderer*>(CEGUI::System::getSingleton().getRenderer())-> |
| 43 |
enableExtraStateSettings(true); |
| 44 |
#else |
| 45 |
throw GuiException("CEGUI can be used only if opengl is enabled!"); |
| 46 |
#endif |
| 47 |
m_inputProcessor = new CEGuiInputProcessor(); |
| 48 |
|
| 49 |
m_lastTimePulse = TimeManager::instance()->getTime() / 1000.0; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
CEGuiManager::~CEGuiManager() { |
| 54 |
delete m_inputProcessor; |
| 55 |
|
| 56 |
CEGUI::OpenGLRenderer::destroySystem(); |
| 57 |
} |
| 58 |
|
| 59 |
void CEGuiManager::turn() { |
| 60 |
injectTimePulse(); |
| 61 |
|
| 62 |
CEGUI::System::getSingleton().renderAllGUIContexts(); |
| 63 |
} |
| 64 |
|
| 65 |
void CEGuiManager::resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height) { |
| 66 |
CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(width, height)); |
| 67 |
} |
| 68 |
|
| 69 |
bool CEGuiManager::onSdlEvent(SDL_Event &event) { |
| 70 |
return m_inputProcessor->onSdlEvent(event); |
| 71 |
} |
| 72 |
|
| 73 |
void CEGuiManager::setRootWindow(CEGUI::Window* root) { |
| 74 |
m_guiRoot = root; |
| 75 |
CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(m_guiRoot); |
| 76 |
} |
| 77 |
|
| 78 |
CEGUI::Window* CEGuiManager::getRootWindow() { |
| 79 |
return m_guiRoot; |
| 80 |
} |
| 81 |
|
| 82 |
void CEGuiManager::injectTimePulse() { |
| 83 |
|
| 84 |
double timeNow = TimeManager::instance()->getTime() / 1000.0; |
| 85 |
float time_pulse = float(timeNow - m_lastTimePulse); |
| 86 |
|
| 87 |
CEGUI::System::getSingleton().injectTimePulse(time_pulse); |
| 88 |
CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse(time_pulse); |
| 89 |
|
| 90 |
m_lastTimePulse = timeNow; |
| 91 |
} |
| 92 |
} |