6f086b9f8f1cdef0360ba01f808efa92fcefd68d
[supertux.git] / src / gui / button.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program 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
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #ifndef SUPERTUX_BUTTON_H
21 #define SUPERTUX_BUTTON_H
22
23 #include <vector>
24 #include <string>
25
26 #include "math/vector.hpp"
27 #include "video/drawing_context.hpp"
28
29 class Surface;
30
31 class ButtonGroup;
32
33 enum {
34   BT_NONE,
35   BT_HOVER,
36   BT_SELECTED,
37   BT_SHOW_INFO
38   };
39
40 class Button
41 {
42 public:
43   Button(Surface* image_, std::string info_, SDLKey binding_);
44   ~Button();
45   
46   void draw(DrawingContext& context, bool selected);
47   int event(SDL_Event& event, int x_offset = 0, int y_offset = 0);
48
49   static Font* info_font;
50
51 private:
52   friend class ButtonGroup;
53
54   Vector pos, size;
55
56   Surface* image;
57   SDLKey binding;
58
59   int id;
60   int state;
61   std::string info;
62 };
63
64 class ButtonGroup
65 {
66 public:
67   ButtonGroup(Vector pos_, Vector size_, Vector button_box_);
68   ~ButtonGroup();
69
70   void draw(DrawingContext& context);
71   bool event(SDL_Event& event);
72
73   void add_button(Button button, int id, bool select = false);
74   void add_pair_of_buttons(Button button1, int id1, Button button2, int id2);
75   
76   int selected_id();
77   void set_unselected();
78   bool is_hover();
79
80 private:
81   Vector pos, buttons_size, buttons_box;
82   typedef std::vector <Button> Buttons;
83   Buttons buttons;
84
85   int button_selected, row;
86   bool mouse_hover, mouse_left_button;
87
88   int buttons_pair_nb;
89 };
90
91 #endif