ManaPlus
checkbox.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_CHECKBOX_H
68 #define GUI_WIDGETS_CHECKBOX_H
69 
70 #include "listeners/keylistener.h"
72 
74 
75 #include "gui/fonts/textchunk.h"
76 
77 #include "gui/widgets/widget.h"
78 
79 #include "localconsts.h"
80 
81 class Skin;
82 
88 class CheckBox final : public Widget,
89  public ToolTipListener,
90  public KeyListener,
91  public WidgetListener
92 {
93  public:
97  CheckBox(const Widget2 *const widget,
98  const std::string &restrict caption,
99  const bool selected,
100  ActionListener *const listener,
101  const std::string &restrict eventId);
102 
104 
105 
108  ~CheckBox() override final;
109 
113  void draw(Graphics *const graphics) override final A_NONNULL(2);
114 
115  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
116 
120  void updateAlpha();
121 
125  void drawBox(Graphics *const graphics) A_NONNULL(2);
126 
130  void mouseEntered(MouseEvent& event) override final;
131 
135  void mouseExited(MouseEvent& event) override final;
136 
137  void keyPressed(KeyEvent& event) override final;
138 
139  void adjustSize();
140 
147  bool isSelected() const
148  { return mSelected; }
149 
156  void setSelected(const bool selected)
157  { mSelected = selected; }
158 
165  const std::string &getCaption() const
166  { return mCaption; }
167 
176  void setCaption(const std::string& caption);
177 
178  void mouseClicked(MouseEvent& event) override final;
179 
180  void mouseDragged(MouseEvent& event) override final;
181 
182  void setParent(Widget *widget) override final;
183 
184  void widgetHidden(const Event &event) override final;
185 
186  void setWindow(Widget *const widget) override final;
187 
188  private:
189  void toggleSelected();
190 
194  bool mSelected;
195 
199  std::string mCaption;
200 
202 
203  int mPadding;
206  int mSpacing;
207  int mTextX;
208  bool mHasMouse;
209  bool mDrawBox;
211 
212  static int instances;
213  static Skin *mSkin;
214  static float mAlpha;
215 };
216 
217 #endif // GUI_WIDGETS_CHECKBOX_H
int mImageSize
Definition: checkbox.h:205
void toggleSelected()
Definition: checkbox.cpp:305
void mouseExited(MouseEvent &event)
Definition: checkbox.cpp:267
static float mAlpha
Definition: checkbox.h:214
void safeDraw(Graphics *const graphics)
Definition: checkbox.cpp:192
bool mDrawBox
Definition: checkbox.h:209
int mImagePadding
Definition: checkbox.h:204
void adjustSize()
Definition: checkbox.cpp:284
const std::string & getCaption() const
Definition: checkbox.h:165
int mSpacing
Definition: checkbox.h:206
CheckBox(const Widget2 *const widget, const std::string &caption, const bool selected, ActionListener *const listener, const std::string &eventId)
Definition: checkbox.cpp:88
static int instances
Definition: checkbox.h:212
std::string mCaption
Definition: checkbox.h:199
bool mSelected
Definition: checkbox.h:194
bool mHasMouse
Definition: checkbox.h:208
void setSelected(const bool selected)
Definition: checkbox.h:156
void mouseEntered(MouseEvent &event)
Definition: checkbox.cpp:262
void setWindow(Widget *const widget)
Definition: checkbox.cpp:331
void keyPressed(KeyEvent &event)
Definition: checkbox.cpp:273
void setCaption(const std::string &caption)
Definition: checkbox.cpp:311
void draw(Graphics *const graphics)
Definition: checkbox.cpp:167
static Skin * mSkin
Definition: checkbox.h:213
bool mTextChanged
Definition: checkbox.h:210
void setParent(Widget *widget)
Definition: checkbox.cpp:318
TextChunk mTextChunk
Definition: checkbox.h:201
int mPadding
Definition: checkbox.h:203
void mouseClicked(MouseEvent &event)
Definition: checkbox.cpp:291
void updateAlpha()
Definition: checkbox.cpp:197
int mTextX
Definition: checkbox.h:207
void drawBox(Graphics *const graphics)
Definition: checkbox.cpp:218
void widgetHidden(const Event &event)
Definition: checkbox.cpp:325
void mouseDragged(MouseEvent &event)
Definition: checkbox.cpp:300
bool isSelected() const
Definition: checkbox.h:147
Definition: event.h:79
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