Adonthell  0.4
win_manager.h
Go to the documentation of this file.
1 /*
2  $Id: win_manager.h,v 1.13 2004/10/25 06:55:01 ksterker Exp $
3 
4  (C) Copyright 2000/2001/2004 Joel Vennin
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details
13 */
14 
15 /**
16  * @file win_manager.h
17  *
18  * @author Joel Vennin
19  * @brief Declares the win_manager class.
20  */
21 
22 #ifndef _WIN_MANAGER_
23 #define _WIN_MANAGER_
24 
25 #include "str_hash.h"
26 #include "win_theme.h"
27 #include "win_ttf.h"
28 
29 #ifndef SWIG
30 using namespace std;
31 #endif
32 
33 /**
34  * The window manager takes care of basic GUI functions, such as
35  * %input focus, window state updates and displaying everything in
36  * the right order.
37  * It also provides centralised access to fonts and themes, so
38  * that they can be used by different windows without having to
39  * load them multiple times.
40  * For something to appear on screen, it has to be passes to the
41  * window manager.
42  *
43  * Before the window manager can be used, adonthell::main() has
44  * to be called. This instanciates a window manager object and
45  * makes it available to other classes via the static
46  * win_manager::active pointer. All windows added to that instance
47  * have access to the input focus, although only one window can
48  * own it at any given time.
49  *
50  * Another call to adonthell::main() will create a new window
51  * manager instance that grabs the input focus. As long as it
52  * is in existance, none of the parent windows are updated, nor may
53  * they recieve the focus. A call to adonthell::main_quit() will
54  * delete the topmost window manager and return focus to the underlying
55  * windows.
56  *
57  * That way it is possible to create a hierarchie of windows, where
58  * where only windows on the same level may share the input focus,
59  * but only those on the highest level receive input.
60  */
62 {
63 public:
64  /**
65  * Standard constructor
66  */
67  win_manager ();
68 
69  /**
70  * Destructor
71  */
72  ~win_manager ();
73 
74  /**
75  * @name Window handling methods
76  *
77  */
78  //@{
79 
80  /**
81  * Add a window to the window manager.
82  *
83  * @param wnd The window to be added
84  */
85  void add (win_base *wnd);
86 
87  // static bool exist (win_base *);
88 
89  /**
90  * Remove a window from the window manager. The
91  * window is erased from the window list, but not deleted.
92  * If it had the %input focus, it is passed on to the topmost
93  * window, i.e. the last one in the window list (if such a
94  * window exists).
95  *
96  * @param wnd The window to be removed
97  */
98  void remove (win_base *wnd);
99 
100  /**
101  * Update the state of all top level windows. Calls the
102  * %update() method of all windows in the window list. If
103  * that method returns 0, it will be removed from the window
104  * list and deleted.
105  */
106  void update ();
107 
108  /**
109  * Checks for user input. Calls the %input_update() method of
110  * the window that has the %input focus.
111  *
112  * @sa set_focus ()
113  */
114  void input_update ();
115 
116  /**
117  * Draws <b>all</b> windows. If the window hierarchie consists
118  * of multiple levels, the lowest windows are drawn first. Within
119  * each level, windows are drawn in the order they appear in the
120  * window list.
121  */
122  void draw ();
123 
124  /**
125  * Gives the input focus to wnd. Only one window can have the
126  * focus at a time, so focus will be removed from the window
127  * that had it so far. Only the window with the focus will
128  * receive user input.
129  *
130  * @sa input_update ()
131  */
132  void set_focus (win_base *wnd);
133 
134  /**
135  * Closes and deletes all windows of the current level.
136  */
137  void destroy ();
138 
139 #ifndef SWIG
140  /**
141  * Pointer to the active, i.e. topmost window manager.
142  */
144 #endif
145 
146  /**
147  * Use this method to get the active manger from Python
148  */
150  {
151  return active;
152  }
153  //@}
154 
155  /**
156  * @name Theme and font related methods
157  *
158  */
159  //@{
160 
161  /**
162  * Empty for now
163  */
164  static void init (const string & font);
165 
166  /**
167  * Delete all themes and fonts currently loaded.
168  */
169  static void cleanup ();
170 
171  /**
172  * Load a theme from disk.
173  *
174  * @param name The name of the theme to load.
175  */
176  static void add_theme (string name);
177 
178  /**
179  * Delete a theme.
180  *
181  * @param name The name of the theme to delete.
182  * @return
183  * @li true in case of success.
184  * @li false in case of error.
185  */
186  static bool remove_theme (string name);
187 
188  /**
189  * Returns a pointer to a theme. Loads the theme from disk
190  * if it isn't in memory yet.
191  *
192  * @param name The name of the theme to get.
193  * @return Pointer to the theme.
194  */
195  static win_theme *get_theme (string name);
196 
197  /**
198  * Load a font from disk.
199  *
200  * @param name The name of the font to load.
201  */
202  static void add_font (string name);
203 
204  /**
205  * Delete a font.
206  *
207  * @param name The name of the font to delete.
208  * @return
209  * @li true in case of success.
210  * @li false in case of error.
211  */
212  static bool remove_font (string name);
213 
214  /**
215  * Returns a pointer to a font. Loads the font from disk
216  * if it isn't in memory yet.
217  *
218  * @param name The name of the font to get.
219  * @return Pointer to the font.
220  */
221  static win_font *get_font (string name);
222 
223  //@}
224 
225  private:
226 #ifndef SWIG
227  static hash_map<string, win_theme *> theme;
228  static hash_map<string, win_ttf *> font;
229 
230  list<win_base *> wnd_list;
231  list<win_base *>::iterator current;
232  win_base *wnd_focus;
233  win_manager *prev;
234  static string font_file;
235 #endif // SWIG
236 };
237 
238 #endif
239