Added reload of levels on F7 (Update levelpack) to ease the test of changes.
[enigmagame.git] / src / gui / Menu.hh
blob024b2052bcceb12503d02101a691021502e82db2
1 /*
2 * Copyright (C) 2002,2003,2004,2005,2006 Daniel Heck
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef GUI_MENU_HH_INCLUDED
20 #define GUI_MENU_HH_INCLUDED
22 #include "gui/widgets.hh"
23 #include "gui/Menu.hh"
24 #include "ecl_fwd.hh"
25 #include "ecl_geom.hh"
26 #include "SDL.h"
27 #include <cmath>
28 #include <vector>
30 namespace enigma { namespace gui {
31 /* -------------------- Menu -------------------- */
33 class Menu : public Container {
34 public:
35 Menu();
37 //! true: ok, false: menu aborted by user
38 virtual bool manage();
40 void add(Widget *w);
41 void add(Widget *w, ecl::Rect r);
42 void center();
44 void draw (ecl::GC &gc, const ecl::Rect &r);
46 virtual void quit();
47 void abort();
49 // Container interface
50 virtual void set_key_focus(Widget *newfocus);
51 virtual bool is_key_focus(Widget *focus);
53 protected:
54 void reset_active_widget() { active_widget = NULL; }
55 void reset_key_focus_widget() { key_focus_widget = NULL; }
57 // Menu interface.
58 virtual void draw_background(ecl::GC &/*gc*/) {}
60 private:
61 void handle_event(const SDL_Event &e);
63 void switch_active_widget(Widget *to_activate);
64 void track_active_widget( int x, int y ); // used by mouse
65 void goto_adjacent_widget(int xdir, int ydir); // used by keyboard
67 // Variables.
68 Widget *active_widget;
69 Widget *key_focus_widget;
70 bool quitp, abortp;
73 class BuildVList {
74 ecl::Rect r;
75 Menu *container;
76 int skip;
77 public:
78 BuildVList(Menu *cc, const ecl::Rect &rr, int s)
79 : r(rr), container(cc), skip(s)
82 Widget *add(Widget *w) {
83 container->add(w, r);
84 r.y += r.h+skip;
85 return w;
88 ecl::Rect pos() const { return r; }
91 class BuildHList {
92 ecl::Rect r;
93 Menu *container;
94 int skip;
95 public:
96 BuildHList(Menu *cc, const ecl::Rect &rr, int s)
97 : r(rr), container(cc), skip(s)
100 Widget * add(Widget *w) {
101 container->add(w, r);
102 r.x += r.w+skip;
103 return w;
105 Widget *add (Widget *w, int width) {
106 ecl::Rect rr(r.x, r.y, width, r.h);
107 container->add(w, rr);
108 r.x += width + skip;
109 return w;
112 ecl::Rect pos() const { return r; }
115 }} // namespace enigma::gui
116 #endif