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 "special/timer.h"
32 /// Possible states of a button.
46 /** Buttons can be placed on the screen and used like any other
47 simple button known from desktop applications. */
50 friend class ButtonPanel;
54 Button(Surface* button_image, const std::string& ninfo,
55 SDLKey nshortcut, int x, int y, int mw = -1, int mh = -1);
56 Button(const std::string& imagefilename, const std::string& ninfo,
57 SDLKey nshortcut, int x, int y, int mw = -1, int mh = -1);
61 /// Apply SDL_Event on button.
62 void event(SDL_Event& event);
64 void draw(DrawingContext& context);
67 /// Activate/Deactivate button.
68 void set_active(bool active)
69 { active ? state = BUTTON_NONE : state = BUTTON_DEACTIVE; };
71 /** The last added icon is the last one, which gets drawn. */
72 void add_icon(const std::string& imagefile, int mw, int mh);
73 /// Get position of the button on screen.
74 /** Returns a SDL_Rect. */
77 /// Get tag of the button
78 /** Useable for button identification etc. */
81 // void set_drawable(Drawable* newdrawable)
82 // { drawable = newdrawable; }
85 static Timer popup_timer;
86 // Drawable* drawable;
87 std::vector<Surface*> icon;
97 /** A ButtonPanel manages buttons inside
98 its scope. It also dispatches events
99 and draws the buttons it contains. */
104 /** Expects X,Y coordinates and the width and height values
105 of the ButtonPanel. */
106 ButtonPanel(int x, int y, int w, int h);
108 /** SDL_Rect version of above. */
109 ButtonPanel(const SDL_Rect& rect);
112 /// Draw the panel and its buttons.
113 void draw(DrawingContext& context);
114 /// Dispatch button events.
115 Button* event(SDL_Event &event);
116 /// Add a button to the panel.
117 /** @param tag: Can be used to identify a button. */
118 void additem(Button* pbutton, int tag);
119 /// Set the default size of contained buttons.
120 void set_button_size(int w, int h);
121 /// Manipulate a button.
122 Button* manipulate_button(int i);
123 /// Set if the last clicked/used item, should be drawn highlighted.
124 void highlight_last(bool b);
125 /// Set the last clicked/used button.
126 /** Set which button is internally the last clicked/used and
127 therefore drawn highlighted in case button highlighting
128 is enabled for the ButtonPanel. */
129 void set_last_clicked(unsigned int last);
136 std::vector<Button*> item;
137 std::vector<Button*>::iterator last_clicked;
140 } // namespace SuperTux
142 #endif /*SUPERTUX_BUTTON_H*/