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