FIFE  2008.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
togglebutton.h
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 {
47  class ToggleButton : public Button, public ActionListener {
48  public:
58  ToggleButton(Image *up_image = 0, Image *down_image = 0, Image *hover_image = 0, const std::string& caption = "", const std::string& group = "");
59 
63  ~ToggleButton();
64 
68  void draw(Graphics *graphics);
69 
73  void adjustSize();
74 
80  void setUpImage(Image* image);
81 
87  void setDownImage(Image* image);
88 
94  void setHoverImage(Image* image);
95 
105  void setDownOffset(int32_t x, int32_t y);
106 
114  int32_t getDownXOffset() const;
115 
123  int32_t getDownYOffset() const;
124 
131  bool isToggled() const;
132 
140  void setToggled(bool toggled);
141 
142  // From Guichan 0.8.1
151  void setGroup(const std::string &group);
152 
159  const std::string &getGroup() const;
160 
161  protected:
162  // Inherited from gcn::Widget
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  int32_t x_downoffset;
183  int32_t y_downoffset;
184 
188  bool m_toggled;
189 
190  //-- From Guichan 0.8.1 --
194  std::string m_group;
195 
199  typedef std::multimap<std::string, ToggleButton *> GroupMap;
200 
204  typedef GroupMap::iterator GroupIterator;
205 
209  static GroupMap m_groupMap;
210  };
211 
212 }
213 
214 #endif
215 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */