Mercurial > fife-parpg
comparison engine/core/gui/widgets/togglebutton.h @ 697:ecaa4d98f05f tip
Abstracted the GUI code and refactored the GUIChan-specific code into its own module.
* Most of the GUIChan code has been refactored into its own gui/guichan module. However, references to the GuiFont class still persist in the Engine and GuiManager code and these will need further refactoring.
* GuiManager is now an abstract base class which specific implementations (e.g. GUIChan) should subclass.
* The GUIChan GUI code is now a concrete implementation of GuiManager, most of which is in the new GuiChanGuiManager class.
* The GUI code in the Console class has been refactored out of the Console and into the GUIChan module as its own GuiChanConsoleWidget class. The rest of the Console class related to executing commands was left largely unchanged.
* Existing client code may need to downcast the GuiManager pointer received from FIFE::Engine::getGuiManager() to GuiChanGuiManager, since not all functionality is represented in the GuiManager abstract base class. Python client code can use the new GuiChanGuiManager.castTo static method for this purpose.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 18 Jun 2011 00:28:40 -1000 |
parents | e201abd8c807 |
children |
comparison
equal
deleted
inserted
replaced
696:e201abd8c807 | 697:ecaa4d98f05f |
---|---|
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 and caption | |
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 * Checks if the radio button is selected. | |
127 * | |
128 * @return True if the radio button is selecte, false otherwise. | |
129 * @see setSelected | |
130 */ | |
131 bool isToggled() const; | |
132 | |
133 /** | |
134 * Sets the radio button to selected or not. | |
135 * | |
136 * @param selected True if the radio button should be selected, | |
137 * false otherwise. | |
138 * @see isSelected | |
139 */ | |
140 void setToggled(bool toggled); | |
141 | |
142 // From Guichan 0.8.1 | |
143 /** | |
144 * Sets the group the toggle button should belong to. Note that | |
145 * a toggle button group is unique per application, not per Gui object | |
146 * as the group is stored in a static map. | |
147 * | |
148 * @param group The name of the group. | |
149 * @see getGroup | |
150 */ | |
151 void setGroup(const std::string &group); | |
152 | |
153 /** | |
154 * Gets the group the toggle button belongs to. | |
155 * | |
156 * @return The group the toggle button belongs to. | |
157 * @see setGroup | |
158 */ | |
159 const std::string &getGroup() const; | |
160 | |
161 protected: | |
162 // Inherited from gcn::Widget | |
163 /** | |
164 * Toggle button when it is activated | |
165 * | |
166 * @param actionEvent ActionEvent object | |
167 */ | |
168 void action(const ActionEvent& actionEvent); | |
169 | |
170 private: | |
171 // Image to be used when the button is not toggle | |
172 Image *m_upImage; | |
173 | |
174 // Image to be used when the button is toggled or pressed | |
175 Image *m_downImage; | |
176 | |
177 // Image to be used when the mouse cursor is over the image | |
178 Image *m_hoverImage; | |
179 | |
180 // Number of pixels the image/text will be offset from the top left | |
181 // corner, when the button is pressed or toggled | |
182 int x_downoffset; | |
183 int y_downoffset; | |
184 | |
185 /** | |
186 * Whether the button is toggled or not. | |
187 */ | |
188 bool m_toggled; | |
189 | |
190 //-- From Guichan 0.8.1 -- | |
191 /** | |
192 * Holds the group of the toggle button. | |
193 */ | |
194 std::string m_group; | |
195 | |
196 /** | |
197 * Typedef. | |
198 */ | |
199 typedef std::multimap<std::string, ToggleButton *> GroupMap; | |
200 | |
201 /** | |
202 * Typedef. | |
203 */ | |
204 typedef GroupMap::iterator GroupIterator; | |
205 | |
206 /** | |
207 * Holds all available toggle button groups. | |
208 */ | |
209 static GroupMap m_groupMap; | |
210 }; | |
211 | |
212 } | |
213 | |
214 #endif | |
215 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */ |