-converted remaining classes to GameObject
[supertux.git] / src / button.h
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.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
19 //  02111-1307, USA.
20
21 #ifndef SUPERTUX_BUTTON_H
22 #define SUPERTUX_BUTTON_H
23
24 #include <vector>
25 #include "texture.h"
26 #include "drawable.h"
27
28 enum ButtonState {
29   BUTTON_NONE = -1,
30   BUTTON_CLICKED,
31   BUTTON_PRESSED,
32   BUTTON_HOVER,
33   BUTTON_WHEELUP,
34   BUTTON_WHEELDOWN,
35   BUTTON_DEACTIVE
36 };
37
38 class ButtonPanel;
39
40 class Button
41 {
42   friend class ButtonPanel;
43
44 public:
45   Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1);
46   ~Button();
47   void event(SDL_Event& event);
48   void draw();
49   int get_state();
50   void set_active(bool active) { active ? state = BUTTON_NONE : state = BUTTON_DEACTIVE; };
51   void add_icon(std::string icon_file, int mw, int mh);
52   SDL_Rect get_pos() { return rect; }
53   int get_tag(){return tag; }
54   void set_drawable(Drawable* newdrawable)
55   { drawable = newdrawable; }
56
57 private:
58   static Timer popup_timer;
59   Drawable* drawable;
60   std::vector<Surface*> icon;
61   std::string info;
62   SDLKey shortcut;
63   SDL_Rect rect;
64   bool show_info;
65   ButtonState state;
66   int tag;
67 };
68
69 class ButtonPanel
70 {
71 public:
72   ButtonPanel(int x, int y, int w, int h);
73   ~ButtonPanel();
74   void draw();
75   Button* event(SDL_Event &event);
76   void additem(Button* pbutton, int tag);
77   Button* button_panel_event(SDL_Event& event);
78   void set_button_size(int w, int h);
79   Button* manipulate_button(int i);
80   void highlight_last(bool b);
81   void set_last_clicked(unsigned int last)
82   { if(hlast) { if(item.size() >= last) { last_clicked = item.begin() + last; } } };
83
84 private:
85   int bw, bh;
86   bool hlast;
87   bool hidden;
88   SDL_Rect rect;
89   std::vector<Button*> item;
90   std::vector<Button*>::iterator last_clicked;
91 };
92
93 #endif /*SUPERTUX_BUTTON_H*/