Mercurial > fife-parpg
comparison engine/core/controller/engine.cpp @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | e201abd8c807 |
children |
comparison
equal
deleted
inserted
replaced
696:e201abd8c807 | 697:ecaa4d98f05f |
---|---|
33 // Second block: files included from the same folder | 33 // Second block: files included from the same folder |
34 #include "util/base/exception.h" | 34 #include "util/base/exception.h" |
35 #include "util/log/logger.h" | 35 #include "util/log/logger.h" |
36 #include "util/time/timemanager.h" | 36 #include "util/time/timemanager.h" |
37 #include "audio/soundmanager.h" | 37 #include "audio/soundmanager.h" |
38 #include "gui/console/console.h" | 38 #include "gui/console.h" |
39 #include "gui/guimanager.h" | 39 #include "gui/guichan/guichanguimanager.h" |
40 #include "gui/guichan/gui_font.h" | |
40 #include "vfs/vfs.h" | 41 #include "vfs/vfs.h" |
41 #include "vfs/vfsdirectory.h" | 42 #include "vfs/vfsdirectory.h" |
42 #include "vfs/directoryprovider.h" | 43 #include "vfs/directoryprovider.h" |
43 #ifdef HAVE_ZIP | 44 #ifdef HAVE_ZIP |
44 #include "vfs/zip/zipprovider.h" | 45 #include "vfs/zip/zipprovider.h" |
51 #include "video/cursor.h" | 52 #include "video/cursor.h" |
52 #include "video/devicecaps.h" | 53 #include "video/devicecaps.h" |
53 #ifdef HAVE_OPENGL | 54 #ifdef HAVE_OPENGL |
54 #include "video/opengl/fife_opengl.h" | 55 #include "video/opengl/fife_opengl.h" |
55 #include "video/opengl/renderbackendopengl.h" | 56 #include "video/opengl/renderbackendopengl.h" |
56 #include "gui/base/opengl/opengl_gui_graphics.h" | 57 #endif |
57 #endif | |
58 #include "gui/base/sdl/sdl_gui_graphics.h" | |
59 #include "gui/base/gui_font.h" | |
60 #include "video/sdl/renderbackendsdl.h" | 58 #include "video/sdl/renderbackendsdl.h" |
61 #include "video/fonts/abstractfont.h" | 59 #include "video/fonts/abstractfont.h" |
62 #include "loaders/native/video_loaders/subimage_loader.h" | 60 #include "loaders/native/video_loaders/subimage_loader.h" |
63 #include "loaders/native/video_loaders/image_loader.h" | 61 #include "loaders/native/video_loaders/image_loader.h" |
64 #include "loaders/native/audio_loaders/ogg_loader.h" | 62 #include "loaders/native/audio_loaders/ogg_loader.h" |
74 #include "view/renderers/cellselectionrenderer.h" | 72 #include "view/renderers/cellselectionrenderer.h" |
75 #include "view/renderers/blockinginforenderer.h" | 73 #include "view/renderers/blockinginforenderer.h" |
76 #include "view/renderers/genericrenderer.h" | 74 #include "view/renderers/genericrenderer.h" |
77 #include "view/renderers/lightrenderer.h" | 75 #include "view/renderers/lightrenderer.h" |
78 #include "video/image.h" | 76 #include "video/image.h" |
79 #include "gui/console/console.h" | |
80 #include "engine.h" | 77 #include "engine.h" |
81 | 78 |
82 #ifdef USE_COCOA | 79 #ifdef USE_COCOA |
83 | 80 |
84 #include <objc/message.h> | 81 #include <objc/message.h> |
102 m_imagepool(0), | 99 m_imagepool(0), |
103 m_animpool(0), | 100 m_animpool(0), |
104 m_soundclippool(0), | 101 m_soundclippool(0), |
105 m_vfs(0), | 102 m_vfs(0), |
106 m_model(0), | 103 m_model(0), |
107 m_gui_graphics(0), | |
108 m_logmanager(0), | 104 m_logmanager(0), |
109 m_cursor(0), | 105 m_cursor(0), |
110 m_prerender_callback(0), | 106 m_prerender_callback(0), |
111 m_postrender_callback(0), | 107 m_postrender_callback(0), |
112 m_settings(), | 108 m_settings(), |
143 m_defaultfont->invalidate(); | 139 m_defaultfont->invalidate(); |
144 m_guimanager->invalidateFonts(); | 140 m_guimanager->invalidateFonts(); |
145 | 141 |
146 Image* screen = m_renderbackend->setScreenMode(mode); | 142 Image* screen = m_renderbackend->setScreenMode(mode); |
147 | 143 |
148 m_guimanager->resizeTopContainer(0,0,mode.getWidth(), mode.getHeight()); | 144 m_guimanager->resize(0, 0, mode.getWidth(), mode.getHeight()); |
149 m_guimanager->getConsole()->reLayout(); | |
150 | 145 |
151 std::vector<IEngineChangeListener*>::iterator i = m_changelisteners.begin(); | 146 std::vector<IEngineChangeListener*>::iterator i = m_changelisteners.begin(); |
152 while (i != m_changelisteners.end()) { | 147 while (i != m_changelisteners.end()) { |
153 (*i)->onScreenModeChanged(mode); | 148 (*i)->onScreenModeChanged(mode); |
154 ++i; | 149 ++i; |
254 m_settings.getWindowTitle(), | 249 m_settings.getWindowTitle(), |
255 m_settings.getWindowIcon()); | 250 m_settings.getWindowIcon()); |
256 FL_LOG(_log, "Main screen created"); | 251 FL_LOG(_log, "Main screen created"); |
257 | 252 |
258 #ifdef HAVE_OPENGL | 253 #ifdef HAVE_OPENGL |
259 if( rbackend != "SDL" ) { | |
260 m_gui_graphics = new OpenGLGuiGraphics(*m_imagepool); | |
261 } | |
262 | |
263 if (m_settings.getLightingModel() != 0) { | 254 if (m_settings.getLightingModel() != 0) { |
264 m_renderbackend->setLightingModel(m_settings.getLightingModel()); | 255 m_renderbackend->setLightingModel(m_settings.getLightingModel()); |
265 } | 256 } |
266 | 257 #endif |
267 #endif | |
268 if( rbackend == "SDL" ) { | |
269 m_gui_graphics = new SdlGuiGraphics(*m_imagepool); | |
270 } | |
271 FL_LOG(_log, "Constructing GUI manager"); | 258 FL_LOG(_log, "Constructing GUI manager"); |
272 m_guimanager = new GUIManager(*m_imagepool); | 259 // TODO M. George Hansen 2011-06-15: There needs to be a plugin-like |
260 // mechanism to select which GuiManager subclass to use. | |
261 m_guimanager = new GuiChanGuiManager(*m_imagepool); | |
273 FL_LOG(_log, "Events bind to GUI manager"); | 262 FL_LOG(_log, "Events bind to GUI manager"); |
274 m_eventmanager->addSdlEventListener(m_guimanager); | 263 m_eventmanager->addSdlEventListener(m_guimanager); |
275 | 264 |
276 FL_LOG(_log, "Creating default font"); | 265 FL_LOG(_log, "Creating default font"); |
266 // FIXME M. George Hansen 2011-06-17: A font has to be created before | |
267 // the GuiManager is initialized (at least for GuiChan). This is not | |
268 // obvious if you just look at the code. | |
277 m_defaultfont = m_guimanager->setDefaultFont( | 269 m_defaultfont = m_guimanager->setDefaultFont( |
278 m_settings.getDefaultFontPath(), | 270 m_settings.getDefaultFontPath(), |
279 m_settings.getDefaultFontSize(), | 271 m_settings.getDefaultFontSize(), |
280 m_settings.getDefaultFontGlyphs()); | 272 m_settings.getDefaultFontGlyphs() |
273 ); | |
274 | |
281 FL_LOG(_log, "Initializing GUI manager"); | 275 FL_LOG(_log, "Initializing GUI manager"); |
282 m_guimanager->init(m_gui_graphics, m_renderbackend->getScreenWidth(), m_renderbackend->getScreenHeight()); | 276 m_guimanager->init(m_renderbackend, m_renderbackend->getScreenWidth(), |
277 m_renderbackend->getScreenHeight()); | |
283 FL_LOG(_log, "GUI manager initialized"); | 278 FL_LOG(_log, "GUI manager initialized"); |
284 SDL_EnableUNICODE(1); | 279 SDL_EnableUNICODE(1); |
285 | 280 |
286 FL_LOG(_log, "Creating sound manager"); | 281 FL_LOG(_log, "Creating sound manager"); |
287 m_soundmanager = new SoundManager(m_soundclippool); | 282 m_soundmanager = new SoundManager(m_soundclippool); |
320 FL_LOG(_log, "Destructing engine"); | 315 FL_LOG(_log, "Destructing engine"); |
321 delete m_cursor; | 316 delete m_cursor; |
322 delete m_model; | 317 delete m_model; |
323 delete m_soundmanager; | 318 delete m_soundmanager; |
324 delete m_guimanager; | 319 delete m_guimanager; |
325 delete m_gui_graphics; | |
326 | 320 |
327 // Note the dependancy between image and animation pools | 321 // Note the dependancy between image and animation pools |
328 // as animations reference images they have to be deleted | 322 // as animations reference images they have to be deleted |
329 // before clearing the image pool. | 323 // before clearing the image pool. |
330 delete m_animpool; | 324 delete m_animpool; |