FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
guimanager.h
1 /***************************************************************************
2  * Copyright (C) 2005-2008 by the FIFE team *
3  * http://www.fifengine.de *
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_VIDEO_GUI_GUIMANAGER_H
23 #define FIFE_VIDEO_GUI_GUIMANAGER_H
24 
25 // Standard C++ library includes
26 #include <set>
27 
28 // 3rd party library includes
29 #include <guichan.hpp>
30 
31 // FIFE includes
32 // These includes are split up in two parts, separated by one empty line
33 // First block: files included from the FIFE root src directory
34 // Second block: files included from the same folder
35 #include "util/base/singleton.h"
36 #include "eventchannel/sdl/ec_isdleventlistener.h"
37 // #include "eventchannel/mouse/ec_imouselistener.h"
38 // #include "eventchannel/key/ec_ikeylistener.h"
39 
40 namespace gcn {
41 
42  class Gui;
43  class Container;
44  class Widget;
45  class SDLInput;
46  class FocusHandler;
47 
48 }
49 
50 
51 namespace FIFE {
52 
53  class ImagePool;
54  class GuiImageLoader;
55  class Console;
56  class KeyEvent;
57  class MouseEvent;
58  class AbstractFont;
59  class GuiFont;
60 
61  /* GUI Manager.
62  *
63  * This class controls the GUI system in FIFE.
64  */
65  class GUIManager :
66  public DynamicSingleton<GUIManager>,
67  public ISdlEventListener
68  {
69  public:
72  GUIManager(ImagePool& pool);
75  virtual ~GUIManager();
76 
81  gcn::Gui* getGuichanGUI() const;
82 
87  void turn();
88 
94  void init(gcn::Graphics* graphics, int screenWidth, int screenHeight);
95 
103  void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height);
104 
109  void add(gcn::Widget* widget);
114  void remove(gcn::Widget* widget);
119  gcn::Container* getTopContainer() const { return m_gcn_topcontainer; }
120 
125  Console* getConsole() const { return m_console; };
126 
129  GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs);
130 
133  GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = "");
134 
137  void releaseFont(GuiFont* font);
138 
139  void invalidateFonts();
140 
141  bool onSdlEvent(SDL_Event& evt);
142 
143  KeyEvent translateKeyEvent(const gcn::KeyEvent& evt);
144  MouseEvent translateMouseEvent(const gcn::MouseEvent& evt);
145 
146  protected:
147  static int convertGuichanKeyToFifeKey(int value);
148 
149  private:
150  // The Guichan GUI.
151  gcn::Gui* m_gcn_gui;
152  // Focus handler for input management
153  gcn::FocusHandler* m_focushandler;
154  // The top container of the GUI.
155  gcn::Container* m_gcn_topcontainer;
156  // The imageloader.
157  GuiImageLoader* m_imgloader;
158  // The input controller.
159  gcn::SDLInput *m_input;
160  // The console.
161  Console *m_console;
162  // The fonts used
163  std::vector<GuiFont*> m_fonts;
164  // Added widgets
165  std::set<gcn::Widget*> m_widgets;
166 
167  // Used to accept mouse motion events that leave widget space
168  bool m_had_mouse;
169 
170  // pool used for images
171  ImagePool& m_pool;
172 
173  // default font settings
174  std::string m_fontpath;
175  std::string m_fontglyphs;
176  int m_fontsize;
177 
178  // true, if guichan logic has already been executed for this round
179  bool m_logic_executed;
180  };
181 
182 }
183 
184 #endif