guichanmanager.h

00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 by the FIFE team                              *
00003  *   http://www.fifengine.net                                              *
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_GUICHANMANAGER_H
00023 #define FIFE_VIDEO_GUI_GUICHANMANAGER_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/fife_stdint.h"
00036 #include "util/base/singleton.h"
00037 #include "eventchannel/sdl/ec_isdleventlistener.h"
00038 
00039 #include "gui/guimanager.h"
00040 
00041 namespace gcn {
00042 
00043     class Gui;
00044     class Container;
00045     class Widget;
00046     class SDLInput;
00047     class FocusHandler;
00048 
00049 }
00050 
00051 
00052 namespace FIFE {
00053 
00054     class GuiImageLoader;
00055     class Console;
00056     class KeyEvent;
00057     class MouseEvent;
00058     class IFont;
00059     class GuiFont;
00060 
00061 
00062     /* GUI Chan Manager.
00063      *
00064      * This class controls the GUI system in FIFE.
00065      */
00066     class GUIChanManager :
00067         public IGUIManager,
00068         public DynamicSingleton<GUIChanManager>
00069          {
00070         public:
00073             GUIChanManager();
00076             virtual ~GUIChanManager();
00077 
00082             gcn::Gui* getGuichanGUI() const;
00083 
00088             virtual void turn();
00089 
00095             void init(const std::string& backend, int32_t screenWidth, int32_t  screenHeight);
00096 
00104             void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
00105 
00110             void add(gcn::Widget* widget);
00115             void remove(gcn::Widget* widget);
00120             gcn::Container* getTopContainer() const { return m_gcn_topcontainer; }
00121 
00126             Console* getConsole() const { return m_console; };
00127 
00130             GuiFont* setDefaultFont(const std::string& path, uint32_t size, const std::string& glyphs);
00131 
00134             GuiFont* getDefaultFont() { return m_defaultfont; };
00135 
00138             GuiFont* createFont(const std::string& path = "", uint32_t size = 0, const std::string& glyphs = "");
00139 
00142             void releaseFont(GuiFont* font);
00143 
00144             void invalidateFonts();
00145 
00146             virtual bool onSdlEvent(SDL_Event& evt);
00147 
00148             KeyEvent translateKeyEvent(const gcn::KeyEvent& evt);
00149             MouseEvent translateMouseEvent(const gcn::MouseEvent& evt);
00150 
00151         protected:
00152             static int32_t convertGuichanKeyToFifeKey(int32_t value);
00153 
00154         private:
00155             // The Guichan GUI.
00156             gcn::Gui* m_gcn_gui;
00157             // GUIChan Graphics
00158             gcn::Graphics* m_gui_graphics;
00159             // Focus handler for input management
00160             gcn::FocusHandler* m_focushandler;
00161             // The top container of the GUI.
00162             gcn::Container* m_gcn_topcontainer;
00163             // The imageloader.
00164             GuiImageLoader* m_imgloader;
00165             // The input controller.
00166             gcn::SDLInput *m_input;
00167             // The console.
00168             Console       *m_console;
00169             //The default font
00170             GuiFont* m_defaultfont;
00171             // The fonts used
00172             std::vector<GuiFont*> m_fonts;
00173             // Added widgets
00174             std::set<gcn::Widget*> m_widgets;
00175 
00176             // Used to accept mouse motion events that leave widget space
00177             bool m_had_mouse;
00178             bool m_had_widget;
00179 
00180             // default font settings
00181             std::string m_fontpath;
00182             std::string m_fontglyphs;
00183             int32_t m_fontsize;
00184 
00185             // true, if guichan logic has already been executed for this round
00186             bool m_logic_executed;
00187     };
00188 
00189 }
00190 
00191 #endif