FifeGUI 0.2.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#include <memory>
9#include <string>
10
11#include "fifechan/platform.hpp"
12#include "fifechan/widgets/imagebutton.hpp"
13
14namespace fcn
15{
16 class Image;
17
26 class FIFEGUI_API CheckBox : public fcn::ImageButton
27 {
28 public:
32 enum class MarkerStyle : uint8_t
33 {
34 Checkmark = 0,
35 Cross,
36 Dot,
37 Rhombus,
38 Image
39 };
40
41 CheckBox();
42
50 explicit CheckBox(std::string const & caption, bool selected = false);
51
52 ~CheckBox() override;
53
54 CheckBox(CheckBox const &) = delete;
55 CheckBox& operator=(CheckBox const &) = delete;
56 CheckBox(CheckBox&&) = delete;
57 CheckBox& operator=(CheckBox&&) = delete;
58
65 virtual bool isSelected() const;
66
73 virtual void setSelected(bool selected);
74
79 virtual void toggleSelected();
80
87 void setBackgroundImage(std::string const & filename);
88
95 void setBackgroundImage(Image const * image);
96
102 Image const * getBackgroundImage() const;
103
109 MarkerStyle getMarkerStyle() const;
110
116 void setMarkerStyle(MarkerStyle mode);
117
118 // Inherited from Widget
119
120 void adjustSize() override;
121 void draw(Graphics* graphics) override;
122
123 // Inherited from KeyListener
124
125 void keyPressed(KeyEvent& keyEvent) override;
126 void keyReleased(KeyEvent& keyEvent) override;
127
128 // Inherited from MouseListener
129
130 void mousePressed(MouseEvent& mouseEvent) override;
131 void mouseReleased(MouseEvent& mouseEvent) override;
132 void mouseClicked(MouseEvent& mouseEvent) override;
133
134 protected:
140 virtual void drawBox(Graphics* graphics);
141
151 void adjustSizeImpl() override;
152
159 void drawCheckmark(Graphics* graphics, Rectangle const & rec);
160
167 void drawCross(Graphics* graphics, Rectangle const & rec);
168
175 void drawDot(Graphics* graphics, Rectangle const & rec);
176
183 void drawMarkerImage(Graphics* graphics, Rectangle const & rec);
184
190 void drawRhombus(Graphics* graphics);
191
195 Image const * mBackgroundImage{nullptr};
196 // std::shared_ptr<Image const> mBackgroundImage{nullptr};
197
201 std::string mCaption;
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 where a user can select or deselect the check box and where the stat...
Definition checkbox.hpp:27
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:195
bool mSelected
True if the check box is selected, false otherwise.
Definition checkbox.hpp:211
std::string mCaption
Holds the caption of the button.
Definition checkbox.hpp:201
bool mInternalBackgroundImage
True if the background image was loaded internally, false otherwise.
Definition checkbox.hpp:206
MarkerStyle
Marker style.
Definition checkbox.hpp:33
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
An implementation of a regular clickable button.
Abstract holder for image data.
Definition image.hpp:32
Represents a key event.
Definition keyevent.hpp:22
Represents a mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20