guimanager.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2008 by the FIFE team                              *
00003  *   http://www.fifengine.de                                               *
00004  *   This file is part of FIFE.                                            *
00005  *                                                                         *
00006  *   FIFE is free software; you can redistribute it and/or                 *
00007  *   modify it under the terms of the GNU Lesser General Public            *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2.1 of the License, or (at your option) any later version.    *
00010  *                                                                         *
00011  *   This library is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00014  *   Lesser General Public License for more details.                       *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Lesser General Public      *
00017  *   License along with this library; if not, write to the                 *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00020  ***************************************************************************/
00021 
00022 #ifndef FIFE_VIDEO_GUI_GUIMANAGER_H
00023 #define FIFE_VIDEO_GUI_GUIMANAGER_H
00024 
00025 // Standard C++ library includes
00026 #include <set>
00027 
00028 // 3rd party library includes
00029 #include <guichan.hpp>
00030 
00031 // FIFE includes
00032 // These includes are split up in two parts, separated by one empty line
00033 // First block: files included from the FIFE root src directory
00034 // Second block: files included from the same folder
00035 #include "util/base/singleton.h"
00036 #include "eventchannel/sdl/ec_isdleventlistener.h"
00037 // #include "eventchannel/mouse/ec_imouselistener.h"
00038 // #include "eventchannel/key/ec_ikeylistener.h"
00039 
00040 namespace gcn {
00041 
00042     class Gui;
00043     class Container;
00044     class Widget;
00045     class SDLInput;
00046     class FocusHandler;
00047 
00048 }
00049 
00050 
00051 namespace FIFE {
00052 
00053     class ImagePool;
00054     class GuiImageLoader;
00055     class Console;
00056     class KeyEvent;
00057     class MouseEvent;
00058     class AbstractFont;
00059     class GuiFont;
00060 
00061     /* GUI Manager.
00062      *
00063      * This class controls the GUI system in FIFE.
00064      */
00065     class GUIManager : 
00066         public DynamicSingleton<GUIManager>, 
00067         public ISdlEventListener
00068          {
00069         public:
00072             GUIManager(ImagePool& pool);
00075             virtual ~GUIManager();
00076 
00081             gcn::Gui* getGuichanGUI() const;
00082 
00087             void turn();
00088             
00094             void init(gcn::Graphics* graphics, int screenWidth, int screenHeight);
00095             
00103             void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
00104             
00109             void add(gcn::Widget* widget);
00114             void remove(gcn::Widget* widget);
00119             gcn::Container* getTopContainer() const { return m_gcn_topcontainer; }
00120             
00125             Console* getConsole() const { return m_console; };
00126 
00129             GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs);
00130             
00133             GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = "");
00134 
00137             void releaseFont(GuiFont* font);
00138 
00139             bool onSdlEvent(SDL_Event& evt);
00140 
00141             KeyEvent translateKeyEvent(const gcn::KeyEvent& evt);
00142             MouseEvent translateMouseEvent(const gcn::MouseEvent& evt);
00143 
00144         protected:
00145             static int convertGuichanKeyToFifeKey(int value);
00146 
00147         private:
00148             // The Guichan GUI.
00149             gcn::Gui* m_gcn_gui;
00150             // Focus handler for input management
00151             gcn::FocusHandler* m_focushandler;
00152             // The top container of the GUI.
00153             gcn::Container* m_gcn_topcontainer;
00154             // The imageloader.
00155             GuiImageLoader* m_imgloader;
00156             // The input controller.
00157             gcn::SDLInput *m_input;
00158             // The console.
00159             Console       *m_console;
00160             // The fonts used
00161             std::vector<GuiFont*> m_fonts;
00162             // Added widgets
00163             std::set<gcn::Widget*> m_widgets;
00164 
00165             // Used to accept mouse motion events that leave widget space
00166             bool m_had_mouse;
00167 
00168             // pool used for images
00169             ImagePool& m_pool;
00170 
00171             // default font settings
00172             std::string m_fontpath;
00173             std::string m_fontglyphs;
00174             int m_fontsize;
00175             
00176             // true, if guichan logic has already been executed for this round
00177             bool m_logic_executed;
00178     };
00179 
00180 }
00181 
00182 #endif
Generated by  doxygen 1.6.2-20100208