Mercurial > fife-parpg
diff engine/core/gui/guimanager.h @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/engine/core/gui/guimanager.h Sun Jun 29 18:44:17 2008 +0000 @@ -0,0 +1,197 @@ +/*************************************************************************** + * Copyright (C) 2005-2008 by the FIFE team * + * http://www.fifengine.de * + * This file is part of FIFE. * + * * + * FIFE is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + +#ifndef FIFE_VIDEO_GUI_GUIMANAGER_H +#define FIFE_VIDEO_GUI_GUIMANAGER_H + +// Standard C++ library includes +#include <set> + +// 3rd party library includes +#include <guichan.hpp> + +// FIFE includes +// These includes are split up in two parts, separated by one empty line +// First block: files included from the FIFE root src directory +// Second block: files included from the same folder +#include "util/base/singleton.h" +#include "eventchannel/sdl/ec_isdleventlistener.h" +#include "eventchannel/mouse/ec_imouselistener.h" +#include "eventchannel/key/ec_ikeylistener.h" +#include "eventchannel/widget/ec_iwidgetlistener.h" + +namespace gcn { + + class Gui; + class Container; + class Widget; + class SDLInput; + class FocusHandler; + +} + + +namespace FIFE { + + class ImagePool; + class GuiImageLoader; + class Console; + class KeyEvent; + class MouseEvent; + class AbstractFont; + class GuiFont; + + /* GUI Manager. + * + * This class controls the GUI system in FIFE. + */ + class GUIManager : + public DynamicSingleton<GUIManager>, + public ISdlEventListener, + public IKeyListener, + public IMouseListener, + public gcn::ActionListener + { + public: + /** Constructor. + */ + GUIManager(IWidgetListener* widgetListener, ImagePool& pool); + /** Destructor. + */ + virtual ~GUIManager(); + + /** Gets the member pointer to the Guichan GUI. + * + * @return The member pointer to the Guichan GUI. + */ + gcn::Gui* getGuichanGUI() const; + + /** Performs the GUI logic and draws the GUI accordingly. + * + * This will be called each frame. + */ + void turn(); + + /** Inits the GUI Manager. + * @param graphics backend specific grapchics object to use + * @param screenWidth width for the gui top container + * @param screenHeight height for the gui top container + */ + void init(gcn::Graphics* graphics, int screenWidth, int screenHeight); + + /** Resizes the top container. + * + * @param x The new starting X coordinate. + * @param y The new starting Y coordinate. + * @param width The new width. + * @param height The new height. + */ + void resizeTopContainer(unsigned int x, unsigned int y, unsigned int width, unsigned int height); + + /** Adds a new widget. + * + * @param A pointer to the widget to add. + */ + void add(gcn::Widget* widget); + /** Removes a widget. + * + * @param A pointer to the widget to remove. + */ + void remove(gcn::Widget* widget); + /** Gets the top container. + * + * @return The top container. + */ + gcn::Container* getTopContainer() { return m_gcn_topcontainer; } + + /** Gets the console. + * + * @return The console. + */ + Console* getConsole() { return m_console; }; + + /** Set the global font properties. + */ + GuiFont* setDefaultFont(const std::string& path, unsigned int size, const std::string& glyphs); + + /** Gets font with given properties. Note that font will be owned by guimanager + */ + GuiFont* createFont(const std::string& path = "", unsigned int size = 0, const std::string& glyphs = ""); + + /** Releases given font. + */ + void releaseFont(GuiFont* font); + + /** Callback from guichan + */ + void action(const gcn::ActionEvent & event); + + void onSdlEvent(SDL_Event& evt); + void keyPressed(KeyEvent& evt) { evaluateKeyEventConsumption(evt); } + void keyReleased(KeyEvent& evt) { evaluateKeyEventConsumption(evt); } + void mouseEntered(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseExited(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mousePressed(MouseEvent& evt); + void mouseReleased(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseClicked(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseWheelMovedUp(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseWheelMovedDown(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseMoved(MouseEvent& evt) { evaluateMouseEventConsumption(evt); } + void mouseDragged(MouseEvent& evt); + + private: + void evaluateKeyEventConsumption(KeyEvent& evt); + void evaluateMouseEventConsumption(MouseEvent& evt); + + // The Guichan GUI. + gcn::Gui* m_gcn_gui; + // Focus handler for input management + gcn::FocusHandler* m_focushandler; + // The top container of the GUI. + gcn::Container* m_gcn_topcontainer; + // The imageloader. + GuiImageLoader* m_imgloader; + // The input controller. + gcn::SDLInput *m_input; + // The console. + Console *m_console; + // The fonts used + std::vector<GuiFont*> m_fonts; + // Added widgets + std::set<gcn::Widget*> m_widgets; + + // instance whom to deliver widget events coming from guichan + IWidgetListener* m_widgetlistener; + // pool used for images + ImagePool& m_pool; + + // default font settings + std::string m_fontpath; + std::string m_fontglyphs; + int m_fontsize; + + // true, if guichan logic has already been executed for this round + bool m_logic_executed; + }; + +} + +#endif