FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
togglebutton.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
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 
210  };
211 
212 }
213 
214 #endif
215 /* vim: set noexpandtab: set shiftwidth=2: set tabstop=2: */
void setGroup(const std::string &group)
Sets the group the toggle button should belong to.
void draw(Graphics *graphics)
Draws the button.
bool m_toggled
Whether the button is toggled or not.
Definition: togglebutton.h:188
void setUpImage(Image *image)
Sets the image that will be displayed when the button isn&#39;t toggled.
void setHoverImage(Image *image)
Sets the image which will be displayed when the mouse cursor is over the button.
int32_t getDownXOffset() const
Gets the number of pixels the image or text will be offset from the left of button when the button is...
void action(const ActionEvent &actionEvent)
Toggle button when it is activated.
static GroupMap m_groupMap
Holds all available toggle button groups.
Definition: togglebutton.h:209
GroupMap::iterator GroupIterator
Typedef.
Definition: togglebutton.h:204
void adjustSize()
Adjust size to fit image and caption.
std::string m_group
Holds the group of the toggle button.
Definition: togglebutton.h:194
ToggleButton(Image *up_image=0, Image *down_image=0, Image *hover_image=0, const std::string &caption="", const std::string &group="")
Constructor.
~ToggleButton()
Destructor.
An implementation of a toggleable button.
Definition: togglebutton.h:47
std::multimap< std::string, ToggleButton * > GroupMap
Typedef.
Definition: togglebutton.h:199
const std::string & getGroup() const
Gets the group the toggle button belongs to.
void setDownImage(Image *image)
Sets the image that will be displayed when the button is toggled or pressed.
bool isToggled() const
Checks if the radio button is selected.
int32_t getDownYOffset() const
Gets the number of pixels the image or text will be offset from the top of button when the button is ...
void setDownOffset(int32_t x, int32_t y)
Sets the number of pixels the image or text will be offset from the top left corner of button when th...
void setToggled(bool toggled)
Sets the radio button to selected or not.