lots of improvements all over the code.
[supertux.git] / src / button.h
1 //
2 // C Interface: button
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_BUTTON_H
14 #define SUPERTUX_BUTTON_H
15
16 #include <vector>
17 #include "texture.h"
18
19 enum ButtonState {
20   BUTTON_NONE = -1,
21   BUTTON_CLICKED,
22   BUTTON_PRESSED,
23   BUTTON_HOVER
24 };
25
26 class ButtonPanel;
27
28 class Button
29   {
30     friend class ButtonPanel;
31
32   public:
33     Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1);
34     ~Button();
35     void event(SDL_Event& event);
36     void draw();
37     int get_state();
38     void change_icon(std::string icon_file, int mw, int mh);
39     int get_tag()
40     {
41       return tag;
42     }
43
44   private:
45     texture_type icon;
46     texture_type* bkgd;
47     std::string info;
48     SDLKey shortcut;
49     SDL_Rect rect;
50     bool show_info;
51     ButtonState state;
52     int tag;
53   };
54
55 class ButtonPanel
56   {
57   public:
58     ButtonPanel(int x, int y, int w, int h);
59     ~ButtonPanel();
60     void draw();
61     Button* event(SDL_Event &event);
62     void additem(Button* pbutton, int tag);
63     Button* button_panel_event(SDL_Event& event);
64     void set_button_size(int w, int h) { bw = w; bh = h; }
65
66   private:
67     int bw, bh;
68     bool hidden;
69     SDL_Rect rect;
70     std::vector<Button*> item;
71   };
72
73 #endif /*SUPERTUX_BUTTON_H*/