FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
guichanmanager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 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"
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  */
67  public IGUIManager,
68  public DynamicSingleton<GUIChanManager>
69  {
70  public:
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 
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.
165  // The input controller.
166  gcn::SDLInput *m_input;
167  // The console.
169  //The default font
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
180 
181  // default font settings
182  std::string m_fontpath;
183  std::string m_fontglyphs;
184  int32_t m_fontsize;
185 
186  // true, if guichan logic has already been executed for this round
188  };
189 
190 }
191 
192 #endif
GuiFont * setDefaultFont(const std::string &path, uint32_t size, const std::string &glyphs)
Set the global font properties.
void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
Resizes the top container.
gcn::Gui * getGuichanGUI() const
Gets the member pointer to the Guichan GUI.
gcn::Graphics * m_gui_graphics
Class for mouse events.
Definition: ec_mouseevent.h:42
MouseEvent translateMouseEvent(const gcn::MouseEvent &evt)
gcn::Container * m_gcn_topcontainer
virtual void turn()
Performs the GUI logic and draws the GUI accordingly.
KeyEvent translateKeyEvent(const gcn::KeyEvent &evt)
GuiFont * createFont(const std::string &path="", uint32_t size=0, const std::string &glyphs="")
Gets font with given properties.
void add(gcn::Widget *widget)
Adds a new widget.
gcn::FocusHandler * m_focushandler
GuiFont * getDefaultFont()
Gets the default font.
void releaseFont(GuiFont *font)
Releases given font.
void init(const std::string &backend, int32_t screenWidth, int32_t screenHeight)
Inits the GUI Manager.
std::string m_fontglyphs
Another Singleton.
Definition: singleton.h:82
gcn::Container * getTopContainer() const
Gets the top container.
Console * getConsole() const
Gets the console.
GuiImageLoader * m_imgloader
Class for key events.
Definition: ec_keyevent.h:45
static int32_t convertGuichanKeyToFifeKey(int32_t value)
GUIChanManager()
Constructor.
Ingame Console.
Definition: console.h:64
unsigned int uint32_t
Definition: core.h:40
virtual bool onSdlEvent(SDL_Event &evt)
Called when an SDL event is received from SDL.
virtual ~GUIChanManager()
Destructor.
std::set< gcn::Widget * > m_widgets
std::vector< GuiFont * > m_fonts
gcn::SDLInput * m_input