Adonthell 0.4
win_manager.h
Go to the documentation of this file.
00001 /*
00002    $Id: win_manager.h,v 1.13 2004/10/25 06:55:01 ksterker Exp $
00003    
00004    (C) Copyright 2000/2001/2004 Joel Vennin
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details
00013 */
00014 
00015 /** 
00016  * @file win_manager.h
00017  *
00018  * @author Joel Vennin 
00019  * @brief Declares the win_manager class.
00020  */
00021 
00022 #ifndef _WIN_MANAGER_
00023 #define _WIN_MANAGER_
00024 
00025 #include "str_hash.h"
00026 #include "win_theme.h"
00027 #include "win_ttf.h"
00028 
00029 #ifndef SWIG
00030 using namespace std;   
00031 #endif
00032 
00033 /** 
00034  * The window manager takes care of basic GUI functions, such as
00035  * %input focus, window state updates and displaying everything in
00036  * the right order.
00037  * It also provides centralised access to fonts and themes, so
00038  * that they can be used by different windows without having to
00039  * load them multiple times.
00040  * For something to appear on screen, it has to be passes to the
00041  * window manager.
00042  *
00043  * Before the window manager can be used, adonthell::main() has 
00044  * to be called. This instanciates a window manager object and 
00045  * makes it available to other classes via the static 
00046  * win_manager::active pointer. All windows added to that instance
00047  * have access to the input focus, although only one window can
00048  * own it at any given time.
00049  *
00050  * Another call to adonthell::main() will create a new window
00051  * manager instance that grabs the input focus. As long as it
00052  * is in existance, none of the parent windows are updated, nor may 
00053  * they recieve the focus. A call to adonthell::main_quit() will
00054  * delete the topmost window manager and return focus to the underlying
00055  * windows.
00056  *
00057  * That way it is possible to create a hierarchie of windows, where
00058  * where only windows on the same level may share the input focus,
00059  * but only those on the highest level receive input.
00060  */
00061 class win_manager
00062 {
00063 public:
00064     /**
00065      * Standard constructor
00066      */
00067     win_manager ();
00068 
00069     /**
00070      * Destructor
00071      */
00072     ~win_manager ();
00073     
00074     /**
00075      * @name Window handling methods
00076      * 
00077      */ 
00078     //@{
00079     
00080     /**
00081      * Add a window to the window manager.
00082      *
00083      * @param wnd The window to be added
00084      */
00085     void add (win_base *wnd);
00086   
00087     // static bool exist (win_base *);
00088     
00089     /**
00090      * Remove a window from the window manager. The
00091      * window is erased from the window list, but not deleted.
00092      * If it had the %input focus, it is passed on to the topmost
00093      * window, i.e. the last one in the window list (if such a 
00094      * window exists).
00095      *
00096      * @param wnd The window to be removed
00097      */
00098     void remove (win_base *wnd);
00099     
00100     /**
00101      * Update the state of all top level windows. Calls the
00102      * %update() method of all windows in the window list. If
00103      * that method returns 0, it will be removed from the window
00104      * list and deleted.
00105      */
00106     void update ();
00107     
00108     /**
00109      * Checks for user input. Calls the %input_update() method of
00110      * the window that has the %input focus.
00111      *
00112      * @sa set_focus ()
00113      */
00114     void input_update ();
00115     
00116     /**
00117      * Draws <b>all</b> windows. If the window hierarchie consists
00118      * of multiple levels, the lowest windows are drawn first. Within
00119      * each level, windows are drawn in the order they appear in the
00120      * window list.
00121      */
00122     void draw ();
00123     
00124     /**
00125      * Gives the input focus to wnd. Only one window can have the
00126      * focus at a time, so focus will be removed from the window
00127      * that had it so far. Only the window with the focus will
00128      * receive user input.
00129      *
00130      * @sa input_update ()
00131      */
00132     void set_focus (win_base *wnd);
00133     
00134     /**
00135      * Closes and deletes all windows of the current level.
00136      */
00137     void destroy ();
00138 
00139 #ifndef SWIG
00140     /**
00141      * Pointer to the active, i.e. topmost window manager.
00142      */
00143     static win_manager *active;
00144 #endif
00145     
00146     /**
00147      * Use this method to get the active manger from Python
00148      */
00149     static win_manager *get_active ()
00150     {
00151         return active;
00152     }
00153     //@}
00154 
00155     /**
00156      * @name Theme and font related methods
00157      * 
00158      */ 
00159     //@{ 
00160              
00161     /**
00162      * Empty for now
00163      */
00164     static void init (const string & font);
00165     
00166     /**
00167      * Delete all themes and fonts currently loaded.
00168      */
00169     static void cleanup ();
00170 
00171     /**
00172      * Load a theme from disk.
00173      *
00174      * @param name The name of the theme to load.
00175      */
00176     static void add_theme (string name); 
00177 
00178     /**
00179      * Delete a theme.
00180      *
00181      * @param name The name of the theme to delete.
00182      * @return 
00183      *      @li true in case of success.
00184      *      @li false in case of error.
00185      */
00186     static bool remove_theme (string name); 
00187     
00188     /**
00189      * Returns a pointer to a theme. Loads the theme from disk
00190      * if it isn't in memory yet.
00191      *
00192      * @param name The name of the theme to get.
00193      * @return Pointer to the theme.
00194      */
00195     static win_theme *get_theme (string name); 
00196 
00197     /**
00198      * Load a font from disk.
00199      *
00200      * @param name The name of the font to load.
00201      */
00202     static void add_font (string name); 
00203 
00204     /**
00205      * Delete a font.
00206      *
00207      * @param name The name of the font to delete.
00208      * @return 
00209      *      @li true in case of success.
00210      *      @li false in case of error.
00211      */
00212     static bool remove_font (string name); 
00213     
00214     /**
00215      * Returns a pointer to a font. Loads the font from disk
00216      * if it isn't in memory yet.
00217      *
00218      * @param name The name of the font to get.
00219      * @return Pointer to the font.
00220      */
00221     static win_font *get_font (string name); 
00222     
00223     //@}
00224 
00225  private:
00226 #ifndef SWIG
00227     static hash_map<string, win_theme *> theme; 
00228     static hash_map<string, win_ttf *> font; 
00229     
00230     list<win_base *> wnd_list;
00231     list<win_base *>::iterator current;
00232     win_base *wnd_focus;
00233     win_manager *prev;
00234     static string font_file; 
00235 #endif // SWIG
00236 };
00237 
00238 #endif
00239