FifeGUI 0.3.0
A C++ GUI library designed for games.
checkbox.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_WIDGETS_CHECKBOX_HPP_
6#define INCLUDE_FIFECHAN_WIDGETS_CHECKBOX_HPP_
7
8// Standard library includes
9#include <memory>
10#include <string>
11
12// Platform config include
13#include "fifechan/platform.hpp"
14
15// Project headers (subdirs before local)
16#include "fifechan/widgets/imagebutton.hpp"
17
18namespace fcn
19{
20 class Image;
21
32 class FIFEGUI_API CheckBox : public fcn::ImageButton
33 {
34 public:
38 enum class MarkerStyle : uint8_t
39 {
40 Checkmark = 0,
41 Cross,
42 Dot,
43 Rhombus,
44 Image
45 };
46
47 CheckBox();
48
56 explicit CheckBox(std::string const & caption, bool selected = false);
57
58 ~CheckBox() override;
59
60 CheckBox(CheckBox const &) = delete;
61 CheckBox& operator=(CheckBox const &) = delete;
62 CheckBox(CheckBox&&) = delete;
63 CheckBox& operator=(CheckBox&&) = delete;
64
71 virtual bool isSelected() const;
72
79 virtual void setSelected(bool selected);
80
85 virtual void toggleSelected();
86
93 void setBackgroundImage(std::string const & filename);
94
101 void setBackgroundImage(Image const * image);
102
108 Image const * getBackgroundImage() const;
109
115 MarkerStyle getMarkerStyle() const;
116
122 void setMarkerStyle(MarkerStyle mode);
123
124 // Inherited from Widget
125
126 void adjustSize() override;
127 void draw(Graphics* graphics) override;
128
129 // Inherited from KeyListener
130
131 void keyPressed(KeyEvent& keyEvent) override;
132 void keyReleased(KeyEvent& keyEvent) override;
133
134 // Inherited from MouseListener
135
136 void mousePressed(MouseEvent& mouseEvent) override;
137 void mouseReleased(MouseEvent& mouseEvent) override;
138 void mouseClicked(MouseEvent& mouseEvent) override;
139
140 protected:
146 virtual void drawBox(Graphics* graphics);
147
157 void adjustSizeImpl() override; // cppcheck-suppress virtualCallInConstructor
158
165 static void drawCheckmark(Graphics* graphics, Rectangle const & rec);
166
173 static void drawCross(Graphics* graphics, Rectangle const & rec);
174
181 static void drawDot(Graphics* graphics, Rectangle const & rec);
182
189 void drawMarkerImage(Graphics* graphics, Rectangle const & rec);
190
196 void drawRhombus(Graphics* graphics);
197
201 Image const * mBackgroundImage{nullptr};
202
207
211 bool mSelected{false};
212
216 MarkerStyle mMode{MarkerStyle::Checkmark};
217 };
218} // namespace fcn
219
220#endif // INCLUDE_FIFECHAN_WIDGETS_CHECKBOX_HPP_
An implementation of a check box.
Definition checkbox.hpp:33
MarkerStyle mMode
Holds the marker style of the check box.
Definition checkbox.hpp:216
Image const * mBackgroundImage
Holds the background image, that includes the caption region.
Definition checkbox.hpp:201
bool mSelected
True if the check box is selected, false otherwise.
Definition checkbox.hpp:211
bool mInternalBackgroundImage
True if the background image was loaded internally, false otherwise.
Definition checkbox.hpp:206
MarkerStyle
Marker style.
Definition checkbox.hpp:39
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
An implementation of a regular clickable button.
Abstract holder for image data.
Definition image.hpp:34
Represents a key event.
Definition keyevent.hpp:26
Represents a mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
Used replacement tokens by configure_file():