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