FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fifechanmanager.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 <fifechan.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 fcn {
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 Fifechan Manager.
63  *
64  * This class controls the Fifechan GUI system in FIFE.
65  */
67  public IGUIManager,
68  public DynamicSingleton<FifechanManager>
69  {
70  public:
76  virtual ~FifechanManager();
77 
82  fcn::Gui* getFifechanGUI() 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(fcn::Widget* widget);
115  void remove(fcn::Widget* widget);
120  fcn::Container* getTopContainer() const { return m_fcn_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 fcn::KeyEvent& evt);
149  MouseEvent translateMouseEvent(const fcn::MouseEvent& evt);
150 
151  protected:
152  static int32_t convertFifechanKeyToFifeKey(int32_t value);
153 
154  private:
155  // The Fifechan GUI.
156  fcn::Gui* m_fcn_gui;
157  // Fifechan Graphics
158  fcn::Graphics* m_gui_graphics;
159  // Focus handler for input management
160  fcn::FocusHandler* m_focushandler;
161  // The top container of the GUI.
162  fcn::Container* m_fcn_topcontainer;
163  // The imageloader.
165  // The input controller.
166  fcn::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<fcn::Widget*> m_widgets;
175 
176  // Used to accept mouse motion events that leave widget space
179 
180  // default font settings
181  std::string m_fontpath;
182  std::string m_fontglyphs;
183  int32_t m_fontsize;
184 
185  // true, if fifechan logic has already been executed for this round
187  };
188 
189 }
190 
191 #endif
KeyEvent translateKeyEvent(const fcn::KeyEvent &evt)
void add(fcn::Widget *widget)
Adds a new widget.
virtual void turn()
Performs the GUI logic and draws the GUI accordingly.
Class for mouse events.
Definition: ec_mouseevent.h:42
fcn::FocusHandler * m_focushandler
GuiFont * getDefaultFont()
Gets the default font.
FifechanManager()
Constructor.
void resizeTopContainer(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
Resizes the top container.
GuiFont * setDefaultFont(const std::string &path, uint32_t size, const std::string &glyphs)
Set the global font properties.
virtual ~FifechanManager()
Destructor.
virtual bool onSdlEvent(SDL_Event &evt)
Called when an SDL event is received from SDL.
GuiFont * createFont(const std::string &path="", uint32_t size=0, const std::string &glyphs="")
Gets font with given properties.
fcn::SDLInput * m_input
Console * getConsole() const
Gets the console.
fcn::Container * m_fcn_topcontainer
Another Singleton.
Definition: singleton.h:82
GuiImageLoader * m_imgloader
std::vector< GuiFont * > m_fonts
std::set< fcn::Widget * > m_widgets
void releaseFont(GuiFont *font)
Releases given font.
fcn::Graphics * m_gui_graphics
void init(const std::string &backend, int32_t screenWidth, int32_t screenHeight)
Inits the Fifechan GUI Manager.
Class for key events.
Definition: ec_keyevent.h:45
MouseEvent translateMouseEvent(const fcn::MouseEvent &evt)
fcn::Container * getTopContainer() const
Gets the top container.
static int32_t convertFifechanKeyToFifeKey(int32_t value)
Ingame Console.
Definition: console.h:64
unsigned int uint32_t
Definition: core.h:40
fcn::Gui * getFifechanGUI() const
Gets the member pointer to the Fifechan GUI.