renamed timer_type to Timer
[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     static Timer popup_timer;
46     texture_type icon;
47     texture_type* bkgd;
48     std::string info;
49     SDLKey shortcut;
50     SDL_Rect rect;
51     bool show_info;
52     ButtonState state;
53     int tag;
54   };
55
56 class ButtonPanel
57   {
58   public:
59     ButtonPanel(int x, int y, int w, int h);
60     ~ButtonPanel();
61     void draw();
62     Button* event(SDL_Event &event);
63     void additem(Button* pbutton, int tag);
64     Button* button_panel_event(SDL_Event& event);
65     void set_button_size(int w, int h) { bw = w; bh = h; }
66
67   private:
68     int bw, bh;
69     bool hidden;
70     SDL_Rect rect;
71     std::vector<Button*> item;
72   };
73
74 #endif /*SUPERTUX_BUTTON_H*/