FIFE  2008.0
guichanmanager.h
1 /***************************************************************************
2  * Copyright (C) 2005-2011 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_VIDEO_GUI_GUICHANMANAGER_H
23 #define FIFE_VIDEO_GUI_GUICHANMANAGER_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/fife_stdint.h"
36 #include "util/base/singleton.h"
37 #include "eventchannel/sdl/ec_isdleventlistener.h"
38 
39 #include "gui/guimanager.h"
40 
41 namespace gcn {
42 
43  class Gui;
44  class Container;
45  class Widget;
46  class SDLInput;
47  class FocusHandler;
48 
49 }
50 
51 
52 namespace FIFE {
53 
54  class GuiImageLoader;
55  class Console;
56  class KeyEvent;
57  class MouseEvent;
58  class IFont;
59  class GuiFont;
60 
61 
62  /* GUI Chan Manager.
63  *
64  * This class controls the GUI system in FIFE.
65  */
66  class GUIChanManager :
67  public IGUIManager,
68  public DynamicSingleton<GUIChanManager>
69  {
70  public:
73  GUIChanManager();
76  virtual ~GUIChanManager();
77 
82  gcn::Gui* getGuichanGUI() const;
83 
88  virtual void turn();
89 
95  void init(const std::string& backend, int32_t screenWidth, int32_t screenHeight);
96 
104  void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
105 
110  void add(gcn::Widget* widget);
115  void remove(gcn::Widget* widget);
120  gcn::Container* getTopContainer() const { return m_gcn_topcontainer; }
121 
126  Console* getConsole() const { return m_console; };
127 
130  GuiFont* setDefaultFont(const std::string& path, uint32_t size, const std::string& glyphs);
131 
134  GuiFont* getDefaultFont() { return m_defaultfont; };
135 
138  GuiFont* createFont(const std::string& path = "", uint32_t size = 0, const std::string& glyphs = "");
139 
142  void releaseFont(GuiFont* font);
143 
144  void invalidateFonts();
145 
146  virtual bool onSdlEvent(SDL_Event& evt);
147 
148  KeyEvent translateKeyEvent(const gcn::KeyEvent& evt);
149  MouseEvent translateMouseEvent(const gcn::MouseEvent& evt);
150 
151  protected:
152  static int32_t convertGuichanKeyToFifeKey(int32_t value);
153 
154  private:
155  // The Guichan GUI.
156  gcn::Gui* m_gcn_gui;
157  // GUIChan Graphics
158  gcn::Graphics* m_gui_graphics;
159  // Focus handler for input management
160  gcn::FocusHandler* m_focushandler;
161  // The top container of the GUI.
162  gcn::Container* m_gcn_topcontainer;
163  // The imageloader.
164  GuiImageLoader* m_imgloader;
165  // The input controller.
166  gcn::SDLInput *m_input;
167  // The console.
168  Console *m_console;
169  //The default font
170  GuiFont* m_defaultfont;
171  // The fonts used
172  std::vector<GuiFont*> m_fonts;
173  // Added widgets
174  std::set<gcn::Widget*> m_widgets;
175 
176  // Used to accept mouse motion events that leave widget space
177  bool m_had_mouse;
178  bool m_had_widget;
179 
180  // default font settings
181  std::string m_fontpath;
182  std::string m_fontglyphs;
183  int32_t m_fontsize;
184 
185  // true, if guichan logic has already been executed for this round
186  bool m_logic_executed;
187  };
188 
189 }
190 
191 #endif
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39