5a78d4592dee969703b05d4092cc19067d2a9d4b
[supertux.git] / lib / gui / button.h
1 /***************************************************************************
2                           button.h  -  graphical buttons
3                              -------------------
4     begin                : June, 23 2004
5     copyright            : (C) 2004 by Ricardo Cruz
6     email                : rick2@aeiou.pt
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef SUPERTUX_BUTTON_H
19 #define SUPERTUX_BUTTON_H
20
21 #include <vector>
22 #include <string>
23
24 #include "math/vector.h"
25 #include "video/drawing_context.h"
26
27 namespace SuperTux
28   {
29 class Surface;
30 class ButtonGroup;
31
32 enum {
33   BT_NONE,
34   BT_HOVER,
35   BT_SELECTED,
36   BT_SHOW_INFO
37   };
38
39 class Button
40 {
41 public:
42   Button(Surface* image_, std::string info_, SDLKey binding_);
43   ~Button();
44   
45   void draw(DrawingContext& context, bool selected);
46   int event(SDL_Event& event, int x_offset = 0, int y_offset = 0);
47
48   static Font* info_font;
49
50 private:
51   friend class ButtonGroup;
52
53   Vector pos, size;
54
55   Surface* image;
56   SDLKey binding;
57
58   int id;
59   int state;
60   std::string info;
61 };
62
63 class ButtonGroup
64 {
65 public:
66   ButtonGroup(Vector pos_, Vector size_, Vector button_box_);
67   ~ButtonGroup();
68
69   void draw(DrawingContext& context);
70   bool event(SDL_Event& event);
71
72   void add_button(Button button, int id, bool select = false);
73   void add_pair_of_buttons(Button button1, int id1, Button button2, int id2);
74   
75   int selected_id();
76   void set_unselected();
77   bool is_hover();
78
79 private:
80   Vector pos, buttons_size, buttons_box;
81   typedef std::vector <Button> Buttons;
82   Buttons buttons;
83
84   int button_selected, row;
85   bool mouse_hover, mouse_left_button;
86
87   int buttons_pair_nb;
88 };
89
90 } //namespace SuperTux
91
92 #endif