| 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 |
#ifndef FIFE_GUI_LIBROCKETMANAGER_H |
| 23 |
#define FIFE_GUI_LIBROCKETMANAGER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <map> |
| 27 |
#include <string> |
| 28 |
|
| 29 |
// 3rd party library includes |
| 30 |
#include <Rocket/Core/SystemInterface.h> |
| 31 |
|
| 32 |
// FIFE includes |
| 33 |
// These includes are split up in two parts, separated by one empty line |
| 34 |
// First block: files included from the FIFE root src directory |
| 35 |
// Second block: files included from the same folder |
| 36 |
#include "util/base/singleton.h" |
| 37 |
#include "gui/guimanager.h" |
| 38 |
|
| 39 |
namespace Rocket { |
| 40 |
|
| 41 |
namespace Core { |
| 42 |
class Context; |
| 43 |
class ElementDocument; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
namespace FIFE { |
| 48 |
|
| 49 |
class LibRocketInputProcessor; |
| 50 |
class LibRocketRenderInterface; |
| 51 |
|
| 52 |
class LibRocketManager : |
| 53 |
public Rocket::Core::SystemInterface, |
| 54 |
public IGUIManager, |
| 55 |
public DynamicSingleton<LibRocketManager> { |
| 56 |
|
| 57 |
public: |
| 58 |
|
| 59 |
/** Constructor. |
| 60 |
*/ |
| 61 |
LibRocketManager(); |
| 62 |
|
| 63 |
/** |
| 64 |
* Destructor. |
| 65 |
*/ |
| 66 |
virtual ~LibRocketManager(); |
| 67 |
|
| 68 |
/** |
| 69 |
* Initializes the librocket manager. |
| 70 |
*/ |
| 71 |
void init(const std::string& backend, int32_t screenWidth, int32_t screenHeight); |
| 72 |
|
| 73 |
/** |
| 74 |
* NOTE |
| 75 |
* There is an inconsistency in the naming of this method. |
| 76 |
* It's in upper camelcase and should have been in lower camelcase, |
| 77 |
* but it overrides Rocket::Core::SystemInterface::GetElapsedTime. |
| 78 |
* |
| 79 |
* @return The number of seconds elapsed since the start of the application. |
| 80 |
*/ |
| 81 |
virtual float GetElapsedTime(); |
| 82 |
|
| 83 |
/** Updates and renders the gui. |
| 84 |
*/ |
| 85 |
virtual void turn(); |
| 86 |
|
| 87 |
/** Resizes the top container. |
| 88 |
* |
| 89 |
* @param x The new starting X coordinate. |
| 90 |
* @param y The new starting Y coordinate. |
| 91 |
* @param width The new width. |
| 92 |
* @param height The new height. |
| 93 |
*/ |
| 94 |
virtual void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height); |
| 95 |
|
| 96 |
/** Loads a rocket .rml file and shows it. |
| 97 |
* |
| 98 |
* @param id Id of the document chosen by the user. |
| 99 |
* @param documentPath Path to the file. |
| 100 |
* @return A document if the .rml file exists, NULL otherwise. |
| 101 |
*/ |
| 102 |
virtual Rocket::Core::ElementDocument* loadDocument(const std::string& id, const std::string& documentPath); |
| 103 |
|
| 104 |
/** @return Document with id. |
| 105 |
*/ |
| 106 |
virtual Rocket::Core::ElementDocument* getDocument(const std::string& id); |
| 107 |
|
| 108 |
/** Unloads a rocket document. |
| 109 |
*/ |
| 110 |
virtual void unloadDocument(Rocket::Core::ElementDocument* document); |
| 111 |
|
| 112 |
/** Unloads a rocket document with given id. |
| 113 |
*/ |
| 114 |
virtual void unloadDocument(const std::string& id); |
| 115 |
|
| 116 |
/** |
| 117 |
* Loads a font to be used by librocket. |
| 118 |
* |
| 119 |
* @param filepath Path of the font. |
| 120 |
*/ |
| 121 |
virtual void loadFont(const std::string& filepath); |
| 122 |
|
| 123 |
/** Receives input and converts it to librocket format, then it forwards it |
| 124 |
* to librocket. |
| 125 |
*/ |
| 126 |
virtual bool onSdlEvent(SDL_Event& evt); |
| 127 |
|
| 128 |
/** Shows the librocket debugger. |
| 129 |
*/ |
| 130 |
void showDebugger() const; |
| 131 |
|
| 132 |
/** |
| 133 |
* Hides the librocket debugger. |
| 134 |
*/ |
| 135 |
void hideDebugger() const; |
| 136 |
|
| 137 |
private: |
| 138 |
|
| 139 |
/** |
| 140 |
* Unloads documents opened by librocket. |
| 141 |
*/ |
| 142 |
void unloadDocuments(); |
| 143 |
|
| 144 |
/** Librocket's context. |
| 145 |
*/ |
| 146 |
Rocket::Core::Context* m_context; |
| 147 |
|
| 148 |
/** Render Interface for librocket. |
| 149 |
*/ |
| 150 |
LibRocketRenderInterface* m_renderInterface; |
| 151 |
|
| 152 |
/** Input processor for librocket. |
| 153 |
*/ |
| 154 |
LibRocketInputProcessor* m_inputProcessor; |
| 155 |
|
| 156 |
/** A set of all open documents. |
| 157 |
*/ |
| 158 |
std::map<std::string, Rocket::Core::ElementDocument*> m_openDocuments; |
| 159 |
|
| 160 |
}; |
| 161 |
}; |
| 162 |
|
| 163 |
#endif //FIFE_GUI_LIBROCKETMANAGER_H |