leveleditor menu IDisation and little improvements
[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
27 enum ButtonState {
28   BUTTON_NONE = -1,
29   BUTTON_CLICKED,
30   BUTTON_PRESSED,
31   BUTTON_HOVER
32 };
33
34 class ButtonPanel;
35
36 class Button
37 {
38   friend class ButtonPanel;
39
40 public:
41   Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1);
42   ~Button();
43   void event(SDL_Event& event);
44   void draw();
45   int get_state();
46   void change_icon(std::string icon_file, int mw, int mh);
47   SDL_Rect get_pos() { return rect; }
48   int get_tag(){return tag; }
49   void set_game_object(GameObject* game_object_) { game_object = game_object_; }
50   GameObject* get_game_object() { return game_object; };
51
52 private:
53   static Timer popup_timer;
54   GameObject* game_object;
55   Surface* icon;
56   Surface* bkgd;
57   std::string info;
58   SDLKey shortcut;
59   SDL_Rect rect;
60   bool show_info;
61   ButtonState state;
62   int tag;
63 };
64
65 class ButtonPanel
66 {
67 public:
68   ButtonPanel(int x, int y, int w, int h);
69   ~ButtonPanel();
70   void draw();
71   Button* event(SDL_Event &event);
72   void additem(Button* pbutton, int tag);
73   Button* button_panel_event(SDL_Event& event);
74   void set_button_size(int w, int h);
75   Button* manipulate_button(int i);
76
77 private:
78   int bw, bh;
79   bool hidden;
80   SDL_Rect rect;
81   std::vector<Button*> item;
82 };
83
84 #endif /*SUPERTUX_BUTTON_H*/