ManaPlus
radiobutton.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /* _______ __ __ __ ______ __ __ _______ __ __
25  * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
26  * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
27  * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
28  * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
29  * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
30  * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
31  *
32  * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
33  *
34  *
35  * Per Larsson a.k.a finalman
36  * Olof Naessén a.k.a jansem/yakslem
37  *
38  * Visit: http://guichan.sourceforge.net
39  *
40  * License: (BSD)
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  * 1. Redistributions of source code must retain the above copyright
45  * notice, this list of conditions and the following disclaimer.
46  * 2. Redistributions in binary form must reproduce the above copyright
47  * notice, this list of conditions and the following disclaimer in
48  * the documentation and/or other materials provided with the
49  * distribution.
50  * 3. Neither the name of Guichan nor the names of its contributors may
51  * be used to endorse or promote products derived from this software
52  * without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
60  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
61  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
62  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
63  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  */
66 
67 #ifndef GUI_WIDGETS_RADIOBUTTON_H
68 #define GUI_WIDGETS_RADIOBUTTON_H
69 
70 #include "listeners/keylistener.h"
73 
74 #include "gui/fonts/textchunk.h"
75 
76 #include "gui/widgets/widget.h"
77 
78 #include "localconsts.h"
79 
80 class Skin;
81 
85 class RadioButton final : public Widget,
86  public MouseListener,
87  public KeyListener,
88  public WidgetListener
89 
90 {
91  public:
95  RadioButton(const Widget2 *const widget,
96  const std::string &restrict caption,
97  const std::string &restrict group,
98  const bool marked);
99 
101 
102 
105  ~RadioButton() override final;
106 
110  void drawBox(Graphics *const graphics) A_NONNULL(2);
111 
116  void draw(Graphics *const graphics) override final A_NONNULL(2);
117 
118  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
119 
123  void mouseEntered(MouseEvent& event) override final;
124 
128  void mouseExited(MouseEvent& event) override final;
129 
130  void keyPressed(KeyEvent& event) override final;
131 
132  void updateAlpha();
133 
134  void adjustSize();
135 
142  bool isSelected() const
143  { return mSelected; }
144 
152  void setSelected(const bool selected);
153 
160  const std::string &getCaption() const
161  { return mCaption; }
162 
171  void setCaption(const std::string &caption);
172 
173  void mouseClicked(MouseEvent& event) override final;
174 
175  void mouseDragged(MouseEvent& event) override final;
176 
185  void setGroup(const std::string &group);
186 
193  const std::string &getGroup() const
194  { return mGroup; }
195 
196  void setParent(Widget *widget) override final;
197 
198  void widgetHidden(const Event &event) override final;
199 
200  void setWindow(Widget *const widget) override final;
201 
202  private:
203  static int instances;
204  static Skin *mSkin;
205  static float mAlpha;
206 
210  bool mSelected;
211 
215  std::string mCaption;
216 
220  std::string mGroup;
221 
223 
227  typedef std::multimap<std::string, RadioButton *> GroupMap;
228 
232  typedef GroupMap::iterator GroupIterator;
233 
238 
239  int mPadding;
242  int mSpacing;
243  int mTextX;
244  bool mHasMouse;
246 };
247 
248 #endif // GUI_WIDGETS_RADIOBUTTON_H
Definition: event.h:79
void setGroup(const std::string &group)
RadioButton(const Widget2 *const widget, const std::string &caption, const std::string &group, const bool marked)
Definition: radiobutton.cpp:90
const std::string & getGroup() const
Definition: radiobutton.h:193
void drawBox(Graphics *const graphics)
static float mAlpha
Definition: radiobutton.h:205
TextChunk mTextChunk
Definition: radiobutton.h:222
void safeDraw(Graphics *const graphics)
void mouseDragged(MouseEvent &event)
static Skin * mSkin
Definition: radiobutton.h:204
void setSelected(const bool selected)
const std::string & getCaption() const
Definition: radiobutton.h:160
std::string mGroup
Definition: radiobutton.h:220
void setWindow(Widget *const widget)
void updateAlpha()
GroupMap::iterator GroupIterator
Definition: radiobutton.h:232
void setParent(Widget *widget)
void widgetHidden(const Event &event)
int mImagePadding
Definition: radiobutton.h:240
bool isSelected() const
Definition: radiobutton.h:142
void adjustSize()
std::string mCaption
Definition: radiobutton.h:215
static GroupMap mGroupMap
Definition: radiobutton.h:237
void draw(Graphics *const graphics)
bool mSelected
Definition: radiobutton.h:210
void mouseClicked(MouseEvent &event)
void mouseEntered(MouseEvent &event)
void keyPressed(KeyEvent &event)
static int instances
Definition: radiobutton.h:203
std::multimap< std::string, RadioButton * > GroupMap
Definition: radiobutton.h:227
bool mHasMouse
Definition: radiobutton.h:244
void mouseExited(MouseEvent &event)
void setCaption(const std::string &caption)
bool mTextChanged
Definition: radiobutton.h:245
Definition: skin.h:37
Definition: widget.h:99
#define restrict
Definition: localconsts.h:165
#define A_NONNULL(...)
Definition: localconsts.h:168
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53