- Cleanups
[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
26 #include "screen/surface.h"
27 #include "timer.h"
28
29 enum ButtonState {
30   BUTTON_NONE = -1,
31   BUTTON_CLICKED,
32   BUTTON_PRESSED,
33   BUTTON_HOVER,
34   BUTTON_WHEELUP,
35   BUTTON_WHEELDOWN,
36   BUTTON_DEACTIVE
37 };
38
39 class ButtonPanel;
40
41 class Button
42 {
43   friend class ButtonPanel;
44
45 public:
46   Button(Surface* icon_file, const std::string& info, SDLKey shortcut,
47       int x, int y, int mw = -1, int h = -1);
48   Button(const std::string& icon_name, const std::string& info, SDLKey shortcut,
49       int x, int y, int mw = -1, int h = -1);
50   
51   ~Button();
52   void event(SDL_Event& event);
53   void draw(DrawingContext& context);
54   int get_state();
55   void set_active(bool active) { active ? state = BUTTON_NONE : state = BUTTON_DEACTIVE; };
56   void add_icon(const std::string& imagefile, int mw, int mh);
57   SDL_Rect get_pos() { return rect; }
58   int get_tag(){return tag; }
59 //  void set_drawable(Drawable* newdrawable)
60 //  { drawable = newdrawable; }
61
62 private:
63   static Timer popup_timer;
64 //  Drawable* drawable;
65   std::vector<Surface*> icon;
66   std::string info;
67   SDLKey shortcut;
68   SDL_Rect rect;
69   bool show_info;
70   ButtonState state;
71   int tag;
72 };
73
74 class ButtonPanel
75 {
76 public:
77   ButtonPanel(int x, int y, int w, int h);
78   ~ButtonPanel();
79   void draw(DrawingContext& context);
80   Button* event(SDL_Event &event);
81   void additem(Button* pbutton, int tag);
82   Button* button_panel_event(SDL_Event& event);
83   void set_button_size(int w, int h);
84   Button* manipulate_button(int i);
85   void highlight_last(bool b);
86   void set_last_clicked(unsigned int last)
87   { if(hlast) { if(item.size() >= last) { last_clicked = item.begin() + last; } } };
88
89 private:
90   int bw, bh;
91   bool hlast;
92   bool hidden;
93   SDL_Rect rect;
94   std::vector<Button*> item;
95   std::vector<Button*>::iterator last_clicked;
96 };
97
98 #endif /*SUPERTUX_BUTTON_H*/