4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
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.
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.
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
21 #ifndef SUPERTUX_BUTTON_H
22 #define SUPERTUX_BUTTON_H
26 #include "../video/surface.h"
27 #include "../video/font.h"
28 #include "../special/timer.h"
33 /// Possible states of a button.
47 /** Buttons can be placed on the screen and used like any other
48 simple button known from desktop applications. */
51 friend class ButtonPanel;
55 Button(Surface* button_image, const std::string& ninfo,
56 SDLKey nshortcut, int x, int y, int mw = -1, int mh = -1);
57 Button(const std::string& imagefilename, const std::string& ninfo,
58 SDLKey nshortcut, int x, int y, int mw = -1, int mh = -1);
62 /// Apply SDL_Event on button.
63 void event(SDL_Event& event);
65 void draw(DrawingContext& context);
68 /// Activate/Deactivate button.
69 void set_active(bool active)
70 { active ? state = BUTTON_NONE : state = BUTTON_DEACTIVE; };
72 /** The last added icon is the last one, which gets drawn. */
73 void add_icon(const std::string& imagefile, int mw, int mh);
74 /// Get position of the button on screen.
75 /** Returns a SDL_Rect. */
78 /// Get tag of the button
79 /** Useable for button identification etc. */
82 // void set_drawable(Drawable* newdrawable)
83 // { drawable = newdrawable; }
85 static Font* info_font;
88 static Timer popup_timer;
89 // Drawable* drawable;
90 std::vector<Surface*> icon;
100 /** A ButtonPanel manages buttons inside
101 its scope. It also dispatches events
102 and draws the buttons it contains. */
107 /** Expects X,Y coordinates and the width and height values
108 of the ButtonPanel. */
109 ButtonPanel(int x, int y, int w, int h);
111 /** SDL_Rect version of above. */
112 ButtonPanel(const SDL_Rect& rect);
115 /// Draw the panel and its buttons.
116 void draw(DrawingContext& context);
117 /// Dispatch button events.
118 Button* event(SDL_Event &event);
119 /// Add a button to the panel.
120 /** @param tag: Can be used to identify a button. */
121 void additem(Button* pbutton, int tag);
122 /// Set the default size of contained buttons.
123 void set_button_size(int w, int h);
124 /// Manipulate a button.
125 Button* manipulate_button(int i);
126 /// Set if the last clicked/used item, should be drawn highlighted.
127 void highlight_last(bool b);
128 /// Set the last clicked/used button.
129 /** Set which button is internally the last clicked/used and
130 therefore drawn highlighted in case button highlighting
131 is enabled for the ButtonPanel. */
132 void set_last_clicked(unsigned int last);
139 std::vector<Button*> item;
140 std::vector<Button*>::iterator last_clicked;
143 } // namespace SuperTux
145 #endif /*SUPERTUX_BUTTON_H*/