Mercurial > fife-parpg
comparison engine/core/gui/widgets/togglebutton.h @ 177:3fb17daa1b27
* Added ToggleButton widget
* Modified editor to use togglebuttons in toolbox
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 25 Jan 2009 20:17:41 +0000 |
parents | |
children | d76169461729 |
comparison
equal
deleted
inserted
replaced
176:542213eebe73 | 177:3fb17daa1b27 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or * | |
7 * modify it under the terms of the GNU Lesser General Public * | |
8 * License as published by the Free Software Foundation; either * | |
9 * version 2.1 of the License, or (at your option) any later version. * | |
10 * * | |
11 * This library 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 GNU * | |
14 * Lesser General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU Lesser General Public * | |
17 * License along with this library; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 #ifndef FIFE_GUICHAN_ADDON_TOGGLEBUTTON_H | |
23 #define FIFE_GUICHAN_ADDON_TOGGLEBUTTON_H | |
24 | |
25 // Standard C++ library includes | |
26 #include <string> | |
27 #include <map> | |
28 | |
29 // 3rd party library includes | |
30 #include <guichan.hpp> | |
31 #include <guichan/actionlistener.hpp> | |
32 | |
33 // FIFE includes | |
34 // These includes are split up in two parts, separated by one empty line | |
35 // First block: files included from the FIFE root src directory | |
36 // Second block: files included from the same folder | |
37 | |
38 namespace gcn { | |
39 /** | |
40 * An implementation of a toggleable button. | |
41 * | |
42 * If the button is in a group, all other buttons in that group will be untoggled | |
43 * when a button gets toggled. If the button is already toggled, you can untoggle | |
44 * it by clicking on it. | |
45 * | |
46 */ | |
47 class ToggleButton : public Button, public ActionListener { | |
48 public: | |
49 /** | |
50 * Constructor | |
51 * | |
52 * @param up_image Image displayed when the button isn't toggled | |
53 * @param down_image Image displayed when the button is toggled | |
54 * @param hover_file Image displayed when the mouse cursor is over button | |
55 * @param caption Text to be displayed on button | |
56 * @param group The group the button belongs to | |
57 */ | |
58 ToggleButton(Image *up_image = 0, Image *down_image = 0, Image *hover_image = 0, const std::string& caption = "", const std::string& group = ""); | |
59 | |
60 /** | |
61 * Destructor | |
62 */ | |
63 ~ToggleButton(); | |
64 | |
65 /** | |
66 * Draws the button | |
67 */ | |
68 void draw(Graphics *graphics); | |
69 | |
70 /** | |
71 * Adjust size to fit image | |
72 */ | |
73 void adjustSize(); | |
74 | |
75 /** | |
76 * Sets the image that will be displayed when the button isn't toggled | |
77 * | |
78 * @param image Image to be displayed | |
79 */ | |
80 void setUpImage(Image* image); | |
81 | |
82 /** | |
83 * Sets the image that will be displayed when the button is toggled or pressed | |
84 * | |
85 * @param image Image to be displayed | |
86 */ | |
87 void setDownImage(Image* image); | |
88 | |
89 /** | |
90 * Sets the image which will be displayed when the mouse cursor is over the button | |
91 * | |
92 * @param image Image to be displayed | |
93 */ | |
94 void setHoverImage(Image* image); | |
95 | |
96 /** | |
97 * Sets the number of pixels the image or text will be offset from | |
98 * the top left corner of button when the button is pressed or toggled. | |
99 * | |
100 * @param x Offset from left | |
101 * @param y Offset from top | |
102 * @see getDownXOffset | |
103 * @see getDownYOffset | |
104 */ | |
105 void setDownOffset(int x, int y); | |
106 | |
107 /** | |
108 * Gets the number of pixels the image or text will be offset | |
109 * from the left of button when the button is pressed or toggled. | |
110 * | |
111 * @return Offset from left when button is pressed | |
112 * @see setDownOffset | |
113 */ | |
114 int getDownXOffset() const; | |
115 | |
116 /** | |
117 * Gets the number of pixels the image or text will be offset | |
118 * from the top of button when the button is pressed or toggled. | |
119 * | |
120 * @return Offset from top when button is pressed | |
121 * @see setDownOffset | |
122 */ | |
123 int getDownYOffset() const; | |
124 | |
125 /** | |
126 * Sets the help text for the button | |
127 * | |
128 * @param txt The help text | |
129 * | |
130 * @see getHelpText | |
131 */ | |
132 void setHelpText(const std::string& txt); | |
133 | |
134 /** | |
135 * Gets the help text for the button | |
136 * | |
137 * @return The help text | |
138 * | |
139 * @see setHelpText | |
140 */ | |
141 const std::string& getHelpText(); | |
142 | |
143 /** | |
144 * Checks if the radio button is selected. | |
145 * | |
146 * @return True if the radio button is selecte, false otherwise. | |
147 * @see setSelected | |
148 */ | |
149 bool isToggled() const; | |
150 | |
151 /** | |
152 * Sets the radio button to selected or not. | |
153 * | |
154 * @param selected True if the radio button should be selected, | |
155 * false otherwise. | |
156 * @see isSelected | |
157 */ | |
158 void setToggled(bool toggled); | |
159 | |
160 // From Guichan 0.8.1 | |
161 /** | |
162 * Sets the group the toggle button should belong to. Note that | |
163 * a toggle button group is unique per application, not per Gui object | |
164 * as the group is stored in a static map. | |
165 * | |
166 * @param group The name of the group. | |
167 * @see getGroup | |
168 */ | |
169 void setGroup(const std::string &group); | |
170 | |
171 /** | |
172 * Gets the group the toggle button belongs to. | |
173 * | |
174 * @return The group the toggle button belongs to. | |
175 * @see setGroup | |
176 */ | |
177 const std::string &getGroup() const; | |
178 | |
179 protected: | |
180 // Inherited from gcn::Widget | |
181 /** | |
182 * Toggle button when it is activated | |
183 * | |
184 * @param actionEvent ActionEvent object | |
185 */ | |
186 void action(const ActionEvent& actionEvent); | |
187 | |
188 private: | |
189 // Image to be used when the button is not toggle | |
190 Image *m_upImage; | |
191 | |
192 // Image to be used when the button is toggled or pressed | |
193 Image *m_downImage; | |
194 | |
195 // Image to be used when the mouse cursor is over the image | |
196 Image *m_hoverImage; | |
197 | |
198 // Number of pixels the image/text will be offset from the top left | |
199 // corner, when the button is pressed or toggled | |
200 int x_downoffset; | |
201 int y_downoffset; | |
202 | |
203 // Help text for the button | |
204 std::string m_helptext; | |
205 | |
206 /** | |
207 * Whether the button is toggled or not. | |
208 */ | |
209 bool m_toggled; | |
210 | |
211 //-- From Guichan 0.8.1 -- | |
212 /** | |
213 * Holds the group of the toggle button. | |
214 */ | |
215 std::string m_group; | |
216 | |
217 /** | |
218 * Typedef. | |
219 */ | |
220 typedef std::multimap<std::string, ToggleButton *> GroupMap; | |
221 | |
222 /** | |
223 * Typedef. | |
224 */ | |
225 typedef GroupMap::iterator GroupIterator; | |
226 | |
227 /** | |
228 * Holds all available toggle button groups. | |
229 */ | |
230 static GroupMap m_groupMap; | |
231 }; | |
232 | |
233 } | |
234 | |
235 #endif | |
236 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */ |